GNUnet 0.22.2
GNS Record library

Manipulate GNS record data. More...

Collaboration diagram for GNS Record library:

Data Structures

struct  GNUNET_GNSRECORD_Data
 A GNS record. More...
 
struct  GNUNET_GNSRECORD_PlaceData
 Data stored in a PLACE record. More...
 
struct  GNUNET_GNSRECORD_EcdsaBlock
 Information we have in an encrypted block with record data (i.e. More...
 
struct  GNUNET_GNSRECORD_EddsaBlock
 Information we have in an encrypted block with record data (i.e. More...
 
struct  GNUNET_GNSRECORD_Block
 
struct  GNUNET_GNSRECORD_BoxRecord
 Record type used to box up SRV and TLSA records. More...
 
struct  GNUNET_GNSRECORD_SBoxRecord
 Record type used to box up SMIMEA records. More...
 
struct  GNUNET_GNSRECORD_ReverseRecord
 Record type used internally to keep track of reverse mappings into a namespace. More...
 
struct  GNUNET_GNSRECORD_PowP
 Struct for a proof of work as part of the revocation. More...
 
struct  GNUNET_GNSRECORD_SignaturePurposePS
 The signature object we use for the PoW. More...
 

Macros

#define GNUNET_GNS_EMPTY_LABEL_AT   "@"
 String we use to indicate an empty label (top-level entry in the zone). More...
 
#define GNUNET_GNSRECORD_MAX_BLOCK_SIZE   (63 * 1024)
 Maximum size of a value that can be stored in a GNS block. More...
 
#define GNUNET_GNSRECORD_TYPE_ANY   0
 Record type indicating any record/'*'. More...
 
#define GNUNET_GNSRECORD_RF_RCMP_FLAGS   (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)
 Include the record types generated from GANA. More...
 
#define GNUNET_MAX_POW_SIZE
 Maximum length of a revocation. More...
 
#define POW_COUNT   32
 The proof-of-work narrowing factor. More...
 

Typedefs

typedef void(* GNUNET_GNSRECORD_RecordCallback) (void *cls, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
 Process a records that were decrypted from a block. More...
 

Enumerations

enum  GNUNET_GNSRECORD_Flags {
  GNUNET_GNSRECORD_RF_NONE = 0 , GNUNET_GNSRECORD_RF_CRITICAL = 1 << (15 - 15) , GNUNET_GNSRECORD_RF_SHADOW = 1 << (15 - 14) , GNUNET_GNSRECORD_RF_SUPPLEMENTAL = 1 << (15 - 13) ,
  GNUNET_GNSRECORD_RF_MAINTENANCE = 1 << (15 - 2) , GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION = 1 << (15 - 1) , GNUNET_GNSRECORD_RF_PRIVATE = 1 << (15 - 0)
}
 Flags that can be set for a record. More...
 
enum  GNUNET_GNSRECORD_Filter { GNUNET_GNSRECORD_FILTER_NONE = 0 , GNUNET_GNSRECORD_FILTER_INCLUDE_MAINTENANCE = 1 , GNUNET_GNSRECORD_FILTER_OMIT_PRIVATE = 2 }
 Filter for GNUNET_GNSRECORD_normalize_record_set(). More...
 

Functions

struct GNUNET_JSON_Specification GNUNET_GNSRECORD_JSON_spec_gnsrecord (struct GNUNET_GNSRECORD_Data **rd, unsigned int *rd_count, char **name)
 JSON Specification for GNS Records. More...
 
json_t * GNUNET_GNSRECORD_JSON_from_gnsrecord (const char *rname, const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count)
 Convert GNS record to JSON. More...
 
char * GNUNET_GNSRECORD_value_to_string (uint32_t type, const void *data, size_t data_size)
 Convert the binary value data of a record of type type to a human-readable string. More...
 
int GNUNET_GNSRECORD_string_to_value (uint32_t type, const char *s, void **data, size_t *data_size)
 Convert human-readable version of the value s of a record of type type to the respective binary representation. More...
 
uint32_t GNUNET_GNSRECORD_typename_to_number (const char *dns_typename)
 Convert a type name (e.g. More...
 
const char * GNUNET_GNSRECORD_number_to_typename (uint32_t type)
 Convert a type number to the corresponding type string (e.g. More...
 
ssize_t GNUNET_GNSRECORD_records_get_size (unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
 Calculate how many bytes we will need to serialize the given records. More...
 
ssize_t GNUNET_GNSRECORD_records_serialize (unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, size_t dest_size, char *dest)
 Serialize the given records to the given destination buffer. More...
 
unsigned int GNUNET_GNSRECORD_records_deserialize_get_size (size_t len, const char *src)
 
int GNUNET_GNSRECORD_records_deserialize (size_t len, const char *src, unsigned int rd_count, struct GNUNET_GNSRECORD_Data *dest)
 Deserialize the given records to the given destination. More...
 
int GNUNET_GNSRECORD_is_expired (const struct GNUNET_GNSRECORD_Data *rd)
 Test if a given record is expired. More...
 
char * GNUNET_GNSRECORD_string_normalize (const char *src)
 Normalize a UTF-8 string to a GNS name. More...
 
const char * GNUNET_GNSRECORD_z2s (const struct GNUNET_CRYPTO_PublicKey *z)
 Convert a zone to a string (for printing debug messages). More...
 
const char * GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_CRYPTO_PublicKey *pkey)
 Convert public key to the respective absolute domain name in the ".zkey" pTLD. More...
 
int GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey, struct GNUNET_CRYPTO_PublicKey *pkey)
 Convert an absolute domain name to the respective public key. More...
 
void GNUNET_GNSRECORD_query_from_private_key (const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label, struct GNUNET_HashCode *query)
 Calculate the DHT query for a given label in a given zone. More...
 
void GNUNET_GNSRECORD_query_from_public_key (const struct GNUNET_CRYPTO_PublicKey *pub, const char *label, struct GNUNET_HashCode *query)
 Calculate the DHT query for a given label in a given zone. More...
 
ssize_t GNUNET_GNSRECORD_block_calculate_size (const struct GNUNET_CRYPTO_PrivateKey *key, const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count)
 Get size of buffer for block creation. More...
 
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_block_sign (const struct GNUNET_CRYPTO_PrivateKey *key, const char *label, struct GNUNET_GNSRECORD_Block *block)
 Sign a block create with GNUNET_GNSRECORD_block_create_unsigned. More...
 
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_block_create (const struct GNUNET_CRYPTO_PrivateKey *key, struct GNUNET_TIME_Absolute expire, const char *label, const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count, struct GNUNET_GNSRECORD_Block **block)
 Sign name and records. More...
 
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_block_create_unsigned (const struct GNUNET_CRYPTO_PrivateKey *key, struct GNUNET_TIME_Absolute expire, const char *label, const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count, struct GNUNET_GNSRECORD_Block **result)
 Create name and records but do not sign! Sign later with GNUNET_GNSRECORD_block_sign(). More...
 
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_block_create2 (const struct GNUNET_CRYPTO_PrivateKey *key, struct GNUNET_TIME_Absolute expire, const char *label, const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count, struct GNUNET_GNSRECORD_Block **result)
 Sign name and records, cache derived public key (also keeps the private key in static memory, so do not use this function if keeping the private key in the process'es RAM is a major issue). More...
 
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block)
 Check if a signature is valid. More...
 
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_block_decrypt (const struct GNUNET_GNSRECORD_Block *block, const struct GNUNET_CRYPTO_PublicKey *zone_key, const char *label, GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls)
 Decrypt block. More...
 
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_records_cmp (const struct GNUNET_GNSRECORD_Data *a, const struct GNUNET_GNSRECORD_Data *b)
 Compares if two records are equal. More...
 
struct GNUNET_TIME_Absolute GNUNET_GNSRECORD_record_get_expiration_time (unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, struct GNUNET_TIME_Absolute min)
 Returns the expiration time of the given block of records. More...
 
size_t GNUNET_GNSRECORD_block_get_size (const struct GNUNET_GNSRECORD_Block *block)
 Returns the length of this block in bytes. More...
 
struct GNUNET_TIME_Absolute GNUNET_GNSRECORD_block_get_expiration (const struct GNUNET_GNSRECORD_Block *block)
 Returns the expiration of a block. More...
 
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_query_from_block (const struct GNUNET_GNSRECORD_Block *block, struct GNUNET_HashCode *query)
 Builds the query hash from a block. More...
 
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_identity_from_data (const char *data, size_t data_size, uint32_t type, struct GNUNET_CRYPTO_PublicKey *key)
 Build a #GNUNET_GNSRECORD_PublicKey from zone delegation resource record data. More...
 
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_data_from_identity (const struct GNUNET_CRYPTO_PublicKey *key, char **data, size_t *data_size, uint32_t *type)
 Create record data and size from an identity key. More...
 
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_is_zonekey_type (uint32_t type)
 Check if this type is one of the supported GNS zone types. More...
 
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_is_critical (uint32_t type)
 Check if this type is a critical record. More...
 
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_normalize_record_set (const char *label, const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count, struct GNUNET_GNSRECORD_Data *rd_public, unsigned int *rd_count_public, struct GNUNET_TIME_Absolute *min_expiry, enum GNUNET_GNSRECORD_Filter filter, char **emsg)
 Normalize namestore records: Check for consistency and expirations. More...
 
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_label_check (const char *label, char **emsg)
 Check label for invalid characters. More...
 
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_check_pow (const struct GNUNET_GNSRECORD_PowP *pow, unsigned int matching_bits, struct GNUNET_TIME_Relative epoch_duration)
 Check if the given proof-of-work is valid. More...
 
void GNUNET_GNSRECORD_pow_init (const struct GNUNET_CRYPTO_PrivateKey *key, struct GNUNET_GNSRECORD_PowP *pow)
 Initializes a fresh PoW computation. More...
 
struct GNUNET_GNSRECORD_PowCalculationHandleGNUNET_GNSRECORD_pow_start (struct GNUNET_GNSRECORD_PowP *pow, int epochs, unsigned int difficulty)
 Starts a proof-of-work calculation given the pow object as well as target epochs and difficulty. More...
 
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_pow_round (struct GNUNET_GNSRECORD_PowCalculationHandle *pc)
 Calculate a single round in the key revocation PoW. More...
 
size_t GNUNET_GNSRECORD_proof_get_size (const struct GNUNET_GNSRECORD_PowP *pow)
 
void GNUNET_GNSRECORD_pow_stop (struct GNUNET_GNSRECORD_PowCalculationHandle *pc)
 Stop a PoW calculation. More...
 

Detailed Description

Manipulate GNS record data.

See also
Documentation

Macro Definition Documentation

◆ GNUNET_GNS_EMPTY_LABEL_AT

#define GNUNET_GNS_EMPTY_LABEL_AT   "@"

String we use to indicate an empty label (top-level entry in the zone).

DNS uses "@", so do we.

Definition at line 55 of file gnunet_gnsrecord_lib.h.

◆ GNUNET_GNSRECORD_MAX_BLOCK_SIZE

#define GNUNET_GNSRECORD_MAX_BLOCK_SIZE   (63 * 1024)

Maximum size of a value that can be stored in a GNS block.

Definition at line 60 of file gnunet_gnsrecord_lib.h.

◆ GNUNET_GNSRECORD_TYPE_ANY

#define GNUNET_GNSRECORD_TYPE_ANY   0

Record type indicating any record/'*'.

Definition at line 66 of file gnunet_gnsrecord_lib.h.

◆ GNUNET_GNSRECORD_RF_RCMP_FLAGS

#define GNUNET_GNSRECORD_RF_RCMP_FLAGS   (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)

Include the record types generated from GANA.

When comparing flags for record equality for removal, which flags should must match (in addition to the type, name, expiration value and data of the record)? All flags that are not listed here will be ignored for this purpose. (for example, we don't expect that users will remember to pass the '–private' option when removing a record from the namestore, hence we don't require this particular option to match upon removal). See also GNUNET_GNSRECORD_records_cmp.

Definition at line 84 of file gnunet_gnsrecord_lib.h.

◆ GNUNET_MAX_POW_SIZE

#define GNUNET_MAX_POW_SIZE
Value:
sizeof(struct GNUNET_GNSRECORD_PowP) \
+ sizeof(struct GNUNET_CRYPTO_PublicKey) \
+ 1024
An identity key as per LSD0001.
Struct for a proof of work as part of the revocation.

Maximum length of a revocation.

Definition at line 864 of file gnunet_gnsrecord_lib.h.

◆ POW_COUNT

#define POW_COUNT   32

The proof-of-work narrowing factor.

The number of PoWs that are calculates as part of revocation.

Definition at line 872 of file gnunet_gnsrecord_lib.h.

Typedef Documentation

◆ GNUNET_GNSRECORD_RecordCallback

typedef void(* GNUNET_GNSRECORD_RecordCallback) (void *cls, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)

Process a records that were decrypted from a block.

Parameters
clsclosure
rd_countnumber of entries in rd array
rdarray of records with data to store

Definition at line 389 of file gnunet_gnsrecord_lib.h.

Enumeration Type Documentation

◆ GNUNET_GNSRECORD_Flags

Flags that can be set for a record.

The numbers in the registry correspond to the bit index as specified in LSD0001 Chapter "Resource Records". Each enum member represents the 16-bit integer value of the flags field if only that particular flag was set. The value can be used to efficiently compare the bitmask setting for the record flag in C. WARNING: The values are in host byte order! In order to correctly check against the flags field a record, the respective fields must also be converted to HBO (or the enum value to NBO).

Enumerator
GNUNET_GNSRECORD_RF_NONE 

Entry for no flags / cleared flags.

GNUNET_GNSRECORD_RF_CRITICAL 

This record is critical.

If it cannot be processed (for example because the record type is unknown) resolution MUST fail

GNUNET_GNSRECORD_RF_SHADOW 

This record should not be used unless all (other) records in the set with an absolute expiration time have expired.

GNUNET_GNSRECORD_RF_SUPPLEMENTAL 

This is a supplemental record.

GNUNET_GNSRECORD_RF_MAINTENANCE 

Maintenance records.

E.g. TOMBSTONEs

GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION 

This expiration time of the record is a relative time (not an absolute time).

Used in GNUnet implementation.

GNUNET_GNSRECORD_RF_PRIVATE 

This is a private record of this peer and it should thus not be published.

Definition at line 99 of file gnunet_gnsrecord_lib.h.

100{
105
106
110 GNUNET_GNSRECORD_RF_CRITICAL = 1 << (15 - 15),
111
112
116 GNUNET_GNSRECORD_RF_SHADOW = 1 << (15 - 14),
117
118
122 GNUNET_GNSRECORD_RF_SUPPLEMENTAL = 1 << (15 - 13),
123
127 GNUNET_GNSRECORD_RF_MAINTENANCE = 1 << (15 - 2),
128
133
134
138 GNUNET_GNSRECORD_RF_PRIVATE = 1 << (15 - 0),
139
140};
@ GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION
This expiration time of the record is a relative time (not an absolute time).
@ GNUNET_GNSRECORD_RF_CRITICAL
This record is critical.
@ GNUNET_GNSRECORD_RF_SUPPLEMENTAL
This is a supplemental record.
@ GNUNET_GNSRECORD_RF_MAINTENANCE
Maintenance records.
@ GNUNET_GNSRECORD_RF_SHADOW
This record should not be used unless all (other) records in the set with an absolute expiration time...
@ GNUNET_GNSRECORD_RF_PRIVATE
This is a private record of this peer and it should thus not be published.
@ GNUNET_GNSRECORD_RF_NONE
Entry for no flags / cleared flags.

◆ GNUNET_GNSRECORD_Filter

Filter for GNUNET_GNSRECORD_normalize_record_set().

Enumerator
GNUNET_GNSRECORD_FILTER_NONE 

No filter flags set.

Private and public records are returned, maintenance records (TOMBSTONE etc) are not.

GNUNET_GNSRECORD_FILTER_INCLUDE_MAINTENANCE 

Include maintenance records (TOMBSTONE etc).

GNUNET_GNSRECORD_FILTER_OMIT_PRIVATE 

Filter private records.

Definition at line 146 of file gnunet_gnsrecord_lib.h.

147{
154
159
164
169 // GNUNET_NAMESTORE_FILTER_OMIT_PUBLIC = 4,
170};
@ GNUNET_GNSRECORD_FILTER_NONE
No filter flags set.
@ GNUNET_GNSRECORD_FILTER_INCLUDE_MAINTENANCE
Include maintenance records (TOMBSTONE etc).
@ GNUNET_GNSRECORD_FILTER_OMIT_PRIVATE
Filter private records.

Function Documentation

◆ GNUNET_GNSRECORD_JSON_spec_gnsrecord()

struct GNUNET_JSON_Specification GNUNET_GNSRECORD_JSON_spec_gnsrecord ( struct GNUNET_GNSRECORD_Data **  rd,
unsigned int *  rd_count,
char **  name 
)

JSON Specification for GNS Records.

Parameters
gnsrecord_objectstruct of GNUNET_GNSRECORD_Data to fill
Returns
JSON Specification

Definition at line 284 of file json_gnsrecord.c.

287{
288 struct GnsRecordInfo *gnsrecord_info = GNUNET_new (struct GnsRecordInfo);
290 .cleaner = &clean_gnsrecordobject,
291 .cls = NULL,
292 .field = NULL,
293 .ptr = (struct GnsRecordInfo *)
294 gnsrecord_info,
295 .ptr_size = 0,
296 .size_ptr = NULL };
297
298 gnsrecord_info->rd = rd;
299 gnsrecord_info->name = name;
300 gnsrecord_info->rd_count = rd_count;
301 return ret;
302}
static int ret
Final status code.
Definition: gnunet-arm.c:93
static char * name
Name (label) of the records to list.
static unsigned int rd_count
Number of records for currently parsed set.
static struct GNUNET_GNSRECORD_Data rd[50]
The record data under a single label.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static void clean_gnsrecordobject(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing the record.
static int parse_gnsrecordobject(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Entry in parser specification for GNUNET_JSON_parse().
struct GNUNET_GNSRECORD_Data ** rd
unsigned int * rd_count

References clean_gnsrecordobject(), GNUNET_new, name, GnsRecordInfo::name, parse_gnsrecordobject(), rd, GnsRecordInfo::rd, rd_count, GnsRecordInfo::rd_count, and ret.

Referenced by bulk_tx_start(), and namestore_add_or_update().

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

◆ GNUNET_GNSRECORD_JSON_from_gnsrecord()

json_t * GNUNET_GNSRECORD_JSON_from_gnsrecord ( const char *  rname,
const struct GNUNET_GNSRECORD_Data rd,
unsigned int  rd_count 
)

Convert GNS record to JSON.

Parameters
rnamename of record
rdrecord data
Returns
corresponding JSON encoding

Definition at line 313 of file json_gnsrecord.c.

316{
317 const char *record_type_str;
318 char *value_str;
319 json_t *data;
320 json_t *record;
321 json_t *records;
322
323 data = json_object ();
324 if (NULL == data)
325 {
326 GNUNET_break (0);
327 return NULL;
328 }
329 if (0 !=
330 json_object_set_new (data,
331 "record_name",
332 json_string (rname)))
333 {
334 GNUNET_break (0);
335 json_decref (data);
336 return NULL;
337 }
338 records = json_array ();
339 if (NULL == records)
340 {
341 GNUNET_break (0);
342 json_decref (data);
343 return NULL;
344 }
345 for (int i = 0; i < rd_count; i++)
346 {
347 value_str = GNUNET_GNSRECORD_value_to_string (rd[i].record_type,
348 rd[i].data,
349 rd[i].data_size);
350 record_type_str = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type);
352 "Packing %s %s %" PRIu64 " %d\n",
353 value_str, record_type_str, rd[i].expiration_time, rd[i].flags);
354 record = json_pack (
355 "{s:s, s:s, s:I, s:b, s:b, s:b, s:b, s:b}",
357 GNUNET_JSON_GNSRECORD_TYPE, record_type_str,
361 rd[i].expiration_time,
371 rd[i].flags & GNUNET_GNSRECORD_RF_SHADOW);
372 GNUNET_free (value_str);
373 if (NULL == record)
374 {
375 GNUNET_break (0);
376 json_decref (records);
377 json_decref (data);
378 return NULL;
379 }
380 if (0 !=
381 json_array_append_new (records,
382 record))
383 {
384 GNUNET_break (0);
385 json_decref (records);
386 json_decref (data);
387 return NULL;
388 }
389 }
390 if (0 !=
391 json_object_set_new (data,
392 "data",
393 records))
394 {
395 GNUNET_break (0);
396 json_decref (data);
397 return NULL;
398 }
399 return data;
400}
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
static char * data
The data to insert into the dht.
static size_t data_size
Number of bytes in data.
static unsigned int records
Number of records we found.
const char * GNUNET_GNSRECORD_number_to_typename(uint32_t type)
Convert a type number to the corresponding type string (e.g.
Definition: gnsrecord.c:219
char * GNUNET_GNSRECORD_value_to_string(uint32_t type, const void *data, size_t data_size)
Convert the binary value data of a record of type type to a human-readable string.
Definition: gnsrecord.c:147
#define GNUNET_log(kind,...)
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_JSON_GNSRECORD_FLAG_SHADOW
#define GNUNET_JSON_GNSRECORD_VALUE
#define GNUNET_JSON_GNSRECORD_FLAG_PRIVATE
#define GNUNET_JSON_GNSRECORD_FLAG_MAINTENANCE
#define GNUNET_JSON_GNSRECORD_ABSOLUTE_EXPIRATION_TIME
#define GNUNET_JSON_GNSRECORD_FLAG_SUPPLEMENTAL
#define GNUNET_JSON_GNSRECORD_RELATIVE_EXPIRATION_TIME
#define GNUNET_JSON_GNSRECORD_FLAG_RELATIVE
#define GNUNET_JSON_GNSRECORD_TYPE

References data, data_size, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_GNSRECORD_number_to_typename(), GNUNET_GNSRECORD_RF_MAINTENANCE, GNUNET_GNSRECORD_RF_PRIVATE, GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION, GNUNET_GNSRECORD_RF_SHADOW, GNUNET_GNSRECORD_RF_SUPPLEMENTAL, GNUNET_GNSRECORD_value_to_string(), GNUNET_JSON_GNSRECORD_ABSOLUTE_EXPIRATION_TIME, GNUNET_JSON_GNSRECORD_FLAG_MAINTENANCE, GNUNET_JSON_GNSRECORD_FLAG_PRIVATE, GNUNET_JSON_GNSRECORD_FLAG_RELATIVE, GNUNET_JSON_GNSRECORD_FLAG_SHADOW, GNUNET_JSON_GNSRECORD_FLAG_SUPPLEMENTAL, GNUNET_JSON_GNSRECORD_RELATIVE_EXPIRATION_TIME, GNUNET_JSON_GNSRECORD_TYPE, GNUNET_JSON_GNSRECORD_VALUE, GNUNET_log, rd, rd_count, record(), and records.

Referenced by handle_gns_response(), namestore_list_iteration(), and ns_get_lookup_cb().

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

◆ GNUNET_GNSRECORD_value_to_string()

char * GNUNET_GNSRECORD_value_to_string ( uint32_t  type,
const void *  data,
size_t  data_size 
)

Convert the binary value data of a record of type type to a human-readable string.

Parameters
typetype of the record
datavalue in binary encoding
data_sizenumber of bytes in data
Returns
NULL on error, otherwise human-readable representation of the value

Convert the binary value data of a record of type type to a human-readable string.

Parameters
typetype of the record
datavalue in binary encoding
data_sizenumber of bytes in data
Returns
NULL on error, otherwise human-readable representation of the value

Definition at line 147 of file gnsrecord.c.

150{
151 struct Plugin *plugin;
152 char *ret;
153
154 init ();
155 for (unsigned int i = 0; i < num_plugins; i++)
156 {
157 plugin = gns_plugins[i];
158 if (NULL != (ret = plugin->api->value_to_string (plugin->api->cls,
159 type,
160 data,
161 data_size)))
162 return ret;
163 }
164 return NULL;
165}
static unsigned int num_plugins
Size of the 'plugins' array.
Definition: gnsrecord.c:60
static struct Plugin ** gns_plugins
Array of our plugins.
Definition: gnsrecord.c:55
static void init()
Loads all plugins (lazy initialization).
Definition: gnsrecord.c:97
static struct GNUNET_TESTING_PluginFunctions * plugin
Plugin to dynamically load a test case.
static uint32_t type
Type string converted to DNS type value.
void * cls
Closure to pass to start_testcase.
Handle for a plugin.
Definition: block.c:38

References GNUNET_TESTING_PluginFunctions::cls, data, data_size, gns_plugins, init(), num_plugins, plugin, ret, and type.

Referenced by check_pkey(), del_monitor(), display_record(), display_records_from_block(), gns_value_to_string(), GNUNET_GNSRECORD_JSON_from_gnsrecord(), GNUNET_GNSRECORD_records_deserialize(), GNUNET_GNSRECORD_records_get_size(), GNUNET_GNSRECORD_records_serialize(), process_lookup_result(), and start_phone().

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

◆ GNUNET_GNSRECORD_string_to_value()

int GNUNET_GNSRECORD_string_to_value ( uint32_t  type,
const char *  s,
void **  data,
size_t *  data_size 
)

Convert human-readable version of the value s of a record of type type to the respective binary representation.

Parameters
typetype of the record
shuman-readable string
dataset to value in binary encoding (will be allocated)
data_sizeset to number of bytes in data
Returns
GNUNET_OK on success

Definition at line 169 of file gnsrecord.c.

173{
174 struct Plugin *plugin;
175
176 init ();
177 for (unsigned int i = 0; i < num_plugins; i++)
178 {
179 plugin = gns_plugins[i];
180 if (GNUNET_OK == plugin->api->string_to_value (plugin->api->cls,
181 type,
182 s,
183 data,
184 data_size))
185 return GNUNET_OK;
186 }
187 return GNUNET_SYSERR;
188}
@ GNUNET_OK
@ GNUNET_SYSERR

References GNUNET_TESTING_PluginFunctions::cls, data, data_size, gns_plugins, GNUNET_OK, GNUNET_SYSERR, init(), num_plugins, plugin, and type.

Referenced by gns_string_to_value(), parse(), parse_record(), parse_recordline(), run(), run_with_zone_pkey(), and store_cb().

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

◆ GNUNET_GNSRECORD_typename_to_number()

uint32_t GNUNET_GNSRECORD_typename_to_number ( const char *  dns_typename)

Convert a type name (e.g.

"AAAA") to the corresponding number.

Parameters
dns_typenamename to convert
Returns
corresponding number, UINT32_MAX on error

Definition at line 192 of file gnsrecord.c.

193{
194 struct Plugin *plugin;
195 uint32_t ret;
196
197 if (0 == strcasecmp (dns_typename,
198 "ANY"))
200 init ();
201 for (unsigned int i = 0; i < num_plugins; i++)
202 {
203 plugin = gns_plugins[i];
204 if (UINT32_MAX != (ret = plugin->api->typename_to_number (plugin->api->cls,
205 dns_typename)))
206 return ret;
207 }
208 return UINT32_MAX;
209}
#define GNUNET_GNSRECORD_TYPE_ANY
Record type indicating any record/'*'.

References GNUNET_TESTING_PluginFunctions::cls, gns_plugins, GNUNET_GNSRECORD_TYPE_ANY, init(), num_plugins, plugin, and ret.

Referenced by del_monitor(), DID_create_namestore_lookup_cb(), display_record(), get_gns_cont(), namestore_get(), parse(), parse_record(), parse_recordline(), run(), and run_with_zone_pkey().

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

◆ GNUNET_GNSRECORD_number_to_typename()

const char * GNUNET_GNSRECORD_number_to_typename ( uint32_t  type)

Convert a type number to the corresponding type string (e.g.

1 to "A")

Parameters
typenumber of a type to convert
Returns
corresponding typestring, NULL on error

Definition at line 219 of file gnsrecord.c.

220{
221 struct Plugin *plugin;
222 const char *ret;
223
225 return "ANY";
226 init ();
227 for (unsigned int i = 0; i < num_plugins; i++)
228 {
229 plugin = gns_plugins[i];
230 if (NULL != (ret = plugin->api->number_to_typename (plugin->api->cls,
231 type)))
232 return ret;
233 }
234 return NULL;
235}

References GNUNET_TESTING_PluginFunctions::cls, gns_plugins, GNUNET_GNSRECORD_TYPE_ANY, init(), num_plugins, plugin, ret, and type.

Referenced by display_record(), display_records_from_block(), GNUNET_GNSRECORD_JSON_from_gnsrecord(), parse_recordline(), process_lookup_result(), and run_with_zone_pkey().

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

◆ GNUNET_GNSRECORD_records_get_size()

ssize_t GNUNET_GNSRECORD_records_get_size ( unsigned int  rd_count,
const struct GNUNET_GNSRECORD_Data rd 
)

Calculate how many bytes we will need to serialize the given records.

Parameters
rd_countnumber of records in the rd array
rdarray of GNUNET_GNSRECORD_Data with rd_count elements
Returns
the required size to serialize, -1 on error

Efficiently round up to the next power of 2 for padding https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2

Definition at line 78 of file gnsrecord_serialization.c.

80{
81 size_t ret;
82
83 if (0 == rd_count)
84 return 0;
85
86 ret = sizeof(struct NetworkRecord) * rd_count;
87 for (unsigned int i = 0; i < rd_count; i++)
88 {
89 if ((ret + rd[i].data_size) < ret)
90 {
91 GNUNET_break (0);
92 return -1;
93 }
94 ret += rd[i].data_size;
95#if DEBUG_GNSRECORDS
96 {
97 char *str;
98
100 rd[i].data,
101 rd[i].data_size);
102 if (NULL == str)
103 {
104 GNUNET_break_op (0);
105 return -1;
106 }
107 GNUNET_free (str);
108 }
109#endif
110 }
111 if (ret > SSIZE_MAX)
112 {
113 GNUNET_break (0);
114 return -1;
115 }
116 // Do not pad PKEY
119 return ret;ret--;
125 ret |= ret >> 1;
126 ret |= ret >> 2;
127 ret |= ret >> 4;
128 ret |= ret >> 8;
129 ret |= ret >> 16;
130 ret++;
131 return (ssize_t) ret;
132}
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_GNSRECORD_TYPE_PKEY
WARNING: This header is generated! In order to add GNS record types, you must register them in GANA,...
#define GNUNET_GNSRECORD_TYPE_EDKEY
GNS zone delegation (EDKEY)
uint32_t record_type
Type of the GNS/DNS record.
size_t data_size
Number of bytes in data.
Internal format of a record in the serialized form.
uint32_t record_type
Type of the GNS/DNS record, network byte order.

References data, data_size, GNUNET_GNSRECORD_Data::data_size, GNUNET_break, GNUNET_break_op, GNUNET_free, GNUNET_GNSRECORD_TYPE_EDKEY, GNUNET_GNSRECORD_TYPE_PKEY, GNUNET_GNSRECORD_value_to_string(), rd, rd_count, GNUNET_GNSRECORD_Data::record_type, NetworkRecord::record_type, and ret.

Referenced by block_create_ecdsa(), block_create_eddsa(), block_get_size_ecdsa(), block_get_size_eddsa(), consistency_iter(), GNUNET_NAMESTORE_records_store(), handle_zone_to_name_it(), lookup_it(), namestore_postgres_store_records(), namestore_sqlite_store_records(), result_processor(), run_edkey(), run_pkey(), rvk_ticket_update(), send_lookup_response(), send_lookup_response_with_filter(), and store_and_free_entries().

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

◆ GNUNET_GNSRECORD_records_serialize()

ssize_t GNUNET_GNSRECORD_records_serialize ( unsigned int  rd_count,
const struct GNUNET_GNSRECORD_Data rd,
size_t  dest_size,
char *  dest 
)

Serialize the given records to the given destination buffer.

Parameters
rd_countnumber of records in the rd array
rdarray of GNUNET_GNSRECORD_Data with rd_count elements
dest_sizesize of the destination array dst
destwhere to write the result
Returns
the size of serialized records, -1 if records do not fit

Definition at line 136 of file gnsrecord_serialization.c.

140{
141 struct NetworkRecord rec;
142 size_t off;
143
144 off = 0;
145 for (unsigned int i = 0; i < rd_count; i++)
146 {
148 "Serializing record %u with flags %d and expiration time %llu\n",
149 i,
150 rd[i].flags,
151 (unsigned long long) rd[i].expiration_time);
152 rec.expiration_time = GNUNET_htonll (rd[i].expiration_time);
153 rec.data_size = htons ((uint16_t) rd[i].data_size);
154 rec.record_type = htonl (rd[i].record_type);
155 rec.flags = htons (rd[i].flags);
156 if ((off + sizeof(rec) > dest_size) ||
157 (off + sizeof(rec) < off))
158 {
159 GNUNET_break (0);
160 return -1;
161 }
162 GNUNET_memcpy (&dest[off],
163 &rec,
164 sizeof(rec));
165 off += sizeof(rec);
166 if ((off + rd[i].data_size > dest_size) ||
167 (off + rd[i].data_size < off))
168 {
169 GNUNET_break (0);
170 return -1;
171 }
172 GNUNET_memcpy (&dest[off],
173 rd[i].data,
174 rd[i].data_size);
175 off += rd[i].data_size;
176#if DEBUG_GNSRECORDS
177 {
178 char *str;
179
181 rd[i].data,
182 rd[i].data_size);
183 if (NULL == str)
184 {
185 GNUNET_break_op (0);
186 return -1;
187 }
188 GNUNET_free (str);
189 }
190#endif
191 }
192 memset (&dest[off],
193 0,
194 dest_size - off);
195 return dest_size;
196}
#define LOG(kind,...)
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:37
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
uint64_t expiration_time
Expiration time for the DNS record; relative or absolute depends on flags, network byte order.
uint16_t flags
Flags for the record, network byte order.

References data, data_size, GNUNET_GNSRECORD_Data::data_size, NetworkRecord::data_size, warningfilter::dest, NetworkRecord::expiration_time, NetworkRecord::flags, GNUNET_break, GNUNET_break_op, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_GNSRECORD_value_to_string(), GNUNET_htonll(), GNUNET_memcpy, LOG, rd, rd_count, and NetworkRecord::record_type.

Referenced by block_create_ecdsa(), block_create_eddsa(), consistency_iter(), GNUNET_NAMESTORE_records_store(), handle_zone_to_name_it(), lookup_it(), namestore_postgres_store_records(), namestore_sqlite_store_records(), result_processor(), run_edkey(), run_pkey(), rvk_ticket_update(), send_lookup_response(), send_lookup_response_with_filter(), and store_and_free_entries().

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

◆ GNUNET_GNSRECORD_records_deserialize_get_size()

unsigned int GNUNET_GNSRECORD_records_deserialize_get_size ( size_t  len,
const char *  src 
)

Definition at line 199 of file gnsrecord_serialization.c.

201{
202 struct NetworkRecord rec;
203 struct NetworkRecord rec_zero;
204 size_t off;
205 unsigned int rd_count = 0;
206
207 memset (&rec_zero, 0, sizeof (rec_zero));
208
209 off = 0;
210 for (off = 0; (off + sizeof(rec) <= len) && (off + sizeof(rec) >= off);)
211 {
212 GNUNET_memcpy (&rec,
213 &src[off],
214 sizeof(rec));
215 /*
216 * If we have found a byte string of zeroes, we have reached
217 * the padding
218 */
219 if (0 == GNUNET_memcmp (&rec, &rec_zero))
220 break;
221 off += sizeof(rec);
222 if ((off + ntohs ((uint16_t) rec.data_size) > len) ||
223 (off + ntohs ((uint16_t) rec.data_size) < off))
224 {
225 GNUNET_break_op (0);
226 return 0;
227 }
228 off += ntohs ((uint16_t) rec.data_size);
229 rd_count++;
230 }
231 return rd_count;
232}
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.

References NetworkRecord::data_size, GNUNET_break_op, GNUNET_memcmp, GNUNET_memcpy, and rd_count.

Referenced by block_decrypt_ecdsa(), and block_decrypt_eddsa().

Here is the caller graph for this function:

◆ GNUNET_GNSRECORD_records_deserialize()

int GNUNET_GNSRECORD_records_deserialize ( size_t  len,
const char *  src,
unsigned int  rd_count,
struct GNUNET_GNSRECORD_Data dest 
)

Deserialize the given records to the given destination.

Parameters
lensize of the serialized record data
srcthe serialized record data
rd_countnumber of records in the dest array
destwhere to put the data
Returns
GNUNET_OK on success, GNUNET_SYSERR on error
Parameters
lensize of the serialized record data
srcthe serialized record data
rd_countnumber of records parsed
destwhere to put the data
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 244 of file gnsrecord_serialization.c.

248{
249 struct NetworkRecord rec;
250 size_t off;
251
252 off = 0;
253 for (unsigned int i = 0; i < rd_count; i++)
254 {
255 if ((off + sizeof(rec) > len) ||
256 (off + sizeof(rec) < off))
257 {
258 GNUNET_break_op (0);
259 return GNUNET_SYSERR;
260 }
261 GNUNET_memcpy (&rec,
262 &src[off],
263 sizeof(rec));
264 dest[i].expiration_time = GNUNET_ntohll (rec.expiration_time);
265 dest[i].data_size = ntohs ((uint16_t) rec.data_size);
266 dest[i].record_type = ntohl (rec.record_type);
267 dest[i].flags = ntohs (rec.flags);
268 off += sizeof(rec);
269 if ((off + dest[i].data_size > len) ||
270 (off + dest[i].data_size < off))
271 {
272 GNUNET_break_op (0);
273 return GNUNET_SYSERR;
274 }
275 dest[i].data = &src[off];
276 off += dest[i].data_size;
277#if GNUNET_EXTRA_LOGGING
278 {
279 char *str;
280
282 dest[i].data,
283 dest[i].data_size);
284 if (NULL == str)
285 {
286 GNUNET_break_op (0);
287 return GNUNET_SYSERR;
288 }
289 GNUNET_free (str);
290 }
291#endif
293 "Deserialized record %u with flags %d and expiration time %llu\n",
294 i,
295 dest[i].flags,
296 (unsigned long long) dest[i].expiration_time);
297 }
298 return GNUNET_OK;
299}
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:54

