GNUnet  0.11.x
Data Structures | Macros | Typedefs | Enumerations | Functions
gnunet_common.h File Reference

commonly used definitions; globals in this file are exempt from the rule that the module name ("common") must be part of the symbol name. More...

#include <stdlib.h>
#include "gettext.h"
Include dependency graph for gnunet_common.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  GNUNET_HashCode
 A 512-bit hashcode. More...
 
struct  GNUNET_ShortHashCode
 A 256-bit hashcode. More...
 
struct  GNUNET_Uuid
 A UUID, a 128 bit "random" value. More...
 
struct  GNUNET_MessageHeader
 Header for all communications. More...
 
struct  GNUNET_OperationResultMessage
 Answer from service to client about last operation. More...
 
struct  GNUNET_AsyncScopeId
 Identifier for an asynchronous execution context. More...
 
struct  GNUNET_AsyncScopeSave
 Saved async scope identifier or root scope. More...
 

Macros

#define GNUNET_UTIL_VERSION   0x000A0104
 Version of the API (for entire gnunetutil.so library). More...
 
#define GNUNET_MIN(a, b)   (((a) < (b)) ? (a) : (b))
 
#define GNUNET_MAX(a, b)   (((a) > (b)) ? (a) : (b))
 
#define GNUNET_VA_ARG_ENUM(va, X)   ((enum X) va_arg (va, int))
 wrap va_arg for enums More...
 
#define GNUNET_EXTRA_LOGGING   1
 define GNUNET_EXTRA_LOGGING if using this header outside the GNUnet source tree where gnunet_config.h is unavailable More...
 
#define BYTE_SWAP_16(x)   ((((x) & 0x00ff) << 8) | (((x) & 0xff00) >> 8))
 Endian operations. More...
 
#define BYTE_SWAP_32(x)
 
#define BYTE_SWAP_64(x)
 
#define GNUNET_htobe16(x)   BYTE_SWAP_16 (x)
 
#define GNUNET_htole16(x)   (x)
 
#define GNUNET_be16toh(x)   BYTE_SWAP_16 (x)
 
#define GNUNET_le16toh(x)   (x)
 
#define GNUNET_htobe32(x)   BYTE_SWAP_32 (x)
 
#define GNUNET_htole32(x)   (x)
 
#define GNUNET_be32toh(x)   BYTE_SWAP_32 (x)
 
#define GNUNET_le32toh(x)   (x)
 
#define GNUNET_htobe64(x)   BYTE_SWAP_64 (x)
 
#define GNUNET_htole64(x)   (x)
 
#define GNUNET_be64toh(x)   BYTE_SWAP_64 (x)
 
#define GNUNET_le64toh(x)   (x)
 
#define GNUNET_htobe16(x)   (x)
 
#define GNUNET_htole16(x)   BYTE_SWAP_16 (x)
 
#define GNUNET_be16toh(x)   (x)
 
#define GNUNET_le16toh(x)   BYTE_SWAP_16 (x)
 
#define GNUNET_htobe32(x)   (x)
 
#define GNUNET_htole32(x)   BYTE_SWAP_32 (x)
 
#define GNUNET_be32toh(x)   (x)
 
#define GNUNET_le32toh(x)   BYTE_SWAP_32 (x)
 
#define GNUNET_htobe64(x)   (x)
 
#define GNUNET_htole64(x)   BYTE_SWAP_64 (x)
 
#define GNUNET_be64toh(x)   (x)
 
#define GNUNET_le64toh(x)   BYTE_SWAP_64 (x)
 
#define GNUNET_NZL(l)   GNUNET_MAX (1, l)
 Macro used to avoid using 0 for the length of a variable-size array (Non-Zero-Length). More...
 
#define GNUNET_PACKED   __attribute__ ((packed))
 gcc-ism to get packed structs. More...
 
#define GNUNET_GCC_STRUCT_LAYOUT
 gcc-ism to get gcc bitfield layout when compiling with -mms-bitfields More...
 
#define GNUNET_ALIGN   __attribute__ ((aligned (8)))
 gcc-ism to force alignment; we use this to align char-arrays that may then be cast to 'struct's. More...
 
#define GNUNET_UNUSED   __attribute__ ((unused))
 gcc-ism to document unused arguments More...
 
#define GNUNET_NORETURN   __attribute__ ((noreturn))
 gcc-ism to document functions that don't return More...
 
#define GNUNET_NETWORK_STRUCT_BEGIN
 Define as empty, GNUNET_PACKED should suffice, but this won't work on W32. More...
 
#define GNUNET_NETWORK_STRUCT_END
 Define as empty, GNUNET_PACKED should suffice, but this won't work on W32;. More...
 
#define GN_LIKELY(expr)   (expr)
 
#define GN_UNLIKELY(expr)   (expr)
 
#define GNUNET_LOG_CALL_STATUS   -1
 
#define GNUNET_log_from(kind, comp, ...)
 
#define GNUNET_log(kind, ...)
 
#define GNUNET_assert(cond)
 Use this for fatal errors that cannot be handled. More...
 
#define GNUNET_assert_at(cond, f, l)
 Use this for fatal errors that cannot be handled. More...
 
#define GNUNET_assert_from(cond, comp)
 Use this for fatal errors that cannot be handled. More...
 
#define GNUNET_static_assert(cond)   GNUNET_assert (cond)
 Assertion to be checked (if supported by C compiler) at compile time, otherwise checked at runtime and resulting in an abort() on failure. More...
 
#define GNUNET_break(cond)
 Use this for internal assertion violations that are not fatal (can be handled) but should not occur. More...
 
