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-2021 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 0x000A0104
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 #if defined(__linux__)
147 #define BYTE_SWAP_16(x) __bswap_16 (x)
148 #define BYTE_SWAP_32(x) __bswap_32 (x)
149 #define BYTE_SWAP_64(x) __bswap_64 (x)
150 #else
151 #define BYTE_SWAP_16(x) ((((x) & 0x00ff) << 8) | (((x) & 0xff00) >> 8))
152 
153 #define BYTE_SWAP_32(x) \
154  ((((x) & 0x000000ffU) << 24) | (((x) & 0x0000ff00U) << 8) \
155  | (((x) & 0x00ff0000U) >> 8) | (((x) & 0xff000000U) >> 24))
156 
157 #define BYTE_SWAP_64(x) \
158  ((((x) & 0x00000000000000ffUL) << 56) | (((x) & 0x000000000000ff00UL) << 40) \
159  | (((x) & 0x0000000000ff0000UL) << 24) | (((x) & 0x00000000ff000000UL) << 8) \
160  | (((x) & 0x000000ff00000000UL) >> 8) | (((x) & 0x0000ff0000000000UL) >> 24) \
161  | (((x) & 0x00ff000000000000UL) >> 40) | (((x) & 0xff00000000000000UL) >> \
162  56))
163 #endif
164 
165 #define GNUNET_htobe16(x) BYTE_SWAP_16 (x)
166 #define GNUNET_htole16(x) (x)
167 #define GNUNET_be16toh(x) BYTE_SWAP_16 (x)
168 #define GNUNET_le16toh(x) (x)
169 
170 #define GNUNET_htobe32(x) BYTE_SWAP_32 (x)
171 #define GNUNET_htole32(x) (x)
172 #define GNUNET_be32toh(x) BYTE_SWAP_32 (x)
173 #define GNUNET_le32toh(x) (x)
174 
175 #define GNUNET_htobe64(x) BYTE_SWAP_64 (x)
176 #define GNUNET_htole64(x) (x)
177 #define GNUNET_be64toh(x) BYTE_SWAP_64 (x)
178 #define GNUNET_le64toh(x) (x)
179 #endif
180 #if __BYTE_ORDER == __BIG_ENDIAN
181 #define GNUNET_htobe16(x) (x)
182 #define GNUNET_htole16(x) BYTE_SWAP_16 (x)
183 #define GNUNET_be16toh(x) (x)
184 #define GNUNET_le16toh(x) BYTE_SWAP_16 (x)
185 
186 #define GNUNET_htobe32(x) (x)
187 #define GNUNET_htole32(x) BYTE_SWAP_32 (x)
188 #define GNUNET_be32toh(x) (x)
189 #define GNUNET_le32toh(x) BYTE_SWAP_32 (x)
190 
191 #define GNUNET_htobe64(x) (x)
192 #define GNUNET_htole64(x) BYTE_SWAP_64 (x)
193 #define GNUNET_be64toh(x) (x)
194 #define GNUNET_le64toh(x) BYTE_SWAP_64 (x)
195 #endif
196 
197 
210 #define GNUNET_NZL(l) GNUNET_MAX (1, l)
211 
212 
216 #define GNUNET_PACKED __attribute__ ((packed))
217 
221 #define GNUNET_GCC_STRUCT_LAYOUT
222 
228 #ifdef __BIGGEST_ALIGNMENT__
229 #define GNUNET_ALIGN __attribute__ ((aligned (__BIGGEST_ALIGNMENT__)))
230 #else
231 #define GNUNET_ALIGN __attribute__ ((aligned (8)))
232 #endif
233 
237 #define GNUNET_UNUSED __attribute__ ((unused))
238 
242 #define GNUNET_NORETURN __attribute__ ((noreturn))
243 
247 #define GNUNET_NETWORK_STRUCT_BEGIN
248 
252 #define GNUNET_NETWORK_STRUCT_END
253 
254 /* ************************ super-general types *********************** */
255 
257 
262 {
263  uint32_t bits[512 / 8 / sizeof(uint32_t)]; /* = 16 */
264 };
265 
266 
272 {
273  uint32_t bits[256 / 8 / sizeof(uint32_t)]; /* = 8 */
274 };
275 
276 
286 {
290  uint32_t value[4];
291 };
292 
293 
298 {
303  uint16_t size GNUNET_PACKED;
304 
308  uint16_t type GNUNET_PACKED;
309 };
310 
311 
316 {
317  struct GNUNET_MessageHeader header;
318 
320 
324  uint64_t op_id GNUNET_PACKED;
325 
329  uint64_t result_code GNUNET_PACKED;
330 
331  /* Followed by data. */
332 };
333 
334 
339 {
340  uint32_t bits[16 / sizeof(uint32_t)]; /* = 16 bytes */
341 };
342 
344 
345 
350 {
354  struct GNUNET_AsyncScopeId scope_id;
355 
360 };
361 
362 
372 typedef enum GNUNET_GenericReturnValue
374  const char *filename);
375 
376 
382 typedef void
384 
385 
398 typedef void
399 (*GNUNET_ResultCallback) (void *cls,
400  int64_t result_code,
401  const void *data,
402  uint16_t data_size);
403 
404 
405 /* ****************************** logging ***************************** */
406 
412 {
417  /* UX: We need a message type that is output by
418  * default without looking like there is a problem.
419  */
425 };
426 
427 
438 typedef void
439 (*GNUNET_Logger) (void *cls,
440  enum GNUNET_ErrorType kind,
441  const char *component,
442  const char *date,
443  const char *message);
444 
445 
452 int
453 GNUNET_get_log_skip (void);
454 
455 
456 #if ! defined(GNUNET_CULL_LOGGING)
457 int
458 GNUNET_get_log_call_status (int caller_level,
459  const char *comp,
460  const char *file,
461  const char *function,
462  int line);
463 
464 #endif
465 
466 
475 void
476 GNUNET_log_nocheck (enum GNUNET_ErrorType kind, const char *message, ...)
477 __attribute__ ((format (printf, 2, 3)));
478 
479 /* from glib */
480 #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
481 #define _GNUNET_BOOLEAN_EXPR(expr) \
482  __extension__ ({ \
483  int _gnunet_boolean_var_; \
484  if (expr) \
485  _gnunet_boolean_var_ = 1; \
486  else \
487  _gnunet_boolean_var_ = 0; \
488  _gnunet_boolean_var_; \
489  })
490 #define GN_LIKELY(expr) (__builtin_expect (_GNUNET_BOOLEAN_EXPR (expr), 1))
491 #define GN_UNLIKELY(expr) (__builtin_expect (_GNUNET_BOOLEAN_EXPR (expr), 0))
492 #else
493 #define GN_LIKELY(expr) (expr)
494 #define GN_UNLIKELY(expr) (expr)
495 #endif
496 
497 #if ! defined(GNUNET_LOG_CALL_STATUS)
498 #define GNUNET_LOG_CALL_STATUS -1
499 #endif
500 
501 
512 void
514  const char *comp,
515  const char *message,
516  ...)
517 __attribute__ ((format (printf, 3, 4)));
518 
519 #if ! defined(GNUNET_CULL_LOGGING)
520 #define GNUNET_log_from(kind, comp, ...) \
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  (comp), \
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_from_nocheck ((kind), comp, __VA_ARGS__); \
542  } \
543  } \
544  } while (0)
545 
546 #define GNUNET_log(kind, ...) \
547  do \
548  { \
549  static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \
550  if ((GNUNET_EXTRA_LOGGING > 0) || \
551  ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \
552  { \
553  if (GN_UNLIKELY (log_call_enabled == -1)) \
554  log_call_enabled = \
555  GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \
556  NULL, \
557  __FILE__, \
558  __FUNCTION__, \
559  __LINE__); \
560  if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \
561  { \
562  GNUNET_log_skip (-1, GNUNET_NO); \
563  } \
564  else \
565  { \
566  if (GN_UNLIKELY (log_call_enabled)) \
567  GNUNET_log_nocheck ((kind), __VA_ARGS__); \
568  } \
569  } \
570  } while (0)
571 #else
572 #define GNUNET_log(...)
573 #define GNUNET_log_from(...)
574 #endif
575 
576 
585 void
587  const char *section,
588  const char *option);
589 
590 
600 void
602  const char *section,
603  const char *option,
604  const char *required);
605 
606 
613 void
615 
616 
624 void
625 GNUNET_log_skip (int n, int check_reset);
626 
627 
637 int
638 GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile);
639 
640 
651 void
652 GNUNET_logger_add (GNUNET_Logger logger, void *logger_cls);
653 
654 
662 void
663 GNUNET_logger_remove (GNUNET_Logger logger, void *logger_cls);
664 
665 
675 const char *
676 GNUNET_sh2s (const struct GNUNET_ShortHashCode *shc);
677 
678 
688 const char *
689 GNUNET_uuid2s (const struct GNUNET_Uuid *uuid);
690 
691 
701 const char *
702 GNUNET_h2s (const struct GNUNET_HashCode *hc);
703 
704 
716 const char *
717 GNUNET_h2s2 (const struct GNUNET_HashCode *hc);
718 
719 
730 const char *
731 GNUNET_h2s_full (const struct GNUNET_HashCode *hc);
732 
733 
738 
739 
744 
745 
755 const char *
757 
758 
768 const char *
770 
771 
781 const char *
783 
784 
794 const char *
796 
797 
801 struct GNUNET_PeerIdentity;
802 
803 
814 const char *
815 GNUNET_i2s (const struct GNUNET_PeerIdentity *pid);
816 
817 
830 const char *
831 GNUNET_i2s2 (const struct GNUNET_PeerIdentity *pid);
832 
833 
844 const char *
845 GNUNET_i2s_full (const struct GNUNET_PeerIdentity *pid);
846 
847 
859 const char *
860 GNUNET_a2s (const struct sockaddr *addr, socklen_t addrlen);
861 
862 
870 const char *
872 
873 
878 #if __GNUC__ >= 6 || __clang_major__ >= 6
879 #define GNUNET_assert(cond) \
880  do \
881  { \
882  _Pragma("GCC diagnostic push") \
883  _Pragma("GCC diagnostic ignored \"-Wtautological-compare\"") \
884  if (! (cond)) \
885  { \
886  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
887  _ ("Assertion failed at %s:%d. Aborting.\n"), \
888  __FILE__, \
889  __LINE__); \
890  GNUNET_abort_ (); \
891  } \
892  _Pragma("GCC diagnostic pop") \
893  } while (0)
894 #else
895 /* older GCC/clangs do not support -Wtautological-compare */
896 #define GNUNET_assert(cond) \
897  do \
898  { \
899  if (! (cond)) \
900  { \
901  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
902  _ ("Assertion failed at %s:%d. Aborting.\n"), \
903  __FILE__, \
904  __LINE__); \
905  GNUNET_abort_ (); \
906  } \
907  } while (0)
908 #endif
909 
914 #define GNUNET_assert_at(cond, f, l) \
915  do \
916  { \
917  if (! (cond)) \
918  { \
919  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
920  _ ("Assertion failed at %s:%d. Aborting.\n"), \
921  f, \
922  l); \
923  GNUNET_abort_ (); \
924  } \
925  } while (0)
926 
927 
935 #define GNUNET_assert_from(cond, comp) \
936  do \
937  { \
938  if (! (cond)) \
939  { \
940  GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, \
941  comp, \
942  _ ("Assertion failed at %s:%d. Aborting.\n"), \
943  __FILE__, \
944  __LINE__); \
945  GNUNET_abort_ (); \
946  } \
947  } while (0)
948 
949 
950 #if HAVE_STATIC_ASSERT
951 
958 #define GNUNET_static_assert(cond) _Static_assert (cond, "")
959 #else
960 
968 #define GNUNET_static_assert(cond) GNUNET_assert (cond)
969 #endif
970 
971 
977 #define GNUNET_break(cond) \
978  do \
979  { \
980  if (! (cond)) \
981  { \
982  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
983  _ ("Assertion failed at %s:%d.\n"), \
984  __FILE__, \
985  __LINE__); \
986  } \
987  } while (0)
988 
989 
999 #define GNUNET_break_op(cond) \
1000  do \
1001  { \
1002  if (! (cond)) \
1003  { \
1004  GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, \
1005  _ ("External protocol violation detected at %s:%d.\n"), \
1006  __FILE__, \
1007  __LINE__); \
1008  } \
1009  } while (0)
1010 
1011 
1018 #define GNUNET_log_strerror(level, cmd) \
1019  do \
1020  { \
1021  GNUNET_log (level, \
1022  _ ("`%s' failed at %s:%d with error: %s\n"), \
1023  cmd, \
1024  __FILE__, \
1025  __LINE__, \
1026  strerror (errno)); \
1027  } while (0)
1028 
1029 
1036 #define GNUNET_log_from_strerror(level, component, cmd) \
1037  do \
1038  { \
1039  GNUNET_log_from (level, \
1040  component, \
1041  _ ("`%s' failed at %s:%d with error: %s\n"), \
1042  cmd, \
1043  __FILE__, \
1044  __LINE__, \
1045  strerror (errno)); \
1046  } while (0)
1047 
1048 
1055 #define GNUNET_log_strerror_file(level, cmd, filename) \
1056  do \
1057  { \
1058  GNUNET_log (level, \
1059  _ ("`%s' failed on file `%s' at %s:%d with error: %s\n"), \
1060  cmd, \
1061  filename, \
1062  __FILE__, \
1063  __LINE__, \
1064  strerror (errno)); \
1065  } while (0)
1066 
1067 
1074 #define GNUNET_log_from_strerror_file(level, component, cmd, filename) \
1075  do \
1076  { \
1077  GNUNET_log_from (level, \
1078  component, \
1079  _ ("`%s' failed on file `%s' at %s:%d with error: %s\n"), \
1080  cmd, \
1081  filename, \
1082  __FILE__, \
1083  __LINE__, \
1084  strerror (errno)); \
1085  } while (0)
1086 
1087 /* ************************* endianness conversion ****************** */
1088 
1089 #ifdef htonbe64
1090 
1091 #define GNUNET_htonll(n) htobe64 (n)
1092 
1093 #else
1094 
1102 uint64_t
1103 GNUNET_htonll (uint64_t n);
1104 
1105 #endif
1106 
1107 
1108 #ifdef be64toh
1109 
1110 #define GNUNET_ntohll(n) be64toh (n)
1111 
1112 #else
1113 
1121 uint64_t
1122 GNUNET_ntohll (uint64_t n);
1123 
1124 #endif
1125 
1126 
1135 double
1136 GNUNET_hton_double (double d);
1137 
1138 
1147 double
1148 GNUNET_ntoh_double (double d);
1149 
1150 
1151 /* ************************* allocation functions ****************** */
1152 
1157 #define GNUNET_MAX_MALLOC_CHECKED (1024 * 1024 * 40)
1158 
1167 #define GNUNET_new(type) (type *) GNUNET_malloc (sizeof(type))
1168 
1169 
1177 #define GNUNET_memcmp(a, b) \
1178  ({ \
1179  const typeof (*b) * _a = (a); \
1180  const typeof (*a) * _b = (b); \
1181  memcmp (_a, _b, sizeof(*a)); \
1182  })
1183 
1184 
1194 int
1195 GNUNET_memcmp_ct_ (const void *b1,
1196  const void *b2,
1197  size_t len);
1198 
1206 #define GNUNET_memcmp_priv(a, b) \
1207  ({ \
1208  const typeof (*b) * _a = (a); \
1209  const typeof (*a) * _b = (b); \
1210  GNUNET_memcmp_ct_ (_a, _b, sizeof(*a)); \
1211  })
1212 
1213 
1223 GNUNET_is_zero_ (const void *a,
1224  size_t n);
1225 
1226 
1234 #define GNUNET_is_zero(a) \
1235  GNUNET_is_zero_ (a, sizeof (*a))
1236 
1237 
1247 #define GNUNET_memcpy(dst, src, n) \
1248  do \
1249  { \
1250  if (0 != n) \
1251  { \
1252  (void) memcpy (dst, src, n); \
1253  } \
1254  } while (0)
1255 
1256 
1266 #define GNUNET_new_array(n, type) ({ \
1267  GNUNET_assert (SIZE_MAX / sizeof (type) >= n); \
1268  (type *) GNUNET_malloc ((n) * sizeof(type)); \
1269  })
1270 
1280 #define GNUNET_new_array_2d(n, m, type) \
1281  (type **) GNUNET_xnew_array_2d_ (n, m, sizeof(type), __FILE__, __LINE__)
1282 
1293 #define GNUNET_new_array_3d(n, m, o, type) \
1294  (type ***) GNUNET_xnew_array_3d_ (n, m, o, sizeof(type), __FILE__, __LINE__)
1295 
1305 #define GNUNET_malloc(size) GNUNET_xmalloc_ (size, __FILE__, __LINE__)
1306 
1315 #define GNUNET_memdup(buf, size) GNUNET_xmemdup_ (buf, size, __FILE__, __LINE__)
1316 
1325 #define GNUNET_malloc_large(size) \
1326  GNUNET_xmalloc_unchecked_ (size, __FILE__, __LINE__)
1327 
1328 
1338 #define GNUNET_realloc(ptr, size) \
1339  GNUNET_xrealloc_ (ptr, size, __FILE__, __LINE__)
1340 
1341 
1351 #define GNUNET_free_nz(ptr) GNUNET_xfree_ (ptr, __FILE__, __LINE__)
1352 
1353 
1365 #define GNUNET_free(ptr) do { \
1366  GNUNET_xfree_ (ptr, __FILE__, __LINE__); \
1367  ptr = NULL; \
1368 } while (0)
1369 
1370 
1379 #define GNUNET_strdup(a) GNUNET_xstrdup_ (a, __FILE__, __LINE__)
1380 
1390 #define GNUNET_strndup(a, length) \
1391  GNUNET_xstrndup_ (a, length, __FILE__, __LINE__)
1392 
1428 #define GNUNET_array_grow(arr, size, tsize) \
1429  GNUNET_xgrow_ ((void **) &(arr), \
1430  sizeof((arr)[0]), \
1431  &size, \
1432  tsize, \
1433  __FILE__, \
1434  __LINE__)
1435 
1449 #define GNUNET_array_append(arr, len, element) \
1450  do \
1451  { \
1452  GNUNET_assert ((len) + 1 > (len)); \
1453  GNUNET_array_grow (arr, len, len + 1); \
1454  (arr) [len - 1] = element; \
1455  } while (0)
1456 
1457 
1481 #define GNUNET_array_concatenate(arr1, len1, arr2, len2) \
1482  do \
1483  { \
1484  const typeof (*arr2) * _a1 = (arr1); \
1485  const typeof (*arr1) * _a2 = (arr2); \
1486  GNUNET_assert ((len1) + (len2) >= (len1)); \
1487  GNUNET_assert (SIZE_MAX / sizeof (*_a1) >= ((len1) + (len2))); \
1488  GNUNET_array_grow (arr1, len1, (len1) + (len2)); \
1489  memcpy (&(arr1) [(len1) - (len2)], _a2, (len2) * sizeof (*arr1)); \
1490  } while (0)
1491 
1492 
1503 int
1504 GNUNET_snprintf (char *buf,
1505  size_t size,
1506  const char *format,
1507  ...)
1508 __attribute__ ((format (printf, 3, 4)));
1509 
1510 
1520 int
1521 GNUNET_asprintf (char **buf,
1522  const char *format,
1523  ...)
1524 __attribute__ ((format (printf, 2, 3)));
1525 
1526 
1527 /* ************** internal implementations, use macros above! ************** */
1528 
1540 void *
1541 GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber);
1542 
1543 
1558 void **
1559 GNUNET_xnew_array_2d_ (size_t n,
1560  size_t m,
1561  size_t elementSize,
1562  const char *filename,
1563  int linenumber);
1564 
1565 
1581 void ***
1582 GNUNET_xnew_array_3d_ (size_t n,
1583  size_t m,
1584  size_t o,
1585  size_t elementSize,
1586  const char *filename,
1587  int linenumber);
1588 
1589 
1601 void *
1602 GNUNET_xmemdup_ (const void *buf,
1603  size_t size,
1604  const char *filename,
1605  int linenumber);
1606 
1607 
1620 void *
1621 GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber);
1622 
1623 
1628 void *
1629 GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber);
1630 
1631 
1641 void
1642 GNUNET_xfree_ (void *ptr, const char *filename, int linenumber);
1643 
1644 
1652 char *
1653 GNUNET_xstrdup_ (const char *str, const char *filename, int linenumber);
1654 
1664 char *
1665 GNUNET_xstrndup_ (const char *str,
1666  size_t len,
1667  const char *filename,
1668  int linenumber);
1669 
1685 void
1686 GNUNET_xgrow_ (void **old,
1687  size_t elementSize,
1688  unsigned int *oldCount,
1689  unsigned int newCount,
1690  const char *filename,
1691  int linenumber);
1692 
1693 
1701 struct GNUNET_MessageHeader *
1703 
1704 
1711 void
1713  struct GNUNET_AsyncScopeSave *old_scope);
1714 
1715 
1721 void
1723 
1724 
1730 void
1731 GNUNET_async_scope_get (struct GNUNET_AsyncScopeSave *scope_ret);
1732 
1733 
1739 void
1741 
1742 
1743 #if __STDC_VERSION__ < 199901L
1744 #if __GNUC__ >= 2
1745 #define __func__ __FUNCTION__
1746 #else
1747 #define __func__ "<unknown>"
1748 #endif
1749 #endif
1750 
1751 
1760 {
1765 
1770 
1776 
1784 
1790 
1796 
1804 
1814 
1820 };
1821 
1822 
1823 #if 0 /* keep Emacsens' auto-indent happy */
1824 {
1825 #endif
1826 #ifdef __cplusplus
1827 }
1828 #endif
1829 
1830 #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.
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.
int GNUNET_snprintf(char *buf, size_t size, const char *format,...) __attribute__((format(printf
Like snprintf, just aborts if the buffer is of insufficient size.
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.
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.
A 512-bit hashcode.
void GNUNET_async_scope_get(struct GNUNET_AsyncScopeSave *scope_ret)
Get the current async scope.
Run when otherwise idle.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
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.
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.
void GNUNET_log_from_nocheck(enum GNUNET_ErrorType kind, const char *comp, const char *message,...) __attribute__((format(printf
Log function that specifies an alternative component.
#define GNUNET_NORETURN
gcc-ism to document functions that don&#39;t return
int int void * GNUNET_xmalloc_(size_t size, const char *filename, int linenumber)
Allocate memory.
#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...
enum GNUNET_GenericReturnValue(* GNUNET_FileNameCallback)(void *cls, const char *filename)
Function called with a filename.
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...