GNUnet 0.21.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
87extern "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
153#ifndef GNUNET_EXTRA_LOGGING
154#define GNUNET_EXTRA_LOGGING 1
155#endif
156
161#if defined(bswap_16) || defined(bswap_32) || defined(bswap_64)
162#define BYTE_SWAP_16(x) bswap_16 (x)
163#define BYTE_SWAP_32(x) bswap_32 (x)
164#define BYTE_SWAP_64(x) bswap_64 (x)
165#else
166#define BYTE_SWAP_16(x) ((((x) & 0x00ff) << 8) | (((x) & 0xff00) >> 8))
167
168#define BYTE_SWAP_32(x) \
169 ((((x) & 0x000000ffU) << 24) | (((x) & 0x0000ff00U) << 8) \
170 | (((x) & 0x00ff0000U) >> 8) | (((x) & 0xff000000U) >> 24))
171
172#define BYTE_SWAP_64(x) \
173 ((((x) & 0x00000000000000ffUL) << 56) | (((x) & 0x000000000000ff00UL) << \
174 40) \
175 | (((x) & 0x0000000000ff0000UL) << 24) | (((x) & 0x00000000ff000000UL) \
176 << 8) \
177 | (((x) & 0x000000ff00000000UL) >> 8) | (((x) & 0x0000ff0000000000UL) \
178 >> 24) \
179 | (((x) & 0x00ff000000000000UL) >> 40) | (((x) & 0xff00000000000000UL) \
180 >> \
181 56))
182#endif
183
184#if __BYTE_ORDER == __LITTLE_ENDIAN
185#define GNUNET_htobe16(x) BYTE_SWAP_16 (x)
186#define GNUNET_htole16(x) (x)
187#define GNUNET_be16toh(x) BYTE_SWAP_16 (x)
188#define GNUNET_le16toh(x) (x)
189
190#define GNUNET_htobe32(x) BYTE_SWAP_32 (x)
191#define GNUNET_htole32(x) (x)
192#define GNUNET_be32toh(x) BYTE_SWAP_32 (x)
193#define GNUNET_le32toh(x) (x)
194
195#define GNUNET_htobe64(x) BYTE_SWAP_64 (x)
196#define GNUNET_htole64(x) (x)
197#define GNUNET_be64toh(x) BYTE_SWAP_64 (x)
198#define GNUNET_le64toh(x) (x)
199#endif
200#if __BYTE_ORDER == __BIG_ENDIAN
201#define GNUNET_htobe16(x) (x)
202#define GNUNET_htole16(x) BYTE_SWAP_16 (x)
203#define GNUNET_be16toh(x) (x)
204#define GNUNET_le16toh(x) BYTE_SWAP_16 (x)
205
206#define GNUNET_htobe32(x) (x)
207#define GNUNET_htole32(x) BYTE_SWAP_32 (x)
208#define GNUNET_be32toh(x) (x)
209#define GNUNET_le32toh(x) BYTE_SWAP_32 (x)
210
211#define GNUNET_htobe64(x) (x)
212#define GNUNET_htole64(x) BYTE_SWAP_64 (x)
213#define GNUNET_be64toh(x) (x)
214#define GNUNET_le64toh(x) BYTE_SWAP_64 (x)
215#endif
216
217
230#define GNUNET_NZL(l) GNUNET_MAX (1, l)
231
232
236#define GNUNET_PACKED __attribute__ ((packed))
237
241#define GNUNET_GCC_STRUCT_LAYOUT
242
248#ifdef __BIGGEST_ALIGNMENT__
249#define GNUNET_ALIGN __attribute__ ((aligned (__BIGGEST_ALIGNMENT__)))
250#else
251#define GNUNET_ALIGN __attribute__ ((aligned (8)))
252#endif
253
257#define GNUNET_UNUSED __attribute__ ((unused))
258
262#define GNUNET_NORETURN __attribute__ ((noreturn))
263
267#define GNUNET_NETWORK_STRUCT_BEGIN
268
272#define GNUNET_NETWORK_STRUCT_END
273
274/* ************************ super-general types *********************** */
275
277
282{
283 uint32_t bits[512 / 8 / sizeof(uint32_t)]; /* = 16 */
284};
285
286
292{
293 uint32_t bits[256 / 8 / sizeof(uint32_t)]; /* = 8 */
294};
295
296
306{
310 uint32_t value[4];
311};
312
313
318{
324
329};
330
331
336{
338
340
345
350
351 /* Followed by data. */
352};
353
354
359{
360 uint32_t bits[16 / sizeof(uint32_t)]; /* = 16 bytes */
361};
362
364
365
370{
375
380};
381
382
392typedef enum GNUNET_GenericReturnValue
393(*GNUNET_FileNameCallback) (void *cls,
394 const char *filename);
395
396
402typedef void
403(*GNUNET_ContinuationCallback) (void *cls);
404
405
418typedef void
419(*GNUNET_ResultCallback) (void *cls,
420 int64_t result_code,
421 const void *data,
422 uint16_t data_size);
423
424
425/* ****************************** logging ***************************** */
426
432{
437 /* UX: We need a message type that is output by
438 * default without looking like there is a problem.
439 */
446
447
458typedef void
459(*GNUNET_Logger) (void *cls,
460 enum GNUNET_ErrorType kind,
461 const char *component,
462 const char *date,
463 const char *message);
464
465
472int
474
475
476#if ! defined(GNUNET_CULL_LOGGING)
477int
478GNUNET_get_log_call_status (int caller_level,
479 const char *comp,
480 const char *file,
481 const char *function,
482 int line);
483
484#endif
485
486/* *INDENT-OFF* */
495void
497 const char *message,
498 ...)
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/* *INDENT-ON* */
523
524
535void
537 const char *comp,
538 const char *message,
539 ...)
540__attribute__ ((format (printf, 3, 4)));
541
542#if ! defined(GNUNET_CULL_LOGGING)
543#define GNUNET_log_from(kind, comp, ...) \
544 do \
545 { \
546 static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \
547 if ((GNUNET_EXTRA_LOGGING > 0) || \
548 ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \
549 { \
550 if (GN_UNLIKELY (log_call_enabled == -1)) \
551 log_call_enabled = \
552 GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \
553 (comp), \
554 __FILE__, \
555 __FUNCTION__, \
556 __LINE__); \
557 if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \
558 { \
559 GNUNET_log_skip (-1, GNUNET_NO); \
560 } \
561 else \
562 { \
563 if (GN_UNLIKELY (log_call_enabled)) \
564 GNUNET_log_from_nocheck ((kind), comp, __VA_ARGS__); \
565 } \
566 } \
567 } while (0)
568
569#define GNUNET_log(kind, ...) \
570 do \
571 { \
572 static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \
573 if ((GNUNET_EXTRA_LOGGING > 0) || \
574 ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \
575 { \
576 if (GN_UNLIKELY (log_call_enabled == -1)) \
577 log_call_enabled = \
578 GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \
579 NULL, \
580 __FILE__, \
581 __FUNCTION__, \
582 __LINE__); \
583 if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \
584 { \
585 GNUNET_log_skip (-1, GNUNET_NO); \
586 } \
587 else \
588 { \
589 if (GN_UNLIKELY (log_call_enabled)) \
590 GNUNET_log_nocheck ((kind), __VA_ARGS__); \
591 } \
592 } \
593 } while (0)
594#else
595#define GNUNET_log(...)
596#define GNUNET_log_from(...)
597#endif
598
599
608void
610 const char *section,
611 const char *option);
612
613
623void
625 const char *section,
626 const char *option,
627 const char *required);
628
629
636void
638
639
650const char *
651GNUNET_b2s (const void *buf,
652 size_t buf_size);
653
654
662#define GNUNET_B2S(obj) GNUNET_b2s ((obj), sizeof (*(obj)))
663
664
672void
673GNUNET_log_skip (int n, int check_reset);
674
675
686GNUNET_log_setup (const char *comp,
687 const char *loglevel,
688 const char *logfile);
689
690
701void
703 void *logger_cls);
704
705
713void
715 void *logger_cls);
716
717
727const char *
728GNUNET_sh2s (const struct GNUNET_ShortHashCode *shc);
729
730
740const char *
741GNUNET_uuid2s (const struct GNUNET_Uuid *uuid);
742
743
753const char *
754GNUNET_h2s (const struct GNUNET_HashCode *hc);
755
756
768const char *
769GNUNET_h2s2 (const struct GNUNET_HashCode *hc);
770
771
782const char *
783GNUNET_h2s_full (const struct GNUNET_HashCode *hc);
784
785
790
791
796
797
807const char *
809
810
820const char *
822
823
833const char *
835
836
846const char *
848
849
854
855
866const char *
867GNUNET_i2s (const struct GNUNET_PeerIdentity *pid);
868
869
882const char *
883GNUNET_i2s2 (const struct GNUNET_PeerIdentity *pid);
884
885
896const char *
898
899
911const char *
912GNUNET_a2s (const struct sockaddr *addr, socklen_t addrlen);
913
926size_t
927GNUNET_hex2b (char *src, void *dst, size_t dstlen, int invert);
928
939void
940GNUNET_print_bytes (const void *buf,
941 size_t buf_len,
942 int fold,
943 int in_be);
951const char *
953
954
959#if __GNUC__ >= 6 || __clang_major__ >= 6
960#define GNUNET_assert(cond) \
961 do \
962 { \
963 _Pragma("GCC diagnostic push") \
964 _Pragma("GCC diagnostic ignored \"-Wtautological-compare\"") \
965 if (! (cond)) \
966 { \
967 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
968 dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \
969 __FILE__, \
970 __LINE__); \
971 GNUNET_abort_ (); \
972 } \
973 _Pragma("GCC diagnostic pop") \
974 } while (0)
975#else
976/* older GCC/clangs do not support -Wtautological-compare */
977#define GNUNET_assert(cond) \
978 do \
979 { \
980 if (! (cond)) \
981 { \
982 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
983 dgettext ("gnunet", \
984 "Assertion failed at %s:%d. Aborting.\n"), \
985 __FILE__, \
986 __LINE__); \
987 GNUNET_abort_ (); \
988 } \
989 } while (0)
990#endif
991
996#define GNUNET_assert_at(cond, f, l) \
997 do \
998 { \
999 if (! (cond)) \
1000 { \
1001 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
1002 dgettext ("gnunet", \
1003 "Assertion failed at %s:%d. Aborting.\n"), \
1004 f, \
1005 l); \
1006 GNUNET_abort_ (); \
1007 } \
1008 } while (0)
1009
1010
1018#define GNUNET_assert_from(cond, comp) \
1019 do \
1020 { \
1021 if (! (cond)) \
1022 { \
1023 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, \
1024 comp, \
1025 dgettext ("gnunet", \
1026 "Assertion failed at %s:%d. Aborting.\n") \
1027 , \
1028 __FILE__, \
1029 __LINE__); \
1030 GNUNET_abort_ (); \
1031 } \
1032 } while (0)
1033
1034
1035#ifdef _Static_assert
1043#define GNUNET_static_assert(cond) _Static_assert (cond, "")
1044#else
1053#define GNUNET_static_assert(cond) GNUNET_assert (cond)
1054#endif
1055
1056
1062#define GNUNET_break(cond) \
1063 do \
1064 { \
1065 if (! (cond)) \
1066 { \
1067 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
1068 dgettext ("gnunet", "Assertion failed at %s:%d.\n"), \
1069 __FILE__, \
1070 __LINE__); \
1071 } \
1072 } while (0)
1073
1074
1084#define GNUNET_break_op(cond) \
1085 do \
1086 { \
1087 if (! (cond)) \
1088 { \
1089 GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, \
1090 dgettext ("gnunet", \
1091 "External protocol violation detected at %s:%d.\n"), \
1092 __FILE__, \
1093 __LINE__); \
1094 } \
1095 } while (0)
1096
1097
1104#define GNUNET_log_strerror(level, cmd) \
1105 do \
1106 { \
1107 GNUNET_log (level, \
1108 dgettext ("gnunet", \
1109 "`%s' failed at %s:%d with error: %s\n"), \
1110 cmd, \
1111 __FILE__, \
1112 __LINE__, \
1113 strerror (errno)); \
1114 } while (0)
1115
1116
1123#define GNUNET_log_from_strerror(level, component, cmd) \
1124 do \
1125 { \
1126 GNUNET_log_from (level, \
1127 component, \
1128 dgettext ("gnunet", \
1129 "`%s' failed at %s:%d with error: %s\n"), \
1130 cmd, \
1131 __FILE__, \
1132 __LINE__, \
1133 strerror (errno)); \
1134 } while (0)
1135
1136
1143#define GNUNET_log_strerror_file(level, cmd, filename) \
1144 do \
1145 { \
1146 GNUNET_log (level, \
1147 dgettext ("gnunet", \
1148 "`%s' failed on file `%s' at %s:%d with error: %s\n"), \
1149 cmd, \
1150 filename, \
1151 __FILE__, \
1152 __LINE__, \
1153 strerror (errno)); \
1154 } while (0)
1155
1156
1163#define GNUNET_log_from_strerror_file(level, component, cmd, filename) \
1164 do \
1165 { \
1166 GNUNET_log_from (level, \
1167 component, \
1168 dgettext ("gnunet", \
1169 "`%s' failed on file `%s' at %s:%d with error: %s\n"), \
1170 cmd, \
1171 filename, \
1172 __FILE__, \
1173 __LINE__, \
1174 strerror (errno)); \
1175 } while (0)
1176
1177/* ************************* endianness conversion ****************** */
1178
1179#ifdef htonbe64
1180
1181#define GNUNET_htonll(n) htobe64 (n)
1182
1183#else
1192uint64_t
1193GNUNET_htonll (uint64_t n);
1194
1195#endif
1196
1197
1198#ifdef be64toh
1199
1200#define GNUNET_ntohll(n) be64toh (n)
1201
1202#else
1211uint64_t
1212GNUNET_ntohll (uint64_t n);
1213
1214#endif
1215
1216
1225double
1226GNUNET_hton_double (double d);
1227
1228
1237double
1238GNUNET_ntoh_double (double d);
1239
1240
1241/* ************************* allocation functions ****************** */
1242
1247#define GNUNET_MAX_MALLOC_CHECKED (1024 * 1024 * 40)
1248
1257#define GNUNET_new(type) (type *) GNUNET_malloc (sizeof(type))
1258
1259
1267#define GNUNET_memcmp(a, b) \
1268 ({ \
1269 const typeof (*b) * _a = (a); \
1270 const typeof (*a) * _b = (b); \
1271 memcmp (_a, _b, sizeof(*a)); \
1272 })
1273
1274
1284int
1285GNUNET_memcmp_ct_ (const void *b1,
1286 const void *b2,
1287 size_t len);
1288
1296#define GNUNET_memcmp_priv(a, b) \
1297 ({ \
1298 const typeof (*b) * _a = (a); \
1299 const typeof (*a) * _b = (b); \
1300 GNUNET_memcmp_ct_ (_a, _b, sizeof(*a)); \
1301 })
1302
1303
1312bool
1313GNUNET_is_zero_ (const void *a,
1314 size_t n);
1315
1316
1324#define GNUNET_is_zero(a) \
1325 GNUNET_is_zero_ ((a), sizeof (*(a)))
1326
1327
1337#define GNUNET_memcpy(dst, src, n) \
1338 do \
1339 { \
1340 if (0 != n) \
1341 { \
1342 (void) memcpy (dst, src, n); \
1343 } \
1344 } while (0)
1345
1346
1347/* *INDENT-OFF* */
1357#define GNUNET_new_array(n, type) ({ \
1358 GNUNET_assert (SIZE_MAX / sizeof (type) >= n); \
1359 (type *) GNUNET_malloc ((n) * sizeof(type)); \
1360 })
1361/* *INDENT-ON* */
1362
1372#define GNUNET_new_array_2d(n, m, type) \
1373 (type **) GNUNET_xnew_array_2d_ (n, m, sizeof(type), __FILE__, __LINE__)
1374
1385#define GNUNET_new_array_3d(n, m, o, type) \
1386 (type ***) GNUNET_xnew_array_3d_ (n, m, o, sizeof(type), __FILE__, \
1387 __LINE__)
1388
1398#define GNUNET_malloc(size) GNUNET_xmalloc_ (size, __FILE__, __LINE__)
1399
1408#define GNUNET_memdup(buf, size) GNUNET_xmemdup_ (buf, size, __FILE__, __LINE__)
1409
1418#define GNUNET_malloc_large(size) \
1419 GNUNET_xmalloc_unchecked_ (size, __FILE__, __LINE__)
1420
1421
1431#define GNUNET_realloc(ptr, size) \
1432 GNUNET_xrealloc_ (ptr, size, __FILE__, __LINE__)
1433
1434
1444#define GNUNET_free_nz(ptr) GNUNET_xfree_ (ptr, __FILE__, __LINE__)
1445
1446
1458#define GNUNET_free(ptr) do { \
1459 GNUNET_xfree_ (ptr, __FILE__, __LINE__); \
1460 ptr = NULL; \
1461} while (0)
1462
1463
1472#define GNUNET_strdup(a) GNUNET_xstrdup_ (a, __FILE__, __LINE__)
1473
1474
1484#define GNUNET_strndup(a, length) \
1485 GNUNET_xstrndup_ (a, length, __FILE__, __LINE__)
1486
1522#define GNUNET_array_grow(arr, size, tsize) \
1523 GNUNET_xgrow_ ((void **) &(arr), \
1524 sizeof((arr)[0]), \
1525 &size, \
1526 tsize, \
1527 __FILE__, \
1528 __LINE__)
1529
1543#define GNUNET_array_append(arr, len, element) \
1544 do \
1545 { \
1546 GNUNET_assert ((len) + 1 > (len)); \
1547 GNUNET_array_grow (arr, len, len + 1); \
1548 (arr) [len - 1] = element; \
1549 } while (0)
1550
1551
1575#define GNUNET_array_concatenate(arr1, len1, arr2, len2) \
1576 do \
1577 { \
1578 const typeof (*arr2) * _a1 = (arr1); \
1579 const typeof (*arr1) * _a2 = (arr2); \
1580 GNUNET_assert ((len1) + (len2) >= (len1)); \
1581 GNUNET_assert (SIZE_MAX / sizeof (*_a1) >= ((len1) + (len2))); \
1582 GNUNET_array_grow (arr1, len1, (len1) + (len2)); \
1583 memcpy (&(arr1) [(len1) - (len2)], _a2, (len2) * sizeof (*arr1)); \
1584 } while (0)
1585
1586
1597int
1599 size_t size,
1600 const char *format,
1601 ...)
1602__attribute__ ((format (printf, 3, 4)));
1603
1604
1614int
1616 const char *format,
1617 ...)
1618__attribute__ ((format (printf, 2, 3)));
1619
1620
1621/* ************** internal implementations, use macros above! ************** */
1622
1634void *
1635GNUNET_xmalloc_ (size_t size,
1636 const char *filename,
1637 int linenumber);
1638
1639
1654void **
1655GNUNET_xnew_array_2d_ (size_t n,
1656 size_t m,
1657 size_t elementSize,
1658 const char *filename,
1659 int linenumber);
1660
1661
1677void ***
1678GNUNET_xnew_array_3d_ (size_t n,
1679 size_t m,
1680 size_t o,
1681 size_t elementSize,
1682 const char *filename,
1683 int linenumber);
1684
1685
1697void *
1698GNUNET_xmemdup_ (const void *buf,
1699 size_t size,
1700 const char *filename,
1701 int linenumber);
1702
1703
1716void *
1718 const char *filename,
1719 int linenumber);
1720
1721
1726void *
1727GNUNET_xrealloc_ (void *ptr,
1728 size_t n,
1729 const char *filename,
1730 int linenumber);
1731
1732
1742void
1743GNUNET_xfree_ (void *ptr,
1744 const char *filename,
1745 int linenumber);
1746
1747
1755char *
1756GNUNET_xstrdup_ (const char *str,
1757 const char *filename,
1758 int linenumber);
1759
1769char *
1770GNUNET_xstrndup_ (const char *str,
1771 size_t len,
1772 const char *filename,
1773 int linenumber);
1774
1790void
1791GNUNET_xgrow_ (void **old,
1792 size_t elementSize,
1793 unsigned int *oldCount,
1794 unsigned int newCount,
1795 const char *filename,
1796 int linenumber);
1797
1798
1806struct GNUNET_MessageHeader *
1808
1809
1816void
1818 struct GNUNET_AsyncScopeSave *old_scope);
1819
1820
1826void
1828
1829
1835void
1837
1838
1844void
1846
1847
1848#if __STDC_VERSION__ < 199901L
1849#if __GNUC__ >= 2
1850#define __func__ __FUNCTION__
1851#else
1852#define __func__ "<unknown>"
1853#endif
1854#endif
1855
1856
1865{
1870
1875
1881
1889
1895
1901
1909
1919
1926
1927
1928/* *INDENT-OFF* */
1929
1930#if 0 /* keep Emacsens' auto-indent happy */
1931{
1932#endif
1933#ifdef __cplusplus
1934}
1935#endif
1936
1937#endif /* GNUNET_COMMON_H */
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static char * component
Running component.
static mp_limb_t d[(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)]
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 * data
The data to insert into the dht.
static char * filename
static size_t data_size
Number of bytes in data.
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
struct GNUNET_PQ_ResultSpec __attribute__
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.
uint32_t bits[256/8/sizeof(uint32_t)]
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32.
double GNUNET_ntoh_double(double d)
Convert double to host byte order.
Definition: common_endian.c:83
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
enum GNUNET_GenericReturnValue(* GNUNET_FileNameCallback)(void *cls, const char *filename)
Function called with a filename.
struct GNUNET_MessageHeader header
char * GNUNET_xstrndup_(const char *str, size_t len, const char *filename, int linenumber)
Dup partially a string.
const char * GNUNET_b2s(const void *buf, size_t buf_size)
Convert a buffer to an 8-character string representative of the contents.
#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.
char * GNUNET_xstrdup_(const char *str, const char *filename, int linenumber)
Dup a string.
void(* GNUNET_ContinuationCallback)(void *cls)
Generic continuation callback.
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.
uint32_t bits[16/sizeof(uint32_t)]
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_xmalloc_unchecked_(size_t size, const char *filename, int linenumber)
Allocate memory.
void GNUNET_xfree_(void *ptr, const char *filename, int linenumber)
Free memory.
void * GNUNET_xrealloc_(void *ptr, size_t n, const char *filename, int linenumber)
Reallocate 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;.
int int void * GNUNET_xmalloc_(size_t size, const char *filename, int linenumber)
Allocate memory.
int have_scope
GNUNET_YES unless this saved scope is the unnamed root scope.
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
uint64_t result_code
Status code for the operation.
void GNUNET_async_scope_get(struct GNUNET_AsyncScopeSave *scope_ret)
Get the current async scope.
bool GNUNET_is_zero_(const void *a, size_t n)
Check that memory in a is all zeros.
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_xmemdup_(const void *buf, size_t size, const char *filename, int linenumber)
Allocate and initialize memory.
void GNUNET_async_scope_restore(struct GNUNET_AsyncScopeSave *old_scope)
Clear the current thread's async scope.
GNUNET_GenericReturnValue
Named constants for return values.
struct GNUNET_AsyncScopeId scope_id
Saved scope.
uint64_t op_id
Operation ID.
uint32_t value[4]
128 random bits.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
#define GNUNET_PACKED
gcc-ism to get packed structs.
uint32_t bits[512/8/sizeof(uint32_t)]
@ 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
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).
size_t GNUNET_hex2b(char *src, void *dst, size_t dstlen, int invert)
Parse an ascii-encoded hexadecimal string into the buffer.
const char * GNUNET_uuid2s(const struct GNUNET_Uuid *uuid)
Convert a UUID to a string (for printing debug messages).
void GNUNET_print_bytes(const void *buf, size_t buf_len, int fold, int in_be)
Print a byte string in hexadecimal ascii notation.
const char * GNUNET_i2s(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).
void GNUNET_log_nocheck(enum GNUNET_ErrorType kind, const char *message,...) __attribute__((format(printf
Main log function.
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_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
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).
enum GNUNET_GenericReturnValue GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
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_log_skip(int n, int check_reset)
Ignore the next n calls to the log function.
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_h2s2(const struct GNUNET_HashCode *hc)
Convert a hash value 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.
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_i2s2(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity 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).
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.
struct GNUNET_MessageHeader * GNUNET_copy_message(const struct GNUNET_MessageHeader *msg)
Create a copy of the given message.
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 unsigned int size
Size of the "table".
Definition: peer.c:68
Identifier for an asynchronous execution context.
Saved async scope identifier or root 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.
Header for all communications.
Answer from service to client about last operation.
The identity of the host (wraps the signing key of the peer).
A 256-bit hashcode.
A UUID, a 128 bit "random" value.