GNUnet  0.17.6
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 
40 #ifndef GNUNET_COMMON_H
41 #define GNUNET_COMMON_H
42 
43 #include <stdlib.h>
44 #if HAVE_SYS_SOCKET_H
45 #include <sys/socket.h>
46 #endif
47 #if HAVE_NETINET_IN_H
48 #include <netinet/in.h>
49 #endif
50 #ifdef HAVE_STDINT_H
51 #include <stdint.h>
52 #endif
53 #ifdef HAVE_STDARG_H
54 #include <stdarg.h>
55 #endif
56 #ifdef HAVE_SYS_TYPES_H
57 #include <sys/types.h>
58 #endif
59 #ifdef HAVE_SYS_SOCKET_H
60 #include <sys/socket.h>
61 #endif
62 
63 
64 #ifdef HAVE_BYTESWAP_H
65 #include <byteswap.h>
66 #endif
67 
68 
69 /* This is also included in platform.h, but over there a couple of
70  GNUnet-specific gettext-related macros are defined in addition to including
71  the header file. Because this header file uses gettext, this include
72  statement makes sure gettext macros are defined even when platform.h is
73  unavailable. */
74 #include "gettext.h"
75 
76 #ifdef __cplusplus
77 extern "C" {
78 #if 0 /* keep Emacsens' auto-indent happy */
79 }
80 #endif
81 #endif
82 
86 #define GNUNET_UTIL_VERSION 0x000A0104
87 
88 
96 {
98  GNUNET_NO = 0,
99  GNUNET_OK = 1,
100  /* intentionally identical to #GNUNET_OK! */
102 };
103 
104 
105 #define GNUNET_MIN(a, b) (((a) < (b)) ? (a) : (b))
106 
107 #define GNUNET_MAX(a, b) (((a) > (b)) ? (a) : (b))
108 
109 /* some systems use one underscore only, and mingw uses no underscore... */
110 #ifndef __BYTE_ORDER
111 #ifdef _BYTE_ORDER
112 #define __BYTE_ORDER _BYTE_ORDER
113 #else
114 #ifdef BYTE_ORDER
115 #define __BYTE_ORDER BYTE_ORDER
116 #endif
117 #endif
118 #endif
119 #ifndef __BIG_ENDIAN
120 #ifdef _BIG_ENDIAN
121 #define __BIG_ENDIAN _BIG_ENDIAN
122 #else
123 #ifdef BIG_ENDIAN
124 #define __BIG_ENDIAN BIG_ENDIAN
125 #endif
126 #endif
127 #endif
128 #ifndef __LITTLE_ENDIAN
129 #ifdef _LITTLE_ENDIAN
130 #define __LITTLE_ENDIAN _LITTLE_ENDIAN
131 #else
132 #ifdef LITTLE_ENDIAN
133 #define __LITTLE_ENDIAN LITTLE_ENDIAN
134 #endif
135 #endif
136 #endif
137 
141 #define GNUNET_VA_ARG_ENUM(va, X) ((enum X) va_arg (va, int))
142 
143 
149 #ifndef GNUNET_EXTRA_LOGGING
150 #define GNUNET_EXTRA_LOGGING 1
151 #endif
152 
157 #if __BYTE_ORDER == __LITTLE_ENDIAN
158 #ifdef HAVE_BYTESWAP_H
159 #define BYTE_SWAP_16(x) bswap_16 (x)
160 #define BYTE_SWAP_32(x) bswap_32 (x)
161 #define BYTE_SWAP_64(x) bswap_64 (x)
162 #else
163 #define BYTE_SWAP_16(x) ((((x) & 0x00ff) << 8) | (((x) & 0xff00) >> 8))
164 
165 #define BYTE_SWAP_32(x) \
166  ((((x) & 0x000000ffU) << 24) | (((x) & 0x0000ff00U) << 8) \
167  | (((x) & 0x00ff0000U) >> 8) | (((x) & 0xff000000U) >> 24))
168 
169 #define BYTE_SWAP_64(x) \
170  ((((x) & 0x00000000000000ffUL) << 56) | (((x) & 0x000000000000ff00UL) << 40) \
171  | (((x) & 0x0000000000ff0000UL) << 24) | (((x) & 0x00000000ff000000UL) << 8) \
172  | (((x) & 0x000000ff00000000UL) >> 8) | (((x) & 0x0000ff0000000000UL) >> 24) \
173  | (((x) & 0x00ff000000000000UL) >> 40) | (((x) & 0xff00000000000000UL) >> \
174  56))
175 #endif
176 
177 #define GNUNET_htobe16(x) BYTE_SWAP_16 (x)
178 #define GNUNET_htole16(x) (x)
179 #define GNUNET_be16toh(x) BYTE_SWAP_16 (x)
180 #define GNUNET_le16toh(x) (x)
181 
182 #define GNUNET_htobe32(x) BYTE_SWAP_32 (x)
183 #define GNUNET_htole32(x) (x)
184 #define GNUNET_be32toh(x) BYTE_SWAP_32 (x)
185 #define GNUNET_le32toh(x) (x)
186 
187 #define GNUNET_htobe64(x) BYTE_SWAP_64 (x)
188 #define GNUNET_htole64(x) (x)
189 #define GNUNET_be64toh(x) BYTE_SWAP_64 (x)
190 #define GNUNET_le64toh(x) (x)
191 #endif
192 #if __BYTE_ORDER == __BIG_ENDIAN
193 #define GNUNET_htobe16(x) (x)
194 #define GNUNET_htole16(x) BYTE_SWAP_16 (x)
195 #define GNUNET_be16toh(x) (x)
196 #define GNUNET_le16toh(x) BYTE_SWAP_16 (x)
197 
198 #define GNUNET_htobe32(x) (x)
199 #define GNUNET_htole32(x) BYTE_SWAP_32 (x)
200 #define GNUNET_be32toh(x) (x)
201 #define GNUNET_le32toh(x) BYTE_SWAP_32 (x)
202 
203 #define GNUNET_htobe64(x) (x)
204 #define GNUNET_htole64(x) BYTE_SWAP_64 (x)
205 #define GNUNET_be64toh(x) (x)
206 #define GNUNET_le64toh(x) BYTE_SWAP_64 (x)
207 #endif
208 
209 
222 #define GNUNET_NZL(l) GNUNET_MAX (1, l)
223 
224 
228 #define GNUNET_PACKED __attribute__ ((packed))
229 
233 #define GNUNET_GCC_STRUCT_LAYOUT
234 
240 #ifdef __BIGGEST_ALIGNMENT__
241 #define GNUNET_ALIGN __attribute__ ((aligned (__BIGGEST_ALIGNMENT__)))
242 #else
243 #define GNUNET_ALIGN __attribute__ ((aligned (8)))
244 #endif
245 
249 #define GNUNET_UNUSED __attribute__ ((unused))
250 
254 #define GNUNET_NORETURN __attribute__ ((noreturn))
255 
259 #define GNUNET_NETWORK_STRUCT_BEGIN
260 
264 #define GNUNET_NETWORK_STRUCT_END
265 
266 /* ************************ super-general types *********************** */
267 
269 
274 {
275  uint32_t bits[512 / 8 / sizeof(uint32_t)]; /* = 16 */
276 };
277 
278 
284 {
285  uint32_t bits[256 / 8 / sizeof(uint32_t)]; /* = 8 */
286 };
287 
288 
298 {
302  uint32_t value[4];
303 };
304 
305 
310 {
315  uint16_t size GNUNET_PACKED;
316 
320  uint16_t type GNUNET_PACKED;
321 };
322 
323 
328 {
330 
332 
337 
342 
343  /* Followed by data. */
344 };
345 
346 
351 {
352  uint32_t bits[16 / sizeof(uint32_t)]; /* = 16 bytes */
353 };
354 
356 
357 
362 {
367 
372 };
373 
374 
384 typedef enum GNUNET_GenericReturnValue
385 (*GNUNET_FileNameCallback) (void *cls,
386  const char *filename);
387 
388 
394 typedef void
395 (*GNUNET_ContinuationCallback) (void *cls);
396 
397 
410 typedef void
411 (*GNUNET_ResultCallback) (void *cls,
412  int64_t result_code,
413  const void *data,
414  uint16_t data_size);
415 
416 
417 /* ****************************** logging ***************************** */
418 
424 {
429  /* UX: We need a message type that is output by
430  * default without looking like there is a problem.
431  */
437 };
438 
439 
450 typedef void
451 (*GNUNET_Logger) (void *cls,
452  enum GNUNET_ErrorType kind,
453  const char *component,
454  const char *date,
455  const char *message);
456 
457 
464 int
465 GNUNET_get_log_skip (void);
466 
467 
468 #if ! defined(GNUNET_CULL_LOGGING)
469 int
470 GNUNET_get_log_call_status (int caller_level,
471  const char *comp,
472  const char *file,
473  const char *function,
474  int line);
475 
476 #endif
477 
478 
487 void
488 GNUNET_log_nocheck (enum GNUNET_ErrorType kind, const char *message, ...)
489 __attribute__ ((format (printf, 2, 3)));
490 
491 /* from glib */
492 #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
493 #define _GNUNET_BOOLEAN_EXPR(expr) \
494  __extension__ ({ \
495  int _gnunet_boolean_var_; \
496  if (expr) \
497  _gnunet_boolean_var_ = 1; \
498  else \
499  _gnunet_boolean_var_ = 0; \
500  _gnunet_boolean_var_; \
501  })
502 #define GN_LIKELY(expr) (__builtin_expect (_GNUNET_BOOLEAN_EXPR (expr), 1))
503 #define GN_UNLIKELY(expr) (__builtin_expect (_GNUNET_BOOLEAN_EXPR (expr), 0))
504 #else
505 #define GN_LIKELY(expr) (expr)
506 #define GN_UNLIKELY(expr) (expr)
507 #endif
508 
509 #if ! defined(GNUNET_LOG_CALL_STATUS)
510 #define GNUNET_LOG_CALL_STATUS -1
511 #endif
512 
513 
524 void
526  const char *comp,
527  const char *message,
528  ...)
529 __attribute__ ((format (printf, 3, 4)));
530 
531 #if ! defined(GNUNET_CULL_LOGGING)
532 #define GNUNET_log_from(kind, comp, ...) \
533  do \
534  { \
535  static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \
536  if ((GNUNET_EXTRA_LOGGING > 0) || \
537  ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \
538  { \
539  if (GN_UNLIKELY (log_call_enabled == -1)) \
540  log_call_enabled = \
541  GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \
542  (comp), \
543  __FILE__, \
544  __FUNCTION__, \
545  __LINE__); \
546  if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \
547  { \
548  GNUNET_log_skip (-1, GNUNET_NO); \
549  } \
550  else \
551  { \
552  if (GN_UNLIKELY (log_call_enabled)) \
553  GNUNET_log_from_nocheck ((kind), comp, __VA_ARGS__); \
554  } \
555  } \
556  } while (0)
557 
558 #define GNUNET_log(kind, ...) \
559  do \
560  { \
561  static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \
562  if ((GNUNET_EXTRA_LOGGING > 0) || \
563  ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \
564  { \
565  if (GN_UNLIKELY (log_call_enabled == -1)) \
566  log_call_enabled = \
567  GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \
568  NULL, \
569  __FILE__, \
570  __FUNCTION__, \
571  __LINE__); \
572  if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \
573  { \
574  GNUNET_log_skip (-1, GNUNET_NO); \
575  } \
576  else \
577  { \
578  if (GN_UNLIKELY (log_call_enabled)) \
579  GNUNET_log_nocheck ((kind), __VA_ARGS__); \
580  } \
581  } \
582  } while (0)
583 #else
584 #define GNUNET_log(...)
585 #define GNUNET_log_from(...)
586 #endif
587 
588 
597 void
599  const char *section,
600  const char *option);
601 
602 
612 void
614  const char *section,
615  const char *option,
616  const char *required);
617 
618 
625 void
627 
628 
639 const char *
640 GNUNET_b2s (const void *buf,
641  size_t buf_size);
642 
643 
651 #define GNUNET_B2S(obj) GNUNET_b2s ((obj), sizeof (*(obj)))
652 
653 
661 void
662 GNUNET_log_skip (int n, int check_reset);
663 
664 
674 int
675 GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile);
676 
677 
688 void
689 GNUNET_logger_add (GNUNET_Logger logger, void *logger_cls);
690 
691 
699 void
700 GNUNET_logger_remove (GNUNET_Logger logger, void *logger_cls);
701 
702 
712 const char *
713 GNUNET_sh2s (const struct GNUNET_ShortHashCode *shc);
714 
715 
725 const char *
726 GNUNET_uuid2s (const struct GNUNET_Uuid *uuid);
727 
728 
738 const char *
739 GNUNET_h2s (const struct GNUNET_HashCode *hc);
740 
741 
753 const char *
754 GNUNET_h2s2 (const struct GNUNET_HashCode *hc);
755 
756 
767 const char *
768 GNUNET_h2s_full (const struct GNUNET_HashCode *hc);
769 
770 
775 
776 
781 
782 
792 const char *
794 
795 
805 const char *
807 
808 
818 const char *
820 
821 
831 const char *
833 
834 
838 struct GNUNET_PeerIdentity;
839 
840 
851 const char *
852 GNUNET_i2s (const struct GNUNET_PeerIdentity *pid);
853 
854 
867 const char *
868 GNUNET_i2s2 (const struct GNUNET_PeerIdentity *pid);
869 
870 
881 const char *
882 GNUNET_i2s_full (const struct GNUNET_PeerIdentity *pid);
883 
884 
896 const char *
897 GNUNET_a2s (const struct sockaddr *addr, socklen_t addrlen);
898 
899 
907 const char *
909 
910 
915 #if __GNUC__ >= 6 || __clang_major__ >= 6
916 #define GNUNET_assert(cond) \
917  do \
918  { \
919  _Pragma("GCC diagnostic push") \
920  _Pragma("GCC diagnostic ignored \"-Wtautological-compare\"") \
921  if (! (cond)) \
922  { \
923  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
924  dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \
925  __FILE__, \
926  __LINE__); \
927  GNUNET_abort_ (); \
928  } \
929  _Pragma("GCC diagnostic pop") \
930  } while (0)
931 #else
932 /* older GCC/clangs do not support -Wtautological-compare */
933 #define GNUNET_assert(cond) \
934  do \
935  { \
936  if (! (cond)) \
937  { \
938  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
939  dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \
940  __FILE__, \
941  __LINE__); \
942  GNUNET_abort_ (); \
943  } \
944  } while (0)
945 #endif
946 
951 #define GNUNET_assert_at(cond, f, l) \
952  do \
953  { \
954  if (! (cond)) \
955  { \
956  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
957  dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \
958  f, \
959  l); \
960  GNUNET_abort_ (); \
961  } \
962  } while (0)
963 
964 
972 #define GNUNET_assert_from(cond, comp) \
973  do \
974  { \
975  if (! (cond)) \
976  { \
977  GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, \
978  comp, \
979  dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \
980  __FILE__, \
981  __LINE__); \
982  GNUNET_abort_ (); \
983  } \
984  } while (0)
985 
986 
987 #if HAVE_STATIC_ASSERT
995 #define GNUNET_static_assert(cond) _Static_assert (cond, "")
996 #else
1005 #define GNUNET_static_assert(cond) GNUNET_assert (cond)
1006 #endif
1007 
1008 
1014 #define GNUNET_break(cond) \
1015  do \
1016  { \
1017  if (! (cond)) \
1018  { \
1019  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
1020  dgettext ("gnunet", "Assertion failed at %s:%d.\n"), \
1021  __FILE__, \
1022  __LINE__); \
1023  } \
1024  } while (0)
1025 
1026 
1036 #define GNUNET_break_op(cond) \
1037  do \
1038  { \
1039  if (! (cond)) \
1040  { \
1041  GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, \
1042  dgettext ("gnunet", "External protocol violation detected at %s:%d.\n"), \
1043  __FILE__, \
1044  __LINE__); \
1045  } \
1046  } while (0)
1047 
1048 
1055 #define GNUNET_log_strerror(level, cmd) \
1056  do \
1057  { \
1058  GNUNET_log (level, \
1059  dgettext ("gnunet", "`%s' failed at %s:%d with error: %s\n"), \
1060  cmd, \
1061  __FILE__, \
1062  __LINE__, \
1063  strerror (errno)); \
1064  } while (0)
1065 
1066 
1073 #define GNUNET_log_from_strerror(level, component, cmd) \
1074  do \
1075  { \
1076  GNUNET_log_from (level, \
1077  component, \
1078  dgettext ("gnunet", "`%s' failed at %s:%d with error: %s\n"), \
1079  cmd, \
1080  __FILE__, \
1081  __LINE__, \
1082  strerror (errno)); \
1083  } while (0)
1084 
1085 
1092 #define GNUNET_log_strerror_file(level, cmd, filename) \
1093  do \
1094  { \
1095  GNUNET_log (level, \
1096  dgettext ("gnunet", "`%s' failed on file `%s' at %s:%d with error: %s\n"), \
1097  cmd, \
1098  filename, \
1099  __FILE__, \
1100  __LINE__, \
1101  strerror (errno)); \
1102  } while (0)
1103 
1104 
1111 #define GNUNET_log_from_strerror_file(level, component, cmd, filename) \
1112  do \
1113  { \
1114  GNUNET_log_from (level, \
1115  component, \
1116  dgettext ("gnunet", "`%s' failed on file `%s' at %s:%d with error: %s\n"), \
1117  cmd, \
1118  filename, \
1119  __FILE__, \
1120  __LINE__, \
1121  strerror (errno)); \
1122  } while (0)
1123 
1124 /* ************************* endianness conversion ****************** */
1125 
1126 #ifdef htonbe64
1127 
1128 #define GNUNET_htonll(n) htobe64 (n)
1129 
1130 #else
1139 uint64_t
1140 GNUNET_htonll (uint64_t n);
1141 
1142 #endif
1143 
1144 
1145 #ifdef be64toh
1146 
1147 #define GNUNET_ntohll(n) be64toh (n)
1148 
1149 #else
1158 uint64_t
1159 GNUNET_ntohll (uint64_t n);
1160 
1161 #endif
1162 
1163 
1172 double
1173 GNUNET_hton_double (double d);
1174 
1175 
1184 double
1185 GNUNET_ntoh_double (double d);
1186 
1187 
1188 /* ************************* allocation functions ****************** */
1189 
1194 #define GNUNET_MAX_MALLOC_CHECKED (1024 * 1024 * 40)
1195 
1204 #define GNUNET_new(type) (type *) GNUNET_malloc (sizeof(type))
1205 
1206 
1214 #define GNUNET_memcmp(a, b) \
1215  ({ \
1216  const typeof (*b) * _a = (a); \
1217  const typeof (*a) * _b = (b); \
1218  memcmp (_a, _b, sizeof(*a)); \
1219  })
1220 
1221 
1231 int
1232 GNUNET_memcmp_ct_ (const void *b1,
1233  const void *b2,
1234  size_t len);
1235 
1243 #define GNUNET_memcmp_priv(a, b) \
1244  ({ \
1245  const typeof (*b) * _a = (a); \
1246  const typeof (*a) * _b = (b); \
1247  GNUNET_memcmp_ct_ (_a, _b, sizeof(*a)); \
1248  })
1249 
1250 
1260 GNUNET_is_zero_ (const void *a,
1261  size_t n);
1262 
1263 
1271 #define GNUNET_is_zero(a) \
1272  GNUNET_is_zero_ ((a), sizeof (*(a)))
1273 
1274 
1284 #define GNUNET_memcpy(dst, src, n) \
1285  do \
1286  { \
1287  if (0 != n) \
1288  { \
1289  (void) memcpy (dst, src, n); \
1290  } \
1291  } while (0)
1292 
1293 
1303 #define GNUNET_new_array(n, type) ({ \
1304  GNUNET_assert (SIZE_MAX / sizeof (type) >= n); \
1305  (type *) GNUNET_malloc ((n) * sizeof(type)); \
1306  })
1307 
1317 #define GNUNET_new_array_2d(n, m, type) \
1318  (type **) GNUNET_xnew_array_2d_ (n, m, sizeof(type), __FILE__, __LINE__)
1319 
1330 #define GNUNET_new_array_3d(n, m, o, type) \
1331  (type ***) GNUNET_xnew_array_3d_ (n, m, o, sizeof(type), __FILE__, __LINE__)
1332 
1342 #define GNUNET_malloc(size) GNUNET_xmalloc_ (size, __FILE__, __LINE__)
1343 
1352 #define GNUNET_memdup(buf, size) GNUNET_xmemdup_ (buf, size, __FILE__, __LINE__)
1353 
1362 #define GNUNET_malloc_large(size) \
1363  GNUNET_xmalloc_unchecked_ (size, __FILE__, __LINE__)
1364 
1365 
1375 #define GNUNET_realloc(ptr, size) \
1376  GNUNET_xrealloc_ (ptr, size, __FILE__, __LINE__)
1377 
1378 
1388 #define GNUNET_free_nz(ptr) GNUNET_xfree_ (ptr, __FILE__, __LINE__)
1389 
1390 
1402 #define GNUNET_free(ptr) do { \
1403  GNUNET_xfree_ (ptr, __FILE__, __LINE__); \
1404  ptr = NULL; \
1405 } while (0)
1406 
1407 
1416 #define GNUNET_strdup(a) GNUNET_xstrdup_ (a, __FILE__, __LINE__)
1417 
1427 #define GNUNET_strndup(a, length) \
1428  GNUNET_xstrndup_ (a, length, __FILE__, __LINE__)
1429 
1465 #define GNUNET_array_grow(arr, size, tsize) \
1466  GNUNET_xgrow_ ((void **) &(arr), \
1467  sizeof((arr)[0]), \
1468  &size, \
1469  tsize, \
1470  __FILE__, \
1471  __LINE__)
1472 
1486 #define GNUNET_array_append(arr, len, element) \
1487  do \
1488  { \
1489  GNUNET_assert ((len) + 1 > (len)); \
1490  GNUNET_array_grow (arr, len, len + 1); \
1491  (arr) [len - 1] = element; \
1492  } while (0)
1493 
1494 
1518 #define GNUNET_array_concatenate(arr1, len1, arr2, len2) \
1519  do \
1520  { \
1521  const typeof (*arr2) * _a1 = (arr1); \
1522  const typeof (*arr1) * _a2 = (arr2); \
1523  GNUNET_assert ((len1) + (len2) >= (len1)); \
1524  GNUNET_assert (SIZE_MAX / sizeof (*_a1) >= ((len1) + (len2))); \
1525  GNUNET_array_grow (arr1, len1, (len1) + (len2)); \
1526  memcpy (&(arr1) [(len1) - (len2)], _a2, (len2) * sizeof (*arr1)); \
1527  } while (0)
1528 
1529 
1540 int
1542  size_t size,
1543  const char *format,
1544  ...)
1545 __attribute__ ((format (printf, 3, 4)));
1546 
1547 
1557 int
1559  const char *format,
1560  ...)
1561 __attribute__ ((format (printf, 2, 3)));
1562 
1563 
1564 /* ************** internal implementations, use macros above! ************** */
1565 
1577 void *
1578 GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber);
1579 
1580 
1595 void **
1596 GNUNET_xnew_array_2d_ (size_t n,
1597  size_t m,
1598  size_t elementSize,
1599  const char *filename,
1600  int linenumber);
1601 
1602 
1618 void ***
1619 GNUNET_xnew_array_3d_ (size_t n,
1620  size_t m,
1621  size_t o,
1622  size_t elementSize,
1623  const char *filename,
1624  int linenumber);
1625 
1626 
1638 void *
1639 GNUNET_xmemdup_ (const void *buf,
1640  size_t size,
1641  const char *filename,
1642  int linenumber);
1643 
1644 
1657 void *
1658 GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber);
1659 
1660 
1665 void *
1666 GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber);
1667 
1668 
1678 void
1679 GNUNET_xfree_ (void *ptr, const char *filename, int linenumber);
1680 
1681 
1689 char *
1690 GNUNET_xstrdup_ (const char *str, const char *filename, int linenumber);
1691 
1701 char *
1702 GNUNET_xstrndup_ (const char *str,
1703  size_t len,
1704  const char *filename,
1705  int linenumber);
1706 
1722 void
1723 GNUNET_xgrow_ (void **old,
1724  size_t elementSize,
1725  unsigned int *oldCount,
1726  unsigned int newCount,
1727  const char *filename,
1728  int linenumber);
1729 
1730 
1738 struct GNUNET_MessageHeader *
1740 
1741 
1748 void
1750  struct GNUNET_AsyncScopeSave *old_scope);
1751 
1752 
1758 void
1760 
1761 
1767 void
1768 GNUNET_async_scope_get (struct GNUNET_AsyncScopeSave *scope_ret);
1769 
1770 
1776 void
1778 
1779 
1780 #if __STDC_VERSION__ < 199901L
1781 #if __GNUC__ >= 2
1782 #define __func__ __FUNCTION__
1783 #else
1784 #define __func__ "<unknown>"
1785 #endif
1786 #endif
1787 
1788 
1797 {
1802 
1807 
1813 
1821 
1827 
1833 
1841 
1851 
1857 };
1858 
1859 
1860 #if 0 /* keep Emacsens' auto-indent happy */
1861 {
1862 #endif
1863 #ifdef __cplusplus
1864 }
1865 #endif
1866 
1867 #endif /* GNUNET_COMMON_H */
1868  /* end of group addition */
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static char * component
Running component.
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
static char * line
Desired phone line (string to be converted to a hash).
static char * filename
uint32_t data
The data value.
enum RadiotapType __attribute__
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
static char buf[2048]
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-uri.c:37
const char * GNUNET_b2s(const void *buf, size_t buf_size)
Convert a buffer to an 8-character string representative of the contents.
enum GNUNET_GenericReturnValue GNUNET_is_zero_(const void *a, size_t n)
Check that memory in a is all zeros.
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_ResultCallback)(void *cls, int64_t result_code, const void *data, uint16_t data_size)
Function called with the result of an asynchronous operation.
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32.
char * GNUNET_xstrdup_(const char *str, const char *filename, int linenumber)
Dup a string.
double GNUNET_ntoh_double(double d)
Convert double to host byte order.
Definition: common_endian.c:82
enum GNUNET_GenericReturnValue(* GNUNET_FileNameCallback)(void *cls, const char *filename)
Function called with a filename.
void * GNUNET_xrealloc_(void *ptr, size_t n, const char *filename, int linenumber)
Reallocate 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.
#define GNUNET_NORETURN
gcc-ism to document functions that don't return
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.
void(* GNUNET_ContinuationCallback)(void *cls)
Generic continuation callback.
int int void * GNUNET_xmalloc_(size_t size, const char *filename, int linenumber)
Allocate memory.
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:53
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.
void GNUNET_xfree_(void *ptr, const char *filename, int linenumber)
Free memory.
GNUNET_SCHEDULER_Priority
Valid task priorities.
void GNUNET_async_scope_enter(const struct GNUNET_AsyncScopeId *aid, struct GNUNET_AsyncScopeSave *old_scope)
Set the async scope for the current thread.
#define GNUNET_NETWORK_STRUCT_END
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32;.
double GNUNET_hton_double(double d)
Convert double to network byte order.
Definition: common_endian.c:69
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:36
void * GNUNET_xmemdup_(const void *buf, size_t size, const char *filename, int linenumber)
Allocate and initialize memory.
void GNUNET_async_scope_get(struct GNUNET_AsyncScopeSave *scope_ret)
Get the current async scope.
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.
void GNUNET_async_scope_fresh(struct GNUNET_AsyncScopeId *aid_ret)
Generate a fresh async scope identifier.
void GNUNET_async_scope_restore(struct GNUNET_AsyncScopeSave *old_scope)
Clear the current thread's async scope.
char * GNUNET_xstrndup_(const char *str, size_t len, const char *filename, int linenumber)
Dup partially a string.
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:96
#define GNUNET_PACKED
gcc-ism to get packed structs.
void * GNUNET_xmalloc_unchecked_(size_t size, const char *filename, int linenumber)
Allocate memory.
@ GNUNET_SCHEDULER_PRIORITY_UI
Run with priority for interactive tasks.
@ GNUNET_SCHEDULER_PRIORITY_IDLE
Run when otherwise idle.
@ GNUNET_SCHEDULER_PRIORITY_HIGH
Run with high priority (important requests).
@ GNUNET_SCHEDULER_PRIORITY_URGENT
Run with priority for urgent tasks.
@ GNUNET_SCHEDULER_PRIORITY_BACKGROUND
Run as background job (higher than idle, lower than default).
@ GNUNET_SCHEDULER_PRIORITY_COUNT
Number of priorities (must be the last priority).
@ GNUNET_SCHEDULER_PRIORITY_KEEP
Run with the same priority as the current job.
@ GNUNET_SCHEDULER_PRIORITY_DEFAULT
Run with the default priority (normal P2P operations).
@ GNUNET_SCHEDULER_PRIORITY_SHUTDOWN
This is an internal priority level that is only used for tasks that are being triggered due to shutdo...
@ GNUNET_OK
Definition: gnunet_common.h:99
@ GNUNET_YES
@ GNUNET_NO
Definition: gnunet_common.h:98
@ GNUNET_SYSERR
Definition: gnunet_common.h:97
const char * GNUNET_h2s2(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
GNUNET_ErrorType
Types of errors.
const char * GNUNET_e2s2(const struct GNUNET_CRYPTO_EcdhePublicKey *p)
Convert a public key value to a string (for printing debug messages).
const char * GNUNET_p2s2(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).
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
void GNUNET_log_nocheck(enum GNUNET_ErrorType kind, const char *message,...) __attribute__((format(printf
Main log function.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
const char * GNUNET_error_type_to_string(enum GNUNET_ErrorType kind)
Convert error type to string.
int GNUNET_get_log_skip(void)
Get the number of log calls that are going to be skipped.
const char * GNUNET_e2s(const struct GNUNET_CRYPTO_EcdhePublicKey *p)
Convert a public key value to a string (for printing debug messages).
const char * GNUNET_i2s2(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
const char * GNUNET_h2s_full(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
void GNUNET_log_skip(int n, int check_reset)
Ignore the next n calls to the log function.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
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.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
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.
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).
void GNUNET_abort_(void) __attribute__((noreturn))
Abort the process, generate a core dump if possible.
void GNUNET_logger_add(GNUNET_Logger logger, void *logger_cls)
Add a custom logger.
void(* GNUNET_Logger)(void *cls, enum GNUNET_ErrorType kind, const char *component, const char *date, const char *message)
User-defined handler for log messages.
const char * GNUNET_p2s(const struct GNUNET_CRYPTO_EddsaPublicKey *p)
Convert a public key value to a string (for printing debug messages).
void GNUNET_logger_remove(GNUNET_Logger logger, void *logger_cls)
Remove a custom logger.
@ GNUNET_ERROR_TYPE_UNSPECIFIED
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_BULK
@ GNUNET_ERROR_TYPE_NONE
@ GNUNET_ERROR_TYPE_INVALID
@ GNUNET_ERROR_TYPE_MESSAGE
@ GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_ERROR_TYPE_INFO
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
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.
struct GNUNET_MessageHeader * GNUNET_copy_message(const struct GNUNET_MessageHeader *msg)
Create a copy of the given message.
static unsigned int size
Size of the "table".
Definition: peer.c:67
Identifier for an asynchronous execution context.
uint32_t bits[16/sizeof(uint32_t)]
Saved async scope identifier or root scope.
int have_scope
GNUNET_YES unless this saved scope is the unnamed root scope.
struct GNUNET_AsyncScopeId scope_id
Saved scope.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...
A 512-bit hashcode.
uint32_t bits[512/8/sizeof(uint32_t)]
Header for all communications.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
Answer from service to client about last operation.
struct GNUNET_MessageHeader header
uint64_t result_code
Status code for the operation.
uint64_t op_id
Operation ID.
The identity of the host (wraps the signing key of the peer).
A 256-bit hashcode.
uint32_t bits[256/8/sizeof(uint32_t)]
A UUID, a 128 bit "random" value.
uint32_t value[4]
128 random bits.