References data, data_size, NetworkRecord::data_size, warningfilter::dest, NetworkRecord::expiration_time, NetworkRecord::flags, GNUNET_break_op, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_GNSRECORD_value_to_string(), GNUNET_memcpy, GNUNET_ntohll(), GNUNET_OK, GNUNET_SYSERR, LOG, rd_count, and NetworkRecord::record_type.

Referenced by block_decrypt_ecdsa(), block_decrypt_eddsa(), check_rd(), check_result(), continue_store_activity(), database_setup(), get_records_and_call_iterator(), handle_edit_record_set_response(), handle_lookup_result(), handle_record_result(), handle_result(), handle_zone_to_name_response(), parse_result_call_iterator(), process_tickets(), store_record_set(), update_tickets(), and vpn_allocation_cb().

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

◆ GNUNET_GNSRECORD_is_expired()

int GNUNET_GNSRECORD_is_expired ( const struct GNUNET_GNSRECORD_Data rd)

Test if a given record is expired.

Parameters
rdrecord to test
Returns
GNUNET_YES if the record is expired, GNUNET_NO if not
GNUNET_YES if the record is expired, GNUNET_NO if not

Definition at line 205 of file gnsrecord_misc.c.

206{
207 struct GNUNET_TIME_Absolute at;
208
210 return GNUNET_NO;
211 at.abs_value_us = rd->expiration_time;
212 return (0 == GNUNET_TIME_absolute_get_remaining (at).rel_value_us) ?
214}
@ GNUNET_YES
@ GNUNET_NO
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:406
enum GNUNET_GNSRECORD_Flags flags
Flags for the record.
uint64_t expiration_time
Expiration time for the DNS record.
Time for absolute times used by GNUnet, in microseconds.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_GNSRECORD_Data::expiration_time, GNUNET_GNSRECORD_Data::flags, GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION, GNUNET_NO, GNUNET_TIME_absolute_get_remaining(), GNUNET_YES, and rd.