#define GNUNET_break_op(cond)
 Use this for assertion violations caused by other peers (i.e. More...
 
#define GNUNET_log_strerror(level, cmd)
 Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the message given by strerror(errno). More...
 
#define GNUNET_log_from_strerror(level, component, cmd)
 Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the message given by strerror(errno). More...
 
#define GNUNET_log_strerror_file(level, cmd, filename)
 Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the message given by strerror(errno). More...
 
#define GNUNET_log_from_strerror_file(level, component, cmd, filename)
 Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the message given by strerror(errno). More...
 
#define GNUNET_MAX_MALLOC_CHECKED   (1024 * 1024 * 40)
 Maximum allocation with GNUNET_malloc macro. More...
 
#define GNUNET_new(type)   (type *) GNUNET_malloc (sizeof(type))
 Allocate a struct or union of the given type. More...
 
#define GNUNET_memcmp(a, b)
 Compare memory in a and b, where both must be of the same pointer type. More...
 
#define GNUNET_memcmp_priv(a, b)
 Compare memory in a and b in constant time, suitable for private data. More...
 
#define GNUNET_is_zero(a)    GNUNET_is_zero_ (a, sizeof (*a))
 Check that memory in a is all zeros. More...
 
#define GNUNET_memcpy(dst, src, n)
 Call memcpy() but check for n being 0 first. More...
 
#define GNUNET_new_array(n, type)
 Allocate a size n array with structs or unions of the given type. More...
 
#define GNUNET_new_array_2d(n, m, type)    (type **) GNUNET_xnew_array_2d_ (n, m, sizeof(type), __FILE__, __LINE__)
 Allocate a size n times m array with structs or unions of the given type. More...
 
#define GNUNET_new_array_3d(n, m, o, type)    (type ***) GNUNET_xnew_array_3d_ (n, m, o, sizeof(type), __FILE__, __LINE__)
 Allocate a size n times m times o array with structs or unions of the given type. More...
 
#define GNUNET_malloc(size)   GNUNET_xmalloc_ (size, __FILE__, __LINE__)
 Wrapper around malloc. More...
 
#define GNUNET_memdup(buf, size)   GNUNET_xmemdup_ (buf, size, __FILE__, __LINE__)
 Allocate and initialize a block of memory. More...
 
#define GNUNET_malloc_large(size)    GNUNET_xmalloc_unchecked_ (size, __FILE__, __LINE__)
 Wrapper around malloc. More...
 
#define GNUNET_realloc(ptr, size)    GNUNET_xrealloc_ (ptr, size, __FILE__, __LINE__)
 Wrapper around realloc. More...
 
#define GNUNET_free_nz(ptr)   GNUNET_xfree_ (ptr, __FILE__, __LINE__)
 Wrapper around free. More...
 
#define GNUNET_free(ptr)
 Wrapper around free. More...
 
#define GNUNET_strdup(a)   GNUNET_xstrdup_ (a, __FILE__, __LINE__)
 Wrapper around GNUNET_xstrdup_. More...
 
#define GNUNET_strndup(a, length)    GNUNET_xstrndup_ (a, length, __FILE__, __LINE__)
 Wrapper around GNUNET_xstrndup_. More...
 
#define GNUNET_array_grow(arr, size, tsize)
 Grow a well-typed (!) array. More...
 
#define GNUNET_array_append(arr, len, element)
 Append an element to an array (growing the array by one). More...
 
#define GNUNET_array_concatenate(arr1, len1, arr2, len2)
 Append arr2 to arr1 (growing arr1 as needed). More...
 
#define __func__   "<unknown>"
 

Typedefs

typedef enum GNUNET_GenericReturnValue(* GNUNET_FileNameCallback) (void *cls, const char *filename)
 Function called with a filename. More...
 
typedef void(* GNUNET_ContinuationCallback) (void *cls)
 Generic continuation callback. More...
 
typedef 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. More...
 
typedef void(* GNUNET_Logger) (void *cls, enum GNUNET_ErrorType kind, const char *component, const char *date, const char *message)
 User-defined handler for log messages. More...
 

Enumerations

enum  GNUNET_GenericReturnValue { GNUNET_SYSERR = -1 , GNUNET_NO = 0 , GNUNET_OK = 1 , GNUNET_YES = 1 }
 Named constants for return values. More...
 
enum  GNUNET_ErrorType {
  GNUNET_ERROR_TYPE_UNSPECIFIED = -1 , GNUNET_ERROR_TYPE_NONE = 0 , GNUNET_ERROR_TYPE_ERROR = 1 , GNUNET_ERROR_TYPE_WARNING = 2 ,
  GNUNET_ERROR_TYPE_MESSAGE = 4 , GNUNET_ERROR_TYPE_INFO = 8 , GNUNET_ERROR_TYPE_DEBUG = 16 , GNUNET_ERROR_TYPE_INVALID = 32 ,
  GNUNET_ERROR_TYPE_BULK = 64
}
 Types of errors. More...
 
enum  GNUNET_SCHEDULER_Priority {
  GNUNET_SCHEDULER_PRIORITY_KEEP = 0 , GNUNET_SCHEDULER_PRIORITY_IDLE = 1 , GNUNET_SCHEDULER_PRIORITY_BACKGROUND = 2 , GNUNET_SCHEDULER_PRIORITY_DEFAULT = 3 ,
  GNUNET_SCHEDULER_PRIORITY_HIGH = 4 , GNUNET_SCHEDULER_PRIORITY_UI = 5 , GNUNET_SCHEDULER_PRIORITY_URGENT = 6 , GNUNET_SCHEDULER_PRIORITY_SHUTDOWN = 7 ,
  GNUNET_SCHEDULER_PRIORITY_COUNT = 8
}
 Valid task priorities. More...
 

Functions

int GNUNET_get_log_skip (void)
 Get the number of log calls that are going to be skipped. More...
 
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. More...
 
void GNUNET_log_nocheck (enum GNUNET_ErrorType kind, const char *message,...) __attribute__((format(printf
 Main log function. More...
 
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. More...
 
void GNUNET_log_config_missing (enum GNUNET_ErrorType kind, const char *section, const char *option)
 Log error message about missing configuration option. More...
 
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. More...
 
void GNUNET_abort_ (void) __attribute__((noreturn))
 Abort the process, generate a core dump if possible. More...
 
void GNUNET_log_skip (int n, int check_reset)
 Ignore the next n calls to the log function. More...
 
int GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile)
 Setup logging. More...
 
void GNUNET_logger_add (GNUNET_Logger logger, void *logger_cls)
 Add a custom logger. More...
 
void GNUNET_logger_remove (GNUNET_Logger logger, void *logger_cls)
 Remove a custom logger. More...
 
const char * GNUNET_sh2s (const struct GNUNET_ShortHashCode *shc)
 Convert a short hash value to a string (for printing debug messages). More...
 
const char * GNUNET_uuid2s (const struct GNUNET_Uuid *uuid)
 Convert a UUID to a string (for printing debug messages). More...
 
const char * GNUNET_h2s (const struct GNUNET_HashCode *hc)
 Convert a hash value to a string (for printing debug messages). More...
 
const char * GNUNET_h2s2 (const struct GNUNET_HashCode *hc)
 Convert a hash value to a string (for printing debug messages). More...
 
const char * GNUNET_h2s_full (const struct GNUNET_HashCode *hc)
 Convert a hash value to a string (for printing debug messages). More...
 
const char * GNUNET_p2s (const struct GNUNET_CRYPTO_EddsaPublicKey *p)
 Convert a public key value to a string (for printing debug messages). More...
 
const char * GNUNET_p2s2 (const struct GNUNET_CRYPTO_EddsaPublicKey *p)
 Convert a public key value to a string (for printing debug messages). More...
 
const char * GNUNET_e2s (const struct GNUNET_CRYPTO_EcdhePublicKey *p)
 Convert a public key value to a string (for printing debug messages). More...
 
const char * GNUNET_e2s2 (const struct GNUNET_CRYPTO_EcdhePublicKey *p)
 Convert a public key value to a string (for printing debug messages). More...
 
const char * GNUNET_i2s (const struct GNUNET_PeerIdentity *pid)
 Convert a peer identity to a string (for printing debug messages). More...
 
const char * GNUNET_i2s2 (const struct GNUNET_PeerIdentity *pid)
 Convert a peer identity to a string (for printing debug messages). More...
 
const char * GNUNET_i2s_full (const struct GNUNET_PeerIdentity *pid)
 Convert a peer identity to a string (for printing debug messages). More...
 
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). More...
 
const char * GNUNET_error_type_to_string (enum GNUNET_ErrorType kind)
 Convert error type to string. More...
 
uint64_t GNUNET_htonll (uint64_t n)
 Convert unsigned 64-bit integer to network byte order. More...
 
uint64_t GNUNET_ntohll (uint64_t n)
 Convert unsigned 64-bit integer to host byte order. More...
 
double GNUNET_hton_double (double d)
 Convert double to network byte order. More...
 
double GNUNET_ntoh_double (double d)
 Convert double to host byte order. More...
 
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. More...
 
enum GNUNET_GenericReturnValue GNUNET_is_zero_ (const void *a, size_t n)
 Check that memory in a is all zeros. More...
 
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. More...
 
int int GNUNET_asprintf (char **buf, const char *format,...) __attribute__((format(printf
 Like asprintf, just portable. More...
 
int int void * GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber)
 Allocate memory. More...
 
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. More...
 
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. More...
 
void * GNUNET_xmemdup_ (const void *buf, size_t size, const char *filename, int linenumber)
 Allocate and initialize memory. More...
 
void * GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber)
 Allocate memory. More...
 
void * GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber)
 Reallocate memory. More...
 
void GNUNET_xfree_ (void *ptr, const char *filename, int linenumber)
 Free memory. More...
 
char * GNUNET_xstrdup_ (const char *str, const char *filename, int linenumber)
 Dup a string. More...
 
char * GNUNET_xstrndup_ (const char *str, size_t len, const char *filename, int linenumber)
 Dup partially a string. More...
 
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. More...
 
struct GNUNET_MessageHeaderGNUNET_copy_message (const struct GNUNET_MessageHeader *msg)
 Create a copy of the given message. More...
 
void GNUNET_async_scope_enter (const struct GNUNET_AsyncScopeId *aid, struct GNUNET_AsyncScopeSave *old_scope)
 Set the async scope for the current thread. More...
 
void GNUNET_async_scope_restore (struct GNUNET_AsyncScopeSave *old_scope)
 Clear the current thread's async scope. More...
 
void GNUNET_async_scope_get (struct GNUNET_AsyncScopeSave *scope_ret)
 Get the current async scope. More...
 
void GNUNET_async_scope_fresh (struct GNUNET_AsyncScopeId *aid_ret)
 Generate a fresh async scope identifier. More...
 

Detailed Description

commonly used definitions; globals in this file are exempt from the rule that the module name ("common") must be part of the symbol name.

Author
Christian Grothoff
Nils Durner
Martin Schanzenbach

Definition in file gnunet_common.h.

Macro Definition Documentation

◆ GNUNET_UTIL_VERSION

#define GNUNET_UTIL_VERSION   0x000A0104

Version of the API (for entire gnunetutil.so library).

Definition at line 82 of file gnunet_common.h.

◆ GNUNET_MIN

#define GNUNET_MIN (   a,
 
)    (((a) < (b)) ? (a) : (b))

Definition at line 101 of file gnunet_common.h.

◆ GNUNET_MAX

#define GNUNET_MAX (   a,
 
)    (((a) > (b)) ? (a) : (b))

Definition at line 103 of file gnunet_common.h.

◆ GNUNET_VA_ARG_ENUM

