36 #ifndef GNUNET_COMMON_H 37 #define GNUNET_COMMON_H 41 #include <sys/socket.h> 44 #include <netinet/in.h> 52 #ifdef HAVE_SYS_TYPES_H 53 #include <sys/types.h> 55 #ifdef HAVE_SYS_SOCKET_H 56 #include <sys/socket.h> 60 #ifdef HAVE_BYTESWAP_H 74 #define GNUNET_UTIL_VERSION 0x000A0104 93 #define GNUNET_MIN(a, b) (((a) < (b)) ? (a) : (b)) 95 #define GNUNET_MAX(a, b) (((a) > (b)) ? (a) : (b)) 100 #define __BYTE_ORDER _BYTE_ORDER 103 #define __BYTE_ORDER BYTE_ORDER 109 #define __BIG_ENDIAN _BIG_ENDIAN 112 #define __BIG_ENDIAN BIG_ENDIAN 116 #ifndef __LITTLE_ENDIAN 117 #ifdef _LITTLE_ENDIAN 118 #define __LITTLE_ENDIAN _LITTLE_ENDIAN 121 #define __LITTLE_ENDIAN LITTLE_ENDIAN 129 #define GNUNET_VA_ARG_ENUM(va, X) ((enum X) va_arg (va, int)) 137 #ifndef GNUNET_EXTRA_LOGGING 138 #define GNUNET_EXTRA_LOGGING 0 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) 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) 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) 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) 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) 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) 191 #define GNUNET_NZL(l) GNUNET_MAX (1, l) 197 #define GNUNET_PACKED __attribute__ ((packed)) 202 #define GNUNET_GCC_STRUCT_LAYOUT 209 #ifdef __BIGGEST_ALIGNMENT__ 210 #define GNUNET_ALIGN __attribute__ ((aligned (__BIGGEST_ALIGNMENT__))) 212 #define GNUNET_ALIGN __attribute__ ((aligned (8))) 218 #define GNUNET_UNUSED __attribute__ ((unused)) 223 #define GNUNET_NORETURN __attribute__ ((noreturn)) 228 #define GNUNET_NETWORK_STRUCT_BEGIN 233 #define GNUNET_NETWORK_STRUCT_END 244 uint32_t
bits[512 / 8 /
sizeof(uint32_t)];
254 uint32_t
bits[256 / 8 /
sizeof(uint32_t)];
321 uint32_t
bits[16 /
sizeof(uint32_t)];
423 const char *message);
436 #if ! defined(GNUNET_CULL_LOGGING) 441 const char *
function,
460 #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__) 461 #define _GNUNET_BOOLEAN_EXPR(expr) \ 463 int _gnunet_boolean_var_; \ 465 _gnunet_boolean_var_ = 1; \ 467 _gnunet_boolean_var_ = 0; \ 468 _gnunet_boolean_var_; \ 470 #define GN_LIKELY(expr) (__builtin_expect (_GNUNET_BOOLEAN_EXPR (expr), 1)) 471 #define GN_UNLIKELY(expr) (__builtin_expect (_GNUNET_BOOLEAN_EXPR (expr), 0)) 473 #define GN_LIKELY(expr) (expr) 474 #define GN_UNLIKELY(expr) (expr) 477 #if ! defined(GNUNET_LOG_CALL_STATUS) 478 #define GNUNET_LOG_CALL_STATUS -1 499 #if ! defined(GNUNET_CULL_LOGGING) 500 #define GNUNET_log_from(kind, comp, ...) \ 503 static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \ 504 if ((GNUNET_EXTRA_LOGGING > 0) || \ 505 ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \ 507 if (GN_UNLIKELY (log_call_enabled == -1)) \ 509 GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \ 514 if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \ 516 GNUNET_log_skip (-1, GNUNET_NO); \ 520 if (GN_UNLIKELY (log_call_enabled)) \ 521 GNUNET_log_from_nocheck ((kind), comp, __VA_ARGS__); \ 526 #define GNUNET_log(kind, ...) \ 529 static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \ 530 if ((GNUNET_EXTRA_LOGGING > 0) || \ 531 ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \ 533 if (GN_UNLIKELY (log_call_enabled == -1)) \ 535 GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \ 540 if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \ 542 GNUNET_log_skip (-1, GNUNET_NO); \ 546 if (GN_UNLIKELY (log_call_enabled)) \ 547 GNUNET_log_nocheck ((kind), __VA_ARGS__); \ 552 #define GNUNET_log(...) 553 #define GNUNET_log_from(...) 584 const char *required);
618 GNUNET_log_setup (
const char *comp,
const char *loglevel,
const char *logfile);
840 GNUNET_a2s (
const struct sockaddr *addr, socklen_t addrlen);
858 #define GNUNET_assert(cond) \ 863 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \ 864 _ ("Assertion failed at %s:%d. Aborting.\n"), \ 876 #define GNUNET_assert_at(cond, f, l) \ 881 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \ 882 _ ("Assertion failed at %s:%d. Aborting.\n"), \ 897 #define GNUNET_assert_from(cond, comp) \ 902 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, \ 904 _ ("Assertion failed at %s:%d. Aborting.\n"), \ 912 #if HAVE_STATIC_ASSERT 920 #define GNUNET_static_assert(cond) _Static_assert (cond, "") 930 #define GNUNET_static_assert(cond) GNUNET_assert (cond) 939 #define GNUNET_break(cond) \ 944 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \ 945 _ ("Assertion failed at %s:%d.\n"), \ 961 #define GNUNET_break_op(cond) \ 966 GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, \ 967 _ ("External protocol violation detected at %s:%d.\n"), \ 980 #define GNUNET_log_strerror(level, cmd) \ 984 _ ("`%s' failed at %s:%d with error: %s\n"), \ 998 #define GNUNET_log_from_strerror(level, component, cmd) \ 1001 GNUNET_log_from (level, \ 1003 _ ("`%s' failed at %s:%d with error: %s\n"), \ 1007 strerror (errno)); \ 1017 #define GNUNET_log_strerror_file(level, cmd, filename) \ 1020 GNUNET_log (level, \ 1021 _ ("`%s' failed on file `%s' at %s:%d with error: %s\n"), \ 1026 strerror (errno)); \ 1036 #define GNUNET_log_from_strerror_file(level, component, cmd, filename) \ 1039 GNUNET_log_from (level, \ 1041 _ ("`%s' failed on file `%s' at %s:%d with error: %s\n"), \ 1046 strerror (errno)); \ 1053 #define GNUNET_htonll(n) htobe64 (n) 1072 #define GNUNET_ntohll(n) be64toh (n) 1119 #define GNUNET_MAX_MALLOC_CHECKED (1024 * 1024 * 40) 1129 #define GNUNET_new(type) (type *) GNUNET_malloc (sizeof(type)) 1139 #define GNUNET_memcmp(a, b) \ 1141 const typeof (*b) * _a = (a); \ 1142 const typeof (*a) * _b = (b); \ 1143 memcmp (_a, _b, sizeof(*a)); \ 1168 #define GNUNET_memcmp_priv(a, b) \ 1170 const typeof (*b) * _a = (a); \ 1171 const typeof (*a) * _b = (b); \ 1172 GNUNET_memcmp_ct_ (_a, _b, sizeof(*a)); \ 1196 #define GNUNET_is_zero(a) \ 1197 GNUNET_is_zero_ (a, sizeof (*a)) 1209 #define GNUNET_memcpy(dst, src, n) \ 1214 (void) memcpy (dst, src, n); \ 1228 #define GNUNET_new_array(n, type) ({ \ 1229 GNUNET_assert (SIZE_MAX / sizeof (type) >= n); \ 1230 (type *) GNUNET_malloc ((n) * sizeof(type)); \ 1242 #define GNUNET_new_array_2d(n, m, type) \ 1243 (type **) GNUNET_xnew_array_2d_ (n, m, sizeof(type), __FILE__, __LINE__) 1255 #define GNUNET_new_array_3d(n, m, o, type) \ 1256 (type ***) GNUNET_xnew_array_3d_ (n, m, o, sizeof(type), __FILE__, __LINE__) 1267 #define GNUNET_malloc(size) GNUNET_xmalloc_ (size, __FILE__, __LINE__) 1277 #define GNUNET_memdup(buf, size) GNUNET_xmemdup_ (buf, size, __FILE__, __LINE__) 1287 #define GNUNET_malloc_large(size) \ 1288 GNUNET_xmalloc_unchecked_ (size, __FILE__, __LINE__) 1300 #define GNUNET_realloc(ptr, size) \ 1301 GNUNET_xrealloc_ (ptr, size, __FILE__, __LINE__) 1313 #define GNUNET_free_nz(ptr) GNUNET_xfree_ (ptr, __FILE__, __LINE__) 1327 #define GNUNET_free(ptr) do { \ 1328 GNUNET_xfree_ (ptr, __FILE__, __LINE__); \ 1341 #define GNUNET_strdup(a) GNUNET_xstrdup_ (a, __FILE__, __LINE__) 1352 #define GNUNET_strndup(a, length) \ 1353 GNUNET_xstrndup_ (a, length, __FILE__, __LINE__) 1390 #define GNUNET_array_grow(arr, size, tsize) \ 1391 GNUNET_xgrow_ ((void **) &(arr), \ 1411 #define GNUNET_array_append(arr, len, element) \ 1414 GNUNET_assert ((len) + 1 > (len)); \ 1415 GNUNET_array_grow (arr, len, len + 1); \ 1416 (arr) [len - 1] = element; \ 1443 #define GNUNET_array_concatenate(arr1, len1, arr2, len2) \ 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)); \ 1524 const
char *filename,
1548 const
char *filename,
1566 const
char *filename,
1591 GNUNET_xrealloc_ (
void *ptr,
size_t n, const
char *filename,
int linenumber);
1604 GNUNET_xfree_ (
void *ptr, const
char *filename,
int linenumber);
1615 GNUNET_xstrdup_ (const
char *str, const
char *filename,
int linenumber);
1629 const
char *filename,
1650 unsigned int *oldCount,
1651 unsigned int newCount,
1652 const
char *filename,
1705 #if __STDC_VERSION__ < 199901L 1707 #define __func__ __FUNCTION__ 1709 #define __func__ "<unknown>" 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
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.
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.
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't work on W32.
static char * section
Name of the section.
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.
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.
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.
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.
void GNUNET_async_scope_get(struct GNUNET_AsyncScopeSave *scope_ret)
Get the current async scope.
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.
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".
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.
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'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'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'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.
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.
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
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...