GNUnet  0.11.x
gnunet_common.h
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2006-2020 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
36 #ifndef GNUNET_COMMON_H
37 #define GNUNET_COMMON_H
38 
39 #include <stdlib.h>
40 #if HAVE_SYS_SOCKET_H
41 #include <sys/socket.h>
42 #endif
43 #if HAVE_NETINET_IN_H
44 #include <netinet/in.h>
45 #endif
46 #ifdef HAVE_STDINT_H
47 #include <stdint.h>
48 #endif
49 #ifdef HAVE_STDARG_H
50 #include <stdarg.h>
51 #endif
52 #ifdef HAVE_SYS_TYPES_H
53 #include <sys/types.h>
54 #endif
55 #ifdef HAVE_SYS_SOCKET_H
56 #include <sys/socket.h>
57 #endif
58 
59 
60 #ifdef HAVE_BYTESWAP_H
61 #include <byteswap.h>
62 #endif
63 
64 #ifdef __cplusplus
65 extern "C" {
66 #if 0 /* keep Emacsens' auto-indent happy */
67 }
68 #endif
69 #endif
70 
74 #define GNUNET_UTIL_VERSION 0x000A0103
75 
76 
84 {
86  GNUNET_NO = 0,
87  GNUNET_OK = 1,
88  /* intentionally identical to #GNUNET_OK! */
90 };
91 
92 
93 #define GNUNET_MIN(a, b) (((a) < (b)) ? (a) : (b))
94 
95 #define GNUNET_MAX(a, b) (((a) > (b)) ? (a) : (b))
96 
97 /* some systems use one underscore only, and mingw uses no underscore... */
98 #ifndef __BYTE_ORDER
99 #ifdef _BYTE_ORDER
100 #define __BYTE_ORDER _BYTE_ORDER
101 #else
102 #ifdef BYTE_ORDER
103 #define __BYTE_ORDER BYTE_ORDER
104 #endif
105 #endif
106 #endif
107 #ifndef __BIG_ENDIAN
108 #ifdef _BIG_ENDIAN
109 #define __BIG_ENDIAN _BIG_ENDIAN
110 #else
111 #ifdef BIG_ENDIAN
112 #define __BIG_ENDIAN BIG_ENDIAN
113 #endif
114 #endif
115 #endif
116 #ifndef __LITTLE_ENDIAN
117 #ifdef _LITTLE_ENDIAN
118 #define __LITTLE_ENDIAN _LITTLE_ENDIAN
119 #else
120 #ifdef LITTLE_ENDIAN
121 #define __LITTLE_ENDIAN LITTLE_ENDIAN
122 #endif
123 #endif
124 #endif
125 
129 #define GNUNET_VA_ARG_ENUM(va, X) ((enum X) va_arg (va, int))
130 
131 
137 #ifndef GNUNET_EXTRA_LOGGING
138 #define GNUNET_EXTRA_LOGGING 0
139 #endif
140 
145 #if __BYTE_ORDER == __LITTLE_ENDIAN
146 #define GNUNET_htobe16(x) __bswap_16 (x)
147 #define GNUNET_htole16(x) (x)
148 #define GNUNET_be16toh(x) __bswap_16 (x)
149 #define GNUNET_le16toh(x) (x)
150 
151 #define GNUNET_htobe32(x) __bswap_32 (x)
152 #define GNUNET_htole32(x) (x)
153 #define GNUNET_be32toh(x) __bswap_32 (x)
154 #define GNUNET_le32toh(x) (x)
155 
156 #define GNUNET_htobe64(x) __bswap_64 (x)
157 #define GNUNET_htole64(x) (x)
158 #define GNUNET_be64toh(x) __bswap_64 (x)
159 #define GNUNET_le64toh(x) (x)
160 #endif
161 #if __BYTE_ORDER == __BIG_ENDIAN
162 #define GNUNET_htobe16(x) (x)
163 #define GNUNET_htole16(x) __bswap_16 (x)
164 #define GNUNET_be16toh(x) (x)
165 #define GNUNET_le16toh(x) __bswap_16 (x)
166 
167 #define GNUNET_htobe32(x) (x)
168 #define GNUNET_htole32(x) __bswap_32 (x)
169 #define GNUNET_be32toh(x) (x)
170 #define GNUNET_le32toh(x) __bswap_32 (x)
171 
172 #define GNUNET_htobe64(x) (x)
173 #define GNUNET_htole64(x) __bswap_64 (x)
174 #define GNUNET_be64toh(x) (x)
175 #define GNUNET_le64toh(x) __bswap_64 (x)
176 #endif
177 
178 
191 #define GNUNET_NZL(l) GNUNET_MAX (1, l)
192 
193 
197 #define GNUNET_PACKED __attribute__ ((packed))
198 
202 #define GNUNET_GCC_STRUCT_LAYOUT
203 
209 #ifdef __BIGGEST_ALIGNMENT__
210 #define GNUNET_ALIGN __attribute__ ((aligned (__BIGGEST_ALIGNMENT__)))
211 #else
212 #define GNUNET_ALIGN __attribute__ ((aligned (8)))
213 #endif
214 
218 #define GNUNET_UNUSED __attribute__ ((unused))
219 
223 #define GNUNET_NORETURN __attribute__ ((noreturn))
224 
228 #define GNUNET_NETWORK_STRUCT_BEGIN
229 
233 #define GNUNET_NETWORK_STRUCT_END
234 
235 /* ************************ super-general types *********************** */
236 
238 
243 {
244  uint32_t bits[512 / 8 / sizeof(uint32_t)]; /* = 16 */
245 };
246 
247 
253 {
254  uint32_t bits[256 / 8 / sizeof(uint32_t)]; /* = 8 */
255 };
256 
257 
262 {
266  uint32_t value[4];
267 };
268 
269 
274 {
279  uint16_t size GNUNET_PACKED;
280 
284  uint16_t type GNUNET_PACKED;
285 };
286 
287 
292 {
293  struct GNUNET_MessageHeader header;
294 
296 
300  uint64_t op_id GNUNET_PACKED;
301 
305  uint64_t result_code GNUNET_PACKED;
306 
307  /* Followed by data. */
308 };
309 
310 
315 {
316  uint32_t bits[16 / sizeof(uint32_t)]; /* = 16 bytes */
317 };
318 
320 
321 
326 {
330  struct GNUNET_AsyncScopeId scope_id;
331 
336 };
337 
338 
348 typedef int
350  const char *filename);
351 
352 
358 typedef void
360 
361 
374 typedef void
375 (*GNUNET_ResultCallback) (void *cls,
376  int64_t result_code,
377  const void *data,
378  uint16_t data_size);
379 
380 
381 /* ****************************** logging ***************************** */
382 
388 {
393  /* UX: We need a message type that is output by
394  * default without looking like there is a problem.
395  */
401 };
402 
403 
414 typedef void (*GNUNET_Logger) (void *cls,
415  enum GNUNET_ErrorType kind,
416  const char *component,
417  const char *date,
418  const char *message);
419 
420 
427 int
428 GNUNET_get_log_skip (void);
429 
430 
431 #if ! defined(GNUNET_CULL_LOGGING)
432 int
433 GNUNET_get_log_call_status (int caller_level,
434  const char *comp,
435  const char *file,
436  const char *function,
437  int line);
438 
439 #endif
440 
441 
450 void
451 GNUNET_log_nocheck (enum GNUNET_ErrorType kind, const char *message, ...)
452 __attribute__ ((format (printf, 2, 3)));
453 
454 /* from glib */
455 #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
456 #define _GNUNET_BOOLEAN_EXPR(expr) \
457  __extension__ ({ \
458  int _gnunet_boolean_var_; \
459  if (expr) \
460  _gnunet_boolean_var_ = 1; \
461  else \
462  _gnunet_boolean_var_ = 0; \
463  _gnunet_boolean_var_; \
464  })
465 #define GN_LIKELY(expr) (__builtin_expect (_GNUNET_BOOLEAN_EXPR (expr), 1))
466 #define GN_UNLIKELY(expr) (__builtin_expect (_GNUNET_BOOLEAN_EXPR (expr), 0))
467 #else
468 #define GN_LIKELY(expr) (expr)
469 #define GN_UNLIKELY(expr) (expr)
470 #endif
471 
472 #if ! defined(GNUNET_LOG_CALL_STATUS)
473 #define GNUNET_LOG_CALL_STATUS -1
474 #endif
475 
476 
487 void
489  const char *comp,
490  const char *message,
491  ...);
492 
493 #if ! defined(GNUNET_CULL_LOGGING)
494 #define GNUNET_log_from(kind, comp, ...) \
495  do \
496  { \
497  static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \
498  if ((GNUNET_EXTRA_LOGGING > 0) || \
499  ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \
500  { \
501  if (GN_UNLIKELY (log_call_enabled == -1)) \
502  log_call_enabled = \
503  GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \
504  (comp), \
505  __FILE__, \
506  __FUNCTION__, \
507  __LINE__); \
508  if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \
509  { \
510  GNUNET_log_skip (-1, GNUNET_NO); \
511  } \
512  else \
513  { \
514  if (GN_UNLIKELY (log_call_enabled)) \
515  GNUNET_log_from_nocheck ((kind), comp, __VA_ARGS__); \
516  } \
517  } \
518  } while (0)
519 
520 #define GNUNET_log(kind, ...) \
521  do \
522  { \
523  static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \
524  if ((GNUNET_EXTRA_LOGGING > 0) || \
525  ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \
526  { \
527  if (GN_UNLIKELY (log_call_enabled == -1)) \
528  log_call_enabled = \
529  GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \
530  NULL, \
531  __FILE__, \
532  __FUNCTION__, \
533  __LINE__); \
534  if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \
535  { \
536  GNUNET_log_skip (-1, GNUNET_NO); \
537  } \
538  else \
539  { \
540  if (GN_UNLIKELY (log_call_enabled)) \
541  GNUNET_log_nocheck ((kind), __VA_ARGS__); \
542  } \
543  } \
544  } while (0)
545 #else
546 #define GNUNET_log(...)
547 #define GNUNET_log_from(...)
548 #endif
549 
550 
559 void
561  const char *section,
562  const char *option);
563 
564 
574 void
576  const char *section,
577  const char *option,
578  const char *required);
579 
580 
587 void
589 
590 
598 void
599 GNUNET_log_skip (int n, int check_reset);
600 
601 
611 int
612 GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile);
613 
614 
625 void
626 GNUNET_logger_add (GNUNET_Logger logger, void *logger_cls);
627 
628 
636 void
637 GNUNET_logger_remove (GNUNET_Logger logger, void *logger_cls);
638 
639 
649 const char *
650 GNUNET_sh2s (const struct GNUNET_ShortHashCode *shc);
651 
652 
662 const char *
663 GNUNET_uuid2s (const struct GNUNET_Uuid *uuid);
664 
665 
675 const char *
676 GNUNET_h2s (const struct GNUNET_HashCode *hc);
677 
678 
690 const char *
691 GNUNET_h2s2 (const struct GNUNET_HashCode *hc);
692 
693 
704 const char *
705 GNUNET_h2s_full (const struct GNUNET_HashCode *hc);
706 
707 
712 
713 
718 
719 
729 const char *
731 
732 
742 const char *
744 
745 
755 const char *
757 
758 
768 const char *
770 
771 
775 struct GNUNET_PeerIdentity;
776 
777 
788 const char *
789 GNUNET_i2s (const struct GNUNET_PeerIdentity *pid);
790 
791 
804 const char *
805 GNUNET_i2s2 (const struct GNUNET_PeerIdentity *pid);
806 
807 
818 const char *
819 GNUNET_i2s_full (const struct GNUNET_PeerIdentity *pid);
820 
821 
833 const char *
834 GNUNET_a2s (const struct sockaddr *addr, socklen_t addrlen);
835 
836 
844 const char *
846 
847 
852 #define GNUNET_assert(cond) \
853  do \
854  { \
855  if (! (cond)) \
856  { \
857  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
858  _ ("Assertion failed at %s:%d. Aborting.\n"), \
859  __FILE__, \
860  __LINE__); \
861  GNUNET_abort_ (); \
862  } \
863  } while (0)
864 
865 
870 #define GNUNET_assert_at(cond, f, l) \
871  do \
872  { \
873  if (! (cond)) \
874  { \
875  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
876  _ ("Assertion failed at %s:%d. Aborting.\n"), \
877  f, \
878  l); \
879  GNUNET_abort_ (); \
880  } \
881  } while (0)
882 
883 
891 #define GNUNET_assert_from(cond, comp) \
892  do \
893  { \
894  if (! (cond)) \
895  { \
896  GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, \
897  comp, \
898  _ ("Assertion failed at %s:%d. Aborting.\n"), \
899  __FILE__, \
900  __LINE__); \
901  GNUNET_abort_ (); \
902  } \
903  } while (0)
904 
905 
906 #if HAVE_STATIC_ASSERT
907 
914 #define GNUNET_static_assert(cond) _Static_assert (cond, "")
915 #else
916 
924 #define GNUNET_static_assert(cond) GNUNET_assert (cond)
925 #endif
926 
927 
933 #define GNUNET_break(cond) \
934  do \
935  { \
936  if (! (cond)) \
937  { \
938  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
939  _ ("Assertion failed at %s:%d.\n"), \
940  __FILE__, \
941  __LINE__); \
942  } \
943  } while (0)
944 
945 
955 #define GNUNET_break_op(cond) \
956  do \
957  { \
958  if (! (cond)) \
959  { \
960  GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, \
961  _ ("External protocol violation detected at %s:%d.\n"), \
962  __FILE__, \
963  __LINE__); \
964  } \
965  } while (0)
966 
967 
974 #define GNUNET_log_strerror(level, cmd) \
975  do \
976  { \
977  GNUNET_log (level, \
978  _ ("`%s' failed at %s:%d with error: %s\n"), \
979  cmd, \
980  __FILE__, \
981  __LINE__, \
982  strerror (errno)); \
983  } while (0)
984 
985 
992 #define GNUNET_log_from_strerror(level, component, cmd) \
993  do \
994  { \
995  GNUNET_log_from (level, \
996  component, \
997  _ ("`%s' failed at %s:%d with error: %s\n"), \
998  cmd, \
999  __FILE__, \
1000  __LINE__, \
1001  strerror (errno)); \
1002  } while (0)
1003 
1004 
1011 #define GNUNET_log_strerror_file(level, cmd, filename) \
1012  do \
1013  { \
1014  GNUNET_log (level, \
1015  _ ("`%s' failed on file `%s' at %s:%d with error: %s\n"), \
1016  cmd, \
1017  filename, \
1018  __FILE__, \
1019  __LINE__, \
1020  strerror (errno)); \
1021  } while (0)
1022 
1023 
1030 #define GNUNET_log_from_strerror_file(level, component, cmd, filename) \
1031  do \
1032  { \
1033  GNUNET_log_from (level, \
1034  component, \
1035  _ ("`%s' failed on file `%s' at %s:%d with error: %s\n"), \
1036  cmd, \
1037  filename, \
1038  __FILE__, \
1039  __LINE__, \
1040  strerror (errno)); \
1041  } while (0)
1042 
1043 /* ************************* endianess conversion ****************** */
1044 
1045 #ifdef htonbe64
1046 
1047 #define GNUNET_htonll(n) htobe64 (n)
1048 
1049 #else
1050 
1058 uint64_t
1059 GNUNET_htonll (uint64_t n);
1060 
1061 #endif
1062 
1063 
1064 #ifdef be64toh
1065 
1066 #define GNUNET_ntohll(n) be64toh (n)
1067 
1068 #else
1069 
1077 uint64_t
1078 GNUNET_ntohll (uint64_t n);
1079 
1080 #endif
1081 
1082 
1091 double
1092 GNUNET_hton_double (double d);
1093 
1094 
1103 double
1104 GNUNET_ntoh_double (double d);
1105 
1106 
1107 /* ************************* allocation functions ****************** */
1108 
1113 #define GNUNET_MAX_MALLOC_CHECKED (1024 * 1024 * 40)
1114 
1123 #define GNUNET_new(type) (type *) GNUNET_malloc (sizeof(type))
1124 
1125 
1133 #define GNUNET_memcmp(a, b) \
1134  ({ \
1135  const typeof (*b) * _a = (a); \
1136  const typeof (*a) * _b = (b); \
1137  memcmp (_a, _b, sizeof(*a)); \
1138  })
1139 
1140 
1150 int
1151 GNUNET_memcmp_ct_ (const void *b1,
1152  const void *b2,
1153  size_t len);
1154 
1162 #define GNUNET_memcmp_priv(a, b) \
1163  ({ \
1164  const typeof (*b) * _a = (a); \
1165  const typeof (*a) * _b = (b); \
1166  GNUNET_memcmp_ct_ (_a, _b, sizeof(*a)); \
1167  })
1168 
1169 
1179 GNUNET_is_zero_ (const void *a,
1180  size_t n);
1181 
1182 
1190 #define GNUNET_is_zero(a) \
1191  GNUNET_is_zero_ (a, sizeof (*a))
1192 
1193 
1203 #define GNUNET_memcpy(dst, src, n) \
1204  do \
1205  { \
1206  if (0 != n) \
1207  { \
1208  (void) memcpy (dst, src, n); \
1209  } \
1210  } while (0)
1211 
1212 
1222 #define GNUNET_new_array(n, type) ({ \
1223  GNUNET_assert (SIZE_MAX / sizeof (type) >= n); \
1224  (type *) GNUNET_malloc ((n) * sizeof(type)); \
1225  })
1226 
1236 #define GNUNET_new_array_2d(n, m, type) \
1237  (type **) GNUNET_xnew_array_2d_ (n, m, sizeof(type), __FILE__, __LINE__)
1238 
1249 #define GNUNET_new_array_3d(n, m, o, type) \
1250  (type ***) GNUNET_xnew_array_3d_ (n, m, o, sizeof(type), __FILE__, __LINE__)
1251 
1261 #define GNUNET_malloc(size) GNUNET_xmalloc_ (size, __FILE__, __LINE__)
1262 
1271 #define GNUNET_memdup(buf, size) GNUNET_xmemdup_ (buf, size, __FILE__, __LINE__)
1272 
1281 #define GNUNET_malloc_large(size) \
1282  GNUNET_xmalloc_unchecked_ (size, __FILE__, __LINE__)
1283 
1284 
1294 #define GNUNET_realloc(ptr, size) \
1295  GNUNET_xrealloc_ (ptr, size, __FILE__, __LINE__)
1296 
1297 
1307 #define GNUNET_free_nz(ptr) GNUNET_xfree_ (ptr, __FILE__, __LINE__)
1308 
1309 
1321 #define GNUNET_free(ptr) do { \
1322  GNUNET_xfree_ (ptr, __FILE__, __LINE__); \
1323  ptr = NULL; \
1324 } while (0)
1325 
1326 
1335 #define GNUNET_strdup(a) GNUNET_xstrdup_ (a, __FILE__, __LINE__)
1336 
1346 #define GNUNET_strndup(a, length) \
1347  GNUNET_xstrndup_ (a, length, __FILE__, __LINE__)
1348 
1384 #define GNUNET_array_grow(arr, size, tsize) \
1385  GNUNET_xgrow_ ((void **) &(arr), \
1386  sizeof((arr)[0]), \
1387  &size, \
1388  tsize, \
1389  __FILE__, \
1390  __LINE__)
1391 
1405 #define GNUNET_array_append(arr, len, element) \
1406  do \
1407  { \
1408  GNUNET_assert ((len) + 1 > (len)); \
1409  GNUNET_array_grow (arr, len, len + 1); \
1410  (arr) [len - 1] = element; \
1411  } while (0)
1412 
1413 
1437 #define GNUNET_array_concatenate(arr1, len1, arr2, len2) \
1438  do \
1439  { \
1440  const typeof (*arr2) * _a1 = (arr1); \
1441  const typeof (*arr1) * _a2 = (arr2); \
1442  GNUNET_assert ((len1) + (len2) >= (len1)); \
1443  GNUNET_assert (SIZE_MAX / sizeof (*_a1) >= ((len1) + (len2))); \
1444  GNUNET_array_grow (arr1, len1, (len1) + (len2)); \
1445  memcpy (&(arr1) [(len1) - (len2)], _a2, (len2) * sizeof (*arr1)); \
1446  } while (0)
1447 
1458 int
1459 GNUNET_snprintf (char *buf, size_t size, const char *format, ...);
1460 
1461 
1471 int
1472 GNUNET_asprintf (char **buf, const char *format, ...);
1473 
1474 
1475 /* ************** internal implementations, use macros above! ************** */
1476 
1488 void *
1489 GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber);
1490 
1491 
1506 void **
1507 GNUNET_xnew_array_2d_ (size_t n,
1508  size_t m,
1509  size_t elementSize,
1510  const char *filename,
1511  int linenumber);
1512 
1513 
1529 void ***
1530 GNUNET_xnew_array_3d_ (size_t n,
1531  size_t m,
1532  size_t o,
1533  size_t elementSize,
1534  const char *filename,
1535  int linenumber);
1536 
1537 
1549 void *
1550 GNUNET_xmemdup_ (const void *buf,
1551  size_t size,
1552  const char *filename,
1553  int linenumber);
1554 
1555 
1568 void *
1569 GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber);
1570 
1571 
1576 void *
1577 GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber);
1578 
1579 
1589 void
1590 GNUNET_xfree_ (void *ptr, const char *filename, int linenumber);
1591 
1592 
1600 char *
1601 GNUNET_xstrdup_ (const char *str, const char *filename, int linenumber);
1602 
1612 char *
1613 GNUNET_xstrndup_ (const char *str,
1614  size_t len,
1615  const char *filename,
1616  int linenumber);
1617 
1633 void
1634 GNUNET_xgrow_ (void **old,
1635  size_t elementSize,
1636  unsigned int *oldCount,
1637  unsigned int newCount,
1638  const char *filename,
1639  int linenumber);
1640 
1641 
1649 struct GNUNET_MessageHeader *
1651 
1652 
1659 void
1661  struct GNUNET_AsyncScopeSave *old_scope);
1662 
1663 
1669 void
1671 
1672 
1678 void
1679 GNUNET_async_scope_get (struct GNUNET_AsyncScopeSave *scope_ret);
1680 
1681 
1687 void
1689 
1690 
1691 #if __STDC_VERSION__ < 199901L
1692 #if __GNUC__ >= 2
1693 #define __func__ __FUNCTION__
1694 #else
1695 #define __func__ "<unknown>"
1696 #endif
1697 #endif
1698 
1699 
1708 {
1713 
1718 
1724 
1732 
1738 
1744 
1752 
1762 
1768 };
1769 
1770 
1771 #if 0 /* keep Emacsens' auto-indent happy */
1772 {
1773 #endif
1774 #ifdef __cplusplus
1775 }
1776 #endif
1777 
1778 #endif /* GNUNET_COMMON_H */
void GNUNET_logger_add(GNUNET_Logger logger, void *logger_cls)
Add a custom logger.
void GNUNET_xgrow_(void **old, size_t elementSize, unsigned int *oldCount, unsigned int newCount, const char *filename, int linenumber)
Grow an array, the new elements are zeroed out.
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
Run with high priority (important requests).
const char * GNUNET_i2s2(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
void GNUNET_xfree_(void *ptr, const char *filename, int linenumber)
Free memory.
void ** GNUNET_xnew_array_2d_(size_t n, size_t m, size_t elementSize, const char *filename, int linenumber)
Allocate memory for a two dimensional array in one block and set up pointers.
void GNUNET_logger_remove(GNUNET_Logger logger, void *logger_cls)
Remove a custom logger.
int GNUNET_snprintf(char *buf, size_t size, const char *format,...)
Like snprintf, just aborts if the buffer is of insufficient size.
const char * GNUNET_error_type_to_string(enum GNUNET_ErrorType kind)
Convert error type to string.
const char * GNUNET_e2s2(const struct GNUNET_CRYPTO_EcdhePublicKey *p)
Convert a public key value to a string (for printing debug messages).
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
void(* GNUNET_ResultCallback)(void *cls, int64_t result_code, const void *data, uint16_t data_size)
Function called with the result of an asynchronous operation.
void(* GNUNET_ContinuationCallback)(void *cls)
Generic continuation callback.
Run with the same priority as the current job.
const char * GNUNET_p2s2(const struct GNUNET_CRYPTO_EddsaPublicKey *p)
Convert a public key value to a string (for printing debug messages).
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:83
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
GNUNET_ErrorType
Types of errors.
enum GNUNET_GenericReturnValue GNUNET_is_zero_(const void *a, size_t n)
Check that memory in a is all zeros.
void GNUNET_log_config_invalid(enum GNUNET_ErrorType kind, const char *section, const char *option, const char *required)
Log error message about invalid configuration option value.
Identifier for an asynchronous execution context.
GNUNET_SCHEDULER_Priority
Valid task priorities.
Run as background job (higher than idle, lower than default).
static char * component
Running component.
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won&#39;t work on W32.
A 256-bit hashcode.
static char * section
Name of the section.
Definition: gnunet-config.c:33
void GNUNET_async_scope_enter(const struct GNUNET_AsyncScopeId *aid, struct GNUNET_AsyncScopeSave *old_scope)
Set the async scope for the current thread.
void GNUNET_abort_(void) __attribute__((noreturn))
Abort the process, generate a core dump if possible.
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
void * GNUNET_xmemdup_(const void *buf, size_t size, const char *filename, int linenumber)
Allocate and initialize memory.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
const char * GNUNET_h2s2(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
static char * line
Desired phone line (string to be converted to a hash).
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
static char * value
Value of the record to add/remove.
const char * GNUNET_p2s(const struct GNUNET_CRYPTO_EddsaPublicKey *p)
Convert a public key value to a string (for printing debug messages).
const char * GNUNET_uuid2s(const struct GNUNET_Uuid *uuid)
Convert a UUID to a string (for printing debug messages).
Run with priority for interactive tasks.
static char * option
Name of the option.
Definition: gnunet-config.c:38
static char buf[2048]
static char * filename
A UUID, a 128 bit random value.
const char * GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen)
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages)...
char * GNUNET_xstrndup_(const char *str, size_t len, const char *filename, int linenumber)
Dup partially a string.
int(* GNUNET_FileNameCallback)(void *cls, const char *filename)
Function called with a filename.
A 512-bit hashcode.
void GNUNET_async_scope_get(struct GNUNET_AsyncScopeSave *scope_ret)
Get the current async scope.
Run when otherwise idle.
void GNUNET_log_from_nocheck(enum GNUNET_ErrorType kind, const char *comp, const char *message,...)
Log function that specifies an alternative component.
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:36
This is an internal priority level that is only used for tasks that are being triggered due to shutdo...
int GNUNET_get_log_call_status(int caller_level, const char *comp, const char *file, const char *function, int line)
Decides whether a particular logging call should or should not be allowed to be made.
static unsigned int size
Size of the "table".
Definition: peer.c:67
int have_scope
GNUNET_YES unless this saved scope is the unnamed root scope.
double GNUNET_ntoh_double(double d)
Convert double to host byte order.
Definition: common_endian.c:92
Saved async scope identifier or root scope.
void * GNUNET_xmalloc_(size_t size, const char *filename, int linenumber)
Allocate memory.
const char * GNUNET_h2s_full(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
int GNUNET_memcmp_ct_(const void *b1, const void *b2, size_t len)
Compare memory in b1 and b2 in constant time, suitable for private data.
void GNUNET_async_scope_restore(struct GNUNET_AsyncScopeSave *old_scope)
Clear the current thread&#39;s async scope.
void * GNUNET_xmalloc_unchecked_(size_t size, const char *filename, int linenumber)
Allocate memory.
#define GNUNET_NORETURN
gcc-ism to document functions that don&#39;t return
#define GNUNET_NETWORK_STRUCT_END
Define as empty, GNUNET_PACKED should suffice, but this won&#39;t work on W32;.
Answer from service to client about last operation.
enum RadiotapType __attribute__
The identity of the host (wraps the signing key of the peer).
#define GNUNET_PACKED
gcc-ism to get packed structs.
void GNUNET_log_skip(int n, int check_reset)
Ignore the next n calls to the log function.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
char * GNUNET_xstrdup_(const char *str, const char *filename, int linenumber)
Dup a string.
Run with priority for urgent tasks.
void * GNUNET_xrealloc_(void *ptr, size_t n, const char *filename, int linenumber)
Reallocate memory.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
void GNUNET_log_nocheck(enum GNUNET_ErrorType kind, const char *message,...) __attribute__((format(printf
Main log function.
Header for all communications.
int GNUNET_get_log_skip(void)
Get the number of log calls that are going to be skipped.
Number of priorities (must be the last priority).
static unsigned long long reserved
How much space have we currently reserved?
void GNUNET_async_scope_fresh(struct GNUNET_AsyncScopeId *aid_ret)
Generate a fresh async scope identifier.
Run with the default priority (normal P2P operations).
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
const char * GNUNET_e2s(const struct GNUNET_CRYPTO_EcdhePublicKey *p)
Convert a public key value to a string (for printing debug messages).
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
void(* GNUNET_Logger)(void *cls, enum GNUNET_ErrorType kind, const char *component, const char *date, const char *message)
User-defined handler for log messages.
uint32_t data
The data value.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
void *** GNUNET_xnew_array_3d_(size_t n, size_t m, size_t o, size_t elementSize, const char *filename, int linenumber)
Allocate memory for a three dimensional array in one block and set up pointers.
double GNUNET_hton_double(double d)
Convert double to network byte order.
Definition: common_endian.c:74
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:53
struct GNUNET_MessageHeader * GNUNET_copy_message(const struct GNUNET_MessageHeader *msg)
Create a copy of the given message.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
uint32_t bits[512/8/sizeof(uint32_t)]
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...