#define GNUNET_VA_ARG_ENUM (   va,
 
)    ((enum X) va_arg (va, int))

wrap va_arg for enums

Definition at line 137 of file gnunet_common.h.

◆ BYTE_SWAP_16

#define BYTE_SWAP_16 (   x)    ((((x) & 0x00ff) << 8) | (((x) & 0xff00) >> 8))

Endian operations.

Definition at line 159 of file gnunet_common.h.

◆ BYTE_SWAP_32

#define BYTE_SWAP_32 (   x)
Value:
((((x) & 0x000000ffU) << 24) | (((x) & 0x0000ff00U) << 8) \
| (((x) & 0x00ff0000U) >> 8) | (((x) & 0xff000000U) >> 24))

Definition at line 161 of file gnunet_common.h.

◆ BYTE_SWAP_64

#define BYTE_SWAP_64 (   x)
Value:
((((x) & 0x00000000000000ffUL) << 56) | (((x) & 0x000000000000ff00UL) << 40) \
| (((x) & 0x0000000000ff0000UL) << 24) | (((x) & 0x00000000ff000000UL) << 8) \
| (((x) & 0x000000ff00000000UL) >> 8) | (((x) & 0x0000ff0000000000UL) >> 24) \
| (((x) & 0x00ff000000000000UL) >> 40) | (((x) & 0xff00000000000000UL) >> \
56))

Definition at line 165 of file gnunet_common.h.

◆ GNUNET_htobe16 [1/2]

#define GNUNET_htobe16 (   x)    BYTE_SWAP_16 (x)

Definition at line 189 of file gnunet_common.h.

◆ GNUNET_htole16 [1/2]

#define GNUNET_htole16 (   x)    (x)

Definition at line 190 of file gnunet_common.h.

◆ GNUNET_be16toh [1/2]

#define GNUNET_be16toh (   x)    BYTE_SWAP_16 (x)

Definition at line 191 of file gnunet_common.h.

◆ GNUNET_le16toh [1/2]

#define GNUNET_le16toh (   x)    (x)

Definition at line 192 of file gnunet_common.h.

◆ GNUNET_htobe32 [1/2]

#define GNUNET_htobe32 (   x)    BYTE_SWAP_32 (x)

Definition at line 194 of file gnunet_common.h.

◆ GNUNET_htole32 [1/2]

#define GNUNET_htole32 (   x)    (x)

Definition at line 195 of file gnunet_common.h.

◆ GNUNET_be32toh [1/2]

#define GNUNET_be32toh (   x)    BYTE_SWAP_32 (x)

Definition at line 196 of file gnunet_common.h.

◆ GNUNET_le32toh [1/2]

#define GNUNET_le32toh (   x)    (x)

Definition at line 197 of file gnunet_common.h.

◆ GNUNET_htobe64 [1/2]

#define GNUNET_htobe64 (   x)    BYTE_SWAP_64 (x)

Definition at line 199 of file gnunet_common.h.

◆ GNUNET_htole64 [1/2]

#define GNUNET_htole64 (   x)    (x)

Definition at line 200 of file gnunet_common.h.

◆ GNUNET_be64toh [1/2]

#define GNUNET_be64toh (   x)    BYTE_SWAP_64 (x)

Definition at line 201 of file gnunet_common.h.

◆ GNUNET_le64toh [1/2]

#define GNUNET_le64toh (   x)    (x)

Definition at line 202 of file gnunet_common.h.

◆ GNUNET_htobe16 [2/2]

#define GNUNET_htobe16 (   x)    (x)

Definition at line 189 of file gnunet_common.h.

◆ GNUNET_htole16 [2/2]

#define GNUNET_htole16 (   x)    BYTE_SWAP_16 (x)

Definition at line 190 of file gnunet_common.h.

◆ GNUNET_be16toh [2/2]

#define GNUNET_be16toh (   x)    (x)

Definition at line 191 of file gnunet_common.h.

◆ GNUNET_le16toh [2/2]

#define GNUNET_le16toh (   x)    BYTE_SWAP_16 (x)

Definition at line 192 of file gnunet_common.h.

◆ GNUNET_htobe32 [2/2]

#define GNUNET_htobe32 (   x)    (x)

Definition at line 194 of file gnunet_common.h.

◆ GNUNET_htole32 [2/2]

#define GNUNET_htole32 (   x)    BYTE_SWAP_32 (x)

Definition at line 195 of file gnunet_common.h.

◆ GNUNET_be32toh [2/2]

#define GNUNET_be32toh (   x)    (x)

Definition at line 196 of file gnunet_common.h.

◆ GNUNET_le32toh [2/2]

#define GNUNET_le32toh (   x)    BYTE_SWAP_32 (x)

Definition at line 197 of file gnunet_common.h.

◆ GNUNET_htobe64 [2/2]

#define GNUNET_htobe64 (   x)    (x)

Definition at line 199 of file gnunet_common.h.

◆ GNUNET_htole64 [2/2]

#define GNUNET_htole64 (   x)    BYTE_SWAP_64 (x)

Definition at line 200 of file gnunet_common.h.

◆ GNUNET_be64toh [2/2]

#define GNUNET_be64toh (   x)    (x)

Definition at line 201 of file gnunet_common.h.

◆ GNUNET_le64toh [2/2]

#define GNUNET_le64toh (   x)    BYTE_SWAP_64 (x)

Definition at line 202 of file gnunet_common.h.

◆ GNUNET_NZL

#define GNUNET_NZL (   l)    GNUNET_MAX (1, l)

Macro used to avoid using 0 for the length of a variable-size array (Non-Zero-Length).

Basically, C standard says that "int[n] x;" is undefined if n=0. This was supposed to prevent issues with pointer aliasing. However, C compilers may conclude that n!=0 as n=0 would be undefined, and then optimize under the assumption n!=0, which could cause actual issues. Hence, when initializing an array on the stack with a variable-length that might be zero, write "int[GNUNET_NZL(n)] x;" instead of "int[n] x".

Definition at line 218 of file gnunet_common.h.

◆ GNUNET_PACKED

#define GNUNET_PACKED   __attribute__ ((packed))

gcc-ism to get packed structs.

Definition at line 224 of file gnunet_common.h.

◆ GNUNET_GCC_STRUCT_LAYOUT

#define GNUNET_GCC_STRUCT_LAYOUT

gcc-ism to get gcc bitfield layout when compiling with -mms-bitfields

Definition at line 229 of file gnunet_common.h.

◆ GNUNET_ALIGN

#define GNUNET_ALIGN   __attribute__ ((aligned (8)))

gcc-ism to force alignment; we use this to align char-arrays that may then be cast to 'struct's.

See also gcc bug #33594.

Definition at line 239 of file gnunet_common.h.

◆ GNUNET_UNUSED

#define GNUNET_UNUSED   __attribute__ ((unused))

gcc-ism to document unused arguments

Definition at line 245 of file gnunet_common.h.

◆ GNUNET_NORETURN

#define GNUNET_NORETURN   __attribute__ ((noreturn))

gcc-ism to document functions that don't return

Definition at line 250 of file gnunet_common.h.

◆ GNUNET_NETWORK_STRUCT_BEGIN

#define GNUNET_NETWORK_STRUCT_BEGIN

Define as empty, GNUNET_PACKED should suffice, but this won't work on W32.

Definition at line 255 of file gnunet_common.h.

◆ GNUNET_NETWORK_STRUCT_END

#define GNUNET_NETWORK_STRUCT_END

Define as empty, GNUNET_PACKED should suffice, but this won't work on W32;.

Definition at line 260 of file gnunet_common.h.

◆ GN_LIKELY

#define GN_LIKELY (   expr)    (expr)

Definition at line 501 of file gnunet_common.h.

◆ GN_UNLIKELY

#define GN_UNLIKELY (   expr)    (expr)

Definition at line 502 of file gnunet_common.h.

◆ GNUNET_LOG_CALL_STATUS

#define GNUNET_LOG_CALL_STATUS   -1

Definition at line 506 of file gnunet_common.h.

◆ GNUNET_log_from

