GNUnet 0.22.2
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 "gnunet_config.h"
#include <stdbool.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdint.h>
#include <stdarg.h>
#include <sys/types.h>
#include "gettext.h"
Include dependency graph for gnunet_common.h:

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_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_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_B2S(obj)   GNUNET_b2s ((obj), sizeof (*(obj)))
 Convert a fixed-sized object to a string using GNUNET_b2s(). More...
 
#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_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...
 
const char * GNUNET_b2s (const void *buf, size_t buf_size)
 Convert a buffer to an 8-character string representative of the contents. More...
 
void GNUNET_log_skip (int n, int check_reset)
 Ignore the next n calls to the log function. More...
 
enum GNUNET_GenericReturnValue 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...
 
size_t GNUNET_hex2b (const char *src, void *dst, size_t dstlen, int invert)
 Parse an ascii-encoded hexadecimal string into the buffer. More...
 
void GNUNET_print_bytes (const void *buf, size_t buf_len, int fold, int in_be)
 Print a byte string in hexadecimal ascii notation. 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...
 
bool 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_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.