Here is the call graph for this function:

◆ GNUNET_GNSRECORD_string_normalize()

char * GNUNET_GNSRECORD_string_normalize ( const char *  src)

Normalize a UTF-8 string to a GNS name.

Parameters
srcsource string
Returns
converted result

Definition at line 36 of file gnsrecord_misc.c.

37{
38 /*FIXME: We may want to follow RFC5890/RFC5891 */
40}
char * GNUNET_STRINGS_utf8_normalize(const char *input)
Normalize the utf-8 input string to NFC.
Definition: strings.c:438

References GNUNET_STRINGS_utf8_normalize().

Referenced by block_create2(), GNUNET_GNSRECORD_block_create(), GNUNET_GNSRECORD_block_decrypt(), GNUNET_GNSRECORD_block_sign(), GNUNET_GNSRECORD_query_from_private_key(), GNUNET_GNSRECORD_query_from_public_key(), handle_edit_record_set(), handle_edit_record_set_cancel(), handle_record_lookup(), run_edkey(), run_pkey(), and store_record_set().

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

◆ GNUNET_GNSRECORD_z2s()

const char * GNUNET_GNSRECORD_z2s ( const struct GNUNET_CRYPTO_PublicKey z)

Convert a zone to a string (for printing debug messages).

This is one of the very few calls in the entire API that is NOT reentrant!