#define GNUNET_log_from (   kind,
  comp,
  ... 
)
Value:
do \
{ \
static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \
if ((GNUNET_EXTRA_LOGGING > 0) || \
((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \
{ \
if (GN_UNLIKELY (log_call_enabled == -1)) \
log_call_enabled = \
GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \
(comp), \
__FILE__, \
__FUNCTION__, \
__LINE__); \
{ \
GNUNET_log_skip (-1, GNUNET_NO); \
} \
else \
{ \
if (GN_UNLIKELY (log_call_enabled)) \
GNUNET_log_from_nocheck ((kind), comp, __VA_ARGS__); \
} \
} \
} while (0)
#define GNUNET_LOG_CALL_STATUS
#define GN_UNLIKELY(expr)
@ GNUNET_NO
Definition: gnunet_common.h:94
int GNUNET_get_log_skip(void)
Get the number of log calls that are going to be skipped.
#define GNUNET_EXTRA_LOGGING
define GNUNET_EXTRA_LOGGING if using this header outside the GNUnet source tree where gnunet_config....
@ GNUNET_ERROR_TYPE_BULK
@ GNUNET_ERROR_TYPE_DEBUG

Definition at line 528 of file gnunet_common.h.

◆ GNUNET_log

#define GNUNET_log (   kind,
  ... 
)
Value:
do \
{ \
static int log_call_enabled = GNUNET_LOG_CALL_STATUS; \
if ((GNUNET_EXTRA_LOGGING > 0) || \
((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \
{ \
if (GN_UNLIKELY (log_call_enabled == -1)) \
log_call_enabled = \
GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \
NULL, \
__FILE__, \
__FUNCTION__, \
__LINE__); \
{ \
GNUNET_log_skip (-1, GNUNET_NO); \
} \
else \
{ \
if (GN_UNLIKELY (log_call_enabled)) \
GNUNET_log_nocheck ((kind), __VA_ARGS__); \
} \
} \
} while (0)

Definition at line 554 of file gnunet_common.h.

◆ GNUNET_static_assert

#define GNUNET_static_assert (   cond)    GNUNET_assert (cond)

Assertion to be checked (if supported by C compiler) at compile time, otherwise checked at runtime and resulting in an abort() on failure.

This is the case where the compiler does not support static assertions.

Parameters
condcondition to test, 0 implies failure

Definition at line 976 of file gnunet_common.h.

◆ GNUNET_memcmp

#define GNUNET_memcmp (   a,
 
)
Value:
({ \
const typeof (*b) * _a = (a); \
const typeof (*a) * _b = (b); \
memcmp (_a, _b, sizeof(*a)); \
})

Compare memory in a and b, where both must be of the same pointer type.

Do NOT use this function on arrays, it would only compare the first element!

Definition at line 1185 of file gnunet_common.h.

◆ GNUNET_memcmp_priv

#define GNUNET_memcmp_priv (   a,
 
)
Value:
({ \
const typeof (*b) * _a = (a); \
const typeof (*a) * _b = (b); \
GNUNET_memcmp_ct_ (_a, _b, sizeof(*a)); \
})

Compare memory in a and b in constant time, suitable for private data.

Both a and b must be of the same pointer type.

Do NOT use this function on arrays, it would only compare the first element!

Definition at line 1214 of file gnunet_common.h.

◆ GNUNET_is_zero

#define GNUNET_is_zero (   a)     GNUNET_is_zero_ (a, sizeof (*a))

Check that memory in a is all zeros.

a must be a pointer.

Parameters
apointer to a struct which should be tested for the entire memory being zero'ed out.
Returns
GNUNET_YES if a is zero, GNUNET_NO otherwise

Definition at line 1242 of file gnunet_common.h.

◆ GNUNET_memcpy

#define GNUNET_memcpy (   dst,
  src,
 
)
Value:
do \
{ \
if (0 != n) \
{ \
(void) memcpy (dst, src, n); \
} \
} while (0)

Call memcpy() but check for n being 0 first.

In the latter case, it is now safe to pass NULL for src or dst. Unlike traditional memcpy(), returns nothing.

Parameters
dstdestination of the copy, may be NULL if n is zero
srcsource of the copy, may be NULL if n is zero
nnumber of bytes to copy

Definition at line 1255 of file gnunet_common.h.

◆ __func__

#define __func__   "<unknown>"

Definition at line 1755 of file gnunet_common.h.

Typedef Documentation

◆ GNUNET_FileNameCallback

typedef enum GNUNET_GenericReturnValue(* GNUNET_FileNameCallback) (void *cls, const char *filename)

Function called with a filename.

Parameters
clsclosure
filenamecomplete filename (absolute path)
Returns
GNUNET_OK to continue to iterate, GNUNET_NO to stop iteration with no error, GNUNET_SYSERR to abort iteration with error!

Definition at line 1 of file gnunet_common.h.

◆ GNUNET_ContinuationCallback

typedef void(* GNUNET_ContinuationCallback) (void *cls)

Generic continuation callback.

Parameters
clsClosure.

Definition at line 390 of file gnunet_common.h.

◆ GNUNET_ResultCallback

typedef 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.

Parameters
clsClosure.
result_codeResult code for the operation.
dataData result for the operation.
data_sizeSize of data.

Definition at line 406 of file gnunet_common.h.

Enumeration Type Documentation

◆ GNUNET_GenericReturnValue

Named constants for return values.

The following invariants hold: GNUNET_NO == 0 (to allow if (GNUNET_NO)) GNUNET_OK != GNUNET_SYSERR, GNUNET_OK != GNUNET_NO, GNUNET_NO != GNUNET_SYSERR and finally GNUNET_YES != GNUNET_NO.

Enumerator
GNUNET_SYSERR 
GNUNET_NO 
GNUNET_OK 
GNUNET_YES 

Definition at line 91 of file gnunet_common.h.

92 {
93  GNUNET_SYSERR = -1,
94  GNUNET_NO = 0,
95  GNUNET_OK = 1,
96  /* intentionally identical to #GNUNET_OK! */
97  GNUNET_YES = 1,
98 };
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_YES
Definition: gnunet_common.h:97
@ GNUNET_SYSERR
Definition: gnunet_common.h:93

◆ GNUNET_SCHEDULER_Priority

Valid task priorities.

