GNUnet 0.22.1
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#ifndef _LIBGETTEXT_H
85#include "gettext.h"
86#endif
87
88#ifdef __cplusplus
89extern "C" {
90#if 0 /* keep Emacsens' auto-indent happy */
91}
92#endif
93#endif
94
98#define GNUNET_UTIL_VERSION 0x000A0104
99
100
108{
112 /* intentionally identical to #GNUNET_OK! */
114};
115
116
117#define GNUNET_MIN(a, b) (((a) < (b)) ? (a) : (b))
118
119#define GNUNET_MAX(a, b) (((a) > (b)) ? (a) : (b))
120
121/* some systems use one underscore only, and mingw uses no underscore... */
122#ifndef __BYTE_ORDER
123#ifdef _BYTE_ORDER
124#define __BYTE_ORDER _BYTE_ORDER
125#else
126#ifdef BYTE_ORDER
127#define __BYTE_ORDER BYTE_ORDER
128#endif
129#endif
130#endif
131#ifndef __BIG_ENDIAN
132#ifdef _BIG_ENDIAN
133#define __BIG_ENDIAN _BIG_ENDIAN
134#else
135#ifdef BIG_ENDIAN
136#define __BIG_ENDIAN BIG_ENDIAN
137#endif
138#endif
139#endif
140#ifndef __LITTLE_ENDIAN
141#ifdef _LITTLE_ENDIAN
142#define __LITTLE_ENDIAN _LITTLE_ENDIAN
143#else
144#ifdef LITTLE_ENDIAN
145#define __LITTLE_ENDIAN LITTLE_ENDIAN
146#endif
147#endif
148#endif
149
155#ifndef GNUNET_EXTRA_LOGGING
156#define GNUNET_EXTRA_LOGGING 1
157#endif
158
163#if defined(bswap_16) || defined(bswap_32) || defined(bswap_64)
164#define BYTE_SWAP_16(x) bswap_16 (x)
165#define BYTE_SWAP_32(x) bswap_32 (x)
166#define BYTE_SWAP_64(x) bswap_64 (x)
167#else
168#define BYTE_SWAP_16(x) ((((x) & 0x00ff) << 8) | (((x) & 0xff00) >> 8))
169
170#define BYTE_SWAP_32(x) \
171 ((((x) & 0x000000ffU) << 24) | (((x) & 0x0000ff00U) << 8) \
172 | (((x) & 0x00ff0000U) >> 8) | (((x) & 0xff000000U) >> 24))
173
174#define BYTE_SWAP_64(x) \
175 ((((x) & 0x00000000000000ffUL) << 56) | (((x) & 0x000000000000ff00UL) << \
176 40) \
177 | (((x) & 0x0000000000ff0000UL) << 24) | (((x) & 0x00000000ff000000UL) \
178 << 8) \
179 | (((x) & 0x000000ff00000000UL) >> 8) | (((x) & 0x0000ff0000000000UL) \
180 >> 24) \
181 | (((x) & 0x00ff000000000000UL) >> 40) | (((x) & 0xff00000000000000UL) \
182 >> \
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{
326
331};
332
333
338{
339 uint32_t bits[16 / sizeof(uint32_t)]; /* = 16 bytes */
340};
341
343
344
349{
354
359};
360
361
371typedef enum GNUNET_GenericReturnValue
372(*GNUNET_FileNameCallback) (void *cls,
373 const char *filename);
374
375
381typedef void
382(*GNUNET_ContinuationCallback) (void *cls);
383
384
397typedef void
398(*GNUNET_ResultCallback) (void *cls,
399 int64_t result_code,
400 const void *data,
401 uint16_t data_size);
402
403
404/* ****************************** logging ***************************** */
405
411{
416 /* UX: We need a message type that is output by
417 * default without looking like there is a problem.
418 */
425
426
437typedef void
438(*GNUNET_Logger) (void *cls,
439 enum GNUNET_ErrorType kind,
440 const char *component,
441 const char *date,
442 const char *message);
443
444
451int
453
454
455#if ! defined(GNUNET_CULL_LOGGING)
456int
457GNUNET_get_log_call_status (int caller_level,
458 const char *comp,
459 const char *file,
460 const char *function,
461 int line);
462
463#endif
464
465/* *INDENT-OFF* */
474void
476 const char *message,
477 ...)
478__attribute__ ((format (printf, 2, 3)));
479
480/* from glib */
481#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
482#define _GNUNET_BOOLEAN_EXPR(expr) \
483 __extension__ ({ \
484 int _gnunet_boolean_var_; \
485 if (expr) \
486 _gnunet_boolean_var_ = 1; \
487 else \
488 _gnunet_boolean_var_ = 0; \
489 _gnunet_boolean_var_; \
490 })
491#define GN_LIKELY(expr) (__builtin_expect (_GNUNET_BOOLEAN_EXPR (expr), 1))
492#define GN_UNLIKELY(expr) (__builtin_expect (_GNUNET_BOOLEAN_EXPR (expr), 0))
493#else
494#define GN_LIKELY(expr) (expr)
495#define GN_UNLIKELY(expr) (expr)
496#endif
497
498#if ! defined(GNUNET_LOG_CALL_STATUS)
499#define GNUNET_LOG_CALL_STATUS -1
500#endif
501/* *INDENT-ON* */
502
503
514void
516 const char *comp,
517 const char *message,
518 ...)
519__attribute__ ((format (printf, 3, 4)));
520
521#if ! defined(GNUNET_CULL_LOGGING)
522#define GNUNET_log_from(kind, comp, ...) \
523 do \
524 { \
525 static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \
526 if ((GNUNET_EXTRA_LOGGING > 0) || \
527 ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \
528 { \
529 if (GN_UNLIKELY (log_call_enabled == -1)) \
530 log_call_enabled = \
531 GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \
532 (comp), \
533 __FILE__, \
534 __FUNCTION__, \
535 __LINE__); \
536 if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \
537 { \
538 GNUNET_log_skip (-1, GNUNET_NO); \
539 } \
540 else \
541 { \
542 if (GN_UNLIKELY (log_call_enabled)) \
543 GNUNET_log_from_nocheck ((kind), comp, __VA_ARGS__); \
544 } \
545 } \
546 } while (0)
547
548#define GNUNET_log(kind, ...) \
549 do \
550 { \
551 static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \
552 if ((GNUNET_EXTRA_LOGGING > 0) || \
553 ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \
554 { \
555 if (GN_UNLIKELY (log_call_enabled == -1)) \
556 log_call_enabled = \
557 GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \
558 NULL, \
559 __FILE__, \
560 __FUNCTION__, \
561 __LINE__); \
562 if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \
563 { \
564 GNUNET_log_skip (-1, GNUNET_NO); \
565 } \
566 else \
567 { \
568 if (GN_UNLIKELY (log_call_enabled)) \
569 GNUNET_log_nocheck ((kind), __VA_ARGS__); \
570 } \
571 } \
572 } while (0)
573#else
574#define GNUNET_log(...)
575#define GNUNET_log_from(...)
576#endif
577
578
587void
589 const char *section,
590 const char *option);
591
592
602void
604 const char *section,
605 const char *option,
606 const char *required);
607
608
615void
617
618
629const char *
630GNUNET_b2s (const void *buf,
631 size_t buf_size);
632
633
641#define GNUNET_B2S(obj) GNUNET_b2s ((obj), sizeof (*(obj)))
642
643
651void
652GNUNET_log_skip (int n, int check_reset);
653
654
665GNUNET_log_setup (const char *comp,
666 const char *loglevel,
667 const char *logfile);
668
669
680void
682 void *logger_cls);
683
684
692void
694 void *logger_cls);
695
696
706const char *
707GNUNET_sh2s (const struct GNUNET_ShortHashCode *shc);
708
709
719const char *
720GNUNET_uuid2s (const struct GNUNET_Uuid *uuid);
721
722
732const char *
733GNUNET_h2s (const struct GNUNET_HashCode *hc);
734
735
747const char *
748GNUNET_h2s2 (const struct GNUNET_HashCode *hc);
749
750
761const char *
762GNUNET_h2s_full (const struct GNUNET_HashCode *hc);
763
764
769
770
775
776
786const char *
788
789
799const char *
801
802
812const char *
814
815
825const char *
827
828
833
834
845const char *
846GNUNET_i2s (const struct GNUNET_PeerIdentity *pid);
847
848
861const char *
862GNUNET_i2s2 (const struct GNUNET_PeerIdentity *pid);
863
864
875const char *
877
878
890const char *
891GNUNET_a2s (const struct sockaddr *addr, socklen_t addrlen);
892
905size_t
906GNUNET_hex2b (const char *src, void *dst, size_t dstlen, int invert);
907
918void
919GNUNET_print_bytes (const void *buf,
920 size_t buf_len,
921 int fold,
922 int in_be);
930const char *
932
933
938#if __GNUC__ >= 6 || __clang_major__ >= 6
939#define GNUNET_assert(cond) \
940 do \
941 { \
942 _Pragma("GCC diagnostic push") \
943 _Pragma("GCC diagnostic ignored \"-Wtautological-compare\"") \
944 if (! (cond)) \
945 { \
946 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
947 dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \
948 __FILE__, \
949 __LINE__); \
950 GNUNET_abort_ (); \
951 } \
952 _Pragma("GCC diagnostic pop") \
953 } while (0)
954#else
955/* older GCC/clangs do not support -Wtautological-compare */
956#define GNUNET_assert(cond) \
957 do \
958 { \
959 if (! (cond)) \
960 { \
961 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
962 dgettext ("gnunet", \
963 "Assertion failed at %s:%d. Aborting.\n"), \
964 __FILE__, \
965 __LINE__); \
966 GNUNET_abort_ (); \
967 } \
968 } while (0)
969#endif
970
975#define GNUNET_assert_at(cond, f, l) \
976 do \
977 { \
978 if (! (cond)) \
979 { \
980 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
981 dgettext ("gnunet", \
982 "Assertion failed at %s:%d. Aborting.\n"), \
983 f, \
984 l); \
985 GNUNET_abort_ (); \
986 } \
987 } while (0)
988
989
997#define GNUNET_assert_from(cond, comp) \
998 do \
999 { \
1000 if (! (cond)) \
1001 { \
1002 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, \
1003 comp, \
1004 dgettext ("gnunet", \
1005 "Assertion failed at %s:%d. Aborting.\n") \
1006 , \
1007 __FILE__, \
1008 __LINE__); \
1009 GNUNET_abort_ (); \
1010 } \
1011 } while (0)
1012
1013
1014#ifdef _Static_assert
1022#define GNUNET_static_assert(cond) _Static_assert (cond, "")
1023#else
1032#define GNUNET_static_assert(cond) GNUNET_assert (cond)
1033#endif
1034
1035
1041#define GNUNET_break(cond) \
1042 do \
1043 { \
1044 if (! (cond)) \
1045 { \
1046 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
1047 dgettext ("gnunet", "Assertion failed at %s:%d.\n"), \
1048 __FILE__, \
1049 __LINE__); \
1050 } \
1051 } while (0)
1052
1053
1063#define GNUNET_break_op(cond) \
1064 do \
1065 { \
1066 if (! (cond)) \
1067 { \
1068 GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, \
1069 dgettext ("gnunet", \
1070 "External protocol violation detected at %s:%d.\n"), \
1071 __FILE__, \
1072 __LINE__); \
1073 } \
1074 } while (0)
1075
1076
1083#define GNUNET_log_strerror(level, cmd) \
1084 do \
1085 { \
1086 GNUNET_log (level, \
1087 dgettext ("gnunet", \
1088 "`%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_from_strerror(level, component, cmd) \
1103 do \
1104 { \
1105 GNUNET_log_from (level, \
1106 component, \
1107 dgettext ("gnunet", \
1108 "`%s' failed at %s:%d with error: %s\n"), \
1109 cmd, \
1110 __FILE__, \
1111 __LINE__, \
1112 strerror (errno)); \
1113 } while (0)
1114
1115
1122#define GNUNET_log_strerror_file(level, cmd, filename) \
1123 do \
1124 { \
1125 GNUNET_log (level, \
1126 dgettext ("gnunet", \
1127 "`%s' failed on file `%s' at %s:%d with error: %s\n"), \
1128 cmd, \
1129 filename, \
1130 __FILE__, \
1131 __LINE__, \
1132 strerror (errno)); \
1133 } while (0)
1134
1135
1142#define GNUNET_log_from_strerror_file(level, component, cmd, filename) \
1143 do \
1144 { \
1145 GNUNET_log_from (level, \
1146 component, \
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/* ************************* endianness conversion ****************** */
1157
1158#ifdef htonbe64
1159
1160#define GNUNET_htonll(n) htobe64 (n)
1161
1162#else
1171uint64_t
1172GNUNET_htonll (uint64_t n);
1173
1174#endif
1175
1176
1177#ifdef be64toh
1178
1179#define GNUNET_ntohll(n) be64toh (n)
1180
1181#else
1190uint64_t
1191GNUNET_ntohll (uint64_t n);
1192
1193#endif
1194
1195
1204double
1205GNUNET_hton_double (double d);
1206
1207
1216double
1217GNUNET_ntoh_double (double d);
1218
1219
1220/* ************************* allocation functions ****************** */
1221
1226#define GNUNET_MAX_MALLOC_CHECKED (1024 * 1024 * 40)
1227
1236#define GNUNET_new(type) (type *) GNUNET_malloc (sizeof(type))
1237
1238
1246#define GNUNET_memcmp(a, b) \
1247 ({ \
1248 const typeof (*b) * _a = (a); \
1249 const typeof (*a) * _b = (b); \
1250 memcmp (_a, _b, sizeof(*a)); \
1251 })
1252
1253
1263int
1264GNUNET_memcmp_ct_ (const void *b1,
1265 const void *b2,
1266 size_t len);
1267
1275#define GNUNET_memcmp_priv(a, b) \
1276 ({ \
1277 const typeof (*b) * _a = (a); \
1278 const typeof (*a) * _b = (b); \
1279 GNUNET_memcmp_ct_ (_a, _b, sizeof(*a)); \
1280 })
1281
1282
1291bool
1292GNUNET_is_zero_ (const void *a,
1293 size_t n);
1294
1295
1303#define GNUNET_is_zero(a) \
1304 GNUNET_is_zero_ ((a), sizeof (*(a)))
1305
1306
1316#define GNUNET_memcpy(dst, src, n) \
1317 do \
1318 { \
1319 if (0 != n) \
1320 { \
1321 (void) memcpy (dst, src, n); \
1322 } \
1323 } while (0)
1324
1325
1326/* *INDENT-OFF* */
1336#define GNUNET_new_array(n, type) ({ \
1337 GNUNET_assert (SIZE_MAX / sizeof (type) >= n); \
1338 (type *) GNUNET_malloc ((n) * sizeof(type)); \
1339 })
1340/* *INDENT-ON* */
1341
1351#define GNUNET_malloc(size) GNUNET_xmalloc_ (size, __FILE__, __LINE__)
1352
1361#define GNUNET_memdup(buf, size) GNUNET_xmemdup_ (buf, size, __FILE__, __LINE__)
1362
1371#define GNUNET_malloc_large(size) \
1372 GNUNET_xmalloc_unchecked_ (size, __FILE__, __LINE__)
1373
1374
1384#define GNUNET_realloc(ptr, size) \
1385 GNUNET_xrealloc_ (ptr, size, __FILE__, __LINE__)
1386
1387
1397#define GNUNET_free_nz(ptr) GNUNET_xfree_ (ptr, __FILE__, __LINE__)
1398
1399
1411#define GNUNET_free(ptr) do { \
1412 GNUNET_xfree_ (ptr, __FILE__, __LINE__); \
1413 ptr = NULL; \
1414} while (0)
1415
1416
1425#define GNUNET_strdup(a) GNUNET_xstrdup_ (a, __FILE__, __LINE__)
1426
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
1550int
1552 size_t size,
1553 const char *format,
1554 ...)
1555__attribute__ ((format (printf, 3, 4)));
1556
1557
1567int
1569 const char *format,
1570 ...)
1571__attribute__ ((format (printf, 2, 3)));
1572
1573
1574/* ************** internal implementations, use macros above! ************** */
1575
1587void *
1588GNUNET_xmalloc_ (size_t size,
1589 const char *filename,
1590 int linenumber);
1591
1592
1604void *
1605GNUNET_xmemdup_ (const void *buf,
1606 size_t size,
1607 const char *filename,
1608 int linenumber);
1609
1610
1623void *
1625 const char *filename,
1626 int linenumber);
1627
1628
1633void *
1634GNUNET_xrealloc_ (void *ptr,
1635 size_t n,
1636 const char *filename,
1637 int linenumber);
1638
1639
1649void
1650GNUNET_xfree_ (void *ptr,
1651 const char *filename,
1652 int linenumber);
1653
1654
1662char *
1663GNUNET_xstrdup_ (const char *str,
1664 const char *filename,
1665 int linenumber);
1666
1676char *
1677GNUNET_xstrndup_ (const char *str,
1678 size_t len,
1679 const char *filename,
1680 int linenumber);
1681
1697void
1698GNUNET_xgrow_ (void **old,
1699 size_t elementSize,
1700 unsigned int *oldCount,
1701 unsigned int newCount,
1702 const char *filename,
1703 int linenumber);
1704
1705
1713struct GNUNET_MessageHeader *
1715
1716
1723void
1725 struct GNUNET_AsyncScopeSave *old_scope);
1726
1727
1733void
1735
1736
1742void
1744
1745
1751void
1753
1754
1755#if __STDC_VERSION__ < 199901L
1756#if __GNUC__ >= 2
1757#define __func__ __FUNCTION__
1758#else
1759#define __func__ "<unknown>"
1760#endif
1761#endif
1762
1763
1772{
1777
1782
1788
1796
1802
1808
1816
1826
1833
1834
1835/* *INDENT-OFF* */
1836
1837#if 0 /* keep Emacsens' auto-indent happy */
1838{
1839#endif
1840#ifdef __cplusplus
1841}
1842#endif
1843
1844#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 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 struct GNUNET_PEERSTORE_StoreHelloContext * shc
HELLO store context handle.
Definition: gnunet-hello.c:52
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.
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.
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
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_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.
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).
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).
size_t GNUNET_hex2b(const char *src, void *dst, size_t dstlen, int invert)
Parse an ascii-encoded hexadecimal string into the buffer.
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.
The identity of the host (wraps the signing key of the peer).
A 256-bit hashcode.
A UUID, a 128 bit "random" value.