Parameters
zpublic key of a zone
Returns
string form; will be overwritten by next call to GNUNET_GNSRECORD_z2s.

Definition at line 61 of file gnsrecord_misc.c.

62{
63 static char buf[sizeof(struct GNUNET_CRYPTO_PublicKey) * 8];
64 char *end;
65
66 end = GNUNET_STRINGS_data_to_string ((const unsigned char *) z,
67 sizeof(struct
69 buf, sizeof(buf));
70 if (NULL == end)
71 {
72 GNUNET_break (0);
73 return NULL;
74 }
75 *end = '\0';
76 return buf;
77}
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:33
char * GNUNET_STRINGS_data_to_string(const void *data, size_t size, char *out, size_t out_size)
Convert binary data to ASCII encoding using CrockfordBase32.
Definition: strings.c:732

References end, GNUNET_break, and GNUNET_STRINGS_data_to_string().

Referenced by get_nick_record(), handle_gns_resolution_result(), handle_namecache_block_response(), handle_revocation_result(), namestore_flat_zone_to_name(), namestore_sqlite_store_records(), namestore_sqlite_zone_to_name(), recursive_gns_resolution_namecache(), and recursive_gns_resolution_revocation().

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

◆ GNUNET_GNSRECORD_pkey_to_zkey()

const char * GNUNET_GNSRECORD_pkey_to_zkey ( const struct GNUNET_CRYPTO_PublicKey pkey)

Convert public key to the respective absolute domain name in the ".zkey" pTLD.

This is one of the very few calls in the entire API that is NOT reentrant!

Parameters
pkeya public key with a point on the elliptic curve
Returns
string "X.zkey" where X is the coordinates of the public key in an encoding suitable for DNS labels.

This is one of the very few calls in the entire API that is NOT reentrant!

Parameters
pkeya public key with a point on the elliptic curve
Returns
string "X.zkey" where X is the public key in an encoding suitable for DNS labels.

Definition at line 228 of file gnsrecord_misc.c.

229{
230 static char ret[128];
231 char *pkeys;
232
235 sizeof(ret),
236 "%s",
237 pkeys);
238 GNUNET_free (pkeys);
239 return ret;
240}
static char * pkey
Public key of the zone to look in, in ASCII.
char * GNUNET_CRYPTO_public_key_to_string(const struct GNUNET_CRYPTO_PublicKey *key)
Creates a (Base32) string representation of the public key.
Definition: crypto_pkey.c:379
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.

References GNUNET_CRYPTO_public_key_to_string(), GNUNET_free, GNUNET_snprintf(), pkey, and ret.

Referenced by caller_event_handler(), do_accept(), do_call(), do_resume(), do_status(), handle_phone_hangup(), phone_event_handler(), and translate_dot_plus().

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

◆ GNUNET_GNSRECORD_zkey_to_pkey()

int GNUNET_GNSRECORD_zkey_to_pkey ( const char *  zkey,
struct GNUNET_CRYPTO_PublicKey pkey 
)

Convert an absolute domain name to the respective public key.

Parameters
zkeystring "X" where X is the public key in an encoding suitable for DNS labels.
pkeyset to a public key on the elliptic curve
Returns
GNUNET_SYSERR if zkey has the wrong syntax
Parameters
zkeystring encoding the coordinates of the public key in an encoding suitable for DNS labels.
pkeyset to a public key on the elliptic curve
Returns
GNUNET_SYSERR if zkey has the wrong syntax

Definition at line 253 of file gnsrecord_misc.c.

255{
256 if (GNUNET_OK !=
258 pkey))
259 return GNUNET_SYSERR;
260 return GNUNET_OK;
261}
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_public_key_from_string(const char *str, struct GNUNET_CRYPTO_PublicKey *key)
Parses a (Base32) string representation of the public key.
Definition: crypto_pkey.c:399

References GNUNET_CRYPTO_public_key_from_string(), GNUNET_OK, GNUNET_SYSERR, and pkey.

Referenced by GNS_find_tld(), handle_gns_redirect_result(), and recursive_gns2dns_resolution().

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

◆ GNUNET_GNSRECORD_query_from_private_key()

void GNUNET_GNSRECORD_query_from_private_key ( const struct GNUNET_CRYPTO_PrivateKey zone,
const char *  label,
struct GNUNET_HashCode query 
)

Calculate the DHT query for a given label in a given zone.

Parameters
zoneprivate key of the zone
labellabel of the record
queryhash to use for the query

Definition at line 1025 of file gnsrecord_crypto.c.

1029{
1030 char *norm_label;
1032
1033 norm_label = GNUNET_GNSRECORD_string_normalize (label);
1034 switch (ntohl (zone->type))
1035 {
1038
1040 &pub);
1042 norm_label,
1043 query);
1044 break;
1045 default:
1046 GNUNET_assert (0);
1047 }
1048 GNUNET_free (norm_label);
1049}
static struct GNUNET_CRYPTO_EddsaPublicKey pub
Definition: gnunet-scrypt.c:47
void GNUNET_GNSRECORD_query_from_public_key(const struct GNUNET_CRYPTO_PublicKey *pub, const char *label, struct GNUNET_HashCode *query)
Calculate the DHT query for a given label in a given zone.
char * GNUNET_GNSRECORD_string_normalize(const char *src)
Normalize a UTF-8 string to a GNS name.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_key_get_public(const struct GNUNET_CRYPTO_PrivateKey *privkey, struct GNUNET_CRYPTO_PublicKey *key)
Retrieves the public key representation of a private key.
Definition: crypto_pkey.c:430
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
uint32_t type
Type of public key.

References GNUNET_assert, GNUNET_CRYPTO_key_get_public(), GNUNET_free, GNUNET_GNSRECORD_query_from_public_key(), GNUNET_GNSRECORD_string_normalize(), GNUNET_GNSRECORD_TYPE_EDKEY, GNUNET_GNSRECORD_TYPE_PKEY, pub, and GNUNET_CRYPTO_PrivateKey::type.

Referenced by initiate_put_from_pipe_trigger().

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

◆ GNUNET_GNSRECORD_query_from_public_key()

void GNUNET_GNSRECORD_query_from_public_key ( const struct GNUNET_CRYPTO_PublicKey pub,
const char *  label,
struct GNUNET_HashCode query 
)

Calculate the DHT query for a given label in a given zone.

FIXME: We may want to plugin-ize this at some point.

Parameters
pubpublic key of the zone
labellabel of the record
queryhash to use for the query

Definition at line 1053 of file gnsrecord_crypto.c.

1057{
1058 char *norm_label;
1059 struct GNUNET_CRYPTO_PublicKey pd;
1060
1061 norm_label = GNUNET_GNSRECORD_string_normalize (label);
1062
1063 switch (ntohl (pub->type))
1064 {
1066 pd.type = pub->type;
1068 norm_label,
1069 "gns",
1070 &pd.ecdsa_key);
1071 GNUNET_CRYPTO_hash (&pd.ecdsa_key,
1072 sizeof (pd.ecdsa_key),
1073 query);
1074 break;
1076 pd.type = pub->type;
1078 norm_label,
1079 "gns",
1080 &(pd.eddsa_key));
1081 GNUNET_CRYPTO_hash (&pd.eddsa_key,
1082 sizeof (pd.eddsa_key),
1083 query);
1084 break;
1085 default:
1086 GNUNET_assert (0);
1087 }
1088 GNUNET_free (norm_label);
1089}
void GNUNET_CRYPTO_ecdsa_public_key_derive(const struct GNUNET_CRYPTO_EcdsaPublicKey *pub, const char *label, const char *context, struct GNUNET_CRYPTO_EcdsaPublicKey *result)
Derive a public key from a given public key and a label.
void GNUNET_CRYPTO_eddsa_public_key_derive(const struct GNUNET_CRYPTO_EddsaPublicKey *pub, const char *label, const char *context, struct GNUNET_CRYPTO_EddsaPublicKey *result)
Derive a public key from a given public key and a label.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41

References GNUNET_CRYPTO_PublicKey::ecdsa_key, GNUNET_CRYPTO_PublicKey::eddsa_key, GNUNET_assert, GNUNET_CRYPTO_ecdsa_public_key_derive(), GNUNET_CRYPTO_eddsa_public_key_derive(), GNUNET_CRYPTO_hash(), GNUNET_free, GNUNET_GNSRECORD_string_normalize(), GNUNET_GNSRECORD_TYPE_EDKEY, GNUNET_GNSRECORD_TYPE_PKEY, pub, and GNUNET_CRYPTO_PublicKey::type.

Referenced by GNUNET_GNSRECORD_query_from_private_key(), handle_namecache_block_response(), recursive_gns_resolution_namecache(), run(), run_edkey(), and run_pkey().

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

◆ GNUNET_GNSRECORD_block_calculate_size()

ssize_t GNUNET_GNSRECORD_block_calculate_size ( const struct GNUNET_CRYPTO_PrivateKey key,
const struct GNUNET_GNSRECORD_Data rd,
unsigned int  rd_count 
)