Use these, do not pass random integers! For various reasons (#3862 – building with QT Creator, and our restricted cross-compilation with emscripten) this cannot be in gnunet_scheduler_lib.h, but it works if we declare it here. Naturally, logically this is part of the scheduler.

Enumerator
GNUNET_SCHEDULER_PRIORITY_KEEP 

Run with the same priority as the current job.

GNUNET_SCHEDULER_PRIORITY_IDLE 

Run when otherwise idle.

GNUNET_SCHEDULER_PRIORITY_BACKGROUND 

Run as background job (higher than idle, lower than default).

GNUNET_SCHEDULER_PRIORITY_DEFAULT 

Run with the default priority (normal P2P operations).

Any task that is scheduled without an explicit priority being specified will run with this priority.

GNUNET_SCHEDULER_PRIORITY_HIGH 

Run with high priority (important requests).

Higher than DEFAULT.

GNUNET_SCHEDULER_PRIORITY_UI 

Run with priority for interactive tasks.

Higher than "HIGH".

GNUNET_SCHEDULER_PRIORITY_URGENT 

Run with priority for urgent tasks.

Use for things like aborts and shutdowns that need to preempt "UI"-level tasks. Higher than "UI".

GNUNET_SCHEDULER_PRIORITY_SHUTDOWN 

This is an internal priority level that is only used for tasks that are being triggered due to shutdown (they have automatically highest priority).

User code must not use this priority level directly. Tasks run with this priority level that internally schedule other tasks will see their original priority level be inherited (unless otherwise specified).

GNUNET_SCHEDULER_PRIORITY_COUNT 

Number of priorities (must be the last priority).

This priority must not be used by clients.

Definition at line 1767 of file gnunet_common.h.

1768 {
1773 
1778 
1784 
1792 
1798 
1804 
1812 
1822 
1828 };
@ 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...

Function Documentation

◆ GNUNET_get_log_call_status()

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.

Used internally by GNUNET_log*()

Parameters
caller_levelloglevel the caller wants to use
compcomponent name the caller uses (NULL means that global component name is used)
filefile name containing the logging call, usually FILE
functionfunction which tries to make a logging call, usually FUNCTION
lineline at which the call is made, usually LINE
Returns
0 to disallow the call, 1 to allow it

Definition at line 479 of file common_logging.c.

484 {
485  struct LogDef *ld;
486  int i;
487  int force_only;
488 
489  if (NULL == comp)
490  /* Use default component */
491  comp = component_nopid;
492 
493  /* We have no definitions to override globally configured log level,
494  * so just use it right away.
495  */
496  if ((min_level >= 0) && (GNUNET_NO == gnunet_force_log_present))
497  return caller_level <= min_level;
498 
499  /* Only look for forced definitions? */
500  force_only = min_level >= 0;
501  for (i = 0; i < logdefs_len; i++)
502  {
503  ld = &logdefs[i];
504  if (((! force_only) || ld->force) &&
505  ((line >= ld->from_line) && (line <= ld->to_line) ) &&
506  (0 == regexec (&ld->component_regex, comp, 0, NULL, 0)) &&
507  (0 == regexec (&ld->file_regex, file, 0, NULL, 0)) &&
508  (0 == regexec (&ld->function_regex, function, 0, NULL, 0)))
509  {
510  /* We're finished */
511  return caller_level <= ld->level;
512  }
513  }
514  /* No matches - use global level, if defined */
515  if (min_level >= 0)
516  return caller_level <= min_level;
517  /* All programs/services previously defaulted to WARNING.
518  * Now *we* default to WARNING, and THEY default to NULL.
519  * Or rather we default to MESSAGE, since things aren't always bad.
520  */
521  return caller_level <= GNUNET_ERROR_TYPE_MESSAGE;
522 }
static int gnunet_force_log_present
GNUNET_YES if at least one definition with forced == 1 is available.
static int logdefs_len
The number of units used in logdefs array.
static struct LogDef * logdefs
Dynamic array of logging definitions.
static char * component_nopid
Running component (without pid).
static enum GNUNET_ErrorType min_level
Minimum log level.
static char * line
Desired phone line (string to be converted to a hash).
@ GNUNET_ERROR_TYPE_MESSAGE
Represents a single logging definition.
int to_line
Highest line at which this definition matches.
int from_line
Lowest line at which this definition matches.
int force
1 if this definition comes from GNUNET_FORCE_LOG, which means that it overrides any configuration opt...
regex_t file_regex
File name regex.
regex_t function_regex
Function name regex.
int level
Maximal log level allowed for calls that match this definition.
regex_t component_regex
Component name regex.

References component_nopid, LogDef::component_regex, LogDef::file_regex, LogDef::force, LogDef::from_line, LogDef::function_regex, GNUNET_ERROR_TYPE_MESSAGE, gnunet_force_log_present, GNUNET_NO, LogDef::level, line, logdefs, logdefs_len, min_level, and LogDef::to_line.

Referenced by GCCH_debug(), GCT_debug(), and get_nick_record().

Here is the caller graph for this function:

◆ GNUNET_htonll()

uint64_t GNUNET_htonll ( uint64_t  n)

Convert unsigned 64-bit integer to network byte order.

Parameters
nThe value in host byte order.
Returns
The same value in network byte order.

Definition at line 36 of file common_endian.c.

37 {
38 #if __BYTE_ORDER == __BIG_ENDIAN
39  return n;
40 #elif __BYTE_ORDER == __LITTLE_ENDIAN
41  return (((uint64_t) htonl (n)) << 32) + htonl (n >> 32);
42 #else
43  #error byteorder undefined
44 #endif
45 }

Referenced by abd_string_to_value(), block_proc(), change_service(), commit_set(), consider_sending_fc(), create_loc_uri(), determine_id(), GCCH_handle_channel_plaintext_data_ack(), GNUNET_ABD_delegate_issue(), GNUNET_ABD_delegate_serialize(), GNUNET_ABD_delegates_serialize(), GNUNET_ARM_request_service_list(), GNUNET_BIO_write_int64(), GNUNET_CRYPTO_ecc_scalar_from_int(), GNUNET_CRYPTO_random_timeflake(), GNUNET_DATASTORE_get_key(), GNUNET_DATASTORE_get_zero_anonymity(), GNUNET_DATASTORE_reserve(), GNUNET_FS_tree_encoder_next(), GNUNET_GNSRECORD_records_serialize(), GNUNET_hton_double(), GNUNET_NAMESTORE_zone_iterator_next(), GNUNET_NAMESTORE_zone_monitor_next(), GNUNET_PQ_query_param_absolute_time(), GNUNET_PQ_query_param_relative_time(), GNUNET_PQ_query_param_uint64(), GNUNET_RECLAIM_attribute_store(), GNUNET_RECLAIM_credential_store(), GNUNET_TESTBED_controller_connect(), GNUNET_TESTBED_controller_link(), GNUNET_TESTBED_generate_peergetconfig_msg_(), GNUNET_TESTBED_generate_slavegetconfig_msg_(), GST_send_operation_fail_msg(), GST_send_operation_success_msg(), handle_client_accept(), hash_for_index_cb(), notify_change(), opstart_manage_service(), opstart_overlay_connect(), opstart_peer_create(), opstart_peer_destroy(), opstart_peer_reconfigure(), opstart_peer_start(), opstart_peer_stop(), opstart_shutdown_peers(), p2_controller_connect_cb(), run(), save(), send_ack(), send_add_queue(), send_channel_data_ack(), send_client_done(), send_client_element(), send_controller_link_response(), send_hello_thru_rocc(), send_overlay_connect_success_msg(), send_update_queue(), signal_result(), transmit(), transmit_item(), transmit_set(), unindex_process(), union_accept(), uri_chk_parse(), and uri_loc_parse().

◆ GNUNET_ntohll()

uint64_t GNUNET_ntohll ( uint64_t  n)

Convert unsigned 64-bit integer to host byte order.

Parameters
nThe value in network byte order.
Returns
The same value in host byte order.

Definition at line 53 of file common_endian.c.

54 {
55 #if __BYTE_ORDER == __BIG_ENDIAN
56  return n;
57 #elif __BYTE_ORDER == __LITTLE_ENDIAN
58  return (((uint64_t) ntohl (n)) << 32) + ntohl (n >> 32);
59 #else
60  #error byteorder undefined
61 #endif
62 }

Referenced by abd_value_to_string(), backward_resolution(), cb_intersection_element_removed(), cmp_pow_value(), copy_element_cb(), find_proof(), forward_overlay_connect(), GNUNET_ABD_delegate_deserialize(), GNUNET_ABD_delegates_deserialize(), GNUNET_BIO_read_int64(), GNUNET_FRAGMENT_print_ack(), GNUNET_FRAGMENT_process_ack(), GNUNET_FS_handle_on_demand_block(), GNUNET_FS_publish_stop(), GNUNET_FS_uri_chk_get_file_size(), GNUNET_GNSRECORD_records_deserialize(), GNUNET_ntoh_double(), GNUNET_xfree_(), GNUNET_xrealloc_(), handle_add_queue_message(), handle_alice_client_message(), handle_arm_list_result(), handle_arm_result(), handle_attribute_store_message(), handle_bob_client_message(), handle_client_index_start(), handle_client_loc_sign(), handle_credential_store_message(), handle_data(), handle_flow_control(), handle_get(), handle_get_key(), handle_get_zero_anonymity(), handle_iteration_next(), handle_link_controllers(), handle_link_controllers_result(), handle_manage_peer_service(), handle_monitor_next(), handle_op_fail_event(), handle_opsuccess(), handle_overlay_connect(), handle_peer_conevent(), handle_peer_config(), handle_peer_create(), handle_peer_create_success(), handle_peer_destroy(), handle_peer_event(), handle_peer_get_config(), handle_peer_reconfigure(), handle_peer_start(), handle_peer_stop(), handle_remote_overlay_connect(), handle_reserve(), handle_result(), handle_set(), handle_shutdown_peers(), handle_slave_config(), handle_slave_get_config(), handle_start(), handle_statistics_value(), handle_statistics_watch_value(), handle_stop(), handle_union_p2p_strata_estimator(), handle_update_queue_message(), process_result_with_request(), reconstruct_cb(), set_result_cb(), try_match_block(), uri_chk_to_string(), uri_loc_to_string(), and verify_message_crypto().

◆ GNUNET_hton_double()

double GNUNET_hton_double ( double  d)

Convert double to network byte order.

Parameters
dThe value in host byte order.
Returns
The same value in network byte order.

Convert double to network byte order.

Parameters
dthe value in network byte order
Returns
the same value in host byte order

Definition at line 74 of file common_endian.c.

75 {
76  double res;
77  uint64_t *in = (uint64_t *) &d;
78  uint64_t *out = (uint64_t *) &res;
79 
80  out[0] = GNUNET_htonll (in[0]);
81 
82  return res;
83 }
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:36
static int res

References GNUNET_htonll(), and res.

Referenced by setup_estimate_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_ntoh_double()

double GNUNET_ntoh_double ( double  d)

Convert double to host byte order.

Parameters
dThe value in network byte order.
Returns
The same value in host byte order.

Convert double to host byte order.

Parameters
dthe value in network byte order
Returns
the same value in host byte order

Definition at line 92 of file common_endian.c.

93 {
94  double res;
95  uint64_t *in = (uint64_t *) &d;
96  uint64_t *out = (uint64_t *) &res;
97 
98  out[0] = GNUNET_ntohll (in[0]);
99 
100  return res;
101 }
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:53

References GNUNET_ntohll(), and res.

Referenced by handle_estimate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_memcmp_ct_()

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.

Parameters
b1some buffer of size len
b2another buffer of size len
lennumber of bytes in b1 and b2
Returns
0 if buffers are equal,

Definition at line 130 of file consttime_memcmp.c.

131 {
132  const uint8_t *c1, *c2;
133  uint16_t d, r, m;
134 
135 #if USE_VOLATILE_TEMPORARY
136  volatile uint16_t v;
137 #else
138  uint16_t v;
139 #endif
140 
141  c1 = b1;
142  c2 = b2;
143 
144  r = 0;
145  while (len)
146  {
147  /*
148  * Take the low 8 bits of r (in the range 0x00 to 0xff,
149  * or 0 to 255);
150  * As explained elsewhere, the low 8 bits of r will be zero
151  * if and only if all bytes compared so far were identical;
152  * Zero-extend to a 16-bit type (in the range 0x0000 to
153  * 0x00ff);
154  * Add 255, yielding a result in the range 255 to 510;
155  * Save that in a volatile variable to prevent
156  * the compiler from trying any shortcuts (the
157  * use of a volatile variable depends on "#ifdef
158  * USE_VOLATILE_TEMPORARY", and most compilers won't
159  * need it);
160  * Divide by 256 yielding a result of 1 if the original
161  * value of r was non-zero, or 0 if r was zero;
162  * Subtract 1, yielding 0 if r was non-zero, or -1 if r
163  * was zero;
164  * Convert to uint16_t, yielding 0x0000 if r was
165  * non-zero, or 0xffff if r was zero;
166  * Save in m.
167  */v = ((uint16_t) (uint8_t) r) + 255;
168  m = v / 256 - 1;
169 
170  /*
171  * Get the values from *c1 and *c2 as uint8_t (each will
172  * be in the range 0 to 255, or 0x00 to 0xff);
173  * Convert them to signed int values (still in the
174  * range 0 to 255);
175  * Subtract them using signed arithmetic, yielding a
176  * result in the range -255 to +255;
177  * Convert to uint16_t, yielding a result in the range
178  * 0xff01 to 0xffff (for what was previously -255 to
179  * -1), or 0, or in the range 0x0001 to 0x00ff (for what
180  * was previously +1 to +255).
181  */d = (uint16_t) ((int) *c1 - (int) *c2);
182 
183  /*
184  * If the low 8 bits of r were previously 0, then m
185  * is now 0xffff, so (d & m) is the same as d, so we
186  * effectively copy d to r;
187  * Otherwise, if r was previously non-zero, then m is
188  * now 0, so (d & m) is zero, so leave r unchanged.
189  * Note that the low 8 bits of d will be zero if and
190  * only if d == 0, which happens when *c1 == *c2.
191  * The low 8 bits of r are thus zero if and only if the
192  * entirety of r is zero, which happens if and only if
193  * all bytes compared so far were equal. As soon as a
194  * non-zero value is stored in r, it remains unchanged
195  * for the remainder of the loop.
196  */r |= (d & m);
197 
198  /*
199  * Increment pointers, decrement length, and loop.
200  */
201  ++c1;
202  ++c2;
203  --len;
204  }
205 
206  /*
207  * At this point, r is an unsigned value, which will be 0 if the
208  * final result should be zero, or in the range 0x0001 to 0x00ff
209  * (1 to 255) if the final result should be positive, or in the
210  * range 0xff01 to 0xffff (65281 to 65535) if the final result
211  * should be negative.
212  *
213  * We want to convert the unsigned values in the range 0xff01
214  * to 0xffff to signed values in the range -255 to -1, while
215  * converting the other unsigned values to equivalent signed
216  * values (0, or +1 to +255).
217  *
218  * On a machine with two's complement arithmetic, simply copying
219  * the underlying bits (with sign extension if int is wider than
220  * 16 bits) would do the job, so something like this might work:
221  *
222  * return (int16_t)r;
223  *
224  * However, that invokes implementation-defined behaviour,
225  * because values larger than 32767 can't fit in a signed 16-bit
226  * integer without overflow.
227  *
228  * To avoid any implementation-defined behaviour, we go through
229  * these contortions:
230  *
231  * a. Calculate ((uint32_t)r + 0x8000). The cast to uint32_t
232  * it to prevent problems on platforms where int is narrower
233  * than 32 bits. If int is a larger than 32-bits, then the
234  * usual arithmetic conversions cause this addition to be
235  * done in unsigned int arithmetic. If int is 32 bits
236  * or narrower, then this addition is done in uint32_t
237  * arithmetic. In either case, no overflow or wraparound
238  * occurs, and the result from this step has a value that
239  * will be one of 0x00008000 (32768), or in the range
240  * 0x00008001 to 0x000080ff (32769 to 33023), or in the range
241  * 0x00017f01 to 0x00017fff (98049 to 98303).
242  *
243  * b. Cast the result from (a) to uint16_t. This effectively
244  * discards the high bits of the result, in a way that is
245  * well defined by the C language. The result from this step
246  * will be of type uint16_t, and its value will be one of
247  * 0x8000 (32768), or in the range 0x8001 to 0x80ff (32769 to
248  * 33023), or in the range 0x7f01 to 0x7fff (32513 to
249  * 32767).
250  *
251  * c. Cast the result from (b) to int32_t. We use int32_t
252  * instead of int because we need a type that's strictly
253  * larger than 16 bits, and the C standard allows
254  * implementations where int is only 16 bits. The result
255  * from this step will be of type int32_t, and its value will
256  * be one of 0x00008000 (32768), or in the range 0x00008001
257  * to 0x000080ff (32769 to 33023), or in the range 0x00007f01
258  * to 0x00007fff (32513 to 32767).
259  *
260  * d. Take the result from (c) and subtract 0x8000 (32768) using
261  * signed int32_t arithmetic. The result from this step will
262  * be of type int32_t and the value will be one of
263  * 0x00000000 (0), or in the range 0x00000001 to 0x000000ff
264  * (+1 to +255), or in the range 0xffffff01 to 0xffffffff
265  * (-255 to -1).
266  *
267  * e. Cast the result from (d) to int. This does nothing
268  * interesting, except to make explicit what would have been
269  * implicit in the return statement. The final result is an
270  * int in the range -255 to +255.
271  *
272  * Unfortunately, compilers don't seem to be good at figuring
273  * out that most of this can be optimised away by careful choice
274  * of register width and sign extension.
275  *
276  */return (/*e*/ int) (/*d*/
277  (/*c*/ int32_t) (/*b*/ uint16_t) (/*a*/ (uint32_t) r + 0x8000)
278  - 0x8000);
279 }
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...

References consensus-simulation::int, len, and m.

◆ GNUNET_is_zero_()

enum GNUNET_GenericReturnValue GNUNET_is_zero_ ( const void *  a,
size_t  n 
)

Check that memory in a is all zeros.

a must be a pointer.

Parameters
apointer to n bytes which should be tested for the entire memory being zero'ed out.
nnumber of bytes in to be tested
Returns
GNUNET_YES if a is zero, GNUNET_NO otherwise

Definition at line 486 of file common_allocation.c.

510 {
511  const char *b = a;
512 
513  for (size_t i = 0; i < n; i++)
514  if (b[i])
515  return GNUNET_NO;
516  return GNUNET_YES;
517 }

◆ GNUNET_xmalloc_()

int int void* GNUNET_xmalloc_ ( size_t  size,
const char *  filename,
int  linenumber 
)

Allocate memory.

Checks the return value, aborts if no more memory is available. Don't use GNUNET_xmalloc_ directly. Use the GNUNET_malloc macro. The memory will be zero'ed out.

Parameters
sizenumber of bytes to allocate
filenamewhere is this call being made (for debugging)
linenumberline where this call is being made (for debugging)
Returns
allocated memory, never NULL

Checks the return value, aborts if no more memory is available.

Parameters
sizehow many bytes of memory to allocate, do NOT use this function (or GNUNET_malloc()) to allocate more than several MB of memory, if you are possibly needing a very large chunk use GNUNET_xmalloc_unchecked_() instead.
filenamewhere in the code was the call to GNUNET_malloc()
linenumberwhere in the code was the call to GNUNET_malloc()
Returns
pointer to size bytes of memory

Definition at line 59 of file common_allocation.c.

60 {
61  void *ret;
62 
63  /* As a security precaution, we generally do not allow very large
64  * allocations using the default 'GNUNET_malloc()' macro */
66  ret = GNUNET_xmalloc_unchecked_ (size, filename, linenumber);
67  if (NULL == ret)
68  {
70  GNUNET_assert (0);
71  }
72  return ret;
73 }
#define LOG_STRERROR(kind, syscall)
void * GNUNET_xmalloc_unchecked_(size_t size, const char *filename, int linenumber)
Wrapper around malloc().
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static char * filename
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_assert_at(cond, f, l)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_MAX_MALLOC_CHECKED
Maximum allocation with GNUNET_malloc macro.
static unsigned int size
Size of the "table".
Definition: peer.c:67

References filename, GNUNET_assert, GNUNET_assert_at, GNUNET_ERROR_TYPE_ERROR, GNUNET_MAX_MALLOC_CHECKED, GNUNET_xmalloc_unchecked_(), LOG_STRERROR, ret, and size.

Referenced by GNUNET_xgrow_(), GNUNET_xnew_array_2d_(), GNUNET_xnew_array_3d_(), GNUNET_xstrdup_(), and GNUNET_xstrndup_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_xnew_array_2d_()

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.

Aborts if no more memory is available. Don't use GNUNET_xnew_array_2d_ directly. Use the GNUNET_new_array_2d macro. The memory of the elements will be zero'ed out.

Parameters
nsize of the first dimension
msize of the second dimension
elementSizesize of a single element in bytes
filenamewhere is this call being made (for debugging)
linenumberline where this call is being made (for debugging)
Returns
allocated memory, never NULL

Definition at line 91 of file common_allocation.c.

96 {
97  /* use char pointer internally to avoid void pointer arithmetic warnings */
98  char **ret = GNUNET_xmalloc_ (n * sizeof(void *) /* 1. dim header */
99  + n * m * elementSize, /* element data */
100  filename,
101  linenumber);
102 
103  for (size_t i = 0; i < n; i++)
104  ret[i] = (char *) ret /* base address */
105  + n * sizeof(void *) /* skip 1. dim header */
106  + i * m * elementSize; /* skip to 2. dim row header */
107  return (void **) ret;
108 }
void * GNUNET_xmalloc_(size_t size, const char *filename, int linenumber)
Allocate memory.

References filename, GNUNET_xmalloc_(), m, and ret.

Here is the call graph for this function:

◆ GNUNET_xnew_array_3d_()

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.

Aborts if no more memory is available. Don't use GNUNET_xnew_array_3d_ directly. Use the GNUNET_new_array_3d macro. The memory of the elements will be zero'ed out.

Parameters
nsize of the first dimension
msize of the second dimension
osize of the third dimension
elementSizesize of a single element in bytes
filenamewhere is this call being made (for debugging)
linenumberline where this call is being made (for debugging)
Returns
allocated memory, never NULL

Definition at line 127 of file common_allocation.c.

133 {
134  /* use char pointer internally to avoid void pointer arithmetic warnings */
135  char ***ret = GNUNET_xmalloc_ (n * sizeof(void **) /* 1. dim header */
136  + n * m * sizeof(void *) /* 2. dim header */
137  + n * m * o * elementSize, /* element data */
138  filename,
139  linenumber);
140 
141  for (size_t i = 0; i < n; i++)
142  {
143  /* need to cast to (char *) temporarily for byte level accuracy */
144  ret[i] = (char **) ((char *) ret /* base address */
145  + n * sizeof(void **) /* skip 1. dim header */
146  + i * m * sizeof(void *)); /* skip to 2. dim header */
147  for (size_t j = 0; j < m; j++)
148  ret[i][j] = (char *) ret /* base address */
149  + n * sizeof(void **) /* skip 1. dim header */
150  + n * m * sizeof(void *) /* skip 2. dim header */
151  + i * m * o * elementSize /* skip to 2. dim part */
152  + j * o * elementSize; /* skip to 3. dim row data */
153  }
154  return (void ***) ret;
155 }

References filename, GNUNET_xmalloc_(), m, and ret.

Here is the call graph for this function:

◆ GNUNET_xmemdup_()

void* GNUNET_xmemdup_ ( const void *  buf,
size_t  size,
const char *  filename,
int  linenumber 
)

Allocate and initialize memory.

Checks the return value, aborts if no more memory is available. Don't use GNUNET_xmemdup_ directly. Use the GNUNET_memdup macro.

Parameters
bufbuffer to initialize from (must contain size bytes)
sizenumber of bytes to allocate
filenamewhere is this call being made (for debugging)
linenumberline where this call is being made (for debugging)
Returns
allocated memory, never NULL

Checks the return value, aborts if no more memory is available. Don't use GNUNET_xmemdup_() directly. Use the GNUNET_memdup() macro.

Parameters
bufbuffer to initialize from (must contain size bytes)
sizenumber of bytes to allocate
filenamewhere is this call being made (for debugging)
linenumberline where this call is being made (for debugging)
Returns
allocated memory, never NULL

Definition at line 170 of file common_allocation.c.

174 {
175  void *ret;
176 
177  /* As a security precaution, we generally do not allow very large
178  * allocations here */
180  GNUNET_assert_at (size < INT_MAX, filename, linenumber);
181  ret = malloc (size);
182  if (ret == NULL)
183  {
185  GNUNET_assert (0);
186  }
188  return ret;
189 }
#define INT_MAX
static char buf[2048]
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.

References buf, filename, GNUNET_assert, GNUNET_assert_at, GNUNET_ERROR_TYPE_ERROR, GNUNET_MAX_MALLOC_CHECKED, GNUNET_memcpy, INT_MAX, LOG_STRERROR, ret, and size.

◆ GNUNET_xmalloc_unchecked_()

void* GNUNET_xmalloc_unchecked_ ( size_t  size,
const char *  filename,
int  linenumber 
)

Allocate memory.

This function does not check if the allocation request is within reasonable bounds, allowing allocations larger than 40 MB. If you don't expect the possibility of very large allocations, use GNUNET_malloc instead. The memory will be zero'ed out.

Parameters
sizenumber of bytes to allocate
filenamewhere is this call being made (for debugging)
linenumberline where this call is being made (for debugging)
Returns
pointer to size bytes of memory, NULL if we do not have enough memory

Allocate memory.

Allocates size bytes of memory. The memory will be zero'ed out.

Parameters
sizethe number of bytes to allocate
filenamewhere in the code was the call to GNUNET_malloc_unchecked()
linenumberwhere in the code was the call to GNUNET_malloc_unchecked()
Returns
pointer to size bytes of memory, NULL if we do not have enough memory

Definition at line 202 of file common_allocation.c.

203 {
204  void *result;
205 
206  (void) filename;
207  (void) linenumber;
208 
209  result = malloc (size);
210  if (NULL == result)
211  return NULL;
212  memset (result, 0, size);
213 
214  return result;
215 }
static int result
Global testing status.

References filename, result, and size.

Referenced by GNUNET_xmalloc_().

Here is the caller graph for this function:

◆ GNUNET_xrealloc_()

void* GNUNET_xrealloc_ ( void *  ptr,
size_t  n,
const char *  filename,
int  linenumber 
)

Reallocate memory.

Checks the return value, aborts if no more memory is available.

Checks the return value, aborts if no more memory is available. The content of the intersection of the new and old size will be unchanged.

Parameters
ptrthe pointer to reallocate
nhow many bytes of memory to allocate
filenamewhere in the code was the call to GNUNET_realloc()
linenumberwhere in the code was the call to GNUNET_realloc()
Returns
pointer to size bytes of memory

Definition at line 230 of file common_allocation.c.

231 {
232  (void) filename;
233  (void) linenumber;
234 
235 #if defined(M_SIZE)
236 #if ENABLE_POISONING
237  {
238  uint64_t *base = ptr;
239  size_t s = M_SIZE (ptr);
240 
241  if (s > n)
242  {
243  const uint64_t baadfood = GNUNET_ntohll (0xBAADF00DBAADF00DLL);
244  char *cbase = ptr;
245 
246  GNUNET_memcpy (&cbase[n],
247  &baadfood,
248  GNUNET_MIN (8 - (n % 8),
249  s - n));
250  for (size_t i = 1 + (n + 7) / 8; i < s / 8; i++)
251  base[i] = baadfood;
252  GNUNET_memcpy (&base[s / 8],
253  &baadfood,
254  s % 8);
255  }
256  }
257 #endif
258 #endif
259  ptr = realloc (ptr, n);
260  if ((NULL == ptr) && (n > 0))
261  {
263  GNUNET_assert (0);
264  }
265  return ptr;
266 }
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:53
#define GNUNET_MIN(a, b)

References filename, GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_memcpy, GNUNET_MIN, GNUNET_ntohll(), and LOG_STRERROR.

Here is the call graph for this function:

◆ GNUNET_xfree_()

void GNUNET_xfree_ ( void *  ptr,
const char *  filename,
int  linenumber 
)

Free memory.

Merely a wrapper for the case that we want to keep track of allocations. Don't use GNUNET_xfree_ directly. Use the GNUNET_free macro.

Parameters
ptrpointer to memory to free
filenamewhere is this call being made (for debugging)
linenumberline where this call is being made (for debugging)

Merely a wrapper for the case that we want to keep track of allocations.

Parameters
ptrthe pointer to free
filenamewhere in the code was the call to GNUNET_free()
linenumberwhere in the code was the call to GNUNET_free()

Definition at line 294 of file common_allocation.c.

297 {
298  if (NULL == ptr)
299  return;
300 #if defined(M_SIZE)
301 #if ENABLE_POISONING
302  {
303  const uint64_t baadfood = GNUNET_ntohll (0xBAADF00DBAADF00DLL);
304  uint64_t *base = ptr;
305  size_t s = M_SIZE (ptr);
306 
307  for (size_t i = 0; i < s / 8; i++)
308  base[i] = baadfood;
309  GNUNET_memcpy (&base[s / 8], &baadfood, s % 8);
310  }
311 #endif
312 #endif
313  free (ptr);
314 }

References GNUNET_memcpy, and GNUNET_ntohll().

Referenced by GNUNET_xgrow_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_xstrdup_()

char* GNUNET_xstrdup_ ( const char *  str,
const char *  filename,
int  linenumber 
)

Dup a string.

Don't call GNUNET_xstrdup_ directly. Use the GNUNET_strdup macro.

Parameters
strstring to duplicate
filenamewhere is this call being made (for debugging)
linenumberline where this call is being made (for debugging)
Returns
the duplicated string

Dup a string.

Parameters
strthe string to dup
filenamewhere in the code was the call to GNUNET_strdup()
linenumberwhere in the code was the call to GNUNET_strdup()
Returns
strdup(@a str)

Definition at line 326 of file common_allocation.c.

327 {
328  char *res;
329  size_t slen;
330 
331  GNUNET_assert_at (str != NULL, filename, linenumber);
332  slen = strlen (str) + 1;
333  res = GNUNET_xmalloc_ (slen, filename, linenumber);
334  GNUNET_memcpy (res, str, slen);
335  return res;
336 }

References filename, GNUNET_assert_at, GNUNET_memcpy, GNUNET_xmalloc_(), and res.

Here is the call graph for this function:

◆ GNUNET_xstrndup_()

char* GNUNET_xstrndup_ ( const char *  str,
size_t  len,
const char *  filename,
int  linenumber 
)

Dup partially a string.

Don't call GNUNET_xstrndup_ directly. Use the GNUNET_strndup macro.

Parameters
strstring to duplicate
lenlength of the string to duplicate
filenamewhere is this call being made (for debugging)
linenumberline where this call is being made (for debugging)
Returns
the duplicated string

Dup partially a string.

Parameters
strthe string to dup
lenthe length of the string to dup
filenamewhere in the code was the call to GNUNET_strndup()
linenumberwhere in the code was the call to GNUNET_strndup()
Returns
strndup(@a str,@a len)

Definition at line 365 of file common_allocation.c.

369 {
370  char *res;
371 
372  if (0 == len)
373  return GNUNET_strdup ("");
374  GNUNET_assert_at (NULL != str, filename, linenumber);
375  len = strnlen (str, len);
376  res = GNUNET_xmalloc_ (len + 1, filename, linenumber);
377  GNUNET_memcpy (res, str, len);
378  /* res[len] = '\0'; 'malloc' zeros out anyway */
379  return res;
380 }
static size_t strnlen(const char *s, size_t n)
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.

References filename, GNUNET_assert_at, GNUNET_memcpy, GNUNET_strdup, GNUNET_xmalloc_(), len, res, and strnlen().

Here is the call graph for this function:

◆ GNUNET_xgrow_()

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.

Grows old by (*oldCount-newCount)*elementSize bytes and sets *oldCount to newCount.

Don't call GNUNET_xgrow_ directly. Use the GNUNET_array_grow macro.

Parameters
oldaddress of the pointer to the array *old may be NULL
elementSizethe size of the elements of the array
oldCountaddress of the number of elements in the *old array
newCountnumber of elements in the new array, may be 0 (then *old will be NULL afterwards)
filenamewhere is this call being made (for debugging)
linenumberline where this call is being made (for debugging)

Grow an array, the new elements are zeroed out.

Grows old by (*oldCount-newCount)*elementSize bytes and sets *oldCount to newCount.

Parameters
oldaddress of the pointer to the array *old may be NULL
elementSizethe size of the elements of the array
oldCountaddress of the number of elements in the *old array
newCountnumber of elements in the new array, may be 0
filenamewhere in the code was the call to GNUNET_array_grow()
linenumberwhere in the code was the call to GNUNET_array_grow()

Definition at line 396 of file common_allocation.c.

402 {
403  void *tmp;
404  size_t size;
405 
406  GNUNET_assert_at (INT_MAX / elementSize > newCount, filename, linenumber);
407  size = newCount * elementSize;
408  if (0 == size)
409  {
410  tmp = NULL;
411  }
412  else
413  {
414  tmp = GNUNET_xmalloc_ (size, filename, linenumber);
415  if (NULL != *old)
416  {
417  GNUNET_memcpy (tmp, *old, elementSize * GNUNET_MIN (*oldCount, newCount));
418  }
419  }
420 
421  if (NULL != *old)
422  {
423  GNUNET_xfree_ (*old, filename, linenumber);
424  }
425  *old = tmp;
426  *oldCount = newCount;
427 }
void GNUNET_xfree_(void *ptr, const char *filename, int linenumber)
Free memory.

References filename, GNUNET_assert_at, GNUNET_memcpy, GNUNET_MIN, GNUNET_xfree_(), GNUNET_xmalloc_(), INT_MAX, and size.

Here is the call graph for this function:

◆ GNUNET_async_scope_enter()

void GNUNET_async_scope_enter ( const struct GNUNET_AsyncScopeId aid,
struct GNUNET_AsyncScopeSave old_scope 
)

Set the async scope for the current thread.

Parameters
aidthe async scope identifier
old_scope[out]location to save the old scope

Definition at line 1501 of file common_logging.c.

1503 {
1504  *old_scope = current_async_scope;
1507 }
static GNUNET_THREAD_LOCAL struct GNUNET_AsyncScopeSave current_async_scope
Asynchronous scope of the current thread, or NULL if we have not entered an async scope yet.
int have_scope
GNUNET_YES unless this saved scope is the unnamed root scope.
struct GNUNET_AsyncScopeId scope_id
Saved scope.

References current_async_scope, GNUNET_YES, GNUNET_AsyncScopeSave::have_scope, and GNUNET_AsyncScopeSave::scope_id.

Referenced by GNUNET_SCHEDULER_begin_async_scope(), and GNUNET_SCHEDULER_do_work().

Here is the caller graph for this function:

◆ GNUNET_async_scope_restore()

void GNUNET_async_scope_restore ( struct GNUNET_AsyncScopeSave old_scope)

Clear the current thread's async scope.

Parameters
old_scopescope to restore

Definition at line 1516 of file common_logging.c.

1517 {
1518  current_async_scope = *old_scope;
1519 }

References current_async_scope.

Referenced by GNUNET_SCHEDULER_do_work().

Here is the caller graph for this function:

◆ GNUNET_async_scope_get()

void GNUNET_async_scope_get ( struct GNUNET_AsyncScopeSave scope_ret)

Get the current async scope.

Parameters
[out]scope_retpointer to where the result is stored

Definition at line 1542 of file common_logging.c.

1543 {
1544  *scope_ret = current_async_scope;
1545 }

References current_async_scope.

Referenced by add_without_sets(), GNUNET_SCHEDULER_add_at_with_priority(), GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_add_select(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_do_work(), and setup_job_headers().

Here is the caller graph for this function:

◆ GNUNET_async_scope_fresh()

void GNUNET_async_scope_fresh ( struct GNUNET_AsyncScopeId aid_ret)

Generate a fresh async scope identifier.

Parameters
[out]aid_retpointer to where the result is stored

Definition at line 1528 of file common_logging.c.

1529 {
1531  aid_ret,
1532  sizeof(struct GNUNET_AsyncScopeId));
1533 }
void GNUNET_CRYPTO_random_block(enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length)
Fill block with a random values.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
Identifier for an asynchronous execution context.

References GNUNET_CRYPTO_QUALITY_WEAK, and GNUNET_CRYPTO_random_block().

Here is the call graph for this function: