GNUnet 0.28.1-dev.2-13-g57ceb9dfb
 
Loading...
Searching...
No Matches
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 <stddef.h>
47#include <stdlib.h>
48#include <sys/socket.h>
49#include <sys/un.h>
50#include <netinet/in.h>
51#include <arpa/inet.h>
52#include <stdint.h>
53#include <stdarg.h>
54#include <sys/types.h>
55
56#if defined(__FreeBSD__)
57
58#include <sys/endian.h>
59#define bswap_16(x) bswap16 (x)
60#define bswap_32(x) bswap32 (x)
61#define bswap_64(x) bswap64 (x)
62
63#elif defined(__OpenBSD__)
64
65#define bswap_16(x) swap16 (x)
66#define bswap_32(x) swap32 (x)
67#define bswap_64(x) swap64 (x)
68
69#elif defined(__NetBSD__)
70
71#include <machine/bswap.h>
72#if defined(__BSWAP_RENAME) && ! defined(__bswap_32)
73#define bswap_16(x) bswap16 (x)
74#define bswap_32(x) bswap32 (x)
75#define bswap_64(x) bswap64 (x)
76#endif
77
78#elif defined(__linux__) || defined(GNU)
79#include <byteswap.h>
80#endif
81
82
83/* This is also included in platform.h, but over there a couple of
84 GNUnet-specific gettext-related macros are defined in addition to including
85 the header file. Because this header file uses gettext, this include
86 statement makes sure gettext macros are defined even when platform.h is
87 unavailable. */
88#ifndef _LIBGETTEXT_H
89#include "gettext.h"
90#endif
91
92#ifdef __cplusplus
93extern "C" {
94#if 0 /* keep Emacsens' auto-indent happy */
95}
96#endif
97#endif
98
102#define GNUNET_UTIL_VERSION 0x000A0104
103
104
112{
116 /* intentionally identical to #GNUNET_OK! */
118};
119
120
121#define GNUNET_MIN(a, b) (((a) < (b)) ? (a) : (b))
122
123#define GNUNET_MAX(a, b) (((a) > (b)) ? (a) : (b))
124
125/* some systems use one underscore only, and mingw uses no underscore... */
126#ifndef __BYTE_ORDER
127#ifdef _BYTE_ORDER
128#define __BYTE_ORDER _BYTE_ORDER
129#else
130#ifdef BYTE_ORDER
131#define __BYTE_ORDER BYTE_ORDER
132#endif
133#endif
134#endif
135#ifndef __BIG_ENDIAN
136#ifdef _BIG_ENDIAN
137#define __BIG_ENDIAN _BIG_ENDIAN
138#else
139#ifdef BIG_ENDIAN
140#define __BIG_ENDIAN BIG_ENDIAN
141#endif
142#endif
143#endif
144#ifndef __LITTLE_ENDIAN
145#ifdef _LITTLE_ENDIAN
146#define __LITTLE_ENDIAN _LITTLE_ENDIAN
147#else
148#ifdef LITTLE_ENDIAN
149#define __LITTLE_ENDIAN LITTLE_ENDIAN
150#endif
151#endif
152#endif
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) << \
180 40) \
181 | (((x) & 0x0000000000ff0000UL) << 24) | (((x) & 0x00000000ff000000UL) \
182 << 8) \
183 | (((x) & 0x000000ff00000000UL) >> 8) | (((x) & 0x0000ff0000000000UL) \
184 >> 24) \
185 | (((x) & 0x00ff000000000000UL) >> 40) | (((x) & 0xff00000000000000UL) \
186 >> \
187 56))
188#endif
189
190#if __BYTE_ORDER == __LITTLE_ENDIAN
191#define GNUNET_htobe16(x) BYTE_SWAP_16 (x)
192#define GNUNET_htole16(x) (x)
193#define GNUNET_be16toh(x) BYTE_SWAP_16 (x)
194#define GNUNET_le16toh(x) (x)
195
196#define GNUNET_htobe32(x) BYTE_SWAP_32 (x)
197#define GNUNET_htole32(x) (x)
198#define GNUNET_be32toh(x) BYTE_SWAP_32 (x)
199#define GNUNET_le32toh(x) (x)
200
201#define GNUNET_htobe64(x) BYTE_SWAP_64 (x)
202#define GNUNET_htole64(x) (x)
203#define GNUNET_be64toh(x) BYTE_SWAP_64 (x)
204#define GNUNET_le64toh(x) (x)
205#endif
206#if __BYTE_ORDER == __BIG_ENDIAN
207#define GNUNET_htobe16(x) (x)
208#define GNUNET_htole16(x) BYTE_SWAP_16 (x)
209#define GNUNET_be16toh(x) (x)
210#define GNUNET_le16toh(x) BYTE_SWAP_16 (x)
211
212#define GNUNET_htobe32(x) (x)
213#define GNUNET_htole32(x) BYTE_SWAP_32 (x)
214#define GNUNET_be32toh(x) (x)
215#define GNUNET_le32toh(x) BYTE_SWAP_32 (x)
216
217#define GNUNET_htobe64(x) (x)
218#define GNUNET_htole64(x) BYTE_SWAP_64 (x)
219#define GNUNET_be64toh(x) (x)
220#define GNUNET_le64toh(x) BYTE_SWAP_64 (x)
221#endif
222
223
236#define GNUNET_NZL(l) GNUNET_MAX (1, l)
237
238
242#define GNUNET_PACKED __attribute__ ((packed))
243
247#define GNUNET_GCC_STRUCT_LAYOUT
248
254#ifdef __BIGGEST_ALIGNMENT__
255#define GNUNET_ALIGN __attribute__ ((aligned (__BIGGEST_ALIGNMENT__)))
256#else
257#define GNUNET_ALIGN __attribute__ ((aligned (8)))
258#endif
259
263#define GNUNET_UNUSED __attribute__ ((unused))
264
268#define GNUNET_NORETURN __attribute__ ((noreturn))
269
273#define GNUNET_NETWORK_STRUCT_BEGIN
274
278#define GNUNET_NETWORK_STRUCT_END
279
280/* ************************ super-general types *********************** */
281
283
288{
289 uint32_t bits[512 / 8 / sizeof(uint32_t)]; /* = 16 */
290};
291
292
298{
299 uint32_t bits[256 / 8 / sizeof(uint32_t)]; /* = 8 */
300};
301
302
312{
316 uint32_t value[4];
317};
318
319
324{
330
335};
336
337
342{
343 uint32_t bits[16 / sizeof(uint32_t)]; /* = 16 bytes */
344};
345
347
348
364
365
375typedef enum GNUNET_GenericReturnValue
376(*GNUNET_FileNameCallback) (void *cls,
377 const char *filename);
378
379
385typedef void
386(*GNUNET_ContinuationCallback) (void *cls);
387
388
401typedef void
402(*GNUNET_ResultCallback) (void *cls,
403 int64_t result_code,
404 const void *data,
405 uint16_t data_size);
406
407
408/* ****************************** logging ***************************** */
409
415{
420 /* UX: We need a message type that is output by
421 * default without looking like there is a problem.
422 */
429
430
441typedef void
442(*GNUNET_Logger) (void *cls,
443 enum GNUNET_ErrorType kind,
444 const char *component,
445 const char *date,
446 const char *message);
447
448
455int
457
458
459#if ! defined(GNUNET_CULL_LOGGING)
460int
461GNUNET_get_log_call_status (int caller_level,
462 const char *comp,
463 const char *file,
464 const char *function,
465 int line);
466
467#endif
468
469/* *INDENT-OFF* */
478void
480 const char *message,
481 ...)
482__attribute__ ((format (printf, 2, 3)));
483
484/* from glib */
485#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
486#define _GNUNET_BOOLEAN_EXPR(expr) \
487 __extension__ ({ \
488 int _gnunet_boolean_var_; \
489 if (expr) \
490 _gnunet_boolean_var_ = 1; \
491 else \
492 _gnunet_boolean_var_ = 0; \
493 _gnunet_boolean_var_; \
494 })
495#define GN_LIKELY(expr) (__builtin_expect (_GNUNET_BOOLEAN_EXPR (expr), 1))
496#define GN_UNLIKELY(expr) (__builtin_expect (_GNUNET_BOOLEAN_EXPR (expr), 0))
497#else
498#define GN_LIKELY(expr) (expr)
499#define GN_UNLIKELY(expr) (expr)
500#endif
501
502#if ! defined(GNUNET_LOG_CALL_STATUS)
503#define GNUNET_LOG_CALL_STATUS -1
504#endif
505/* *INDENT-ON* */
506
507
518void
520 const char *comp,
521 const char *message,
522 ...)
523__attribute__ ((format (printf, 3, 4)));
524
525#if ! defined(GNUNET_CULL_LOGGING)
526#define GNUNET_log_from(kind, comp, ...) \
527 do \
528 { \
529 static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \
530 if ((GNUNET_EXTRA_LOGGING > 0) || \
531 ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \
532 { \
533 if (GN_UNLIKELY (log_call_enabled == -1)) \
534 log_call_enabled = \
535 GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \
536 (comp), \
537 __FILE__, \
538 __func__, \
539 __LINE__); \
540 if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \
541 { \
542 GNUNET_log_skip (-1, GNUNET_NO); \
543 } \
544 else \
545 { \
546 if (GN_UNLIKELY (log_call_enabled)) \
547 GNUNET_log_from_nocheck ((kind), comp, __VA_ARGS__); \
548 } \
549 } \
550 } while (0)
551
552#define GNUNET_log(kind, ...) \
553 do \
554 { \
555 static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \
556 if ((GNUNET_EXTRA_LOGGING > 0) || \
557 ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \
558 { \
559 if (GN_UNLIKELY (log_call_enabled == -1)) \
560 log_call_enabled = \
561 GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \
562 NULL, \
563 __FILE__, \
564 __func__, \
565 __LINE__); \
566 if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \
567 { \
568 GNUNET_log_skip (-1, GNUNET_NO); \
569 } \
570 else \
571 { \
572 if (GN_UNLIKELY (log_call_enabled)) \
573 GNUNET_log_nocheck ((kind), __VA_ARGS__); \
574 } \
575 } \
576 } while (0)
577#else
578#define GNUNET_log(...)
579#define GNUNET_log_from(...)
580#endif
581
582
591void
593 const char *section,
594 const char *option);
595
596
606void
608 const char *section,
609 const char *option,
610 const char *required);
611
612
619void
621
622
633const char *
634GNUNET_b2s (const void *buf,
635 size_t buf_size);
636
637
645#define GNUNET_B2S(obj) GNUNET_b2s ((obj), sizeof (*(obj)))
646
647
655void
656GNUNET_log_skip (int n, int check_reset);
657
658
669GNUNET_log_setup (const char *comp,
670 const char *loglevel,
671 const char *logfile);
672
673
684void
686 void *logger_cls);
687
688
696void
698 void *logger_cls);
699
700
710const char *
711GNUNET_sh2s (const struct GNUNET_ShortHashCode *shc);
712
713
723const char *
724GNUNET_uuid2s (const struct GNUNET_Uuid *uuid);
725
726
736const char *
737GNUNET_h2s (const struct GNUNET_HashCode *hc);
738
739
751const char *
752GNUNET_h2s2 (const struct GNUNET_HashCode *hc);
753
754
765const char *
766GNUNET_h2s_full (const struct GNUNET_HashCode *hc);
767
768
773
774
779
780
790const char *
792
793
803const char *
805
806
816const char *
818
819
829const char *
831
832
837
838
849const char *
850GNUNET_i2s (const struct GNUNET_PeerIdentity *pid);
851
852
865const char *
866GNUNET_i2s2 (const struct GNUNET_PeerIdentity *pid);
867
868
879const char *
880GNUNET_i2s_full (const struct GNUNET_PeerIdentity *pid);
881
882
894const char *
895GNUNET_a2s (const struct sockaddr *addr, socklen_t addrlen);
896
909size_t
910GNUNET_hex2b (const char *src, void *dst, size_t dstlen, int invert);
911
922void
923GNUNET_print_bytes (const void *buf,
924 size_t buf_len,
925 int fold,
926 int in_be);
927
935const char *
937
938
943#if __GNUC__ >= 6 || __clang_major__ >= 6
944#define GNUNET_assert(cond) \
945 do \
946 { \
947 _Pragma("GCC diagnostic push") \
948 _Pragma("GCC diagnostic ignored \"-Wtautological-compare\"") \
949 if (! (cond)) \
950 { \
951 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
952 dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \
953 __FILE__, \
954 __LINE__); \
955 GNUNET_abort_ (); \
956 } \
957 _Pragma("GCC diagnostic pop") \
958 } while (0)
959#else
960/* older GCC/clangs do not support -Wtautological-compare */
961#define GNUNET_assert(cond) \
962 do \
963 { \
964 if (! (cond)) \
965 { \
966 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
967 dgettext ("gnunet", \
968 "Assertion failed at %s:%d. Aborting.\n"), \
969 __FILE__, \
970 __LINE__); \
971 GNUNET_abort_ (); \
972 } \
973 } while (0)
974#endif
975
980#define GNUNET_assert_at(cond, f, l) \
981 do \
982 { \
983 if (! (cond)) \
984 { \
985 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
986 dgettext ("gnunet", \
987 "Assertion failed at %s:%d. Aborting.\n"), \
988 f, \
989 l); \
990 GNUNET_abort_ (); \
991 } \
992 } while (0)
993
994
1002#define GNUNET_assert_from(cond, comp) \
1003 do \
1004 { \
1005 if (! (cond)) \
1006 { \
1007 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, \
1008 comp, \
1009 dgettext ("gnunet", \
1010 "Assertion failed at %s:%d. Aborting.\n") \
1011 , \
1012 __FILE__, \
1013 __LINE__); \
1014 GNUNET_abort_ (); \
1015 } \
1016 } while (0)
1017
1018
1019/* NOTE: `#ifdef _Static_assert' can never be true -- _Static_assert is a
1020 keyword, not a macro -- so this used to always fall back to the runtime
1021 GNUNET_assert(), which is a `do { } while (0)' statement and therefore
1022 does not even compile at file scope. Test for the language version
1023 instead. @a cond must be an integer constant expression; use
1024 GNUNET_assert() for anything that is only known at runtime. */
1025#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) \
1026 || defined(__GNUC__) || defined(__clang__)
1033#define GNUNET_static_assert(cond) _Static_assert (cond, #cond)
1034#else
1043#define GNUNET_STATIC_ASSERT_CAT2_(a, b) a ## b
1044#define GNUNET_STATIC_ASSERT_CAT_(a, b) GNUNET_STATIC_ASSERT_CAT2_ (a, b)
1045#define GNUNET_static_assert(cond) \
1046 typedef char GNUNET_STATIC_ASSERT_CAT_ (gnunet_static_assert_, \
1047 __LINE__)[(cond) ? 1 : -1]
1048#endif
1049
1050
1056#define GNUNET_break(cond) \
1057 do \
1058 { \
1059 if (! (cond)) \
1060 { \
1061 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
1062 dgettext ("gnunet", "Assertion failed at %s:%d.\n"), \
1063 __FILE__, \
1064 __LINE__); \
1065 } \
1066 } while (0)
1067
1068
1078#define GNUNET_break_op(cond) \
1079 do \
1080 { \
1081 if (! (cond)) \
1082 { \
1083 GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, \
1084 dgettext ("gnunet", \
1085 "External protocol violation detected at %s:%d.\n"), \
1086 __FILE__, \
1087 __LINE__); \
1088 } \
1089 } while (0)
1090
1091
1098#define GNUNET_log_strerror(level, cmd) \
1099 do \
1100 { \
1101 GNUNET_log (level, \
1102 dgettext ("gnunet", \
1103 "`%s' failed at %s:%d with error: %s\n"), \
1104 cmd, \
1105 __FILE__, \
1106 __LINE__, \
1107 strerror (errno)); \
1108 } while (0)
1109
1110
1117#define GNUNET_log_from_strerror(level, component, cmd) \
1118 do \
1119 { \
1120 GNUNET_log_from (level, \
1121 component, \
1122 dgettext ("gnunet", \
1123 "`%s' failed at %s:%d with error: %s\n"), \
1124 cmd, \
1125 __FILE__, \
1126 __LINE__, \
1127 strerror (errno)); \
1128 } while (0)
1129
1130
1137#define GNUNET_log_strerror_file(level, cmd, filename) \
1138 do \
1139 { \
1140 GNUNET_log (level, \
1141 dgettext ("gnunet", \
1142 "`%s' failed on file `%s' at %s:%d with error: %s\n"), \
1143 cmd, \
1144 filename, \
1145 __FILE__, \
1146 __LINE__, \
1147 strerror (errno)); \
1148 } while (0)
1149
1150
1157#define GNUNET_log_from_strerror_file(level, component, cmd, filename) \
1158 do \
1159 { \
1160 GNUNET_log_from (level, \
1161 component, \
1162 dgettext ("gnunet", \
1163 "`%s' failed on file `%s' at %s:%d with error: %s\n"), \
1164 cmd, \
1165 filename, \
1166 __FILE__, \
1167 __LINE__, \
1168 strerror (errno)); \
1169 } while (0)
1170
1171/* ************************* endianness conversion ****************** */
1172
1173#ifdef htobe64
1174
1175#define GNUNET_htonll(n) htobe64 (n)
1176
1177#else
1186uint64_t
1187GNUNET_htonll (uint64_t n);
1188
1189#endif
1190
1191
1192#ifdef be64toh
1193
1194#define GNUNET_ntohll(n) be64toh (n)
1195
1196#else
1205uint64_t
1206GNUNET_ntohll (uint64_t n);
1207
1208#endif
1209
1210
1219double
1220GNUNET_hton_double (double d);
1221
1222
1231double
1232GNUNET_ntoh_double (double d);
1233
1234
1235/* ************************* allocation functions ****************** */
1236
1241#define GNUNET_MAX_MALLOC_CHECKED (1024 * 1024 * 40)
1242
1251#define GNUNET_new(type) (type *) GNUNET_malloc (sizeof(type))
1252
1253
1261#define GNUNET_memcmp(a, b) \
1262 ({ \
1263 const typeof (*b) * _a = (a); \
1264 const typeof (*a) * _b = (b); \
1265 memcmp (_a, _b, sizeof(*a)); \
1266 })
1267
1268
1278int
1279GNUNET_memcmp_ct_ (const void *b1,
1280 const void *b2,
1281 size_t len);
1282
1290#define GNUNET_memcmp_priv(a, b) \
1291 ({ \
1292 const typeof (*b) * _a = (a); \
1293 const typeof (*a) * _b = (b); \
1294 GNUNET_memcmp_ct_ (_a, _b, sizeof(*a)); \
1295 })
1296
1297
1306bool
1307GNUNET_is_zero_ (const void *a,
1308 size_t n);
1309
1310
1318#define GNUNET_is_zero(a) \
1319 GNUNET_is_zero_ ((a), sizeof (*(a)))
1320
1321
1331#define GNUNET_memcpy(dst, src, n) \
1332 do \
1333 { \
1334 if (0 != n) \
1335 { \
1336 (void) memcpy (dst, src, n); \
1337 } \
1338 } while (0)
1339
1340
1341/* *INDENT-OFF* */
1351#define GNUNET_new_array(n, type) ({ \
1352 GNUNET_assert (SIZE_MAX / sizeof (type) >= n); \
1353 (type *) GNUNET_malloc ((n) * sizeof(type)); \
1354 })
1355/* *INDENT-ON* */
1356
1366#define GNUNET_malloc(size) GNUNET_xmalloc_ (size, __FILE__, __LINE__)
1367
1376#define GNUNET_memdup(buf, size) GNUNET_xmemdup_ (buf, size, __FILE__, __LINE__)
1377
1386#define GNUNET_malloc_large(size) \
1387 GNUNET_xmalloc_unchecked_ (size, __FILE__, __LINE__)
1388
1389
1399#define GNUNET_realloc(ptr, size) \
1400 GNUNET_xrealloc_ (ptr, size, __FILE__, __LINE__)
1401
1402
1412#define GNUNET_free_nz(ptr) GNUNET_xfree_ (ptr, __FILE__, __LINE__)
1413
1414
1426#define GNUNET_free(ptr) do { \
1427 GNUNET_xfree_ (ptr, __FILE__, __LINE__); \
1428 ptr = NULL; \
1429} while (0)
1430
1431
1440#define GNUNET_strdup(a) GNUNET_xstrdup_ (a, __FILE__, __LINE__)
1441
1442
1452#define GNUNET_strndup(a, length) \
1453 GNUNET_xstrndup_ (a, length, __FILE__, __LINE__)
1454
1490#define GNUNET_array_grow(arr, size, tsize) \
1491 GNUNET_xgrow_ ((void **) &(arr), \
1492 sizeof((arr)[0]), \
1493 &size, \
1494 tsize, \
1495 __FILE__, \
1496 __LINE__)
1497
1511#define GNUNET_array_append(arr, len, element) \
1512 do \
1513 { \
1514 GNUNET_assert ((len) + 1 > (len)); \
1515 GNUNET_array_grow (arr, len, len + 1); \
1516 (arr) [len - 1] = element; \
1517 } while (0)
1518
1519
1543#define GNUNET_array_concatenate(arr1, len1, arr2, len2) \
1544 do \
1545 { \
1546 const typeof (*arr2) * _a1 = (arr1); \
1547 const typeof (*arr1) * _a2 = (arr2); \
1548 GNUNET_assert ((len1) + (len2) >= (len1)); \
1549 GNUNET_assert (SIZE_MAX / sizeof (*_a1) >= ((len1) + (len2))); \
1550 GNUNET_array_grow (arr1, len1, (len1) + (len2)); \
1551 memcpy (&(arr1) [(len1) - (len2)], _a2, (len2) * sizeof (*arr1)); \
1552 } while (0)
1553
1554
1565int
1567 size_t size,
1568 const char *format,
1569 ...)
1570__attribute__ ((format (printf, 3, 4)));
1571
1572
1582int
1584 const char *format,
1585 ...)
1586__attribute__ ((format (printf, 2, 3)));
1587
1588
1589/* ************** internal implementations, use macros above! ************** */
1590
1602void *
1603GNUNET_xmalloc_ (size_t size,
1604 const char *filename,
1605 int linenumber);
1606
1607
1619void *
1620GNUNET_xmemdup_ (const void *buf,
1621 size_t size,
1622 const char *filename,
1623 int linenumber);
1624
1625
1638void *
1640 const char *filename,
1641 int linenumber);
1642
1643
1648void *
1649GNUNET_xrealloc_ (void *ptr,
1650 size_t n,
1651 const char *filename,
1652 int linenumber);
1653
1654
1664void
1665GNUNET_xfree_ (void *ptr,
1666 const char *filename,
1667 int linenumber);
1668
1669
1677char *
1678GNUNET_xstrdup_ (const char *str,
1679 const char *filename,
1680 int linenumber);
1681
1691char *
1692GNUNET_xstrndup_ (const char *str,
1693 size_t len,
1694 const char *filename,
1695 int linenumber);
1696
1712void
1713GNUNET_xgrow_ (void **old,
1714 size_t elementSize,
1715 unsigned int *oldCount,
1716 unsigned int newCount,
1717 const char *filename,
1718 int linenumber);
1719
1720
1728struct GNUNET_MessageHeader *
1730
1731
1738void
1740 struct GNUNET_AsyncScopeSave *old_scope);
1741
1742
1748void
1750
1751
1757void
1759
1760
1766void
1768
1769
1770#if __STDC_VERSION__ < 199901L
1771#if __GNUC__ >= 2
1772#define __func__ __FUNCTION__
1773#else
1774#define __func__ "<unknown>"
1775#endif
1776#endif
1777
1778
1848
1849
1850/* *INDENT-OFF* */
1851
1852#if 0 /* keep Emacsens' auto-indent happy */
1853{
1854#endif
1855#ifdef __cplusplus
1856}
1857#endif
1858
1859#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.
static size_t data_size
Number of bytes in data.
static struct GNUNET_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.
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.
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.
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
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.
const char * str
Definition time.c:1359