GNUnet 0.24.4-talerdev.1-26-g056a24676
 
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 <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_16(x) bswap16 (x)
59#define bswap_32(x) bswap32 (x)
60#define bswap_64(x) bswap64 (x)
61
62#elif defined(__OpenBSD__)
63
64#define bswap_16(x) swap16 (x)
65#define bswap_32(x) swap32 (x)
66#define bswap_64(x) swap64 (x)
67
68#elif defined(__NetBSD__)
69
70#include <machine/bswap.h>
71#if defined(__BSWAP_RENAME) && ! defined(__bswap_32)
72#define bswap_16(x) bswap16 (x)
73#define bswap_32(x) bswap32 (x)
74#define bswap_64(x) bswap64 (x)
75#endif
76
77#elif defined(__linux__) || defined(GNU)
78#include <byteswap.h>
79#endif
80
81
82/* This is also included in platform.h, but over there a couple of
83 GNUnet-specific gettext-related macros are defined in addition to including
84 the header file. Because this header file uses gettext, this include
85 statement makes sure gettext macros are defined even when platform.h is
86 unavailable. */
87#ifndef _LIBGETTEXT_H
88#include "gettext.h"
89#endif
90
91#ifdef __cplusplus
92extern "C" {
93#if 0 /* keep Emacsens' auto-indent happy */
94}
95#endif
96#endif
97
101#define GNUNET_UTIL_VERSION 0x000A0104
102
103
111{
115 /* intentionally identical to #GNUNET_OK! */
117};
118
119
120#define GNUNET_MIN(a, b) (((a) < (b)) ? (a) : (b))
121
122#define GNUNET_MAX(a, b) (((a) > (b)) ? (a) : (b))
123
124/* some systems use one underscore only, and mingw uses no underscore... */
125#ifndef __BYTE_ORDER
126#ifdef _BYTE_ORDER
127#define __BYTE_ORDER _BYTE_ORDER
128#else
129#ifdef BYTE_ORDER
130#define __BYTE_ORDER BYTE_ORDER
131#endif
132#endif
133#endif
134#ifndef __BIG_ENDIAN
135#ifdef _BIG_ENDIAN
136#define __BIG_ENDIAN _BIG_ENDIAN
137#else
138#ifdef BIG_ENDIAN
139#define __BIG_ENDIAN BIG_ENDIAN
140#endif
141#endif
142#endif
143#ifndef __LITTLE_ENDIAN
144#ifdef _LITTLE_ENDIAN
145#define __LITTLE_ENDIAN _LITTLE_ENDIAN
146#else
147#ifdef LITTLE_ENDIAN
148#define __LITTLE_ENDIAN LITTLE_ENDIAN
149#endif
150#endif
151#endif
152
158#ifndef GNUNET_EXTRA_LOGGING
159#define GNUNET_EXTRA_LOGGING 1
160#endif
161
166#if defined(bswap_16) || defined(bswap_32) || defined(bswap_64)
167#define BYTE_SWAP_16(x) bswap_16 (x)
168#define BYTE_SWAP_32(x) bswap_32 (x)
169#define BYTE_SWAP_64(x) bswap_64 (x)
170#else
171#define BYTE_SWAP_16(x) ((((x) & 0x00ff) << 8) | (((x) & 0xff00) >> 8))
172
173#define BYTE_SWAP_32(x) \
174 ((((x) & 0x000000ffU) << 24) | (((x) & 0x0000ff00U) << 8) \
175 | (((x) & 0x00ff0000U) >> 8) | (((x) & 0xff000000U) >> 24))
176
177#define BYTE_SWAP_64(x) \
178 ((((x) & 0x00000000000000ffUL) << 56) | (((x) & 0x000000000000ff00UL) << \
179 40) \
180 | (((x) & 0x0000000000ff0000UL) << 24) | (((x) & 0x00000000ff000000UL) \
181 << 8) \
182 | (((x) & 0x000000ff00000000UL) >> 8) | (((x) & 0x0000ff0000000000UL) \
183 >> 24) \
184 | (((x) & 0x00ff000000000000UL) >> 40) | (((x) & 0xff00000000000000UL) \
185 >> \
186 56))
187#endif
188
189#if __BYTE_ORDER == __LITTLE_ENDIAN
190#define GNUNET_htobe16(x) BYTE_SWAP_16 (x)
191#define GNUNET_htole16(x) (x)
192#define GNUNET_be16toh(x) BYTE_SWAP_16 (x)
193#define GNUNET_le16toh(x) (x)
194
195#define GNUNET_htobe32(x) BYTE_SWAP_32 (x)
196#define GNUNET_htole32(x) (x)
197#define GNUNET_be32toh(x) BYTE_SWAP_32 (x)
198#define GNUNET_le32toh(x) (x)
199
200#define GNUNET_htobe64(x) BYTE_SWAP_64 (x)
201#define GNUNET_htole64(x) (x)
202#define GNUNET_be64toh(x) BYTE_SWAP_64 (x)
203#define GNUNET_le64toh(x) (x)
204#endif
205#if __BYTE_ORDER == __BIG_ENDIAN
206#define GNUNET_htobe16(x) (x)
207#define GNUNET_htole16(x) BYTE_SWAP_16 (x)
208#define GNUNET_be16toh(x) (x)
209#define GNUNET_le16toh(x) BYTE_SWAP_16 (x)
210
211#define GNUNET_htobe32(x) (x)
212#define GNUNET_htole32(x) BYTE_SWAP_32 (x)
213#define GNUNET_be32toh(x) (x)
214#define GNUNET_le32toh(x) BYTE_SWAP_32 (x)
215
216#define GNUNET_htobe64(x) (x)
217#define GNUNET_htole64(x) BYTE_SWAP_64 (x)
218#define GNUNET_be64toh(x) (x)
219#define GNUNET_le64toh(x) BYTE_SWAP_64 (x)
220#endif
221
222
235#define GNUNET_NZL(l) GNUNET_MAX (1, l)
236
237
241#define GNUNET_PACKED __attribute__ ((packed))
242
246#define GNUNET_GCC_STRUCT_LAYOUT
247
253#ifdef __BIGGEST_ALIGNMENT__
254#define GNUNET_ALIGN __attribute__ ((aligned (__BIGGEST_ALIGNMENT__)))
255#else
256#define GNUNET_ALIGN __attribute__ ((aligned (8)))
257#endif
258
262#define GNUNET_UNUSED __attribute__ ((unused))
263
267#define GNUNET_NORETURN __attribute__ ((noreturn))
268
272#define GNUNET_NETWORK_STRUCT_BEGIN
273
277#define GNUNET_NETWORK_STRUCT_END
278
279/* ************************ super-general types *********************** */
280
282
287{
288 uint32_t bits[512 / 8 / sizeof(uint32_t)]; /* = 16 */
289};
290
291
297{
298 uint32_t bits[256 / 8 / sizeof(uint32_t)]; /* = 8 */
299};
300
301
311{
315 uint32_t value[4];
316};
317
318
323{
329
334};
335
336
341{
342 uint32_t bits[16 / sizeof(uint32_t)]; /* = 16 bytes */
343};
344
346
347
363
364
374typedef enum GNUNET_GenericReturnValue
375(*GNUNET_FileNameCallback) (void *cls,
376 const char *filename);
377
378
384typedef void
385(*GNUNET_ContinuationCallback) (void *cls);
386
387
400typedef void
401(*GNUNET_ResultCallback) (void *cls,
402 int64_t result_code,
403 const void *data,
404 uint16_t data_size);
405
406
407/* ****************************** logging ***************************** */
408
414{
419 /* UX: We need a message type that is output by
420 * default without looking like there is a problem.
421 */
428
429
440typedef void
441(*GNUNET_Logger) (void *cls,
442 enum GNUNET_ErrorType kind,
443 const char *component,
444 const char *date,
445 const char *message);
446
447
454int
456
457
458#if ! defined(GNUNET_CULL_LOGGING)
459int
460GNUNET_get_log_call_status (int caller_level,
461 const char *comp,
462 const char *file,
463 const char *function,
464 int line);
465
466#endif
467
468/* *INDENT-OFF* */
477void
479 const char *message,
480 ...)
481__attribute__ ((format (printf, 2, 3)));
482
483/* from glib */
484#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
485#define _GNUNET_BOOLEAN_EXPR(expr) \
486 __extension__ ({ \
487 int _gnunet_boolean_var_; \
488 if (expr) \
489 _gnunet_boolean_var_ = 1; \
490 else \
491 _gnunet_boolean_var_ = 0; \
492 _gnunet_boolean_var_; \
493 })
494#define GN_LIKELY(expr) (__builtin_expect (_GNUNET_BOOLEAN_EXPR (expr), 1))
495#define GN_UNLIKELY(expr) (__builtin_expect (_GNUNET_BOOLEAN_EXPR (expr), 0))
496#else
497#define GN_LIKELY(expr) (expr)
498#define GN_UNLIKELY(expr) (expr)
499#endif
500
501#if ! defined(GNUNET_LOG_CALL_STATUS)
502#define GNUNET_LOG_CALL_STATUS -1
503#endif
504/* *INDENT-ON* */
505
506
517void
519 const char *comp,
520 const char *message,
521 ...)
522__attribute__ ((format (printf, 3, 4)));
523
524#if ! defined(GNUNET_CULL_LOGGING)
525#define GNUNET_log_from(kind, comp, ...) \
526 do \
527 { \
528 static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \
529 if ((GNUNET_EXTRA_LOGGING > 0) || \
530 ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \
531 { \
532 if (GN_UNLIKELY (log_call_enabled == -1)) \
533 log_call_enabled = \
534 GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \
535 (comp), \
536 __FILE__, \
537 __func__, \
538 __LINE__); \
539 if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \
540 { \
541 GNUNET_log_skip (-1, GNUNET_NO); \
542 } \
543 else \
544 { \
545 if (GN_UNLIKELY (log_call_enabled)) \
546 GNUNET_log_from_nocheck ((kind), comp, __VA_ARGS__); \
547 } \
548 } \
549 } while (0)
550
551#define GNUNET_log(kind, ...) \
552 do \
553 { \
554 static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \
555 if ((GNUNET_EXTRA_LOGGING > 0) || \
556 ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \
557 { \
558 if (GN_UNLIKELY (log_call_enabled == -1)) \
559 log_call_enabled = \
560 GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \
561 NULL, \
562 __FILE__, \
563 __func__, \
564 __LINE__); \
565 if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \
566 { \
567 GNUNET_log_skip (-1, GNUNET_NO); \
568 } \
569 else \
570 { \
571 if (GN_UNLIKELY (log_call_enabled)) \
572 GNUNET_log_nocheck ((kind), __VA_ARGS__); \
573 } \
574 } \
575 } while (0)
576#else
577#define GNUNET_log(...)
578#define GNUNET_log_from(...)
579#endif
580
581
590void
592 const char *section,
593 const char *option);
594
595
605void
607 const char *section,
608 const char *option,
609 const char *required);
610
611
618void
620
621
632const char *
633GNUNET_b2s (const void *buf,
634 size_t buf_size);
635
636
644#define GNUNET_B2S(obj) GNUNET_b2s ((obj), sizeof (*(obj)))
645
646
654void
655GNUNET_log_skip (int n, int check_reset);
656
657
668GNUNET_log_setup (const char *comp,
669 const char *loglevel,
670 const char *logfile);
671
672
683void
685 void *logger_cls);
686
687
695void
697 void *logger_cls);
698
699
709const char *
710GNUNET_sh2s (const struct GNUNET_ShortHashCode *shc);
711
712
722const char *
723GNUNET_uuid2s (const struct GNUNET_Uuid *uuid);
724
725
735const char *
736GNUNET_h2s (const struct GNUNET_HashCode *hc);
737
738
750const char *
751GNUNET_h2s2 (const struct GNUNET_HashCode *hc);
752
753
764const char *
765GNUNET_h2s_full (const struct GNUNET_HashCode *hc);
766
767
772
773
778
779
789const char *
791
792
802const char *
804
805
815const char *
817
818
828const char *
830
831
836
837
848const char *
849GNUNET_i2s (const struct GNUNET_PeerIdentity *pid);
850
851
864const char *
865GNUNET_i2s2 (const struct GNUNET_PeerIdentity *pid);
866
867
878const char *
880
881
893const char *
894GNUNET_a2s (const struct sockaddr *addr, socklen_t addrlen);
895
908size_t
909GNUNET_hex2b (const char *src, void *dst, size_t dstlen, int invert);
910
921void
922GNUNET_print_bytes (const void *buf,
923 size_t buf_len,
924 int fold,
925 int in_be);
926
934const char *
936
937
942#if __GNUC__ >= 6 || __clang_major__ >= 6
943#define GNUNET_assert(cond) \
944 do \
945 { \
946 _Pragma("GCC diagnostic push") \
947 _Pragma("GCC diagnostic ignored \"-Wtautological-compare\"") \
948 if (! (cond)) \
949 { \
950 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
951 dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \
952 __FILE__, \
953 __LINE__); \
954 GNUNET_abort_ (); \
955 } \
956 _Pragma("GCC diagnostic pop") \
957 } while (0)
958#else
959/* older GCC/clangs do not support -Wtautological-compare */
960#define GNUNET_assert(cond) \
961 do \
962 { \
963 if (! (cond)) \
964 { \
965 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
966 dgettext ("gnunet", \
967 "Assertion failed at %s:%d. Aborting.\n"), \
968 __FILE__, \
969 __LINE__); \
970 GNUNET_abort_ (); \
971 } \
972 } while (0)
973#endif
974
979#define GNUNET_assert_at(cond, f, l) \
980 do \
981 { \
982 if (! (cond)) \
983 { \
984 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
985 dgettext ("gnunet", \
986 "Assertion failed at %s:%d. Aborting.\n"), \
987 f, \
988 l); \
989 GNUNET_abort_ (); \
990 } \
991 } while (0)
992
993
1001#define GNUNET_assert_from(cond, comp) \
1002 do \
1003 { \
1004 if (! (cond)) \
1005 { \
1006 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, \
1007 comp, \
1008 dgettext ("gnunet", \
1009 "Assertion failed at %s:%d. Aborting.\n") \
1010 , \
1011 __FILE__, \
1012 __LINE__); \
1013 GNUNET_abort_ (); \
1014 } \
1015 } while (0)
1016
1017
1018#ifdef _Static_assert
1026#define GNUNET_static_assert(cond) _Static_assert (cond, "")
1027#else
1036#define GNUNET_static_assert(cond) GNUNET_assert (cond)
1037#endif
1038
1039
1045#define GNUNET_break(cond) \
1046 do \
1047 { \
1048 if (! (cond)) \
1049 { \
1050 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
1051 dgettext ("gnunet", "Assertion failed at %s:%d.\n"), \
1052 __FILE__, \
1053 __LINE__); \
1054 } \
1055 } while (0)
1056
1057
1067#define GNUNET_break_op(cond) \
1068 do \
1069 { \
1070 if (! (cond)) \
1071 { \
1072 GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, \
1073 dgettext ("gnunet", \
1074 "External protocol violation detected at %s:%d.\n"), \
1075 __FILE__, \
1076 __LINE__); \
1077 } \
1078 } while (0)
1079
1080
1087#define GNUNET_log_strerror(level, cmd) \
1088 do \
1089 { \
1090 GNUNET_log (level, \
1091 dgettext ("gnunet", \
1092 "`%s' failed at %s:%d with error: %s\n"), \
1093 cmd, \
1094 __FILE__, \
1095 __LINE__, \
1096 strerror (errno)); \
1097 } while (0)
1098
1099
1106#define GNUNET_log_from_strerror(level, component, cmd) \
1107 do \
1108 { \
1109 GNUNET_log_from (level, \
1110 component, \
1111 dgettext ("gnunet", \
1112 "`%s' failed at %s:%d with error: %s\n"), \
1113 cmd, \
1114 __FILE__, \
1115 __LINE__, \
1116 strerror (errno)); \
1117 } while (0)
1118
1119
1126#define GNUNET_log_strerror_file(level, cmd, filename) \
1127 do \
1128 { \
1129 GNUNET_log (level, \
1130 dgettext ("gnunet", \
1131 "`%s' failed on file `%s' at %s:%d with error: %s\n"), \
1132 cmd, \
1133 filename, \
1134 __FILE__, \
1135 __LINE__, \
1136 strerror (errno)); \
1137 } while (0)
1138
1139
1146#define GNUNET_log_from_strerror_file(level, component, cmd, filename) \
1147 do \
1148 { \
1149 GNUNET_log_from (level, \
1150 component, \
1151 dgettext ("gnunet", \
1152 "`%s' failed on file `%s' at %s:%d with error: %s\n"), \
1153 cmd, \
1154 filename, \
1155 __FILE__, \
1156 __LINE__, \
1157 strerror (errno)); \
1158 } while (0)
1159
1160/* ************************* endianness conversion ****************** */
1161
1162#ifdef htobe64
1163
1164#define GNUNET_htonll(n) htobe64 (n)
1165
1166#else
1175uint64_t
1176GNUNET_htonll (uint64_t n);
1177
1178#endif
1179
1180
1181#ifdef be64toh
1182
1183#define GNUNET_ntohll(n) be64toh (n)
1184
1185#else
1194uint64_t
1195GNUNET_ntohll (uint64_t n);
1196
1197#endif
1198
1199
1208double
1209GNUNET_hton_double (double d);
1210
1211
1220double
1221GNUNET_ntoh_double (double d);
1222
1223
1224/* ************************* allocation functions ****************** */
1225
1230#define GNUNET_MAX_MALLOC_CHECKED (1024 * 1024 * 40)
1231
1240#define GNUNET_new(type) (type *) GNUNET_malloc (sizeof(type))
1241
1242
1250#define GNUNET_memcmp(a, b) \
1251 ({ \
1252 const typeof (*b) * _a = (a); \
1253 const typeof (*a) * _b = (b); \
1254 memcmp (_a, _b, sizeof(*a)); \
1255 })
1256
1257
1267int
1268GNUNET_memcmp_ct_ (const void *b1,
1269 const void *b2,
1270 size_t len);
1271
1279#define GNUNET_memcmp_priv(a, b) \
1280 ({ \
1281 const typeof (*b) * _a = (a); \
1282 const typeof (*a) * _b = (b); \
1283 GNUNET_memcmp_ct_ (_a, _b, sizeof(*a)); \
1284 })
1285
1286
1295bool
1296GNUNET_is_zero_ (const void *a,
1297 size_t n);
1298
1299
1307#define GNUNET_is_zero(a) \
1308 GNUNET_is_zero_ ((a), sizeof (*(a)))
1309
1310
1320#define GNUNET_memcpy(dst, src, n) \
1321 do \
1322 { \
1323 if (0 != n) \
1324 { \
1325 (void) memcpy (dst, src, n); \
1326 } \
1327 } while (0)
1328
1329
1330/* *INDENT-OFF* */
1340#define GNUNET_new_array(n, type) ({ \
1341 GNUNET_assert (SIZE_MAX / sizeof (type) >= n); \
1342 (type *) GNUNET_malloc ((n) * sizeof(type)); \
1343 })
1344/* *INDENT-ON* */
1345
1355#define GNUNET_malloc(size) GNUNET_xmalloc_ (size, __FILE__, __LINE__)
1356
1365#define GNUNET_memdup(buf, size) GNUNET_xmemdup_ (buf, size, __FILE__, __LINE__)
1366
1375#define GNUNET_malloc_large(size) \
1376 GNUNET_xmalloc_unchecked_ (size, __FILE__, __LINE__)
1377
1378
1388#define GNUNET_realloc(ptr, size) \
1389 GNUNET_xrealloc_ (ptr, size, __FILE__, __LINE__)
1390
1391
1401#define GNUNET_free_nz(ptr) GNUNET_xfree_ (ptr, __FILE__, __LINE__)
1402
1403
1415#define GNUNET_free(ptr) do { \
1416 GNUNET_xfree_ (ptr, __FILE__, __LINE__); \
1417 ptr = NULL; \
1418} while (0)
1419
1420
1429#define GNUNET_strdup(a) GNUNET_xstrdup_ (a, __FILE__, __LINE__)
1430
1431
1441#define GNUNET_strndup(a, length) \
1442 GNUNET_xstrndup_ (a, length, __FILE__, __LINE__)
1443
1479#define GNUNET_array_grow(arr, size, tsize) \
1480 GNUNET_xgrow_ ((void **) &(arr), \
1481 sizeof((arr)[0]), \
1482 &size, \
1483 tsize, \
1484 __FILE__, \
1485 __LINE__)
1486
1500#define GNUNET_array_append(arr, len, element) \
1501 do \
1502 { \
1503 GNUNET_assert ((len) + 1 > (len)); \
1504 GNUNET_array_grow (arr, len, len + 1); \
1505 (arr) [len - 1] = element; \
1506 } while (0)
1507
1508
1532#define GNUNET_array_concatenate(arr1, len1, arr2, len2) \
1533 do \
1534 { \
1535 const typeof (*arr2) * _a1 = (arr1); \
1536 const typeof (*arr1) * _a2 = (arr2); \
1537 GNUNET_assert ((len1) + (len2) >= (len1)); \
1538 GNUNET_assert (SIZE_MAX / sizeof (*_a1) >= ((len1) + (len2))); \
1539 GNUNET_array_grow (arr1, len1, (len1) + (len2)); \
1540 memcpy (&(arr1) [(len1) - (len2)], _a2, (len2) * sizeof (*arr1)); \
1541 } while (0)
1542
1543
1554int
1556 size_t size,
1557 const char *format,
1558 ...)
1559__attribute__ ((format (printf, 3, 4)));
1560
1561
1571int
1573 const char *format,
1574 ...)
1575__attribute__ ((format (printf, 2, 3)));
1576
1577
1578/* ************** internal implementations, use macros above! ************** */
1579
1591void *
1592GNUNET_xmalloc_ (size_t size,
1593 const char *filename,
1594 int linenumber);
1595
1596
1608void *
1609GNUNET_xmemdup_ (const void *buf,
1610 size_t size,
1611 const char *filename,
1612 int linenumber);
1613
1614
1627void *
1629 const char *filename,
1630 int linenumber);
1631
1632
1637void *
1638GNUNET_xrealloc_ (void *ptr,
1639 size_t n,
1640 const char *filename,
1641 int linenumber);
1642
1643
1653void
1654GNUNET_xfree_ (void *ptr,
1655 const char *filename,
1656 int linenumber);
1657
1658
1666char *
1667GNUNET_xstrdup_ (const char *str,
1668 const char *filename,
1669 int linenumber);
1670
1680char *
1681GNUNET_xstrndup_ (const char *str,
1682 size_t len,
1683 const char *filename,
1684 int linenumber);
1685
1701void
1702GNUNET_xgrow_ (void **old,
1703 size_t elementSize,
1704 unsigned int *oldCount,
1705 unsigned int newCount,
1706 const char *filename,
1707 int linenumber);
1708
1709
1717struct GNUNET_MessageHeader *
1719
1720
1727void
1729 struct GNUNET_AsyncScopeSave *old_scope);
1730
1731
1737void
1739
1740
1746void
1748
1749
1755void
1757
1758
1759#if __STDC_VERSION__ < 199901L
1760#if __GNUC__ >= 2
1761#define __func__ __FUNCTION__
1762#else
1763#define __func__ "<unknown>"
1764#endif
1765#endif
1766
1767
1837
1838
1839/* *INDENT-OFF* */
1840
1841#if 0 /* keep Emacsens' auto-indent happy */
1842{
1843#endif
1844#ifdef __cplusplus
1845}
1846#endif
1847
1848#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_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.
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.