Get size of buffer for block creation.

Parameters
keythe zone key
rdrecord data
rd_countnumber of records
Returns
-1 on error (otherwise the length of the block)

Definition at line 512 of file gnsrecord_crypto.c.

516{
518 ssize_t res = -1;
519
521 &pkey);
522 switch (ntohl (key->type))
523 {
526 break;
529 break;
530 default:
531 GNUNET_assert (0);
532 }
533 return res;
534
535}
static ssize_t block_get_size_eddsa(const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count)
static ssize_t block_get_size_ecdsa(const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count)
struct GNUNET_HashCode key
The key used in the DHT.
static char * res
Currently read line or NULL on EOF.

References block_get_size_ecdsa(), block_get_size_eddsa(), GNUNET_assert, GNUNET_CRYPTO_key_get_public(), GNUNET_GNSRECORD_TYPE_EDKEY, GNUNET_GNSRECORD_TYPE_PKEY, key, pkey, rd, rd_count, and res.

Here is the call graph for this function:

◆ GNUNET_GNSRECORD_block_sign()

enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_block_sign ( const struct GNUNET_CRYPTO_PrivateKey key,
const char *  label,
struct GNUNET_GNSRECORD_Block block 
)

Sign a block create with GNUNET_GNSRECORD_block_create_unsigned.

Parameters
keythe private key
labelthe label of the block
blockthe unsigned block
Returns
GNUNET_OK on success

Definition at line 275 of file gnsrecord_crypto.c.

279{
282 char *norm_label;
283
285 &pkey);
286 norm_label = GNUNET_GNSRECORD_string_normalize (label);
287
288 switch (ntohl (key->type))
289 {
291 res = block_sign_ecdsa (&key->ecdsa_key,
292 &pkey.ecdsa_key,
293 norm_label,
294 block);
295 break;
297 res = block_sign_eddsa (&key->eddsa_key,
298 &pkey.eddsa_key,
299 norm_label,
300 block);
301 break;
302 default:
303 GNUNET_assert (0);
304 }
305 GNUNET_free (norm_label);
306 return res;
307}
static enum GNUNET_GenericReturnValue block_sign_ecdsa(const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey, const char *label, struct GNUNET_GNSRECORD_Block *block)
static enum GNUNET_GenericReturnValue block_sign_eddsa(const struct GNUNET_CRYPTO_EddsaPrivateKey *key, const struct GNUNET_CRYPTO_EddsaPublicKey *pkey, const char *label, struct GNUNET_GNSRECORD_Block *block)
GNUNET_GenericReturnValue
Named constants for return values.

References block_sign_ecdsa(), block_sign_eddsa(), GNUNET_assert, GNUNET_CRYPTO_key_get_public(), GNUNET_free, GNUNET_GNSRECORD_string_normalize(), GNUNET_GNSRECORD_TYPE_EDKEY, GNUNET_GNSRECORD_TYPE_PKEY, GNUNET_SYSERR, key, pkey, and res.

Referenced by sign_worker().

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

◆ GNUNET_GNSRECORD_block_create()

enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_block_create ( const struct GNUNET_CRYPTO_PrivateKey key,
struct GNUNET_TIME_Absolute  expire,
const char *  label,
const struct GNUNET_GNSRECORD_Data rd,
unsigned int  rd_count,
struct GNUNET_GNSRECORD_Block **  block 
)

Sign name and records.

Parameters
keythe private key
expireblock expiration
labelthe name for the records
rdrecord data
rd_countnumber of records in rd
resultthe block buffer. Will be allocated.
Returns
GNUNET_OK on success

Definition at line 539 of file gnsrecord_crypto.c.

545{
548 char *norm_label;
549
551 &pkey);
552 norm_label = GNUNET_GNSRECORD_string_normalize (label);
553
554 switch (ntohl (key->type))
555 {
557 res = block_create_ecdsa (&key->ecdsa_key,
558 &pkey.ecdsa_key,
559 expire,
560 norm_label,
561 rd,
562 rd_count,
563 result,
564 GNUNET_YES);
565 break;
567 res = block_create_eddsa (&key->eddsa_key,
568 &pkey.eddsa_key,
569 expire,
570 norm_label,
571 rd,
572 rd_count,
573 result,
574 GNUNET_YES);
575 break;
576 default:
577 GNUNET_assert (0);
578 }
579 GNUNET_free (norm_label);
580 return res;
581}
static enum GNUNET_GenericReturnValue block_create_ecdsa(const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey, struct GNUNET_TIME_Absolute expire, const char *label, const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count, struct GNUNET_GNSRECORD_Block **block, int sign)
Sign name and records.
static enum GNUNET_GenericReturnValue block_create_eddsa(const struct GNUNET_CRYPTO_EddsaPrivateKey *key, const struct GNUNET_CRYPTO_EddsaPublicKey *pkey, struct GNUNET_TIME_Absolute expire, const char *label, const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count, struct GNUNET_GNSRECORD_Block **block, int sign)
Sign name and records (EDDSA version)
static char * expire
DID Document expiration Date Attribute String.
Definition: gnunet-did.c:97
static int result
Global testing status.

References block_create_ecdsa(), block_create_eddsa(), expire, GNUNET_assert, GNUNET_CRYPTO_key_get_public(), GNUNET_free, GNUNET_GNSRECORD_string_normalize(), GNUNET_GNSRECORD_TYPE_EDKEY, GNUNET_GNSRECORD_TYPE_PKEY, GNUNET_SYSERR, GNUNET_YES, key, pkey, rd, rd_count, res, and result.

Referenced by run_edkey(), and run_pkey().

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

◆ GNUNET_GNSRECORD_block_create_unsigned()

enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_block_create_unsigned ( const struct GNUNET_CRYPTO_PrivateKey key,
struct GNUNET_TIME_Absolute  expire,
const char *  label,
const struct GNUNET_GNSRECORD_Data rd,
unsigned int  rd_count,
struct GNUNET_GNSRECORD_Block **  result 
)

Create name and records but do not sign! Sign later with GNUNET_GNSRECORD_block_sign().

Cache derived public key (also keeps the private key in static memory, so do not use this function if keeping the private key in the process'es RAM is a major issue).

Parameters
keythe private key
expireblock expiration
labelthe name for the records
rdrecord data
rd_countnumber of records in rd
resultthe block buffer. Will be allocated.
Returns
GNUNET_OK on success.

Definition at line 663 of file gnsrecord_crypto.c.

670{
671 return block_create2 (pkey, expire, label, rd, rd_count, result, GNUNET_NO);
672}
static enum GNUNET_GenericReturnValue block_create2(const struct GNUNET_CRYPTO_PrivateKey *pkey, struct GNUNET_TIME_Absolute expire, const char *label, const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count, struct GNUNET_GNSRECORD_Block **result, int sign)

References block_create2(), expire, GNUNET_NO, pkey, rd, rd_count, and result.

Referenced by dispatch_job(), and dispatch_job_monitor().

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

◆ GNUNET_GNSRECORD_block_create2()

enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_block_create2 ( const struct GNUNET_CRYPTO_PrivateKey key,
struct GNUNET_TIME_Absolute  expire,
const char *  label,
const struct GNUNET_GNSRECORD_Data rd,
unsigned int  rd_count,
struct GNUNET_GNSRECORD_Block **  result 
)

Sign name and records, cache derived public key (also keeps the private key in static memory, so do not use this function if keeping the private key in the process'es RAM is a major issue).

Parameters
keythe private key
expireblock expiration
labelthe name for the records
rdrecord data
rd_countnumber of records in rd
resultthe block buffer. Will be allocated.
Returns
GNUNET_OK on success.

Definition at line 676 of file gnsrecord_crypto.c.

682{
683 return block_create2 (pkey, expire, label, rd, rd_count, result, GNUNET_YES);
684}

References block_create2(), expire, GNUNET_YES, pkey, rd, rd_count, and result.

Here is the call graph for this function:

◆ GNUNET_GNSRECORD_block_verify()

enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_block_verify ( const struct GNUNET_GNSRECORD_Block block)

Check if a signature is valid.

This API is used by the GNS Block to validate signatures received from the network.

Parameters
blockblock to verify
Returns
GNUNET_OK if the signature is valid

Definition at line 695 of file gnsrecord_crypto.c.

696{
697 struct GNRBlockPS *purp;
698 size_t payload_len = ntohl (block->size)
699 - sizeof (struct GNUNET_GNSRECORD_Block);
701 purp = GNUNET_malloc (sizeof (struct GNRBlockPS) + payload_len);
702 purp->purpose.size = htonl (sizeof (struct GNRBlockPS) + payload_len);
704 GNUNET_memcpy (&purp[1],
705 &block[1],
706 payload_len);
707 switch (ntohl (block->type))
708 {
713 &purp->purpose,
714 &block->ecdsa_block.signature,
715 &block->ecdsa_block.derived_key);
716 break;
721 &purp->purpose,
722 &block->eddsa_block.signature,
723 &block->eddsa_block.derived_key);
724 break;
725 default:
726 res = GNUNET_NO;
727 }
728 GNUNET_free (purp);
729 return res;
730}
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_verify_(uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const struct GNUNET_CRYPTO_EcdsaSignature *sig, const struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Verify ECDSA signature.
Definition: crypto_ecc.c:649
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_verify_(uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const struct GNUNET_CRYPTO_EddsaSignature *sig, const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Verify EdDSA signature.
Definition: crypto_ecc.c:708
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN
GNS record set signature (GNS)
Information we have in an encrypted block with record data (i.e.
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Number of bytes signed; also specifies the number of bytes of encrypted data that follow.
struct GNUNET_TIME_AbsoluteNBO expiration_time
Expiration time of the block.
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!...
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
uint32_t type
The zone type (GNUNET_GNSRECORD_TYPE_PKEY)
struct GNUNET_GNSRECORD_EcdsaBlock ecdsa_block
struct GNUNET_GNSRECORD_EddsaBlock eddsa_block
uint32_t size
Size of the block.
struct GNUNET_CRYPTO_EcdsaSignature signature
Signature of the block.
struct GNUNET_TIME_AbsoluteNBO expiration_time
Expiration time of the block.
struct GNUNET_CRYPTO_EcdsaPublicKey derived_key
Derived key used for signing; hash of this is the query.
struct GNUNET_CRYPTO_EddsaPublicKey derived_key
Derived key used for signing; hash of this is the query.
struct GNUNET_TIME_AbsoluteNBO expiration_time
Expiration time of the block.
struct GNUNET_CRYPTO_EddsaSignature signature
Signature of the block.

References GNUNET_GNSRECORD_EcdsaBlock::derived_key, GNUNET_GNSRECORD_EddsaBlock::derived_key, GNUNET_GNSRECORD_Block::ecdsa_block, GNUNET_GNSRECORD_Block::eddsa_block, GNUNET_GNSRECORD_EcdsaBlock::expiration_time, GNUNET_GNSRECORD_EddsaBlock::expiration_time, GNRBlockPS::expiration_time, GNUNET_CRYPTO_ecdsa_verify_(), GNUNET_CRYPTO_eddsa_verify_(), GNUNET_free, GNUNET_GNSRECORD_TYPE_EDKEY, GNUNET_GNSRECORD_TYPE_PKEY, GNUNET_malloc, GNUNET_memcpy, GNUNET_NO, GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN, GNUNET_CRYPTO_EccSignaturePurpose::purpose, GNRBlockPS::purpose, res, GNUNET_GNSRECORD_EcdsaBlock::signature, GNUNET_GNSRECORD_EddsaBlock::signature, GNUNET_CRYPTO_EccSignaturePurpose::size, GNUNET_GNSRECORD_Block::size, and GNUNET_GNSRECORD_Block::type.

Referenced by block_plugin_gns_check_block(), and handle_lookup_block_response().

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

◆ GNUNET_GNSRECORD_block_decrypt()

enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_block_decrypt ( const struct GNUNET_GNSRECORD_Block block,
const struct GNUNET_CRYPTO_PublicKey zone_key,
const char *  label,
GNUNET_GNSRECORD_RecordCallback  proc,
void *  proc_cls 
)

Decrypt block.

Parameters
blockblock to decrypt
zone_keypublic key of the zone
labelthe name for the records
procfunction to call with the result
proc_clsclosure for proc
Returns
GNUNET_OK on success, GNUNET_SYSERR if the block was not well-formed

Definition at line 986 of file gnsrecord_crypto.c.

992{
994 char *norm_label;
995
996 norm_label = GNUNET_GNSRECORD_string_normalize (label);
997 switch (ntohl (zone_key->type))
998 {
1000 res = block_decrypt_ecdsa (block,
1001 &zone_key->ecdsa_key, norm_label, proc,
1002 proc_cls);
1003 break;
1005 res = block_decrypt_eddsa (block,
1006 &zone_key->eddsa_key, norm_label, proc,
1007 proc_cls);
1008 break;
1009 default:
1011 }
1012 GNUNET_free (norm_label);
1013 return res;
1014}
static enum GNUNET_GenericReturnValue block_decrypt_eddsa(const struct GNUNET_GNSRECORD_Block *block, const struct GNUNET_CRYPTO_EddsaPublicKey *zone_key, const char *label, GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls)
static enum GNUNET_GenericReturnValue block_decrypt_ecdsa(const struct GNUNET_GNSRECORD_Block *block, const struct GNUNET_CRYPTO_EcdsaPublicKey *zone_key, const char *label, GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls)
@ GNUNET_PUBLIC_KEY_TYPE_EDDSA
EDDSA identity.
@ GNUNET_PUBLIC_KEY_TYPE_ECDSA
The identity type.
uint32_t type
Type of public key.
struct GNUNET_CRYPTO_EcdsaPublicKey ecdsa_key
An ECDSA identity key.
struct GNUNET_CRYPTO_EddsaPublicKey eddsa_key
AN EdDSA identtiy key.

References block_decrypt_ecdsa(), block_decrypt_eddsa(), GNUNET_CRYPTO_PublicKey::ecdsa_key, GNUNET_CRYPTO_PublicKey::eddsa_key, GNUNET_free, GNUNET_GNSRECORD_string_normalize(), GNUNET_PUBLIC_KEY_TYPE_ECDSA, GNUNET_PUBLIC_KEY_TYPE_EDDSA, GNUNET_SYSERR, res, and GNUNET_CRYPTO_PublicKey::type.

Referenced by handle_block(), handle_dht_response(), and handle_namecache_block_response().

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

◆ GNUNET_GNSRECORD_records_cmp()

enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_records_cmp ( const struct GNUNET_GNSRECORD_Data a,
const struct GNUNET_GNSRECORD_Data b 
)

Compares if two records are equal.

Parameters
aa record
banother record
Returns
GNUNET_YES if the records are equal, or GNUNET_NO if not.

Compares if two records are equal.

absolute expiration time).

Parameters
arecord
brecord
Returns
GNUNET_YES if the records are equal or GNUNET_NO if they are not

Definition at line 90 of file gnsrecord_misc.c.

92{
94 "Comparing records\n");
95 if (a->record_type != b->record_type)
96 {
98 "Record type %u != %u\n", a->record_type, b->record_type);
99 return GNUNET_NO;
100 }
101 if ((a->expiration_time != b->expiration_time) &&
102 ((a->expiration_time != 0) && (b->expiration_time != 0)))
103 {
105 "Expiration time %llu != %llu\n",
106 (unsigned long long) a->expiration_time,
107 (unsigned long long) b->expiration_time);
108 return GNUNET_NO;
109 }
112 {
114 "Flags %u (%u) != %u (%u)\n", a->flags,
117 return GNUNET_NO;
118 }
119 if (a->data_size != b->data_size)
120 {
122 "Data size %llu != %llu\n",
123 (unsigned long long) a->data_size,
124 (unsigned long long) b->data_size);
125 return GNUNET_NO;
126 }
127 if (0 != memcmp (a->data, b->data, a->data_size))
128 {
130 "Data contents do not match\n");
131 return GNUNET_NO;
132 }
134 "Records are equal\n");
135 return GNUNET_YES;
136}
#define LOG(kind,...)
#define GNUNET_GNSRECORD_RF_RCMP_FLAGS
Include the record types generated from GANA.
const void * data
Binary value stored in the DNS record.

References GNUNET_GNSRECORD_Data::data, GNUNET_GNSRECORD_Data::data_size, GNUNET_GNSRECORD_Data::expiration_time, GNUNET_GNSRECORD_Data::flags, GNUNET_ERROR_TYPE_DEBUG, GNUNET_GNSRECORD_RF_RCMP_FLAGS, GNUNET_NO, GNUNET_YES, LOG, and GNUNET_GNSRECORD_Data::record_type.

◆ GNUNET_GNSRECORD_record_get_expiration_time()

struct GNUNET_TIME_Absolute GNUNET_GNSRECORD_record_get_expiration_time ( unsigned int  rd_count,
const struct GNUNET_GNSRECORD_Data rd,
struct GNUNET_TIME_Absolute  min 
)

Returns the expiration time of the given block of records.

The block expiration time is the expiration time of the record with smallest expiration time.

Parameters
rd_countnumber of records given in rd
rdarray of records
minminimum expiration time
Returns
absolute expiration time

Definition at line 140 of file gnsrecord_misc.c.

144{
146 struct GNUNET_TIME_Absolute at;
147 struct GNUNET_TIME_Relative rt;
148 struct GNUNET_TIME_Absolute at_shadow;
149 struct GNUNET_TIME_Relative rt_shadow;
150
151 if (0 == rd_count)
154 for (unsigned int c = 0; c < rd_count; c++)
155 {
156 if (0 != (rd[c].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
157 {
158 rt.rel_value_us = rd[c].expiration_time;
160 }
161 else
162 {
163 at.abs_value_us = rd[c].expiration_time;
164 }
165
166 for (unsigned int c2 = 0; c2 < rd_count; c2++)
167 {
168 /* Check for shadow record */
169 if ((c == c2) ||
170 (rd[c].record_type != rd[c2].record_type) ||
171 (0 == (rd[c2].flags & GNUNET_GNSRECORD_RF_SHADOW)))
172 continue;
173 /* We have a shadow record */
174 if (0 != (rd[c2].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
175 {
176 rt_shadow.rel_value_us = rd[c2].expiration_time;
177 at_shadow = GNUNET_TIME_relative_to_absolute (rt_shadow);
178 }
179 else
180 {
181 at_shadow.abs_value_us = rd[c2].expiration_time;
182 }
184 at_shadow);
185 }
187 expire);
188 }
191 "Determined expiration time for block with %u records to be %s\n",
192 rd_count,
194 return expire;
195}
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_max(struct GNUNET_TIME_Absolute t1, struct GNUNET_TIME_Absolute t2)
Return the maximum of two absolute time values.
Definition: time.c:368
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:316
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_min(struct GNUNET_TIME_Absolute t1, struct GNUNET_TIME_Absolute t2)
Return the minimum of two absolute time values.
Definition: time.c:360
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:640
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
#define min(x, y)
Time for relative time used by GNUnet, in microseconds.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_GNSRECORD_Data::expiration_time, expire, GNUNET_ERROR_TYPE_DEBUG, GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION, GNUNET_GNSRECORD_RF_SHADOW, GNUNET_STRINGS_absolute_time_to_string(), GNUNET_TIME_absolute_max(), GNUNET_TIME_absolute_min(), GNUNET_TIME_relative_to_absolute(), GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_ZERO_ABS, LOG, min, rd, rd_count, and GNUNET_TIME_Relative::rel_value_us.

Referenced by GNUNET_GNSRECORD_normalize_record_set(), process_lookup_result(), run_edkey(), and run_pkey().

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

◆ GNUNET_GNSRECORD_block_get_size()

size_t GNUNET_GNSRECORD_block_get_size ( const struct GNUNET_GNSRECORD_Block block)

Returns the length of this block in bytes.

Block length strongly depends on the zone type.

Parameters
blockthe block.
Returns
the length of this block in bytes

Definition at line 327 of file gnsrecord_misc.c.

328{
329 return ntohl (block->size);
330}

References GNUNET_GNSRECORD_Block::size.

Referenced by block_plugin_gns_check_block(), block_plugin_gns_check_reply(), dispatch_job(), dispatch_job_monitor(), GNUNET_NAMECACHE_block_cache(), handle_dht_response(), handle_lookup_block_it(), namecache_cache_block(), namecache_postgres_cache_block(), namecache_sqlite_cache_block(), and store_and_free_entries().

Here is the caller graph for this function:

◆ GNUNET_GNSRECORD_block_get_expiration()

struct GNUNET_TIME_Absolute GNUNET_GNSRECORD_block_get_expiration ( const struct GNUNET_GNSRECORD_Block block)

Returns the expiration of a block.

Parameters
blockthe block.
Returns
the block expiration.

Definition at line 334 of file gnsrecord_misc.c.

336{
337
338 switch (ntohl (block->type))
339 {
344 default:
345 GNUNET_break (0); /* Hopefully we never get here, but we might */
346 }
348
349}
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_zero_(void)
Return absolute time of 0ms.
Definition: time.c:142
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:741

References GNUNET_break, GNUNET_GNSRECORD_TYPE_EDKEY, GNUNET_GNSRECORD_TYPE_PKEY, GNUNET_TIME_absolute_get_zero_(), and GNUNET_TIME_absolute_ntoh().

Referenced by expire_blocks(), handle_dht_response(), handle_lookup_block_it(), handle_namecache_block_response(), namecache_postgres_cache_block(), and namecache_sqlite_cache_block().

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

◆ GNUNET_GNSRECORD_query_from_block()

enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_query_from_block ( const struct GNUNET_GNSRECORD_Block block,
struct GNUNET_HashCode query 
)

Builds the query hash from a block.

Parameters
blockthe block.
querywhere to write the query hash.
Returns
GNUNET_SYSERR on error.

Definition at line 353 of file gnsrecord_misc.c.

355{
356 switch (ntohl (block->type))
357 {
360 sizeof (block->ecdsa_block.derived_key),
361 query);
362 return GNUNET_OK;
365 sizeof (block->eddsa_block.derived_key),
366 query);
367 return GNUNET_OK;
368 default:
369 return GNUNET_SYSERR;
370 }
371 return GNUNET_SYSERR;
372
373}

References GNUNET_GNSRECORD_EcdsaBlock::derived_key, GNUNET_GNSRECORD_EddsaBlock::derived_key, GNUNET_GNSRECORD_Block::ecdsa_block, GNUNET_GNSRECORD_Block::eddsa_block, GNUNET_CRYPTO_hash(), GNUNET_GNSRECORD_TYPE_EDKEY, GNUNET_GNSRECORD_TYPE_PKEY, GNUNET_OK, GNUNET_SYSERR, and GNUNET_GNSRECORD_Block::type.

Referenced by block_plugin_gns_get_key(), namecache_cache_block(), namecache_postgres_cache_block(), and namecache_sqlite_cache_block().

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

◆ GNUNET_GNSRECORD_identity_from_data()

enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_identity_from_data ( const char *  data,
size_t  data_size,
uint32_t  type,
struct GNUNET_CRYPTO_PublicKey key 
)

Build a #GNUNET_GNSRECORD_PublicKey from zone delegation resource record data.

Parameters
datathe record data-
data_sizethe data size.
typethe record type
keythe identity key to store the data in (must be allocated).
Returns
GNUNET_OK if successful.

Definition at line 265 of file gnsrecord_misc.c.

269{
271 return GNUNET_SYSERR;
272 switch (type)
273 {
275 if (data_size > sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))
276 return GNUNET_SYSERR;
277 memcpy (&key->ecdsa_key, data, data_size);
278 break;
280 if (data_size > sizeof (struct GNUNET_CRYPTO_EddsaPublicKey))
281 return GNUNET_SYSERR;
282 memcpy (&key->eddsa_key, data, data_size);
283 break;
284 default:
285 return GNUNET_NO;
286 }
287 key->type = htonl (type);
288
289 return GNUNET_YES;
290}
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_is_zonekey_type(uint32_t type)
Check if this type is one of the supported GNS zone types.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...

References data, data_size, GNUNET_GNSRECORD_is_zonekey_type(), GNUNET_GNSRECORD_TYPE_EDKEY, GNUNET_GNSRECORD_TYPE_PKEY, GNUNET_NO, GNUNET_SYSERR, GNUNET_YES, key, and type.

Referenced by check_pkey(), gns_value_to_string(), handle_gns_resolution_result(), namestore_postgres_store_records(), namestore_sqlite_store_records(), and recursive_pkey_resolution().

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

◆ GNUNET_GNSRECORD_data_from_identity()

enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_data_from_identity ( const struct GNUNET_CRYPTO_PublicKey key,
char **  data,
size_t *  data_size,
uint32_t *  type 
)

Create record data and size from an identity key.

Parameters
keythe identity key to use.
datathe record data (will be allocated)
data_sizethe allocated data size.
typethe resulting record type
Returns
GNUNET_OK if successful.

Definition at line 294 of file gnsrecord_misc.c.

299{
300 char *tmp;
301 *type = ntohl (key->type);
303 if (0 == *data_size)
304 return GNUNET_SYSERR;
305 tmp = GNUNET_malloc (*data_size);
306 memcpy (tmp, ((char*) key) + sizeof (key->type), *data_size);
307 *data = tmp;
308 return GNUNET_OK;
309}
ssize_t GNUNET_CRYPTO_public_key_get_length(const struct GNUNET_CRYPTO_PublicKey *key)
Get the compacted length of a GNUNET_CRYPTO_PublicKey.
Definition: crypto_pkey.c:85

References data, data_size, GNUNET_CRYPTO_public_key_get_length(), GNUNET_malloc, GNUNET_OK, GNUNET_SYSERR, key, and type.

Referenced by gns_string_to_value().

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

◆ GNUNET_GNSRECORD_is_zonekey_type()

enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_is_zonekey_type ( uint32_t  type)

Check if this type is one of the supported GNS zone types.

Parameters
typethe type to check
Returns
GNUNET_YES if it is one of the supported types.

Definition at line 313 of file gnsrecord_misc.c.

314{
315 switch (type)
316 {
319 return GNUNET_YES;
320 default:
321 return GNUNET_NO;
322 }
323}

References GNUNET_GNSRECORD_TYPE_EDKEY, GNUNET_GNSRECORD_TYPE_PKEY, GNUNET_NO, GNUNET_YES, and type.

Referenced by GNUNET_GNSRECORD_identity_from_data(), GNUNET_GNSRECORD_normalize_record_set(), namestore_postgres_store_records(), namestore_sqlite_store_records(), and zone_to_name().

Here is the caller graph for this function:

◆ GNUNET_GNSRECORD_is_critical()

enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_is_critical ( uint32_t  type)

Check if this type is a critical record.

Parameters
typethe type to check
Returns
GNUNET_YES if it is critical.

Definition at line 239 of file gnsrecord.c.

240{
241 struct Plugin *plugin;
242
244 return GNUNET_NO;
245 init ();
246 for (unsigned int i = 0; i < num_plugins; i++)
247 {
248 plugin = gns_plugins[i];
249 if (NULL == plugin->api->is_critical)
250 continue;
251 if (GNUNET_NO == plugin->api->is_critical (plugin->api->cls, type))
252 continue;
253 return GNUNET_YES;
254 }
255 return GNUNET_NO;
256}

References GNUNET_TESTING_PluginFunctions::cls, gns_plugins, GNUNET_GNSRECORD_TYPE_ANY, GNUNET_NO, GNUNET_YES, init(), num_plugins, plugin, and type.

Referenced by GNUNET_GNSRECORD_normalize_record_set(), and handle_gns_resolution_result().

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

◆ GNUNET_GNSRECORD_normalize_record_set()

enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_normalize_record_set ( const char *  label,
const struct GNUNET_GNSRECORD_Data rd,
unsigned int  rd_count,
struct GNUNET_GNSRECORD_Data rd_public,
unsigned int *  rd_count_public,
struct GNUNET_TIME_Absolute min_expiry,
enum GNUNET_GNSRECORD_Filter  filter,
char **  emsg 
)

Normalize namestore records: Check for consistency and expirations.

Purge expired records. Returns a "clean" record set. Also returns the minimum expiration time this block should be published under. Also checks rules with respect to labels (e.g. no delegations under the empty label)

Parameters
labelthe label under which this set (supposed to be) stored.
rdinput records
rd_countsize of the rd and rd_public arrays
rd_publicwhere to write the converted records
rd_count_publicnumber of records written to rd_public
min_expirythe minimum expiration of this set
filterthe record set filter, see GNUNET_GNSRECORD_Filter.
emsgthe error message if something went wrong
Returns
GNUNET_OK if set could be normalized and is consistent

Check for delegation and redirect consistency. Note that we check for consistency BEFORE we filter for private records ON PURPOSE. We also want consistent record sets in our local zone(s). The only exception is the tombstone (above) which we ignore for the consistency check(s). FIXME: What about shadow records? Should we ignore them?

Definition at line 377 of file gnsrecord_misc.c.

387{
388 struct GNUNET_TIME_Absolute now;
389 struct GNUNET_TIME_Absolute minimum_expiration;
390 int have_zone_delegation = GNUNET_NO;
391 int have_gns2dns = GNUNET_NO;
392 int have_other = GNUNET_NO;
393 int have_redirect = GNUNET_NO;
394 int have_empty_label = (0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT, label));
395 unsigned int rd_count_tmp;
396
397 minimum_expiration = GNUNET_TIME_UNIT_ZERO_ABS;
399 rd_count_tmp = 0;
400 for (unsigned int i = 0; i < rd_count; i++)
401 {
402 /* Ignore private records for public record set */
404 (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE)))
405 {
407 "Filtering private record filter=%u...\n", filter);
408 continue;
409 }
410 /* Skip expired records */
411 if ((0 == (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) &&
412 (rd[i].expiration_time < now.abs_value_us))
413 {
415 "Filtering expired record...\n");
416 continue; /* record already expired, skip it */
417 }
418 /* Ignore the maintenance record (e.g. tombstone) unless filter permits explicitly.
419 * Remember expiration time. */
420 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_MAINTENANCE))
421 {
423 {
424 rd_public[rd_count_tmp] = rd[i];
425 rd_count_tmp++;
426 }
427 continue;
428 }
429 /* No NICK records unless empty label */
430 if (have_empty_label &&
431 (GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type))
432 continue;
433
443 if (GNUNET_YES == GNUNET_GNSRECORD_is_zonekey_type (rd[i].record_type))
444 {
445 /* No delegation records under empty label*/
446 if (have_empty_label)
447 {
448 *emsg = GNUNET_strdup (_ (
449 "Zone delegation record not allowed in apex."));
450 return GNUNET_SYSERR;
451 }
452 if ((GNUNET_YES == have_other) ||
453 (GNUNET_YES == have_redirect) ||
454 (GNUNET_YES == have_gns2dns))
455 {
456 *emsg = GNUNET_strdup (_ (
457 "Zone delegation record set contains mutually exclusive records."));
458 return GNUNET_SYSERR;
459 }
460 have_zone_delegation = GNUNET_YES;
461 }
462 else if (GNUNET_GNSRECORD_TYPE_REDIRECT == rd[i].record_type)
463 {
464 if (GNUNET_YES == have_redirect)
465 {
466 *emsg = GNUNET_strdup (_ (
467 "Multiple REDIRECT records."));
468 return GNUNET_SYSERR;
469
470 }
471 if ((GNUNET_YES == have_other) ||
472 (GNUNET_YES == have_zone_delegation) ||
473 (GNUNET_YES == have_gns2dns))
474 {
475 *emsg = GNUNET_strdup (_ (
476 "Redirection record set contains mutually exclusive records."));
477 return GNUNET_SYSERR;
478 }
479 /* No redirection records under empty label*/
480 if (have_empty_label)
481 {
482 *emsg = GNUNET_strdup (_ (
483 "Redirection records not allowed in apex."));
484 return GNUNET_SYSERR;
485 }
486 have_redirect = GNUNET_YES;
487 }
488 else if (GNUNET_GNSRECORD_TYPE_GNS2DNS == rd[i].record_type)
489 {
490 /* No gns2dns records under empty label*/
491 if (have_empty_label)
492 {
493 *emsg = GNUNET_strdup (_ (
494 "Redirection records not allowed in apex.."));
495 return GNUNET_SYSERR;
496 }
497 if ((GNUNET_YES == have_other) ||
498 (GNUNET_YES == have_redirect) ||
499 (GNUNET_YES == have_zone_delegation))
500 {
501 *emsg = GNUNET_strdup (_ (
502 "Redirection record set contains mutually exclusive records."));
503 return GNUNET_SYSERR;
504 }
505 have_gns2dns = GNUNET_YES;
506 }
507 else
508 {
509 /* Some other record.
510 * Not allowed for zone delegations or redirections */
511 if ((GNUNET_YES == have_zone_delegation) ||
512 (GNUNET_YES == have_redirect) ||
513 (GNUNET_YES == have_gns2dns))
514 {
515 *emsg = GNUNET_strdup (_ (
516 "Mutually exclusive records."));
517 return GNUNET_SYSERR;
518 }
519 have_other = GNUNET_YES;
520 }
521
522 rd_public[rd_count_tmp] = rd[i];
523 /* Make sure critical record types are marked as such */
524 if (GNUNET_YES == GNUNET_GNSRECORD_is_critical (rd[i].record_type))
525 rd_public[rd_count_tmp].flags |= GNUNET_GNSRECORD_RF_CRITICAL;
526 rd_count_tmp++;
527 }
528
529 *expiry = GNUNET_GNSRECORD_record_get_expiration_time (rd_count_tmp,
530 rd_public,
531 minimum_expiration);
532 *rd_count_public = rd_count_tmp;
533 return GNUNET_OK;
534}
static struct GNUNET_CONTAINER_BloomFilter * filter
Bloomfilter to quickly tell if we don't have the content.
struct GNUNET_TIME_Absolute GNUNET_GNSRECORD_record_get_expiration_time(unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, struct GNUNET_TIME_Absolute min)
Returns the expiration time of the given block of records.
#define GNUNET_GNS_EMPTY_LABEL_AT
String we use to indicate an empty label (top-level entry in the zone).
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_is_critical(uint32_t type)
Check if this type is a critical record.
Definition: gnsrecord.c:239
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:111
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
#define GNUNET_GNSRECORD_TYPE_NICK
GNS zone nickname.
#define GNUNET_GNSRECORD_TYPE_GNS2DNS
Delegation to DNS.
#define GNUNET_GNSRECORD_TYPE_REDIRECT
Redirection record.

References _, GNUNET_TIME_Absolute::abs_value_us, filter, GNUNET_GNSRECORD_Data::flags, GNUNET_ERROR_TYPE_DEBUG, GNUNET_GNS_EMPTY_LABEL_AT, GNUNET_GNSRECORD_FILTER_INCLUDE_MAINTENANCE, GNUNET_GNSRECORD_FILTER_OMIT_PRIVATE, GNUNET_GNSRECORD_is_critical(), GNUNET_GNSRECORD_is_zonekey_type(), GNUNET_GNSRECORD_record_get_expiration_time(), GNUNET_GNSRECORD_RF_CRITICAL, GNUNET_GNSRECORD_RF_MAINTENANCE, GNUNET_GNSRECORD_RF_PRIVATE, GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION, GNUNET_GNSRECORD_TYPE_GNS2DNS, GNUNET_GNSRECORD_TYPE_NICK, GNUNET_GNSRECORD_TYPE_REDIRECT, GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_strdup, GNUNET_SYSERR, GNUNET_TIME_absolute_get(), GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_YES, rd, and rd_count.

Referenced by dispatch_job(), dispatch_job_monitor(), get_existing_rd_exp(), lookup_it(), send_lookup_response_with_filter(), and store_record_set().

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

◆ GNUNET_GNSRECORD_label_check()

enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_label_check ( const char *  label,
char **  emsg 
)

Check label for invalid characters.

Parameters
labelthe label to check
emsgan error message (NULL if label is valid). Will be allocated.
Returns
GNUNET_OK if label is valid.

Definition at line 44 of file gnsrecord_misc.c.

45{
46 if (NULL == label)
47 {
48 *emsg = GNUNET_strdup (_ ("Label is NULL which is not allowed\n"));
49 return GNUNET_NO;
50 }
51 if (0 != strchr (label, '.'))
52 {
53 *emsg = GNUNET_strdup (_ ("Label contains `.' which is not allowed\n"));
54 return GNUNET_NO;
55 }
56 return GNUNET_OK;
57}

References _, GNUNET_NO, GNUNET_OK, and GNUNET_strdup.

Referenced by store_record_set().

Here is the caller graph for this function:

◆ GNUNET_GNSRECORD_check_pow()

enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_check_pow ( const struct GNUNET_GNSRECORD_PowP pow,
unsigned int  difficulty,
struct GNUNET_TIME_Relative  epoch_duration 
)

Check if the given proof-of-work is valid.

Parameters
powproof of work
matching_bitshow many bits must match (configuration)
epoch_durationlength of single epoch in configuration
Returns
GNUNET_YES if the pow is acceptable, GNUNET_NO if not
Parameters
powproof of work
difficultyhow many bits must match (configuration) LSD0001: D
epoch_durationlength of single epoch in configuration
Returns
GNUNET_YES if the pow is acceptable, GNUNET_NO if not

Check if signature valid

First, check if PoW set is strictly monotically increasing

Check expiration

Extend by 10% for unsynchronized clocks

Definition at line 164 of file gnsrecord_pow.c.

167{
168 char buf[sizeof(struct GNUNET_CRYPTO_PublicKey)
169 + sizeof (struct GNUNET_TIME_AbsoluteNBO)
170 + sizeof (uint64_t)] GNUNET_ALIGN;
171 struct GNUNET_HashCode result;
172 struct GNUNET_TIME_Absolute ts;
173 struct GNUNET_TIME_Absolute exp;
175 struct GNUNET_TIME_Relative buffer;
176 /* LSD0001: D' */
177 unsigned int score = 0;
178 unsigned int tmp_score = 0;
179 unsigned int epochs;
180 uint64_t pow_val;
181 ssize_t pklen;
182 const struct GNUNET_CRYPTO_PublicKey *pk;
183
184 pk = (const struct GNUNET_CRYPTO_PublicKey *) &pow[1];
185
189 if (GNUNET_OK != check_signature (pow))
190 {
192 "Proof of work signature invalid!\n");
193 return GNUNET_SYSERR;
194 }
195
199 for (unsigned int i = 0; i < POW_COUNT - 1; i++)
200 {
201 if (GNUNET_ntohll (pow->pow[i]) >= GNUNET_ntohll (pow->pow[i + 1]))
202 return GNUNET_NO;
203 }
204 GNUNET_memcpy (&buf[sizeof(uint64_t)],
205 &pow->timestamp,
206 sizeof (uint64_t));
208 if (0 > pklen)
209 {
210 GNUNET_break (0);
211 return GNUNET_NO;
212 }
213 GNUNET_memcpy (&buf[sizeof(uint64_t) * 2],
214 pk,
215 pklen);
216 for (unsigned int i = 0; i < POW_COUNT; i++)
217 {
218 pow_val = GNUNET_ntohll (pow->pow[i]);
219 GNUNET_memcpy (buf, &pow->pow[i], sizeof(uint64_t));
221 buf,
222 sizeof(buf),
223 &result);
226 "Score %u with %" PRIu64 " (#%u)\n",
227 tmp_score, pow_val, i);
228
229 score += tmp_score;
230
231 }
232 score = score / POW_COUNT;
233 if (score < difficulty)
234 return GNUNET_NO;
235 /* LSD0001: (D'-D+1) */
236 epochs = score - difficulty + 1;
237
243 epochs);
248 10);
249 exp = GNUNET_TIME_absolute_add (ts, ttl);
250 exp = GNUNET_TIME_absolute_add (exp,
251 buffer);
252
253 if (0 != GNUNET_TIME_absolute_get_remaining (ts).rel_value_us)
254 return GNUNET_NO; /* Not yet valid. */
255 /* Revert to actual start time */
257 buffer);
258
259 if (0 == GNUNET_TIME_absolute_get_remaining (exp).rel_value_us)
260 return GNUNET_NO; /* expired */
261 return GNUNET_YES;
262}
static enum GNUNET_GenericReturnValue check_signature(const struct GNUNET_GNSRECORD_PowP *pow)
static struct GNUNET_CRYPTO_PowSalt salt
Definition: gnsrecord_pow.c:84
struct GNUNET_CRYPTO_PrivateKey pk
Private key from command line option, or NULL.
static struct GNUNET_TIME_Relative ttl
Current record $TTL to use.
static struct GNUNET_TIME_Relative epoch_duration
Epoch length.
static unsigned int epochs
-e option.
#define POW_COUNT
The proof-of-work narrowing factor.
unsigned int GNUNET_CRYPTO_hash_count_leading_zeros(const struct GNUNET_HashCode *h)
Count the number of leading 0 bits in h.
Definition: crypto_hash.c:174
void GNUNET_CRYPTO_pow_hash(const struct GNUNET_CRYPTO_PowSalt *salt, const void *buf, size_t buf_len, struct GNUNET_HashCode *result)
Calculate the 'proof-of-work' hash (an expensive hash).
Definition: crypto_pow.c:42
#define GNUNET_ALIGN
gcc-ism to force alignment; we use this to align char-arrays that may then be cast to 'struct's.
@ GNUNET_ERROR_TYPE_ERROR
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:486
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_add(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration)
Add a given relative duration to the given start time.
Definition: time.c:452
struct GNUNET_TIME_Relative GNUNET_TIME_relative_divide(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Divide relative time by a given factor.
Definition: time.c:552
struct GNUNET_TIME_AbsoluteNBO timestamp
The timestamp of the revocation.
uint64_t pow[32]
The PoWs.
A 512-bit hashcode.
Time for absolute time used by GNUnet, in microseconds and in network byte order.

References check_signature(), epoch_duration, epochs, GNUNET_ALIGN, GNUNET_break, GNUNET_CRYPTO_hash_count_leading_zeros(), GNUNET_CRYPTO_pow_hash(), GNUNET_CRYPTO_public_key_get_length(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_memcpy, GNUNET_NO, GNUNET_ntohll(), GNUNET_OK, GNUNET_SYSERR, GNUNET_TIME_absolute_add(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_absolute_ntoh(), GNUNET_TIME_relative_divide(), GNUNET_TIME_relative_multiply(), GNUNET_YES, pk, GNUNET_GNSRECORD_PowP::pow, POW_COUNT, result, salt, GNUNET_GNSRECORD_PowP::timestamp, and ttl.

Referenced by block_plugin_revocation_check_block(), ego_callback(), GNUNET_REVOCATION_revoke(), run(), run_with_key(), and verify_revoke_message().

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

◆ GNUNET_GNSRECORD_pow_init()

void GNUNET_GNSRECORD_pow_init ( const struct GNUNET_CRYPTO_PrivateKey key,
struct GNUNET_GNSRECORD_PowP pow 
)

Initializes a fresh PoW computation.

Parameters
keythe key to calculate the PoW for.
powthe pow object to work with in the calculation.
keythe key to calculate the PoW for.
[out]powstarting point for PoW calculation (not yet valid)

Definition at line 317 of file gnsrecord_pow.c.

319{
321}
static enum GNUNET_GenericReturnValue sign_pow(const struct GNUNET_CRYPTO_PrivateKey *key, struct GNUNET_GNSRECORD_PowP *pow)

References GNUNET_assert, GNUNET_OK, key, and sign_pow().

Referenced by ego_callback(), and run_with_key().

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

◆ GNUNET_GNSRECORD_pow_start()

struct GNUNET_GNSRECORD_PowCalculationHandle * GNUNET_GNSRECORD_pow_start ( struct GNUNET_GNSRECORD_PowP pow,
int  epochs,
unsigned int  difficulty 
)

Starts a proof-of-work calculation given the pow object as well as target epochs and difficulty.

Parameters
powthe PoW to based calculations on.
epochsthe number of epochs for which the PoW must be valid.
difficultythe base difficulty of the PoW.
Returns
a handle for use in PoW rounds

Definition at line 325 of file gnsrecord_pow.c.

328{
331
332
334 pc->pow = pow;
336 epochs);
337 pc->pow->ttl = GNUNET_TIME_relative_hton (ttl);
339 UINT64_MAX);
340 pc->difficulty = difficulty;
341 pc->epochs = epochs;
342 return pc;
343}
static struct GNUNET_FS_PublishContext * pc
Handle to FS-publishing operation.
uint64_t GNUNET_CRYPTO_random_u64(enum GNUNET_CRYPTO_Quality mode, uint64_t max)
Generate a random unsigned 64-bit value.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton(struct GNUNET_TIME_Relative a)
Convert relative time to network byte order.
Definition: time.c:620
#define GNUNET_TIME_UNIT_YEARS
One year (365 days).
The handle to a PoW calculation.
Definition: gnsrecord_pow.c:55

References epochs, GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u64(), GNUNET_new, GNUNET_TIME_relative_hton(), GNUNET_TIME_relative_multiply(), GNUNET_TIME_UNIT_YEARS, pc, and ttl.

Referenced by ego_callback(), run(), and run_with_key().

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

◆ GNUNET_GNSRECORD_pow_round()

enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_pow_round ( struct GNUNET_GNSRECORD_PowCalculationHandle pc)

Calculate a single round in the key revocation PoW.

Parameters
pchandle to the PoW, initially called with NULL.
Returns
GNUNET_YES if the pow is acceptable, GNUNET_NO if not

Calculate a single round in the key revocation PoW.

Parameters
pchandle to the PoW, initially called with NULL.
epochsnumber of epochs for which the revocation must be valid.
powcurrent pow value to try
difficultycurrent base difficulty to achieve
Returns
GNUNET_YES if the pow is acceptable, GNUNET_NO if not

Do not try duplicates

Definition at line 371 of file gnsrecord_pow.c.

372{
373 char buf[sizeof(struct GNUNET_CRYPTO_PublicKey)
374 + sizeof (uint64_t)
375 + sizeof (uint64_t)] GNUNET_ALIGN;
376 struct GNUNET_HashCode result;
377 const struct GNUNET_CRYPTO_PublicKey *pk;
378 unsigned int zeros;
379 int ret;
380 uint64_t pow_nbo;
381 ssize_t ksize;
382
383 pc->current_pow++;
384 pk = (const struct GNUNET_CRYPTO_PublicKey *) &(pc->pow[1]);
385
389 for (unsigned int i = 0; i < POW_COUNT; i++)
390 if (pc->current_pow == pc->best[i].pow)
391 return GNUNET_NO;
392 pow_nbo = GNUNET_htonll (pc->current_pow);
393 GNUNET_memcpy (buf, &pow_nbo, sizeof(uint64_t));
394 GNUNET_memcpy (&buf[sizeof(uint64_t)],
395 &pc->pow->timestamp,
396 sizeof (uint64_t));
398 GNUNET_assert (0 < ksize);
399 GNUNET_memcpy (&buf[sizeof(uint64_t) * 2],
400 pk,
401 ksize);
403 buf,
404 sizeof(buf),
405 &result);
407 for (unsigned int i = 0; i < POW_COUNT; i++)
408 {
409 if (pc->best[i].bits < zeros)
410 {
411 pc->best[i].bits = zeros;
412 pc->best[i].pow = pc->current_pow;
413 pc->pow->pow[i] = pow_nbo;
415 "New best score %u with %" PRIu64 " (#%u)\n",
416 zeros, pc->current_pow, i);
417
418 break;
419 }
420 }
421 ret = calculate_score (pc) >= pc->difficulty + pc->epochs ? GNUNET_YES :
422 GNUNET_NO;
423 if (GNUNET_YES == ret)
424 {
425 /* Sort POWs) */
426 qsort (pc->pow->pow, POW_COUNT, sizeof (uint64_t), &cmp_pow_value);
427 }
428 return ret;
429}
static unsigned int calculate_score(const struct GNUNET_GNSRECORD_PowCalculationHandle *ph)
Calculate the average zeros in the pows.
Definition: gnsrecord_pow.c:93
static int cmp_pow_value(const void *a, const void *b)
Comparison function for quicksort.

References calculate_score(), cmp_pow_value(), GNUNET_ALIGN, GNUNET_assert, GNUNET_CRYPTO_hash_count_leading_zeros(), GNUNET_CRYPTO_pow_hash(), GNUNET_CRYPTO_public_key_get_length(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_htonll(), GNUNET_log, GNUNET_memcpy, GNUNET_NO, GNUNET_YES, pc, pk, POW_COUNT, result, ret, and salt.

Referenced by calculate_pow(), and run_with_key().

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

◆ GNUNET_GNSRECORD_proof_get_size()

size_t GNUNET_GNSRECORD_proof_get_size ( const struct GNUNET_GNSRECORD_PowP pow)

Definition at line 433 of file gnsrecord_pow.c.

434{
435 size_t size;
436 size_t ksize;
437 const struct GNUNET_CRYPTO_PublicKey *pk;
438
439 size = sizeof (struct GNUNET_GNSRECORD_PowP);
440 pk = (const struct GNUNET_CRYPTO_PublicKey *) &pow[1];
442 size += ksize;
444 return size;
445}
ssize_t GNUNET_CRYPTO_signature_get_raw_length_by_type(uint32_t type)
Get the compacted length of a signature by type.
Definition: crypto_pkey.c:209
static unsigned int size
Size of the "table".
Definition: peer.c:68

References GNUNET_CRYPTO_public_key_get_length(), GNUNET_CRYPTO_signature_get_raw_length_by_type(), pk, size, and GNUNET_CRYPTO_PrivateKey::type.

Referenced by calculate_pow(), GNUNET_REVOCATION_revoke(), run(), run_with_key(), and sync_pow().

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

◆ GNUNET_GNSRECORD_pow_stop()

void GNUNET_GNSRECORD_pow_stop ( struct GNUNET_GNSRECORD_PowCalculationHandle pc)

Stop a PoW calculation.

Parameters
pcthe calculation to clean up
Returns
GNUNET_YES if pow valid, GNUNET_NO if pow was set but is not valid

Definition at line 456 of file gnsrecord_pow.c.

457{
458 GNUNET_free (pc);
459}

References GNUNET_free, and pc.

Referenced by calculate_pow_shutdown().

Here is the caller graph for this function: