GNUnet  0.19.2
gnunet_common.h
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2006-2022 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 "gnunet_config.h"
44 
45 #include <stdbool.h>
46 #include <stdlib.h>
47 #include <sys/socket.h>
48 #include <sys/un.h>
49 #include <netinet/in.h>
50 #include <arpa/inet.h>
51 #include <stdint.h>
52 #include <stdarg.h>
53 #include <sys/types.h>
54 
55 #if defined(__FreeBSD__)
56 
57 #include <sys/endian.h>
58 #define bswap_32(x) bswap32(x)
59 #define bswap_64(x) bswap64(x)
60 
61 #elif defined(__OpenBSD__)
62 
63 #define bswap_32(x) swap32(x)
64 #define bswap_64(x) swap64(x)
65 
66 #elif defined(__NetBSD__)
67 
68 #include <machine/bswap.h>
69 #if defined(__BSWAP_RENAME) && !defined(__bswap_32)
70 #define bswap_32(x) bswap32(x)
71 #define bswap_64(x) bswap64(x)
72 #endif
73 
74 #elif defined(__linux__) || defined(GNU)
75 #include <byteswap.h>
76 #endif
77 
78 
79 /* This is also included in platform.h, but over there a couple of
80  GNUnet-specific gettext-related macros are defined in addition to including
81  the header file. Because this header file uses gettext, this include
82  statement makes sure gettext macros are defined even when platform.h is
83  unavailable. */
84 #include "gettext.h"
85 
86 #ifdef __cplusplus
87 extern "C" {
88 #if 0 /* keep Emacsens' auto-indent happy */
89 }
90 #endif
91 #endif
92 
96 #define GNUNET_UTIL_VERSION 0x000A0104
97 
98 
106 {
110  /* intentionally identical to #GNUNET_OK! */
112 };
113 
114 
115 #define GNUNET_MIN(a, b) (((a) < (b)) ? (a) : (b))
116 
117 #define GNUNET_MAX(a, b) (((a) > (b)) ? (a) : (b))
118 
119 /* some systems use one underscore only, and mingw uses no underscore... */
120 #ifndef __BYTE_ORDER
121 #ifdef _BYTE_ORDER
122 #define __BYTE_ORDER _BYTE_ORDER
123 #else
124 #ifdef BYTE_ORDER
125 #define __BYTE_ORDER BYTE_ORDER
126 #endif
127 #endif
128 #endif
129 #ifndef __BIG_ENDIAN
130 #ifdef _BIG_ENDIAN
131 #define __BIG_ENDIAN _BIG_ENDIAN
132 #else
133 #ifdef BIG_ENDIAN
134 #define __BIG_ENDIAN BIG_ENDIAN
135 #endif
136 #endif
137 #endif
138 #ifndef __LITTLE_ENDIAN
139 #ifdef _LITTLE_ENDIAN
140 #define __LITTLE_ENDIAN _LITTLE_ENDIAN
141 #else
142 #ifdef LITTLE_ENDIAN
143 #define __LITTLE_ENDIAN LITTLE_ENDIAN
144 #endif
145 #endif
146 #endif
147 
151 #define GNUNET_VA_ARG_ENUM(va, X) ((enum X) va_arg (va, int))
152 
153 
159 #ifndef GNUNET_EXTRA_LOGGING
160 #define GNUNET_EXTRA_LOGGING 1
161 #endif
162 
167 #if defined(bswap_16) || defined(bswap_32) || defined(bswap_64)
168 #define BYTE_SWAP_16(x) bswap_16 (x)
169 #define BYTE_SWAP_32(x) bswap_32 (x)
170 #define BYTE_SWAP_64(x) bswap_64 (x)
171 #else
172 #define BYTE_SWAP_16(x) ((((x) & 0x00ff) << 8) | (((x) & 0xff00) >> 8))
173 
174 #define BYTE_SWAP_32(x) \
175  ((((x) & 0x000000ffU) << 24) | (((x) & 0x0000ff00U) << 8) \
176  | (((x) & 0x00ff0000U) >> 8) | (((x) & 0xff000000U) >> 24))
177 
178 #define BYTE_SWAP_64(x) \
179  ((((x) & 0x00000000000000ffUL) << 56) | (((x) & 0x000000000000ff00UL) << 40) \
180  | (((x) & 0x0000000000ff0000UL) << 24) | (((x) & 0x00000000ff000000UL) << 8) \
181  | (((x) & 0x000000ff00000000UL) >> 8) | (((x) & 0x0000ff0000000000UL) >> 24) \
182  | (((x) & 0x00ff000000000000UL) >> 40) | (((x) & 0xff00000000000000UL) >> \
183  56))
184 #endif
185 
186 #if __BYTE_ORDER == __LITTLE_ENDIAN
187 #define GNUNET_htobe16(x) BYTE_SWAP_16 (x)
188 #define GNUNET_htole16(x) (x)
189 #define GNUNET_be16toh(x) BYTE_SWAP_16 (x)
190 #define GNUNET_le16toh(x) (x)
191 
192 #define GNUNET_htobe32(x) BYTE_SWAP_32 (x)
193 #define GNUNET_htole32(x) (x)
194 #define GNUNET_be32toh(x) BYTE_SWAP_32 (x)
195 #define GNUNET_le32toh(x) (x)
196 
197 #define GNUNET_htobe64(x) BYTE_SWAP_64 (x)
198 #define GNUNET_htole64(x) (x)
199 #define GNUNET_be64toh(x) BYTE_SWAP_64 (x)
200 #define GNUNET_le64toh(x) (x)
201 #endif
202 #if __BYTE_ORDER == __BIG_ENDIAN
203 #define GNUNET_htobe16(x) (x)
204 #define GNUNET_htole16(x) BYTE_SWAP_16 (x)
205 #define GNUNET_be16toh(x) (x)
206 #define GNUNET_le16toh(x) BYTE_SWAP_16 (x)
207 
208 #define GNUNET_htobe32(x) (x)
209 #define GNUNET_htole32(x) BYTE_SWAP_32 (x)
210 #define GNUNET_be32toh(x) (x)
211 #define GNUNET_le32toh(x) BYTE_SWAP_32 (x)
212 
213 #define GNUNET_htobe64(x) (x)
214 #define GNUNET_htole64(x) BYTE_SWAP_64 (x)
215 #define GNUNET_be64toh(x) (x)
216 #define GNUNET_le64toh(x) BYTE_SWAP_64 (x)
217 #endif
218 
219 
232 #define GNUNET_NZL(l) GNUNET_MAX (1, l)
233 
234 
238 #define GNUNET_PACKED __attribute__ ((packed))
239 
243 #define GNUNET_GCC_STRUCT_LAYOUT
244 
250 #ifdef __BIGGEST_ALIGNMENT__
251 #define GNUNET_ALIGN __attribute__ ((aligned (__BIGGEST_ALIGNMENT__)))
252 #else
253 #define GNUNET_ALIGN __attribute__ ((aligned (8)))
254 #endif
255 
259 #define GNUNET_UNUSED __attribute__ ((unused))
260 
264 #define GNUNET_NORETURN __attribute__ ((noreturn))
265 
269 #define GNUNET_NETWORK_STRUCT_BEGIN
270 
274 #define GNUNET_NETWORK_STRUCT_END
275 
276 /* ************************ super-general types *********************** */
277 
279 
284 {
285  uint32_t bits[512 / 8 / sizeof(uint32_t)]; /* = 16 */
286 };
287 
288 
294 {
295  uint32_t bits[256 / 8 / sizeof(uint32_t)]; /* = 8 */
296 };
297 
298 
308 {
312  uint32_t value[4];
313 };
314 
315 
320 {
325  uint16_t size GNUNET_PACKED;
326 
330  uint16_t type GNUNET_PACKED;
331 };
332 
333 
338 {
340 
342 
347 
352 
353  /* Followed by data. */
354 };
355 
356 
361 {
362  uint32_t bits[16 / sizeof(uint32_t)]; /* = 16 bytes */
363 };
364 
366 
367 
372 {
377 
382 };
383 
384 
394 typedef enum GNUNET_GenericReturnValue
395 (*GNUNET_FileNameCallback) (void *cls,
396  const char *filename);
397 
398 
404 typedef void
405 (*GNUNET_ContinuationCallback) (void *cls);
406 
407 
420 typedef void
421 (*GNUNET_ResultCallback) (void *cls,
422  int64_t result_code,
423  const void *data,
424  uint16_t data_size);
425 
426 
427 /* ****************************** logging ***************************** */
428 
434 {
439  /* UX: We need a message type that is output by
440  * default without looking like there is a problem.
441  */
447 };
448 
449 
460 typedef void
461 (*GNUNET_Logger) (void *cls,
462  enum GNUNET_ErrorType kind,
463  const char *component,
464  const char *date,
465  const char *message);
466 
467 
474 int
475 GNUNET_get_log_skip (void);
476 
477 
478 #if ! defined(GNUNET_CULL_LOGGING)
479 int
480 GNUNET_get_log_call_status (int caller_level,
481  const char *comp,
482  const char *file,
483  const char *function,
484  int line);
485 
486 #endif
487 
488 
497 void
498 GNUNET_log_nocheck (enum GNUNET_ErrorType kind, const char *message, ...)
499 __attribute__ ((format (printf, 2, 3)));
500 
501 /* from glib */
502 #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
503 #define _GNUNET_BOOLEAN_EXPR(expr) \
504  __extension__ ({ \
505  int _gnunet_boolean_var_; \
506  if (expr) \
507  _gnunet_boolean_var_ = 1; \
508  else \
509  _gnunet_boolean_var_ = 0; \
510  _gnunet_boolean_var_; \
511  })
512 #define GN_LIKELY(expr) (__builtin_expect (_GNUNET_BOOLEAN_EXPR (expr), 1))
513 #define GN_UNLIKELY(expr) (__builtin_expect (_GNUNET_BOOLEAN_EXPR (expr), 0))
514 #else
515 #define GN_LIKELY(expr) (expr)
516 #define GN_UNLIKELY(expr) (expr)
517 #endif
518 
519 #if ! defined(GNUNET_LOG_CALL_STATUS)
520 #define GNUNET_LOG_CALL_STATUS -1
521 #endif
522 
523 
534 void
536  const char *comp,
537  const char *message,
538  ...)
539 __attribute__ ((format (printf, 3, 4)));
540 
541 #if ! defined(GNUNET_CULL_LOGGING)
542 #define GNUNET_log_from(kind, comp, ...) \
543  do \
544  { \
545  static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \
546  if ((GNUNET_EXTRA_LOGGING > 0) || \
547  ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \
548  { \
549  if (GN_UNLIKELY (log_call_enabled == -1)) \
550  log_call_enabled = \
551  GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \
552  (comp), \
553  __FILE__, \
554  __FUNCTION__, \
555  __LINE__); \
556  if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \
557  { \
558  GNUNET_log_skip (-1, GNUNET_NO); \
559  } \
560  else \
561  { \
562  if (GN_UNLIKELY (log_call_enabled)) \
563  GNUNET_log_from_nocheck ((kind), comp, __VA_ARGS__); \
564  } \
565  } \
566  } while (0)
567 
568 #define GNUNET_log(kind, ...) \
569  do \
570  { \
571  static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \
572  if ((GNUNET_EXTRA_LOGGING > 0) || \
573  ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \
574  { \
575  if (GN_UNLIKELY (log_call_enabled == -1)) \
576  log_call_enabled = \
577  GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \
578  NULL, \
579  __FILE__, \
580  __FUNCTION__, \
581  __LINE__); \
582  if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \
583  { \
584  GNUNET_log_skip (-1, GNUNET_NO); \
585  } \
586  else \
587  { \
588  if (GN_UNLIKELY (log_call_enabled)) \
589  GNUNET_log_nocheck ((kind), __VA_ARGS__); \
590  } \
591  } \
592  } while (0)
593 #else
594 #define GNUNET_log(...)
595 #define GNUNET_log_from(...)
596 #endif
597 
598 
607 void
609  const char *section,
610  const char *option);
611 
612 
622 void
624  const char *section,
625  const char *option,
626  const char *required);
627 
628 
635 void
637 
638 
649 const char *
650 GNUNET_b2s (const void *buf,
651  size_t buf_size);
652 
653 
661 #define GNUNET_B2S(obj) GNUNET_b2s ((obj), sizeof (*(obj)))
662 
663 
671 void
672 GNUNET_log_skip (int n, int check_reset);
673 
674 
684 int
685 GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile);
686 
687 
698 void
699 GNUNET_logger_add (GNUNET_Logger logger, void *logger_cls);
700 
701 
709 void
710 GNUNET_logger_remove (GNUNET_Logger logger, void *logger_cls);
711 
712 
722 const char *
723 GNUNET_sh2s (const struct GNUNET_ShortHashCode *shc);
724 
725 
735 const char *
736 GNUNET_uuid2s (const struct GNUNET_Uuid *uuid);
737 
738 
748 const char *
749 GNUNET_h2s (const struct GNUNET_HashCode *hc);
750 
751 
763 const char *
764 GNUNET_h2s2 (const struct GNUNET_HashCode *hc);
765 
766 
777 const char *
778 GNUNET_h2s_full (const struct GNUNET_HashCode *hc);
779 
780 
785 
786 
791 
792 
802 const char *
804 
805 
815 const char *
817 
818 
828 const char *
830 
831 
841 const char *
843 
844 
848 struct GNUNET_PeerIdentity;
849 
850 
861 const char *
862 GNUNET_i2s (const struct GNUNET_PeerIdentity *pid);
863 
864 
877 const char *
878 GNUNET_i2s2 (const struct GNUNET_PeerIdentity *pid);
879 
880 
891 const char *
892 GNUNET_i2s_full (const struct GNUNET_PeerIdentity *pid);
893 
894 
906 const char *
907 GNUNET_a2s (const struct sockaddr *addr, socklen_t addrlen);
908 
909 
917 const char *
919 
920 
925 #if __GNUC__ >= 6 || __clang_major__ >= 6
926 #define GNUNET_assert(cond) \
927  do \
928  { \
929  _Pragma("GCC diagnostic push") \
930  _Pragma("GCC diagnostic ignored \"-Wtautological-compare\"") \
931  if (! (cond)) \
932  { \
933  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
934  dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \
935  __FILE__, \
936  __LINE__); \
937  GNUNET_abort_ (); \
938  } \
939  _Pragma("GCC diagnostic pop") \
940  } while (0)
941 #else
942 /* older GCC/clangs do not support -Wtautological-compare */
943 #define GNUNET_assert(cond) \
944  do \
945  { \
946  if (! (cond)) \
947  { \
948  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
949  dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \
950  __FILE__, \
951  __LINE__); \
952  GNUNET_abort_ (); \
953  } \
954  } while (0)
955 #endif
956 
961 #define GNUNET_assert_at(cond, f, l) \
962  do \
963  { \
964  if (! (cond)) \
965  { \
966  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
967  dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \
968  f, \
969  l); \
970  GNUNET_abort_ (); \
971  } \
972  } while (0)
973 
974 
982 #define GNUNET_assert_from(cond, comp) \
983  do \
984  { \
985  if (! (cond)) \
986  { \
987  GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, \
988  comp, \
989  dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \
990  __FILE__, \
991  __LINE__); \
992  GNUNET_abort_ (); \
993  } \
994  } while (0)
995 
996 
997 #ifdef _Static_assert
1005 #define GNUNET_static_assert(cond) _Static_assert (cond, "")
1006 #else
1015 #define GNUNET_static_assert(cond) GNUNET_assert (cond)
1016 #endif
1017 
1018 
1024 #define GNUNET_break(cond) \
1025  do \
1026  { \
1027  if (! (cond)) \
1028  { \
1029  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
1030  dgettext ("gnunet", "Assertion failed at %s:%d.\n"), \
1031  __FILE__, \
1032  __LINE__); \
1033  } \
1034  } while (0)
1035 
1036 
1046 #define GNUNET_break_op(cond) \
1047  do \
1048  { \
1049  if (! (cond)) \
1050  { \
1051  GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, \
1052  dgettext ("gnunet", "External protocol violation detected at %s:%d.\n"), \
1053  __FILE__, \
1054  __LINE__); \
1055  } \
1056  } while (0)
1057 
1058 
1065 #define GNUNET_log_strerror(level, cmd) \
1066  do \
1067  { \
1068  GNUNET_log (level, \
1069  dgettext ("gnunet", "`%s' failed at %s:%d with error: %s\n"), \
1070  cmd, \
1071  __FILE__, \
1072  __LINE__, \
1073  strerror (errno)); \
1074  } while (0)
1075 
1076 
1083 #define GNUNET_log_from_strerror(level, component, cmd) \
1084  do \
1085  { \
1086  GNUNET_log_from (level, \
1087  component, \
1088  dgettext ("gnunet", "`%s' failed at %s:%d with error: %s\n"), \
1089  cmd, \
1090  __FILE__, \
1091  __LINE__, \
1092  strerror (errno)); \
1093  } while (0)
1094 
1095 
1102 #define GNUNET_log_strerror_file(level, cmd, filename) \
1103  do \
1104  { \
1105  GNUNET_log (level, \
1106  dgettext ("gnunet", "`%s' failed on file `%s' at %s:%d with error: %s\n"), \
1107  cmd, \
1108  filename, \
1109  __FILE__, \
1110  __LINE__, \
1111  strerror (errno)); \
1112  } while (0)
1113 
1114 
1121 #define GNUNET_log_from_strerror_file(level, component, cmd, filename) \
1122  do \
1123  { \
1124  GNUNET_log_from (level, \
1125  component, \
1126  dgettext ("gnunet", "`%s' failed on file `%s' at %s:%d with error: %s\n"), \
1127  cmd, \
1128  filename, \
1129  __FILE__, \
1130  __LINE__, \
1131  strerror (errno)); \
1132  } while (0)
1133 
1134 /* ************************* endianness conversion ****************** */
1135 
1136 #ifdef htonbe64
1137 
1138 #define GNUNET_htonll(n) htobe64 (n)
1139 
1140 #else
1149 uint64_t
1150 GNUNET_htonll (uint64_t n);
1151 
1152 #endif
1153 
1154 
1155 #ifdef be64toh
1156 
1157 #define GNUNET_ntohll(n) be64toh (n)
1158 
1159 #else
1168 uint64_t
1169 GNUNET_ntohll (uint64_t n);
1170 
1171 #endif
1172 
1173 
1182 double
1183 GNUNET_hton_double (double d);
1184 
1185 
1194 double
1195 GNUNET_ntoh_double (double d);
1196 
1197 
1198 /* ************************* allocation functions ****************** */
1199 
1204 #define GNUNET_MAX_MALLOC_CHECKED (1024 * 1024 * 40)
1205 
1214 #define GNUNET_new(type) (type *) GNUNET_malloc (sizeof(type))
1215 
1216 
1224 #define GNUNET_memcmp(a, b) \
1225  ({ \
1226  const typeof (*b) * _a = (a); \
1227  const typeof (*a) * _b = (b); \
1228  memcmp (_a, _b, sizeof(*a)); \
1229  })
1230 
1231 
1241 int
1242 GNUNET_memcmp_ct_ (const void *b1,
1243  const void *b2,
1244  size_t len);
1245 
1253 #define GNUNET_memcmp_priv(a, b) \
1254  ({ \
1255  const typeof (*b) * _a = (a); \
1256  const typeof (*a) * _b = (b); \
1257  GNUNET_memcmp_ct_ (_a, _b, sizeof(*a)); \
1258  })
1259 
1260 
1270 GNUNET_is_zero_ (const void *a,
1271  size_t n);
1272 
1273 
1281 #define GNUNET_is_zero(a) \
1282  GNUNET_is_zero_ ((a), sizeof (*(a)))
1283 
1284 
1294 #define GNUNET_memcpy(dst, src, n) \
1295  do \
1296  { \
1297  if (0 != n) \
1298  { \
1299  (void) memcpy (dst, src, n); \
1300  } \
1301  } while (0)
1302 
1303 
1313 #define GNUNET_new_array(n, type) ({ \
1314  GNUNET_assert (SIZE_MAX / sizeof (type) >= n); \
1315  (type *) GNUNET_malloc ((n) * sizeof(type)); \
1316  })
1317 
1327 #define GNUNET_new_array_2d(n, m, type) \
1328  (type **) GNUNET_xnew_array_2d_ (n, m, sizeof(type), __FILE__, __LINE__)
1329 
1340 #define GNUNET_new_array_3d(n, m, o, type) \
1341  (type ***) GNUNET_xnew_array_3d_ (n, m, o, sizeof(type), __FILE__, __LINE__)
1342 
1352 #define GNUNET_malloc(size) GNUNET_xmalloc_ (size, __FILE__, __LINE__)
1353 
1362 #define GNUNET_memdup(buf, size) GNUNET_xmemdup_ (buf, size, __FILE__, __LINE__)
1363 
1372 #define GNUNET_malloc_large(size) \
1373  GNUNET_xmalloc_unchecked_ (size, __FILE__, __LINE__)
1374 
1375 
1385 #define GNUNET_realloc(ptr, size) \
1386  GNUNET_xrealloc_ (ptr, size, __FILE__, __LINE__)
1387 
1388 
1398 #define GNUNET_free_nz(ptr) GNUNET_xfree_ (ptr, __FILE__, __LINE__)
1399 
1400 
1412 #define GNUNET_free(ptr) do { \
1413  GNUNET_xfree_ (ptr, __FILE__, __LINE__); \
1414  ptr = NULL; \
1415 } while (0)
1416 
1417 
1426 #define GNUNET_strdup(a) GNUNET_xstrdup_ (a, __FILE__, __LINE__)
1427 
1437 #define GNUNET_strndup(a, length) \
1438  GNUNET_xstrndup_ (a, length, __FILE__, __LINE__)
1439 
1475 #define GNUNET_array_grow(arr, size, tsize) \
1476  GNUNET_xgrow_ ((void **) &(arr), \
1477  sizeof((arr)[0]), \
1478  &size, \
1479  tsize, \
1480  __FILE__, \
1481  __LINE__)
1482 
1496 #define GNUNET_array_append(arr, len, element) \
1497  do \
1498  { \
1499  GNUNET_assert ((len) + 1 > (len)); \
1500  GNUNET_array_grow (arr, len, len + 1); \
1501  (arr) [len - 1] = element; \
1502  } while (0)
1503 
1504 
1528 #define GNUNET_array_concatenate(arr1, len1, arr2, len2) \
1529  do \
1530  { \
1531  const typeof (*arr2) * _a1 = (arr1); \
1532  const typeof (*arr1) * _a2 = (arr2); \
1533  GNUNET_assert ((len1) + (len2) >= (len1)); \
1534  GNUNET_assert (SIZE_MAX / sizeof (*_a1) >= ((len1) + (len2))); \
1535  GNUNET_array_grow (arr1, len1, (len1) + (len2)); \
1536  memcpy (&(arr1) [(len1) - (len2)], _a2, (len2) * sizeof (*arr1)); \
1537  } while (0)
1538 
1539 
1550 int
1552  size_t size,
1553  const char *format,
1554  ...)
1555 __attribute__ ((format (printf, 3, 4)));
1556 
1557 
1567 int
1569  const char *format,
1570  ...)
1571 __attribute__ ((format (printf, 2, 3)));
1572 
1573 
1574 /* ************** internal implementations, use macros above! ************** */
1575 
1587 void *
1588 GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber);
1589 
1590 
1605 void **
1606 GNUNET_xnew_array_2d_ (size_t n,
1607  size_t m,
1608  size_t elementSize,
1609  const char *filename,
1610  int linenumber);
1611 
1612 
1628 void ***
1629 GNUNET_xnew_array_3d_ (size_t n,
1630  size_t m,
1631  size_t o,
1632  size_t elementSize,
1633  const char *filename,
1634  int linenumber);
1635 
1636 
1648 void *
1649 GNUNET_xmemdup_ (const void *buf,
1650  size_t size,
1651  const char *filename,
1652  int linenumber);
1653 
1654 
1667 void *
1668 GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber);
1669 
1670 
1675 void *
1676 GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber);
1677 
1678 
1688 void
1689 GNUNET_xfree_ (void *ptr, const char *filename, int linenumber);
1690 
1691 
1699 char *
1700 GNUNET_xstrdup_ (const char *str, const char *filename, int linenumber);
1701 
1711 char *
1712 GNUNET_xstrndup_ (const char *str,
1713  size_t len,
1714  const char *filename,
1715  int linenumber);
1716 
1732 void
1733 GNUNET_xgrow_ (void **old,
1734  size_t elementSize,
1735  unsigned int *oldCount,
1736  unsigned int newCount,
1737  const char *filename,
1738  int linenumber);
1739 
1740 
1748 struct GNUNET_MessageHeader *
1750 
1751 
1758 void
1760  struct GNUNET_AsyncScopeSave *old_scope);
1761 
1762 
1768 void
1770 
1771 
1777 void
1778 GNUNET_async_scope_get (struct GNUNET_AsyncScopeSave *scope_ret);
1779 
1780 
1786 void
1788 
1789 
1790 #if __STDC_VERSION__ < 199901L
1791 #if __GNUC__ >= 2
1792 #define __func__ __FUNCTION__
1793 #else
1794 #define __func__ "<unknown>"
1795 #endif
1796 #endif
1797 
1798 
1807 {
1812 
1817 
1823 
1831 
1837 
1843 
1851 
1861 
1867 };
1868 
1869 
1870 #if 0 /* keep Emacsens' auto-indent happy */
1871 {
1872 #endif
1873 #ifdef __cplusplus
1874 }
1875 #endif
1876 
1877 #endif /* GNUNET_COMMON_H */
1878  /* 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:38
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:83
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:54
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:70
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:37
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.
#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
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
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_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_e2s(const struct GNUNET_CRYPTO_EcdhePublicKey *p)
Convert a public key value to a string (for printing debug messages).
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_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).
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_e2s2(const struct GNUNET_CRYPTO_EcdhePublicKey *p)
Convert a public key 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.
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:68
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.