GNUnet  0.11.x
gnunet_common.h
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2006-2020 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 
36 #ifndef GNUNET_COMMON_H
37 #define GNUNET_COMMON_H
38 
39 #include <stdlib.h>
40 #if HAVE_SYS_SOCKET_H
41 #include <sys/socket.h>
42 #endif
43 #if HAVE_NETINET_IN_H
44 #include <netinet/in.h>
45 #endif
46 #ifdef HAVE_STDINT_H
47 #include <stdint.h>
48 #endif
49 #ifdef HAVE_STDARG_H
50 #include <stdarg.h>
51 #endif
52 #ifdef HAVE_SYS_TYPES_H
53 #include <sys/types.h>
54 #endif
55 #ifdef HAVE_SYS_SOCKET_H
56 #include <sys/socket.h>
57 #endif
58 
59 
60 #ifdef HAVE_BYTESWAP_H
61 #include <byteswap.h>
62 #endif
63 
64 #ifdef __cplusplus
65 extern "C" {
66 #if 0 /* keep Emacsens' auto-indent happy */
67 }
68 #endif
69 #endif
70 
74 #define GNUNET_UTIL_VERSION 0x000A0104
75 
76 
84 {
86  GNUNET_NO = 0,
87  GNUNET_OK = 1,
88  /* intentionally identical to #GNUNET_OK! */
90 };
91 
92 
93 #define GNUNET_MIN(a, b) (((a) < (b)) ? (a) : (b))
94 
95 #define GNUNET_MAX(a, b) (((a) > (b)) ? (a) : (b))
96 
97 /* some systems use one underscore only, and mingw uses no underscore... */
98 #ifndef __BYTE_ORDER
99 #ifdef _BYTE_ORDER
100 #define __BYTE_ORDER _BYTE_ORDER
101 #else
102 #ifdef BYTE_ORDER
103 #define __BYTE_ORDER BYTE_ORDER
104 #endif
105 #endif
106 #endif
107 #ifndef __BIG_ENDIAN
108 #ifdef _BIG_ENDIAN
109 #define __BIG_ENDIAN _BIG_ENDIAN
110 #else
111 #ifdef BIG_ENDIAN
112 #define __BIG_ENDIAN BIG_ENDIAN
113 #endif
114 #endif
115 #endif
116 #ifndef __LITTLE_ENDIAN
117 #ifdef _LITTLE_ENDIAN
118 #define __LITTLE_ENDIAN _LITTLE_ENDIAN
119 #else
120 #ifdef LITTLE_ENDIAN
121 #define __LITTLE_ENDIAN LITTLE_ENDIAN
122 #endif
123 #endif
124 #endif
125 
129 #define GNUNET_VA_ARG_ENUM(va, X) ((enum X) va_arg (va, int))
130 
131 
137 #ifndef GNUNET_EXTRA_LOGGING
138 #define GNUNET_EXTRA_LOGGING 0
139 #endif
140 
145 #if __BYTE_ORDER == __LITTLE_ENDIAN
146 #define GNUNET_htobe16(x) __bswap_16 (x)
147 #define GNUNET_htole16(x) (x)
148 #define GNUNET_be16toh(x) __bswap_16 (x)
149 #define GNUNET_le16toh(x) (x)
150 
151 #define GNUNET_htobe32(x) __bswap_32 (x)
152 #define GNUNET_htole32(x) (x)
153 #define GNUNET_be32toh(x) __bswap_32 (x)
154 #define GNUNET_le32toh(x) (x)
155 
156 #define GNUNET_htobe64(x) __bswap_64 (x)
157 #define GNUNET_htole64(x) (x)
158 #define GNUNET_be64toh(x) __bswap_64 (x)
159 #define GNUNET_le64toh(x) (x)
160 #endif
161 #if __BYTE_ORDER == __BIG_ENDIAN
162 #define GNUNET_htobe16(x) (x)
163 #define GNUNET_htole16(x) __bswap_16 (x)
164 #define GNUNET_be16toh(x) (x)
165 #define GNUNET_le16toh(x) __bswap_16 (x)
166 
167 #define GNUNET_htobe32(x) (x)
168 #define GNUNET_htole32(x) __bswap_32 (x)
169 #define GNUNET_be32toh(x) (x)
170 #define GNUNET_le32toh(x) __bswap_32 (x)
171 
172 #define GNUNET_htobe64(x) (x)
173 #define GNUNET_htole64(x) __bswap_64 (x)
174 #define GNUNET_be64toh(x) (x)
175 #define GNUNET_le64toh(x) __bswap_64 (x)
176 #endif
177 
178 
191 #define GNUNET_NZL(l) GNUNET_MAX (1, l)
192 
193 
197 #define GNUNET_PACKED __attribute__ ((packed))
198 
202 #define GNUNET_GCC_STRUCT_LAYOUT
203 
209 #ifdef __BIGGEST_ALIGNMENT__
210 #define GNUNET_ALIGN __attribute__ ((aligned (__BIGGEST_ALIGNMENT__)))
211 #else
212 #define GNUNET_ALIGN __attribute__ ((aligned (8)))
213 #endif
214 
218 #define GNUNET_UNUSED __attribute__ ((unused))
219 
223 #define GNUNET_NORETURN __attribute__ ((noreturn))
224 
228 #define GNUNET_NETWORK_STRUCT_BEGIN
229 
233 #define GNUNET_NETWORK_STRUCT_END
234 
235 /* ************************ super-general types *********************** */
236 
238 
243 {
244  uint32_t bits[512 / 8 / sizeof(uint32_t)]; /* = 16 */
245 };
246 
247 
253 {
254  uint32_t bits[256 / 8 / sizeof(uint32_t)]; /* = 8 */
255 };
256 
257 
267 {
271  uint32_t value[4];
272 };
273 
274 
279 {
284  uint16_t size GNUNET_PACKED;
285 
289  uint16_t type GNUNET_PACKED;
290 };
291 
292 
297 {
298  struct GNUNET_MessageHeader header;
299 
301 
305  uint64_t op_id GNUNET_PACKED;
306 
310  uint64_t result_code GNUNET_PACKED;
311 
312  /* Followed by data. */
313 };
314 
315 
320 {
321  uint32_t bits[16 / sizeof(uint32_t)]; /* = 16 bytes */
322 };
323 
325 
326 
331 {
335  struct GNUNET_AsyncScopeId scope_id;
336 
341 };
342 
343 
353 typedef enum GNUNET_GenericReturnValue
355  const char *filename);
356 
357 
363 typedef void
365 
366 
379 typedef void
380 (*GNUNET_ResultCallback) (void *cls,
381  int64_t result_code,
382  const void *data,
383  uint16_t data_size);
384 
385 
386 /* ****************************** logging ***************************** */
387 
393 {
398  /* UX: We need a message type that is output by
399  * default without looking like there is a problem.
400  */
406 };
407 
408 
419 typedef void (*GNUNET_Logger) (void *cls,
420  enum GNUNET_ErrorType kind,
421  const char *component,
422  const char *date,
423  const char *message);
424 
425 
432 int
433 GNUNET_get_log_skip (void);
434 
435 
436 #if ! defined(GNUNET_CULL_LOGGING)
437 int
438 GNUNET_get_log_call_status (int caller_level,
439  const char *comp,
440  const char *file,
441  const char *function,
442  int line);
443 
444 #endif
445 
446 
455 void
456 GNUNET_log_nocheck (enum GNUNET_ErrorType kind, const char *message, ...)
457 __attribute__ ((format (printf, 2, 3)));
458 
459 /* from glib */
460 #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
461 #define _GNUNET_BOOLEAN_EXPR(expr) \
462  __extension__ ({ \
463  int _gnunet_boolean_var_; \
464  if (expr) \
465  _gnunet_boolean_var_ = 1; \
466  else \
467  _gnunet_boolean_var_ = 0; \
468  _gnunet_boolean_var_; \
469  })
470 #define GN_LIKELY(expr) (__builtin_expect (_GNUNET_BOOLEAN_EXPR (expr), 1))
471 #define GN_UNLIKELY(expr) (__builtin_expect (_GNUNET_BOOLEAN_EXPR (expr), 0))
472 #else
473 #define GN_LIKELY(expr) (expr)
474 #define GN_UNLIKELY(expr) (expr)
475 #endif
476 
477 #if ! defined(GNUNET_LOG_CALL_STATUS)
478 #define GNUNET_LOG_CALL_STATUS -1
479 #endif
480 
481 
492 void
494  const char *comp,
495  const char *message,
496  ...)
497 __attribute__ ((format (printf, 3, 4)));
498 
499 #if ! defined(GNUNET_CULL_LOGGING)
500 #define GNUNET_log_from(kind, comp, ...) \
501  do \
502  { \
503  static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \
504  if ((GNUNET_EXTRA_LOGGING > 0) || \
505  ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \
506  { \
507  if (GN_UNLIKELY (log_call_enabled == -1)) \
508  log_call_enabled = \
509  GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \
510  (comp), \
511  __FILE__, \
512  __FUNCTION__, \
513  __LINE__); \
514  if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \
515  { \
516  GNUNET_log_skip (-1, GNUNET_NO); \
517  } \
518  else \
519  { \
520  if (GN_UNLIKELY (log_call_enabled)) \
521  GNUNET_log_from_nocheck ((kind), comp, __VA_ARGS__); \
522  } \
523  } \
524  } while (0)
525 
526 #define GNUNET_log(kind, ...) \
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  NULL, \
537  __FILE__, \
538  __FUNCTION__, \
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_nocheck ((kind), __VA_ARGS__); \
548  } \
549  } \
550  } while (0)
551 #else
552 #define GNUNET_log(...)
553 #define GNUNET_log_from(...)
554 #endif
555 
556 
565 void
567  const char *section,
568  const char *option);
569 
570 
580 void
582  const char *section,
583  const char *option,
584  const char *required);
585 
586 
593 void
595 
596 
604 void
605 GNUNET_log_skip (int n, int check_reset);
606 
607 
617 int
618 GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile);
619 
620 
631 void
632 GNUNET_logger_add (GNUNET_Logger logger, void *logger_cls);
633 
634 
642 void
643 GNUNET_logger_remove (GNUNET_Logger logger, void *logger_cls);
644 
645 
655 const char *
656 GNUNET_sh2s (const struct GNUNET_ShortHashCode *shc);
657 
658 
668 const char *
669 GNUNET_uuid2s (const struct GNUNET_Uuid *uuid);
670 
671 
681 const char *
682 GNUNET_h2s (const struct GNUNET_HashCode *hc);
683 
684 
696 const char *
697 GNUNET_h2s2 (const struct GNUNET_HashCode *hc);
698 
699 
710 const char *
711 GNUNET_h2s_full (const struct GNUNET_HashCode *hc);
712 
713 
718 
719 
724 
725 
735 const char *
737 
738 
748 const char *
750 
751 
761 const char *
763 
764 
774 const char *
776 
777 
781 struct GNUNET_PeerIdentity;
782 
783 
794 const char *
795 GNUNET_i2s (const struct GNUNET_PeerIdentity *pid);
796 
797 
810 const char *
811 GNUNET_i2s2 (const struct GNUNET_PeerIdentity *pid);
812 
813 
824 const char *
825 GNUNET_i2s_full (const struct GNUNET_PeerIdentity *pid);
826 
827 
839 const char *
840 GNUNET_a2s (const struct sockaddr *addr, socklen_t addrlen);
841 
842 
850 const char *
852 
853 
858 #define GNUNET_assert(cond) \
859  do \
860  { \
861  if (! (cond)) \
862  { \
863  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
864  _ ("Assertion failed at %s:%d. Aborting.\n"), \
865  __FILE__, \
866  __LINE__); \
867  GNUNET_abort_ (); \
868  } \
869  } while (0)
870 
871 
876 #define GNUNET_assert_at(cond, f, l) \
877  do \
878  { \
879  if (! (cond)) \
880  { \
881  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
882  _ ("Assertion failed at %s:%d. Aborting.\n"), \
883  f, \
884  l); \
885  GNUNET_abort_ (); \
886  } \
887  } while (0)
888 
889 
897 #define GNUNET_assert_from(cond, comp) \
898  do \
899  { \
900  if (! (cond)) \
901  { \
902  GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, \
903  comp, \
904  _ ("Assertion failed at %s:%d. Aborting.\n"), \
905  __FILE__, \
906  __LINE__); \
907  GNUNET_abort_ (); \
908  } \
909  } while (0)
910 
911 
912 #if HAVE_STATIC_ASSERT
913 
920 #define GNUNET_static_assert(cond) _Static_assert (cond, "")
921 #else
922 
930 #define GNUNET_static_assert(cond) GNUNET_assert (cond)
931 #endif
932 
933 
939 #define GNUNET_break(cond) \
940  do \
941  { \
942  if (! (cond)) \
943  { \
944  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
945  _ ("Assertion failed at %s:%d.\n"), \
946  __FILE__, \
947  __LINE__); \
948  } \
949  } while (0)
950 
951 
961 #define GNUNET_break_op(cond) \
962  do \
963  { \
964  if (! (cond)) \
965  { \
966  GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, \
967  _ ("External protocol violation detected at %s:%d.\n"), \
968  __FILE__, \
969  __LINE__); \
970  } \
971  } while (0)
972 
973 
980 #define GNUNET_log_strerror(level, cmd) \
981  do \
982  { \
983  GNUNET_log (level, \
984  _ ("`%s' failed at %s:%d with error: %s\n"), \
985  cmd, \
986  __FILE__, \
987  __LINE__, \
988  strerror (errno)); \
989  } while (0)
990 
991 
998 #define GNUNET_log_from_strerror(level, component, cmd) \
999  do \
1000  { \
1001  GNUNET_log_from (level, \
1002  component, \
1003  _ ("`%s' failed at %s:%d with error: %s\n"), \
1004  cmd, \
1005  __FILE__, \
1006  __LINE__, \
1007  strerror (errno)); \
1008  } while (0)
1009 
1010 
1017 #define GNUNET_log_strerror_file(level, cmd, filename) \
1018  do \
1019  { \
1020  GNUNET_log (level, \
1021  _ ("`%s' failed on file `%s' at %s:%d with error: %s\n"), \
1022  cmd, \
1023  filename, \
1024  __FILE__, \
1025  __LINE__, \
1026  strerror (errno)); \
1027  } while (0)
1028 
1029 
1036 #define GNUNET_log_from_strerror_file(level, component, cmd, filename) \
1037  do \
1038  { \
1039  GNUNET_log_from (level, \
1040  component, \
1041  _ ("`%s' failed on file `%s' at %s:%d with error: %s\n"), \
1042  cmd, \
1043  filename, \
1044  __FILE__, \
1045  __LINE__, \
1046  strerror (errno)); \
1047  } while (0)
1048 
1049 /* ************************* endianness conversion ****************** */
1050 
1051 #ifdef htonbe64
1052 
1053 #define GNUNET_htonll(n) htobe64 (n)
1054 
1055 #else
1056 
1064 uint64_t
1065 GNUNET_htonll (uint64_t n);
1066 
1067 #endif
1068 
1069 
1070 #ifdef be64toh
1071 
1072 #define GNUNET_ntohll(n) be64toh (n)
1073 
1074 #else
1075 
1083 uint64_t
1084 GNUNET_ntohll (uint64_t n);
1085 
1086 #endif
1087 
1088 
1097 double
1098 GNUNET_hton_double (double d);
1099 
1100 
1109 double
1110 GNUNET_ntoh_double (double d);
1111 
1112 
1113 /* ************************* allocation functions ****************** */
1114 
1119 #define GNUNET_MAX_MALLOC_CHECKED (1024 * 1024 * 40)
1120 
1129 #define GNUNET_new(type) (type *) GNUNET_malloc (sizeof(type))
1130 
1131 
1139 #define GNUNET_memcmp(a, b) \
1140  ({ \
1141  const typeof (*b) * _a = (a); \
1142  const typeof (*a) * _b = (b); \
1143  memcmp (_a, _b, sizeof(*a)); \
1144  })
1145 
1146 
1156 int
1157 GNUNET_memcmp_ct_ (const void *b1,
1158  const void *b2,
1159  size_t len);
1160 
1168 #define GNUNET_memcmp_priv(a, b) \
1169  ({ \
1170  const typeof (*b) * _a = (a); \
1171  const typeof (*a) * _b = (b); \
1172  GNUNET_memcmp_ct_ (_a, _b, sizeof(*a)); \
1173  })
1174 
1175 
1185 GNUNET_is_zero_ (const void *a,
1186  size_t n);
1187 
1188 
1196 #define GNUNET_is_zero(a) \
1197  GNUNET_is_zero_ (a, sizeof (*a))
1198 
1199 
1209 #define GNUNET_memcpy(dst, src, n) \
1210  do \
1211  { \
1212  if (0 != n) \
1213  { \
1214  (void) memcpy (dst, src, n); \
1215  } \
1216  } while (0)
1217 
1218 
1228 #define GNUNET_new_array(n, type) ({ \
1229  GNUNET_assert (SIZE_MAX / sizeof (type) >= n); \
1230  (type *) GNUNET_malloc ((n) * sizeof(type)); \
1231  })
1232 
1242 #define GNUNET_new_array_2d(n, m, type) \
1243  (type **) GNUNET_xnew_array_2d_ (n, m, sizeof(type), __FILE__, __LINE__)
1244 
1255 #define GNUNET_new_array_3d(n, m, o, type) \
1256  (type ***) GNUNET_xnew_array_3d_ (n, m, o, sizeof(type), __FILE__, __LINE__)
1257 
1267 #define GNUNET_malloc(size) GNUNET_xmalloc_ (size, __FILE__, __LINE__)
1268 
1277 #define GNUNET_memdup(buf, size) GNUNET_xmemdup_ (buf, size, __FILE__, __LINE__)
1278 
1287 #define GNUNET_malloc_large(size) \
1288  GNUNET_xmalloc_unchecked_ (size, __FILE__, __LINE__)
1289 
1290 
1300 #define GNUNET_realloc(ptr, size) \
1301  GNUNET_xrealloc_ (ptr, size, __FILE__, __LINE__)
1302 
1303 
1313 #define GNUNET_free_nz(ptr) GNUNET_xfree_ (ptr, __FILE__, __LINE__)
1314 
1315 
1327 #define GNUNET_free(ptr) do { \
1328  GNUNET_xfree_ (ptr, __FILE__, __LINE__); \
1329  ptr = NULL; \
1330 } while (0)
1331 
1332 
1341 #define GNUNET_strdup(a) GNUNET_xstrdup_ (a, __FILE__, __LINE__)
1342 
1352 #define GNUNET_strndup(a, length) \
1353  GNUNET_xstrndup_ (a, length, __FILE__, __LINE__)
1354 
1390 #define GNUNET_array_grow(arr, size, tsize) \
1391  GNUNET_xgrow_ ((void **) &(arr), \
1392  sizeof((arr)[0]), \
1393  &size, \
1394  tsize, \
1395  __FILE__, \
1396  __LINE__)
1397 
1411 #define GNUNET_array_append(arr, len, element) \
1412  do \
1413  { \
1414  GNUNET_assert ((len) + 1 > (len)); \
1415  GNUNET_array_grow (arr, len, len + 1); \
1416  (arr) [len - 1] = element; \
1417  } while (0)
1418 
1419 
1443 #define GNUNET_array_concatenate(arr1, len1, arr2, len2) \
1444  do \
1445  { \
1446  const typeof (*arr2) * _a1 = (arr1); \
1447  const typeof (*arr1) * _a2 = (arr2); \
1448  GNUNET_assert ((len1) + (len2) >= (len1)); \
1449  GNUNET_assert (SIZE_MAX / sizeof (*_a1) >= ((len1) + (len2))); \
1450  GNUNET_array_grow (arr1, len1, (len1) + (len2)); \
1451  memcpy (&(arr1) [(len1) - (len2)], _a2, (len2) * sizeof (*arr1)); \
1452  } while (0)
1453 
1454 
1465 int
1466 GNUNET_snprintf (char *buf,
1467  size_t size,
1468  const char *format,
1469  ...)
1470 __attribute__ ((format (printf, 3, 4)));
1471 
1472 
1482 int
1483 GNUNET_asprintf (char **buf,
1484  const char *format,
1485  ...)
1486 __attribute__ ((format (printf, 2, 3)));
1487 
1488 
1489 /* ************** internal implementations, use macros above! ************** */
1490 
1502 void *
1503 GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber);
1504 
1505 
1520 void **
1521 GNUNET_xnew_array_2d_ (size_t n,
1522  size_t m,
1523  size_t elementSize,
1524  const char *filename,
1525  int linenumber);
1526 
1527 
1543 void ***
1544 GNUNET_xnew_array_3d_ (size_t n,
1545  size_t m,
1546  size_t o,
1547  size_t elementSize,
1548  const char *filename,
1549  int linenumber);
1550 
1551 
1563 void *
1564 GNUNET_xmemdup_ (const void *buf,
1565  size_t size,
1566  const char *filename,
1567  int linenumber);
1568 
1569 
1582 void *
1583 GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber);
1584 
1585 
1590 void *
1591 GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber);
1592 
1593 
1603 void
1604 GNUNET_xfree_ (void *ptr, const char *filename, int linenumber);
1605 
1606 
1614 char *
1615 GNUNET_xstrdup_ (const char *str, const char *filename, int linenumber);
1616 
1626 char *
1627 GNUNET_xstrndup_ (const char *str,
1628  size_t len,
1629  const char *filename,
1630  int linenumber);
1631 
1647 void
1648 GNUNET_xgrow_ (void **old,
1649  size_t elementSize,
1650  unsigned int *oldCount,
1651  unsigned int newCount,
1652  const char *filename,
1653  int linenumber);
1654 
1655 
1663 struct GNUNET_MessageHeader *
1665 
1666 
1673 void
1675  struct GNUNET_AsyncScopeSave *old_scope);
1676 
1677 
1683 void
1685 
1686 
1692 void
1693 GNUNET_async_scope_get (struct GNUNET_AsyncScopeSave *scope_ret);
1694 
1695 
1701 void
1703 
1704 
1705 #if __STDC_VERSION__ < 199901L
1706 #if __GNUC__ >= 2
1707 #define __func__ __FUNCTION__
1708 #else
1709 #define __func__ "<unknown>"
1710 #endif
1711 #endif
1712 
1713 
1722 {
1727 
1732 
1738 
1746 
1752 
1758 
1766 
1776 
1782 };
1783 
1784 
1785 #if 0 /* keep Emacsens' auto-indent happy */
1786 {
1787 #endif
1788 #ifdef __cplusplus
1789 }
1790 #endif
1791 
1792 #endif /* GNUNET_COMMON_H */
void GNUNET_logger_add(GNUNET_Logger logger, void *logger_cls)
Add a custom logger.
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.
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
Run with high priority (important requests).
const char * GNUNET_i2s2(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
void GNUNET_xfree_(void *ptr, const char *filename, int linenumber)
Free memory.
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.
void GNUNET_logger_remove(GNUNET_Logger logger, void *logger_cls)
Remove a custom logger.
const char * GNUNET_error_type_to_string(enum GNUNET_ErrorType kind)
Convert error type to string.
const char * GNUNET_e2s2(const struct GNUNET_CRYPTO_EcdhePublicKey *p)
Convert a public key value to a string (for printing debug messages).
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
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.
void(* GNUNET_ContinuationCallback)(void *cls)
Generic continuation callback.
Run with the same priority as the current job.
const char * GNUNET_p2s2(const struct GNUNET_CRYPTO_EddsaPublicKey *p)
Convert a public key value to a string (for printing debug messages).
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:83
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).
GNUNET_ErrorType
Types of errors.
enum GNUNET_GenericReturnValue GNUNET_is_zero_(const void *a, size_t n)
Check that memory in a is all zeros.
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.
Identifier for an asynchronous execution context.
GNUNET_SCHEDULER_Priority
Valid task priorities.
Run as background job (higher than idle, lower than default).
static char * component
Running component.
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won&#39;t work on W32.
A 256-bit hashcode.
static char * section
Name of the section.
Definition: gnunet-config.c:33
void GNUNET_async_scope_enter(const struct GNUNET_AsyncScopeId *aid, struct GNUNET_AsyncScopeSave *old_scope)
Set the async scope for the current thread.
void GNUNET_abort_(void) __attribute__((noreturn))
Abort the process, generate a core dump if possible.
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 struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
void * GNUNET_xmemdup_(const void *buf, size_t size, const char *filename, int linenumber)
Allocate and initialize memory.
const char * GNUNET_h2s2(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
static char * line
Desired phone line (string to be converted to a hash).
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
static char * value
Value of the record to add/remove.
const char * GNUNET_p2s(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).
Run with priority for interactive tasks.
static char * option
Name of the option.
Definition: gnunet-config.c:38
static char buf[2048]
static char * filename
A UUID, a 128 bit "random" value.
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)...
char * GNUNET_xstrndup_(const char *str, size_t len, const char *filename, int linenumber)
Dup partially a string.
A 512-bit hashcode.
void GNUNET_async_scope_get(struct GNUNET_AsyncScopeSave *scope_ret)
Get the current async scope.
Run when otherwise idle.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:36
This is an internal priority level that is only used for tasks that are being triggered due to shutdo...
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.
static unsigned int size
Size of the "table".
Definition: peer.c:67
int have_scope
GNUNET_YES unless this saved scope is the unnamed root scope.
double GNUNET_ntoh_double(double d)
Convert double to host byte order.
Definition: common_endian.c:92
Saved async scope identifier or root scope.
const char * GNUNET_h2s_full(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
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_async_scope_restore(struct GNUNET_AsyncScopeSave *old_scope)
Clear the current thread&#39;s async scope.
void * GNUNET_xmalloc_unchecked_(size_t size, const char *filename, int linenumber)
Allocate memory.
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.
#define GNUNET_NORETURN
gcc-ism to document functions that don&#39;t return
int int void * GNUNET_xmalloc_(size_t size, const char *filename, int linenumber)
Allocate memory.
#define GNUNET_NETWORK_STRUCT_END
Define as empty, GNUNET_PACKED should suffice, but this won&#39;t work on W32;.
Answer from service to client about last operation.
enum RadiotapType __attribute__
The identity of the host (wraps the signing key of the peer).
#define GNUNET_PACKED
gcc-ism to get packed structs.
void GNUNET_log_skip(int n, int check_reset)
Ignore the next n calls to the log function.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
enum GNUNET_GenericReturnValue(* GNUNET_FileNameCallback)(void *cls, const char *filename)
Function called with a filename.
char * GNUNET_xstrdup_(const char *str, const char *filename, int linenumber)
Dup a string.
Run with priority for urgent tasks.
void * GNUNET_xrealloc_(void *ptr, size_t n, const char *filename, int linenumber)
Reallocate memory.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
void GNUNET_log_nocheck(enum GNUNET_ErrorType kind, const char *message,...) __attribute__((format(printf
Main log function.
Header for all communications.
int GNUNET_get_log_skip(void)
Get the number of log calls that are going to be skipped.
Number of priorities (must be the last priority).
static unsigned long long reserved
How much space have we currently reserved?
void GNUNET_async_scope_fresh(struct GNUNET_AsyncScopeId *aid_ret)
Generate a fresh async scope identifier.
Run with the default priority (normal P2P operations).
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
const char * GNUNET_e2s(const struct GNUNET_CRYPTO_EcdhePublicKey *p)
Convert a public key value to a string (for printing debug messages).
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
void(* GNUNET_Logger)(void *cls, enum GNUNET_ErrorType kind, const char *component, const char *date, const char *message)
User-defined handler for log messages.
uint32_t data
The data value.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
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.
double GNUNET_hton_double(double d)
Convert double to network byte order.
Definition: common_endian.c:74
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:53
struct GNUNET_MessageHeader * GNUNET_copy_message(const struct GNUNET_MessageHeader *msg)
Create a copy of the given message.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
uint32_t bits[512/8/sizeof(uint32_t)]
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...