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 0x000A0103
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 
262 {
266  uint32_t value[4];
267 };
268 
269 
274 {
279  uint16_t size GNUNET_PACKED;
280 
284  uint16_t type GNUNET_PACKED;
285 };
286 
287 
292 {
293  struct GNUNET_MessageHeader header;
294 
296 
300  uint64_t op_id GNUNET_PACKED;
301 
305  uint64_t result_code GNUNET_PACKED;
306 
307  /* Followed by data. */
308 };
309 
310 
315 {
316  uint32_t bits[16 / sizeof(uint32_t)]; /* = 16 bytes */
317 };
318 
320 
321 
326 {
330  struct GNUNET_AsyncScopeId scope_id;
331 
336 };
337 
338 
348 typedef int
350  const char *filename);
351 
352 
358 typedef void
360 
361 
374 typedef void
375 (*GNUNET_ResultCallback) (void *cls,
376  int64_t result_code,
377  const void *data,
378  uint16_t data_size);
379 
380 
381 /* ****************************** logging ***************************** */
382 
388 {
393  /* UX: We need a message type that is output by
394  * default without looking like there is a problem.
395  */
401 };
402 
403 
414 typedef void (*GNUNET_Logger) (void *cls,
415  enum GNUNET_ErrorType kind,
416  const char *component,
417  const char *date,
418  const char *message);
419 
420 
427 int
428 GNUNET_get_log_skip (void);
429 
430 
431 #if ! defined(GNUNET_CULL_LOGGING)
432 int
433 GNUNET_get_log_call_status (int caller_level,
434  const char *comp,
435  const char *file,
436  const char *function,
437  int line);
438 
439 #endif
440 
441 
450 void
451 GNUNET_log_nocheck (enum GNUNET_ErrorType kind, const char *message, ...)
452 __attribute__ ((format (printf, 2, 3)));
453 
454 /* from glib */
455 #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
456 #define _GNUNET_BOOLEAN_EXPR(expr) \
457  __extension__ ({ \
458  int _gnunet_boolean_var_; \
459  if (expr) \
460  _gnunet_boolean_var_ = 1; \
461  else \
462  _gnunet_boolean_var_ = 0; \
463  _gnunet_boolean_var_; \
464  })
465 #define GN_LIKELY(expr) (__builtin_expect (_GNUNET_BOOLEAN_EXPR (expr), 1))
466 #define GN_UNLIKELY(expr) (__builtin_expect (_GNUNET_BOOLEAN_EXPR (expr), 0))
467 #else
468 #define GN_LIKELY(expr) (expr)
469 #define GN_UNLIKELY(expr) (expr)
470 #endif
471 
472 #if ! defined(GNUNET_LOG_CALL_STATUS)
473 #define GNUNET_LOG_CALL_STATUS -1
474 #endif
475 
476 
487 void
489  const char *comp,
490  const char *message,
491  ...)
492 __attribute__ ((format (printf, 3, 4)));
493 
494 #if ! defined(GNUNET_CULL_LOGGING)
495 #define GNUNET_log_from(kind, comp, ...) \
496  do \
497  { \
498  static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \
499  if ((GNUNET_EXTRA_LOGGING > 0) || \
500  ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \
501  { \
502  if (GN_UNLIKELY (log_call_enabled == -1)) \
503  log_call_enabled = \
504  GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \
505  (comp), \
506  __FILE__, \
507  __FUNCTION__, \
508  __LINE__); \
509  if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \
510  { \
511  GNUNET_log_skip (-1, GNUNET_NO); \
512  } \
513  else \
514  { \
515  if (GN_UNLIKELY (log_call_enabled)) \
516  GNUNET_log_from_nocheck ((kind), comp, __VA_ARGS__); \
517  } \
518  } \
519  } while (0)
520 
521 #define GNUNET_log(kind, ...) \
522  do \
523  { \
524  static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \
525  if ((GNUNET_EXTRA_LOGGING > 0) || \
526  ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \
527  { \
528  if (GN_UNLIKELY (log_call_enabled == -1)) \
529  log_call_enabled = \
530  GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \
531  NULL, \
532  __FILE__, \
533  __FUNCTION__, \
534  __LINE__); \
535  if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \
536  { \
537  GNUNET_log_skip (-1, GNUNET_NO); \
538  } \
539  else \
540  { \
541  if (GN_UNLIKELY (log_call_enabled)) \
542  GNUNET_log_nocheck ((kind), __VA_ARGS__); \
543  } \
544  } \
545  } while (0)
546 #else
547 #define GNUNET_log(...)
548 #define GNUNET_log_from(...)
549 #endif
550 
551 
560 void
562  const char *section,
563  const char *option);
564 
565 
575 void
577  const char *section,
578  const char *option,
579  const char *required);
580 
581 
588 void
590 
591 
599 void
600 GNUNET_log_skip (int n, int check_reset);
601 
602 
612 int
613 GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile);
614 
615 
626 void
627 GNUNET_logger_add (GNUNET_Logger logger, void *logger_cls);
628 
629 
637 void
638 GNUNET_logger_remove (GNUNET_Logger logger, void *logger_cls);
639 
640 
650 const char *
651 GNUNET_sh2s (const struct GNUNET_ShortHashCode *shc);
652 
653 
663 const char *
664 GNUNET_uuid2s (const struct GNUNET_Uuid *uuid);
665 
666 
676 const char *
677 GNUNET_h2s (const struct GNUNET_HashCode *hc);
678 
679 
691 const char *
692 GNUNET_h2s2 (const struct GNUNET_HashCode *hc);
693 
694 
705 const char *
706 GNUNET_h2s_full (const struct GNUNET_HashCode *hc);
707 
708 
713 
714 
719 
720 
730 const char *
732 
733 
743 const char *
745 
746 
756 const char *
758 
759 
769 const char *
771 
772 
776 struct GNUNET_PeerIdentity;
777 
778 
789 const char *
790 GNUNET_i2s (const struct GNUNET_PeerIdentity *pid);
791 
792 
805 const char *
806 GNUNET_i2s2 (const struct GNUNET_PeerIdentity *pid);
807 
808 
819 const char *
820 GNUNET_i2s_full (const struct GNUNET_PeerIdentity *pid);
821 
822 
834 const char *
835 GNUNET_a2s (const struct sockaddr *addr, socklen_t addrlen);
836 
837 
845 const char *
847 
848 
853 #define GNUNET_assert(cond) \
854  do \
855  { \
856  if (! (cond)) \
857  { \
858  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
859  _ ("Assertion failed at %s:%d. Aborting.\n"), \
860  __FILE__, \
861  __LINE__); \
862  GNUNET_abort_ (); \
863  } \
864  } while (0)
865 
866 
871 #define GNUNET_assert_at(cond, f, l) \
872  do \
873  { \
874  if (! (cond)) \
875  { \
876  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
877  _ ("Assertion failed at %s:%d. Aborting.\n"), \
878  f, \
879  l); \
880  GNUNET_abort_ (); \
881  } \
882  } while (0)
883 
884 
892 #define GNUNET_assert_from(cond, comp) \
893  do \
894  { \
895  if (! (cond)) \
896  { \
897  GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, \
898  comp, \
899  _ ("Assertion failed at %s:%d. Aborting.\n"), \
900  __FILE__, \
901  __LINE__); \
902  GNUNET_abort_ (); \
903  } \
904  } while (0)
905 
906 
907 #if HAVE_STATIC_ASSERT
908 
915 #define GNUNET_static_assert(cond) _Static_assert (cond, "")
916 #else
917 
925 #define GNUNET_static_assert(cond) GNUNET_assert (cond)
926 #endif
927 
928 
934 #define GNUNET_break(cond) \
935  do \
936  { \
937  if (! (cond)) \
938  { \
939  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
940  _ ("Assertion failed at %s:%d.\n"), \
941  __FILE__, \
942  __LINE__); \
943  } \
944  } while (0)
945 
946 
956 #define GNUNET_break_op(cond) \
957  do \
958  { \
959  if (! (cond)) \
960  { \
961  GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, \
962  _ ("External protocol violation detected at %s:%d.\n"), \
963  __FILE__, \
964  __LINE__); \
965  } \
966  } while (0)
967 
968 
975 #define GNUNET_log_strerror(level, cmd) \
976  do \
977  { \
978  GNUNET_log (level, \
979  _ ("`%s' failed at %s:%d with error: %s\n"), \
980  cmd, \
981  __FILE__, \
982  __LINE__, \
983  strerror (errno)); \
984  } while (0)
985 
986 
993 #define GNUNET_log_from_strerror(level, component, cmd) \
994  do \
995  { \
996  GNUNET_log_from (level, \
997  component, \
998  _ ("`%s' failed at %s:%d with error: %s\n"), \
999  cmd, \
1000  __FILE__, \
1001  __LINE__, \
1002  strerror (errno)); \
1003  } while (0)
1004 
1005 
1012 #define GNUNET_log_strerror_file(level, cmd, filename) \
1013  do \
1014  { \
1015  GNUNET_log (level, \
1016  _ ("`%s' failed on file `%s' at %s:%d with error: %s\n"), \
1017  cmd, \
1018  filename, \
1019  __FILE__, \
1020  __LINE__, \
1021  strerror (errno)); \
1022  } while (0)
1023 
1024 
1031 #define GNUNET_log_from_strerror_file(level, component, cmd, filename) \
1032  do \
1033  { \
1034  GNUNET_log_from (level, \
1035  component, \
1036  _ ("`%s' failed on file `%s' at %s:%d with error: %s\n"), \
1037  cmd, \
1038  filename, \
1039  __FILE__, \
1040  __LINE__, \
1041  strerror (errno)); \
1042  } while (0)
1043 
1044 /* ************************* endianness conversion ****************** */
1045 
1046 #ifdef htonbe64
1047 
1048 #define GNUNET_htonll(n) htobe64 (n)
1049 
1050 #else
1051 
1059 uint64_t
1060 GNUNET_htonll (uint64_t n);
1061 
1062 #endif
1063 
1064 
1065 #ifdef be64toh
1066 
1067 #define GNUNET_ntohll(n) be64toh (n)
1068 
1069 #else
1070 
1078 uint64_t
1079 GNUNET_ntohll (uint64_t n);
1080 
1081 #endif
1082 
1083 
1092 double
1093 GNUNET_hton_double (double d);
1094 
1095 
1104 double
1105 GNUNET_ntoh_double (double d);
1106 
1107 
1108 /* ************************* allocation functions ****************** */
1109 
1114 #define GNUNET_MAX_MALLOC_CHECKED (1024 * 1024 * 40)
1115 
1124 #define GNUNET_new(type) (type *) GNUNET_malloc (sizeof(type))
1125 
1126 
1134 #define GNUNET_memcmp(a, b) \
1135  ({ \
1136  const typeof (*b) * _a = (a); \
1137  const typeof (*a) * _b = (b); \
1138  memcmp (_a, _b, sizeof(*a)); \
1139  })
1140 
1141 
1151 int
1152 GNUNET_memcmp_ct_ (const void *b1,
1153  const void *b2,
1154  size_t len);
1155 
1163 #define GNUNET_memcmp_priv(a, b) \
1164  ({ \
1165  const typeof (*b) * _a = (a); \
1166  const typeof (*a) * _b = (b); \
1167  GNUNET_memcmp_ct_ (_a, _b, sizeof(*a)); \
1168  })
1169 
1170 
1180 GNUNET_is_zero_ (const void *a,
1181  size_t n);
1182 
1183 
1191 #define GNUNET_is_zero(a) \
1192  GNUNET_is_zero_ (a, sizeof (*a))
1193 
1194 
1204 #define GNUNET_memcpy(dst, src, n) \
1205  do \
1206  { \
1207  if (0 != n) \
1208  { \
1209  (void) memcpy (dst, src, n); \
1210  } \
1211  } while (0)
1212 
1213 
1223 #define GNUNET_new_array(n, type) ({ \
1224  GNUNET_assert (SIZE_MAX / sizeof (type) >= n); \
1225  (type *) GNUNET_malloc ((n) * sizeof(type)); \
1226  })
1227 
1237 #define GNUNET_new_array_2d(n, m, type) \
1238  (type **) GNUNET_xnew_array_2d_ (n, m, sizeof(type), __FILE__, __LINE__)
1239 
1250 #define GNUNET_new_array_3d(n, m, o, type) \
1251  (type ***) GNUNET_xnew_array_3d_ (n, m, o, sizeof(type), __FILE__, __LINE__)
1252 
1262 #define GNUNET_malloc(size) GNUNET_xmalloc_ (size, __FILE__, __LINE__)
1263 
1272 #define GNUNET_memdup(buf, size) GNUNET_xmemdup_ (buf, size, __FILE__, __LINE__)
1273 
1282 #define GNUNET_malloc_large(size) \
1283  GNUNET_xmalloc_unchecked_ (size, __FILE__, __LINE__)
1284 
1285 
1295 #define GNUNET_realloc(ptr, size) \
1296  GNUNET_xrealloc_ (ptr, size, __FILE__, __LINE__)
1297 
1298 
1308 #define GNUNET_free_nz(ptr) GNUNET_xfree_ (ptr, __FILE__, __LINE__)
1309 
1310 
1322 #define GNUNET_free(ptr) do { \
1323  GNUNET_xfree_ (ptr, __FILE__, __LINE__); \
1324  ptr = NULL; \
1325 } while (0)
1326 
1327 
1336 #define GNUNET_strdup(a) GNUNET_xstrdup_ (a, __FILE__, __LINE__)
1337 
1347 #define GNUNET_strndup(a, length) \
1348  GNUNET_xstrndup_ (a, length, __FILE__, __LINE__)
1349 
1385 #define GNUNET_array_grow(arr, size, tsize) \
1386  GNUNET_xgrow_ ((void **) &(arr), \
1387  sizeof((arr)[0]), \
1388  &size, \
1389  tsize, \
1390  __FILE__, \
1391  __LINE__)
1392 
1406 #define GNUNET_array_append(arr, len, element) \
1407  do \
1408  { \
1409  GNUNET_assert ((len) + 1 > (len)); \
1410  GNUNET_array_grow (arr, len, len + 1); \
1411  (arr) [len - 1] = element; \
1412  } while (0)
1413 
1414 
1438 #define GNUNET_array_concatenate(arr1, len1, arr2, len2) \
1439  do \
1440  { \
1441  const typeof (*arr2) * _a1 = (arr1); \
1442  const typeof (*arr1) * _a2 = (arr2); \
1443  GNUNET_assert ((len1) + (len2) >= (len1)); \
1444  GNUNET_assert (SIZE_MAX / sizeof (*_a1) >= ((len1) + (len2))); \
1445  GNUNET_array_grow (arr1, len1, (len1) + (len2)); \
1446  memcpy (&(arr1) [(len1) - (len2)], _a2, (len2) * sizeof (*arr1)); \
1447  } while (0)
1448 
1449 
1460 int
1461 GNUNET_snprintf (char *buf,
1462  size_t size,
1463  const char *format,
1464  ...)
1465 __attribute__ ((format (printf, 3, 4)));
1466 
1467 
1477 int
1478 GNUNET_asprintf (char **buf,
1479  const char *format,
1480  ...)
1481 __attribute__ ((format (printf, 2, 3)));
1482 
1483 
1484 /* ************** internal implementations, use macros above! ************** */
1485 
1497 void *
1498 GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber);
1499 
1500 
1515 void **
1516 GNUNET_xnew_array_2d_ (size_t n,
1517  size_t m,
1518  size_t elementSize,
1519  const char *filename,
1520  int linenumber);
1521 
1522 
1538 void ***
1539 GNUNET_xnew_array_3d_ (size_t n,
1540  size_t m,
1541  size_t o,
1542  size_t elementSize,
1543  const char *filename,
1544  int linenumber);
1545 
1546 
1558 void *
1559 GNUNET_xmemdup_ (const void *buf,
1560  size_t size,
1561  const char *filename,
1562  int linenumber);
1563 
1564 
1577 void *
1578 GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber);
1579 
1580 
1585 void *
1586 GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber);
1587 
1588 
1598 void
1599 GNUNET_xfree_ (void *ptr, const char *filename, int linenumber);
1600 
1601 
1609 char *
1610 GNUNET_xstrdup_ (const char *str, const char *filename, int linenumber);
1611 
1621 char *
1622 GNUNET_xstrndup_ (const char *str,
1623  size_t len,
1624  const char *filename,
1625  int linenumber);
1626 
1642 void
1643 GNUNET_xgrow_ (void **old,
1644  size_t elementSize,
1645  unsigned int *oldCount,
1646  unsigned int newCount,
1647  const char *filename,
1648  int linenumber);
1649 
1650 
1658 struct GNUNET_MessageHeader *
1660 
1661 
1668 void
1670  struct GNUNET_AsyncScopeSave *old_scope);
1671 
1672 
1678 void
1680 
1681 
1687 void
1688 GNUNET_async_scope_get (struct GNUNET_AsyncScopeSave *scope_ret);
1689 
1690 
1696 void
1698 
1699 
1700 #if __STDC_VERSION__ < 199901L
1701 #if __GNUC__ >= 2
1702 #define __func__ __FUNCTION__
1703 #else
1704 #define __func__ "<unknown>"
1705 #endif
1706 #endif
1707 
1708 
1717 {
1722 
1727 
1733 
1741 
1747 
1753 
1761 
1771 
1777 };
1778 
1779 
1780 #if 0 /* keep Emacsens' auto-indent happy */
1781 {
1782 #endif
1783 #ifdef __cplusplus
1784 }
1785 #endif
1786 
1787 #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.
int(* GNUNET_FileNameCallback)(void *cls, const char *filename)
Function called with a filename.
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...
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...