GNUnet 0.21.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#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) << 40) \
174 | (((x) & 0x0000000000ff0000UL) << 24) | (((x) & 0x00000000ff000000UL) << 8) \
175 | (((x) & 0x000000ff00000000UL) >> 8) | (((x) & 0x0000ff0000000000UL) >> 24) \
176 | (((x) & 0x00ff000000000000UL) >> 40) | (((x) & 0xff00000000000000UL) >> \
177 56))
178#endif
179
180#if __BYTE_ORDER == __LITTLE_ENDIAN
181#define GNUNET_htobe16(x) BYTE_SWAP_16 (x)
182#define GNUNET_htole16(x) (x)
183#define GNUNET_be16toh(x) BYTE_SWAP_16 (x)
184#define GNUNET_le16toh(x) (x)
185
186#define GNUNET_htobe32(x) BYTE_SWAP_32 (x)
187#define GNUNET_htole32(x) (x)
188#define GNUNET_be32toh(x) BYTE_SWAP_32 (x)
189#define GNUNET_le32toh(x) (x)
190
191#define GNUNET_htobe64(x) BYTE_SWAP_64 (x)
192#define GNUNET_htole64(x) (x)
193#define GNUNET_be64toh(x) BYTE_SWAP_64 (x)
194#define GNUNET_le64toh(x) (x)
195#endif
196#if __BYTE_ORDER == __BIG_ENDIAN
197#define GNUNET_htobe16(x) (x)
198#define GNUNET_htole16(x) BYTE_SWAP_16 (x)
199#define GNUNET_be16toh(x) (x)
200#define GNUNET_le16toh(x) BYTE_SWAP_16 (x)
201
202#define GNUNET_htobe32(x) (x)
203#define GNUNET_htole32(x) BYTE_SWAP_32 (x)
204#define GNUNET_be32toh(x) (x)
205#define GNUNET_le32toh(x) BYTE_SWAP_32 (x)
206
207#define GNUNET_htobe64(x) (x)
208#define GNUNET_htole64(x) BYTE_SWAP_64 (x)
209#define GNUNET_be64toh(x) (x)
210#define GNUNET_le64toh(x) BYTE_SWAP_64 (x)
211#endif
212
213
226#define GNUNET_NZL(l) GNUNET_MAX (1, l)
227
228
232#define GNUNET_PACKED __attribute__ ((packed))
233
237#define GNUNET_GCC_STRUCT_LAYOUT
238
244#ifdef __BIGGEST_ALIGNMENT__
245#define GNUNET_ALIGN __attribute__ ((aligned (__BIGGEST_ALIGNMENT__)))
246#else
247#define GNUNET_ALIGN __attribute__ ((aligned (8)))
248#endif
249
253#define GNUNET_UNUSED __attribute__ ((unused))
254
258#define GNUNET_NORETURN __attribute__ ((noreturn))
259
263#define GNUNET_NETWORK_STRUCT_BEGIN
264
268#define GNUNET_NETWORK_STRUCT_END
269
270/* ************************ super-general types *********************** */
271
273
278{
279 uint32_t bits[512 / 8 / sizeof(uint32_t)]; /* = 16 */
280};
281
282
288{
289 uint32_t bits[256 / 8 / sizeof(uint32_t)]; /* = 8 */
290};
291
292
302{
306 uint32_t value[4];
307};
308
309
314{
320
325};
326
327
332{
334
336
341
346
347 /* Followed by data. */
348};
349
350
355{
356 uint32_t bits[16 / sizeof(uint32_t)]; /* = 16 bytes */
357};
358
360
361
366{
371
376};
377
378
388typedef enum GNUNET_GenericReturnValue
389(*GNUNET_FileNameCallback) (void *cls,
390 const char *filename);
391
392
398typedef void
399(*GNUNET_ContinuationCallback) (void *cls);
400
401
414typedef void
415(*GNUNET_ResultCallback) (void *cls,
416 int64_t result_code,
417 const void *data,
418 uint16_t data_size);
419
420
421/* ****************************** logging ***************************** */
422
428{
433 /* UX: We need a message type that is output by
434 * default without looking like there is a problem.
435 */
442
443
454typedef void
455(*GNUNET_Logger) (void *cls,
456 enum GNUNET_ErrorType kind,
457 const char *component,
458 const char *date,
459 const char *message);
460
461
468int
470
471
472#if ! defined(GNUNET_CULL_LOGGING)
473int
474GNUNET_get_log_call_status (int caller_level,
475 const char *comp,
476 const char *file,
477 const char *function,
478 int line);
479
480#endif
481
482
491void
492GNUNET_log_nocheck (enum GNUNET_ErrorType kind, const char *message, ...)
493__attribute__ ((format (printf, 2, 3)));
494
495/* from glib */
496#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
497#define _GNUNET_BOOLEAN_EXPR(expr) \
498 __extension__ ({ \
499 int _gnunet_boolean_var_; \
500 if (expr) \
501 _gnunet_boolean_var_ = 1; \
502 else \
503 _gnunet_boolean_var_ = 0; \
504 _gnunet_boolean_var_; \
505 })
506#define GN_LIKELY(expr) (__builtin_expect (_GNUNET_BOOLEAN_EXPR (expr), 1))
507#define GN_UNLIKELY(expr) (__builtin_expect (_GNUNET_BOOLEAN_EXPR (expr), 0))
508#else
509#define GN_LIKELY(expr) (expr)
510#define GN_UNLIKELY(expr) (expr)
511#endif
512
513#if ! defined(GNUNET_LOG_CALL_STATUS)
514#define GNUNET_LOG_CALL_STATUS -1
515#endif
516
517
528void
530 const char *comp,
531 const char *message,
532 ...)
533__attribute__ ((format (printf, 3, 4)));
534
535#if ! defined(GNUNET_CULL_LOGGING)
536#define GNUNET_log_from(kind, comp, ...) \
537 do \
538 { \
539 static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \
540 if ((GNUNET_EXTRA_LOGGING > 0) || \
541 ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \
542 { \
543 if (GN_UNLIKELY (log_call_enabled == -1)) \
544 log_call_enabled = \
545 GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \
546 (comp), \
547 __FILE__, \
548 __FUNCTION__, \
549 __LINE__); \
550 if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \
551 { \
552 GNUNET_log_skip (-1, GNUNET_NO); \
553 } \
554 else \
555 { \
556 if (GN_UNLIKELY (log_call_enabled)) \
557 GNUNET_log_from_nocheck ((kind), comp, __VA_ARGS__); \
558 } \
559 } \
560 } while (0)
561
562#define GNUNET_log(kind, ...) \
563 do \
564 { \
565 static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \
566 if ((GNUNET_EXTRA_LOGGING > 0) || \
567 ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \
568 { \
569 if (GN_UNLIKELY (log_call_enabled == -1)) \
570 log_call_enabled = \
571 GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \
572 NULL, \
573 __FILE__, \
574 __FUNCTION__, \
575 __LINE__); \
576 if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \
577 { \
578 GNUNET_log_skip (-1, GNUNET_NO); \
579 } \
580 else \
581 { \
582 if (GN_UNLIKELY (log_call_enabled)) \
583 GNUNET_log_nocheck ((kind), __VA_ARGS__); \
584 } \
585 } \
586 } while (0)
587#else
588#define GNUNET_log(...)
589#define GNUNET_log_from(...)
590#endif
591
592
601void
603 const char *section,
604 const char *option);
605
606
616void
618 const char *section,
619 const char *option,
620 const char *required);
621
622
629void
631
632
643const char *
644GNUNET_b2s (const void *buf,
645 size_t buf_size);
646
647
655#define GNUNET_B2S(obj) GNUNET_b2s ((obj), sizeof (*(obj)))
656
657
665void
666GNUNET_log_skip (int n, int check_reset);
667
668
679GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile);
680
681
692void
693GNUNET_logger_add (GNUNET_Logger logger, void *logger_cls);
694
695
703void
704GNUNET_logger_remove (GNUNET_Logger logger, void *logger_cls);
705
706
716const char *
717GNUNET_sh2s (const struct GNUNET_ShortHashCode *shc);
718
719
729const char *
730GNUNET_uuid2s (const struct GNUNET_Uuid *uuid);
731
732
742const char *
743GNUNET_h2s (const struct GNUNET_HashCode *hc);
744
745
757const char *
758GNUNET_h2s2 (const struct GNUNET_HashCode *hc);
759
760
771const char *
772GNUNET_h2s_full (const struct GNUNET_HashCode *hc);
773
774
779
780
785
786
796const char *
798
799
809const char *
811
812
822const char *
824
825
835const char *
837
838
843
844
855const char *
856GNUNET_i2s (const struct GNUNET_PeerIdentity *pid);
857
858
871const char *
872GNUNET_i2s2 (const struct GNUNET_PeerIdentity *pid);
873
874
885const char *
887
888
900const char *
901GNUNET_a2s (const struct sockaddr *addr, socklen_t addrlen);
902
903
911const char *
913
914
919#if __GNUC__ >= 6 || __clang_major__ >= 6
920#define GNUNET_assert(cond) \
921 do \
922 { \
923 _Pragma("GCC diagnostic push") \
924 _Pragma("GCC diagnostic ignored \"-Wtautological-compare\"") \
925 if (! (cond)) \
926 { \
927 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
928 dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \
929 __FILE__, \
930 __LINE__); \
931 GNUNET_abort_ (); \
932 } \
933 _Pragma("GCC diagnostic pop") \
934 } while (0)
935#else
936/* older GCC/clangs do not support -Wtautological-compare */
937#define GNUNET_assert(cond) \
938 do \
939 { \
940 if (! (cond)) \
941 { \
942 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
943 dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \
944 __FILE__, \
945 __LINE__); \
946 GNUNET_abort_ (); \
947 } \
948 } while (0)
949#endif
950
955#define GNUNET_assert_at(cond, f, l) \
956 do \
957 { \
958 if (! (cond)) \
959 { \
960 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
961 dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \
962 f, \
963 l); \
964 GNUNET_abort_ (); \
965 } \
966 } while (0)
967
968
976#define GNUNET_assert_from(cond, comp) \
977 do \
978 { \
979 if (! (cond)) \
980 { \
981 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, \
982 comp, \
983 dgettext ("gnunet", "Assertion failed at %s:%d. Aborting.\n"), \
984 __FILE__, \
985 __LINE__); \
986 GNUNET_abort_ (); \
987 } \
988 } while (0)
989
990
991#ifdef _Static_assert
999#define GNUNET_static_assert(cond) _Static_assert (cond, "")
1000#else
1009#define GNUNET_static_assert(cond) GNUNET_assert (cond)
1010#endif
1011
1012
1018#define GNUNET_break(cond) \
1019 do \
1020 { \
1021 if (! (cond)) \
1022 { \
1023 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
1024 dgettext ("gnunet", "Assertion failed at %s:%d.\n"), \
1025 __FILE__, \
1026 __LINE__); \
1027 } \
1028 } while (0)
1029
1030
1040#define GNUNET_break_op(cond) \
1041 do \
1042 { \
1043 if (! (cond)) \
1044 { \
1045 GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, \
1046 dgettext ("gnunet", "External protocol violation detected at %s:%d.\n"), \
1047 __FILE__, \
1048 __LINE__); \
1049 } \
1050 } while (0)
1051
1052
1059#define GNUNET_log_strerror(level, cmd) \
1060 do \
1061 { \
1062 GNUNET_log (level, \
1063 dgettext ("gnunet", "`%s' failed at %s:%d with error: %s\n"), \
1064 cmd, \
1065 __FILE__, \
1066 __LINE__, \
1067 strerror (errno)); \
1068 } while (0)
1069
1070
1077#define GNUNET_log_from_strerror(level, component, cmd) \
1078 do \
1079 { \
1080 GNUNET_log_from (level, \
1081 component, \
1082 dgettext ("gnunet", "`%s' failed at %s:%d with error: %s\n"), \
1083 cmd, \
1084 __FILE__, \
1085 __LINE__, \
1086 strerror (errno)); \
1087 } while (0)
1088
1089
1096#define GNUNET_log_strerror_file(level, cmd, filename) \
1097 do \
1098 { \
1099 GNUNET_log (level, \
1100 dgettext ("gnunet", "`%s' failed on file `%s' at %s:%d with error: %s\n"), \
1101 cmd, \
1102 filename, \
1103 __FILE__, \
1104 __LINE__, \
1105 strerror (errno)); \
1106 } while (0)
1107
1108
1115#define GNUNET_log_from_strerror_file(level, component, cmd, filename) \
1116 do \
1117 { \
1118 GNUNET_log_from (level, \
1119 component, \
1120 dgettext ("gnunet", "`%s' failed on file `%s' at %s:%d with error: %s\n"), \
1121 cmd, \
1122 filename, \
1123 __FILE__, \
1124 __LINE__, \
1125 strerror (errno)); \
1126 } while (0)
1127
1128/* ************************* endianness conversion ****************** */
1129
1130#ifdef htonbe64
1131
1132#define GNUNET_htonll(n) htobe64 (n)
1133
1134#else
1143uint64_t
1144GNUNET_htonll (uint64_t n);
1145
1146#endif
1147
1148
1149#ifdef be64toh
1150
1151#define GNUNET_ntohll(n) be64toh (n)
1152
1153#else
1162uint64_t
1163GNUNET_ntohll (uint64_t n);
1164
1165#endif
1166
1167
1176double
1177GNUNET_hton_double (double d);
1178
1179
1188double
1189GNUNET_ntoh_double (double d);
1190
1191
1192/* ************************* allocation functions ****************** */
1193
1198#define GNUNET_MAX_MALLOC_CHECKED (1024 * 1024 * 40)
1199
1208#define GNUNET_new(type) (type *) GNUNET_malloc (sizeof(type))
1209
1210
1218#define GNUNET_memcmp(a, b) \
1219 ({ \
1220 const typeof (*b) * _a = (a); \
1221 const typeof (*a) * _b = (b); \
1222 memcmp (_a, _b, sizeof(*a)); \
1223 })
1224
1225
1235int
1236GNUNET_memcmp_ct_ (const void *b1,
1237 const void *b2,
1238 size_t len);
1239
1247#define GNUNET_memcmp_priv(a, b) \
1248 ({ \
1249 const typeof (*b) * _a = (a); \
1250 const typeof (*a) * _b = (b); \
1251 GNUNET_memcmp_ct_ (_a, _b, sizeof(*a)); \
1252 })
1253
1254
1264GNUNET_is_zero_ (const void *a,
1265 size_t n);
1266
1267
1275#define GNUNET_is_zero(a) \
1276 GNUNET_is_zero_ ((a), sizeof (*(a)))
1277
1278
1288#define GNUNET_memcpy(dst, src, n) \
1289 do \
1290 { \
1291 if (0 != n) \
1292 { \
1293 (void) memcpy (dst, src, n); \
1294 } \
1295 } while (0)
1296
1297
1307#define GNUNET_new_array(n, type) ({ \
1308 GNUNET_assert (SIZE_MAX / sizeof (type) >= n); \
1309 (type *) GNUNET_malloc ((n) * sizeof(type)); \
1310 })
1311
1321#define GNUNET_new_array_2d(n, m, type) \
1322 (type **) GNUNET_xnew_array_2d_ (n, m, sizeof(type), __FILE__, __LINE__)
1323
1334#define GNUNET_new_array_3d(n, m, o, type) \
1335 (type ***) GNUNET_xnew_array_3d_ (n, m, o, sizeof(type), __FILE__, __LINE__)
1336
1346#define GNUNET_malloc(size) GNUNET_xmalloc_ (size, __FILE__, __LINE__)
1347
1356#define GNUNET_memdup(buf, size) GNUNET_xmemdup_ (buf, size, __FILE__, __LINE__)
1357
1366#define GNUNET_malloc_large(size) \
1367 GNUNET_xmalloc_unchecked_ (size, __FILE__, __LINE__)
1368
1369
1379#define GNUNET_realloc(ptr, size) \
1380 GNUNET_xrealloc_ (ptr, size, __FILE__, __LINE__)
1381
1382
1392#define GNUNET_free_nz(ptr) GNUNET_xfree_ (ptr, __FILE__, __LINE__)
1393
1394
1406#define GNUNET_free(ptr) do { \
1407 GNUNET_xfree_ (ptr, __FILE__, __LINE__); \
1408 ptr = NULL; \
1409} while (0)
1410
1411
1420#define GNUNET_strdup(a) GNUNET_xstrdup_ (a, __FILE__, __LINE__)
1421
1431#define GNUNET_strndup(a, length) \
1432 GNUNET_xstrndup_ (a, length, __FILE__, __LINE__)
1433
1469#define GNUNET_array_grow(arr, size, tsize) \
1470 GNUNET_xgrow_ ((void **) &(arr), \
1471 sizeof((arr)[0]), \
1472 &size, \
1473 tsize, \
1474 __FILE__, \
1475 __LINE__)
1476
1490#define GNUNET_array_append(arr, len, element) \
1491 do \
1492 { \
1493 GNUNET_assert ((len) + 1 > (len)); \
1494 GNUNET_array_grow (arr, len, len + 1); \
1495 (arr) [len - 1] = element; \
1496 } while (0)
1497
1498
1522#define GNUNET_array_concatenate(arr1, len1, arr2, len2) \
1523 do \
1524 { \
1525 const typeof (*arr2) * _a1 = (arr1); \
1526 const typeof (*arr1) * _a2 = (arr2); \
1527 GNUNET_assert ((len1) + (len2) >= (len1)); \
1528 GNUNET_assert (SIZE_MAX / sizeof (*_a1) >= ((len1) + (len2))); \
1529 GNUNET_array_grow (arr1, len1, (len1) + (len2)); \
1530 memcpy (&(arr1) [(len1) - (len2)], _a2, (len2) * sizeof (*arr1)); \
1531 } while (0)
1532
1533
1544int
1546 size_t size,
1547 const char *format,
1548 ...)
1549__attribute__ ((format (printf, 3, 4)));
1550
1551
1561int
1563 const char *format,
1564 ...)
1565__attribute__ ((format (printf, 2, 3)));
1566
1567
1568/* ************** internal implementations, use macros above! ************** */
1569
1581void *
1582GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber);
1583
1584
1599void **
1600GNUNET_xnew_array_2d_ (size_t n,
1601 size_t m,
1602 size_t elementSize,
1603 const char *filename,
1604 int linenumber);
1605
1606
1622void ***
1623GNUNET_xnew_array_3d_ (size_t n,
1624 size_t m,
1625 size_t o,
1626 size_t elementSize,
1627 const char *filename,
1628 int linenumber);
1629
1630
1642void *
1643GNUNET_xmemdup_ (const void *buf,
1644 size_t size,
1645 const char *filename,
1646 int linenumber);
1647
1648
1661void *
1662GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber);
1663
1664
1669void *
1670GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber);
1671
1672
1682void
1683GNUNET_xfree_ (void *ptr, const char *filename, int linenumber);
1684
1685
1693char *
1694GNUNET_xstrdup_ (const char *str, const char *filename, int linenumber);
1695
1705char *
1706GNUNET_xstrndup_ (const char *str,
1707 size_t len,
1708 const char *filename,
1709 int linenumber);
1710
1726void
1727GNUNET_xgrow_ (void **old,
1728 size_t elementSize,
1729 unsigned int *oldCount,
1730 unsigned int newCount,
1731 const char *filename,
1732 int linenumber);
1733
1734
1742struct GNUNET_MessageHeader *
1744
1745
1752void
1754 struct GNUNET_AsyncScopeSave *old_scope);
1755
1756
1762void
1764
1765
1771void
1773
1774
1780void
1782
1783
1784#if __STDC_VERSION__ < 199901L
1785#if __GNUC__ >= 2
1786#define __func__ __FUNCTION__
1787#else
1788#define __func__ "<unknown>"
1789#endif
1790#endif
1791
1792
1801{
1806
1811
1817
1825
1831
1837
1845
1855
1862
1863
1864#if 0 /* keep Emacsens' auto-indent happy */
1865{
1866#endif
1867#ifdef __cplusplus
1868}
1869#endif
1870
1871#endif /* GNUNET_COMMON_H */
1872 /* end of group addition */
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__
enum GNUNET_GenericReturnValue GNUNET_is_zero_(const void *a, size_t n)
Check that memory in a is all zeros.
int GNUNET_memcmp_ct_(const void *b1, const void *b2, size_t len)
Compare memory in b1 and b2 in constant time, suitable for private data.
void(* GNUNET_ResultCallback)(void *cls, int64_t result_code, const void *data, uint16_t data_size)
Function called with the result of an asynchronous operation.
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32.
double GNUNET_ntoh_double(double d)
Convert double to host byte order.
Definition: common_endian.c:83
enum GNUNET_GenericReturnValue(* GNUNET_FileNameCallback)(void *cls, const char *filename)
Function called with a filename.
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.
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.
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.
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.
#define GNUNET_PACKED
gcc-ism to get packed structs.
@ 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).
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.
uint32_t bits[16/sizeof(uint32_t)]
Saved async scope identifier or root scope.
int have_scope
GNUNET_YES unless this saved scope is the unnamed root scope.
struct GNUNET_AsyncScopeId scope_id
Saved scope.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...
A 512-bit hashcode.
uint32_t bits[512/8/sizeof(uint32_t)]
Header for all communications.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
Answer from service to client about last operation.
struct GNUNET_MessageHeader header
uint64_t result_code
Status code for the operation.
uint64_t op_id
Operation ID.
The identity of the host (wraps the signing key of the peer).
A 256-bit hashcode.
uint32_t bits[256/8/sizeof(uint32_t)]
A UUID, a 128 bit "random" value.
uint32_t value[4]
128 random bits.