GNUnet 0.21.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 281 of file json_gnsrecord.c.

284{
285 struct GnsRecordInfo *gnsrecord_info = GNUNET_new (struct GnsRecordInfo);
286
287 gnsrecord_info->rd = rd;
288 gnsrecord_info->name = name;
289 gnsrecord_info->rd_count = rd_count;
291 .cleaner = &clean_gnsrecordobject,
292 .cls = NULL,
293 .field = NULL,
294 .ptr = (struct GnsRecordInfo *)
295 gnsrecord_info,
296 .ptr_size = 0,
297 .size_ptr = NULL };
298 return ret;
299}
static int ret
Final status code.
Definition: gnunet-arm.c:94
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 310 of file json_gnsrecord.c.

313{
314 const char *record_type_str;
315 char *value_str;
316 json_t *data;
317 json_t *record;
318 json_t *records;
319
320 data = json_object ();
321 if (NULL == data)
322 {
323 GNUNET_break (0);
324 return NULL;
325 }
326 if (0 !=
327 json_object_set_new (data,
328 "record_name",
329 json_string (rname)))
330 {
331 GNUNET_break (0);
332 json_decref (data);
333 return NULL;
334 }
335 records = json_array ();
336 if (NULL == records)
337 {
338 GNUNET_break (0);
339 json_decref (data);
340 return NULL;
341 }
342 for (int i = 0; i < rd_count; i++)
343 {
344 value_str = GNUNET_GNSRECORD_value_to_string (rd[i].record_type,
345 rd[i].data,
346 rd[i].data_size);
347 record_type_str = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type);
349 "Packing %s %s %" PRIu64 " %d\n",
350 value_str, record_type_str, rd[i].expiration_time, rd[i].flags);
351 record = json_pack (
352 "{s:s,s:s,s:I,s:b,s:b,s:b,s:b, s:b}",
354 GNUNET_JSON_GNSRECORD_TYPE, record_type_str,
358 rd[i].expiration_time,
368 rd[i].flags & GNUNET_GNSRECORD_RF_SHADOW);
369 GNUNET_free (value_str);
370 if (NULL == record)
371 {
372 GNUNET_break (0);
373 json_decref (records);
374 json_decref (data);
375 return NULL;
376 }
377 if (0 !=
378 json_array_append_new (records,
379 record))
380 {
381 GNUNET_break (0);
382 json_decref (records);
383 json_decref (data);
384 return NULL;
385 }
386 }
387 if (0 !=
388 json_object_set_new (data,
389 "data",
390 records))
391 {
392 GNUNET_break (0);
393 json_decref (data);
394 return NULL;
395 }
396 return data;
397}
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:227
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:155
#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_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_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 155 of file gnsrecord.c.

158{
159 struct Plugin *plugin;
160 char *ret;
161
162 init ();
163 for (unsigned int i = 0; i < num_plugins; i++)
164 {
165 plugin = gns_plugins[i];
166 if (NULL != (ret = plugin->api->value_to_string (plugin->api->cls,
167 type,
168 data,
169 data_size)))
170 return ret;
171 }
172 return NULL;
173}
static unsigned int num_plugins
Size of the 'plugins' array.
Definition: gnsrecord.c:62
static struct Plugin ** gns_plugins
Array of our plugins.
Definition: gnsrecord.c:57
static void init()
Loads all plugins (lazy initialization).
Definition: gnsrecord.c:99
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 177 of file gnsrecord.c.

181{
182 struct Plugin *plugin;
183
184 init ();
185 for (unsigned int i = 0; i < num_plugins; i++)
186 {
187 plugin = gns_plugins[i];
188 if (GNUNET_OK == plugin->api->string_to_value (plugin->api->cls,
189 type,
190 s,
191 data,
192 data_size))
193 return GNUNET_OK;
194 }
195 return GNUNET_SYSERR;
196}
@ 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 200 of file gnsrecord.c.

201{
202 struct Plugin *plugin;
203 uint32_t ret;
204
205 if (0 == strcasecmp (dns_typename,
206 "ANY"))
208 init ();
209 for (unsigned int i = 0; i < num_plugins; i++)
210 {
211 plugin = gns_plugins[i];
212 if (UINT32_MAX != (ret = plugin->api->typename_to_number (plugin->api->cls,
213 dns_typename)))
214 return ret;
215 }
216 return UINT32_MAX;
217}
#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 227 of file gnsrecord.c.

228{
229 struct Plugin *plugin;
230 const char *ret;
231
233 return "ANY";
234 init ();
235 for (unsigned int i = 0; i < num_plugins; i++)
236 {
237 plugin = gns_plugins[i];
238 if (NULL != (ret = plugin->api->number_to_typename (plugin->api->cls,
239 type)))
240 return ret;
241 }
242 return NULL;
243}

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 208 of file gnsrecord_misc.c.

209{
210 struct GNUNET_TIME_Absolute at;
211
213 return GNUNET_NO;
214 at.abs_value_us = rd->expiration_time;
215 return (0 == GNUNET_TIME_absolute_get_remaining (at).rel_value_us) ?
217}
@ 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:405
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 39 of file gnsrecord_misc.c.

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

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 64 of file gnsrecord_misc.c.

65{
66 static char buf[sizeof(struct GNUNET_CRYPTO_PublicKey) * 8];
67 char *end;
68
69 end = GNUNET_STRINGS_data_to_string ((const unsigned char *) z,
70 sizeof(struct
72 buf, sizeof(buf));
73 if (NULL == end)
74 {
75 GNUNET_break (0);
76 return NULL;
77 }
78 *end = '\0';
79 return buf;
80}
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
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:709

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 231 of file gnsrecord_misc.c.

232{
233 static char ret[128];
234 char *pkeys;
235
238 sizeof(ret),
239 "%s",
240 pkeys);
241 GNUNET_free (pkeys);
242 return ret;
243}
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:568
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 256 of file gnsrecord_misc.c.

258{
259 if (GNUNET_OK !=
261 pkey))
262 return GNUNET_SYSERR;
263 return GNUNET_OK;
264}
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:588

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 1024 of file gnsrecord_crypto.c.

1028{
1029 char *norm_label;
1031
1032 norm_label = GNUNET_GNSRECORD_string_normalize (label);
1033 switch (ntohl (zone->type))
1034 {
1037
1039 &pub);
1041 norm_label,
1042 query);
1043 break;
1044 default:
1045 GNUNET_assert (0);
1046 }
1047 GNUNET_free (norm_label);
1048}
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:619
#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 1052 of file gnsrecord_crypto.c.

1056{
1057 char *norm_label;
1058 struct GNUNET_CRYPTO_PublicKey pd;
1059
1060 norm_label = GNUNET_GNSRECORD_string_normalize (label);
1061
1062 switch (ntohl (pub->type))
1063 {
1065 pd.type = pub->type;
1067 norm_label,
1068 "gns",
1069 &pd.ecdsa_key);
1070 GNUNET_CRYPTO_hash (&pd.ecdsa_key,
1071 sizeof (pd.ecdsa_key),
1072 query);
1073 break;
1075 pd.type = pub->type;
1077 norm_label,
1078 "gns",
1079 &(pd.eddsa_key));
1080 GNUNET_CRYPTO_hash (&pd.eddsa_key,
1081 sizeof (pd.eddsa_key),
1082 query);
1083 break;
1084 default:
1085 GNUNET_assert (0);
1086 }
1087 GNUNET_free (norm_label);
1088}
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}
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)
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}
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 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 char * expire
DID Document expiration Date Attribute String.
Definition: gnunet-did.c:98
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:648
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:707
#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 985 of file gnsrecord_crypto.c.

991{
993 char *norm_label;
994
995 norm_label = GNUNET_GNSRECORD_string_normalize (label);
996 switch (ntohl (zone_key->type))
997 {
999 res = block_decrypt_ecdsa (block,
1000 &zone_key->ecdsa_key, norm_label, proc,
1001 proc_cls);
1002 break;
1004 res = block_decrypt_eddsa (block,
1005 &zone_key->eddsa_key, norm_label, proc,
1006 proc_cls);
1007 break;
1008 default:
1010 }
1011 GNUNET_free (norm_label);
1012 return res;
1013}
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)
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 93 of file gnsrecord_misc.c.

95{
97 "Comparing records\n");
98 if (a->record_type != b->record_type)
99 {
101 "Record type %u != %u\n", a->record_type, b->record_type);
102 return GNUNET_NO;
103 }
104 if ((a->expiration_time != b->expiration_time) &&
105 ((a->expiration_time != 0) && (b->expiration_time != 0)))
106 {
108 "Expiration time %llu != %llu\n",
109 (unsigned long long) a->expiration_time,
110 (unsigned long long) b->expiration_time);
111 return GNUNET_NO;
112 }
115 {
117 "Flags %u (%u) != %u (%u)\n", a->flags,
120 return GNUNET_NO;
121 }
122 if (a->data_size != b->data_size)
123 {
125 "Data size %llu != %llu\n",
126 (unsigned long long) a->data_size,
127 (unsigned long long) b->data_size);
128 return GNUNET_NO;
129 }
130 if (0 != memcmp (a->data, b->data, a->data_size))
131 {
133 "Data contents do not match\n");
134 return GNUNET_NO;
135 }
137 "Records are equal\n");
138 return GNUNET_YES;
139}
#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 143 of file gnsrecord_misc.c.

147{
149 struct GNUNET_TIME_Absolute at;
150 struct GNUNET_TIME_Relative rt;
151 struct GNUNET_TIME_Absolute at_shadow;
152 struct GNUNET_TIME_Relative rt_shadow;
153
154 if (0 == rd_count)
157 for (unsigned int c = 0; c < rd_count; c++)
158 {
159 if (0 != (rd[c].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
160 {
161 rt.rel_value_us = rd[c].expiration_time;
163 }
164 else
165 {
166 at.abs_value_us = rd[c].expiration_time;
167 }
168
169 for (unsigned int c2 = 0; c2 < rd_count; c2++)
170 {
171 /* Check for shadow record */
172 if ((c == c2) ||
173 (rd[c].record_type != rd[c2].record_type) ||
174 (0 == (rd[c2].flags & GNUNET_GNSRECORD_RF_SHADOW)))
175 continue;
176 /* We have a shadow record */
177 if (0 != (rd[c2].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
178 {
179 rt_shadow.rel_value_us = rd[c2].expiration_time;
180 at_shadow = GNUNET_TIME_relative_to_absolute (rt_shadow);
181 }
182 else
183 {
184 at_shadow.abs_value_us = rd[c2].expiration_time;
185 }
187 at_shadow);
188 }
190 expire);
191 }
194 "Determined expiration time for block with %u records to be %s\n",
195 rd_count,
197 return expire;
198}
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:367
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:359
#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:617
#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 330 of file gnsrecord_misc.c.

331{
332 return ntohl (block->size);
333}

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 337 of file gnsrecord_misc.c.

339{
340
341 switch (ntohl (block->type))
342 {
347 default:
348 GNUNET_break (0); /* Hopefully we never get here, but we might */
349 }
351
352}
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:737

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 356 of file gnsrecord_misc.c.

358{
359 switch (ntohl (block->type))
360 {
363 sizeof (block->ecdsa_block.derived_key),
364 query);
365 return GNUNET_OK;
368 sizeof (block->eddsa_block.derived_key),
369 query);
370 return GNUNET_OK;
371 default:
372 return GNUNET_SYSERR;
373 }
374 return GNUNET_SYSERR;
375
376}

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 268 of file gnsrecord_misc.c.

272{
274 return GNUNET_SYSERR;
275 switch (type)
276 {
278 if (data_size > sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))
279 return GNUNET_SYSERR;
280 memcpy (&key->ecdsa_key, data, data_size);
281 break;
283 if (data_size > sizeof (struct GNUNET_CRYPTO_EddsaPublicKey))
284 return GNUNET_SYSERR;
285 memcpy (&key->eddsa_key, data, data_size);
286 break;
287 default:
288 return GNUNET_NO;
289 }
290 key->type = htonl (type);
291
292 return GNUNET_YES;
293}
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 297 of file gnsrecord_misc.c.

302{
303 char *tmp;
304 *type = ntohl (key->type);
306 if (0 == *data_size)
307 return GNUNET_SYSERR;
308 tmp = GNUNET_malloc (*data_size);
309 memcpy (tmp, ((char*) key) + sizeof (key->type), *data_size);
310 *data = tmp;
311 return GNUNET_OK;
312}
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 316 of file gnsrecord_misc.c.

317{
318 switch (type)
319 {
322 return GNUNET_YES;
323 default:
324 return GNUNET_NO;
325 }
326}

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 247 of file gnsrecord.c.

248{
249 struct Plugin *plugin;
250
252 return GNUNET_NO;
253 init ();
254 for (unsigned int i = 0; i < num_plugins; i++)
255 {
256 plugin = gns_plugins[i];
257 if (NULL == plugin->api->is_critical)
258 continue;
259 if (GNUNET_NO == plugin->api->is_critical (plugin->api->cls, type))
260 continue;
261 return GNUNET_YES;
262 }
263 return GNUNET_NO;
264}

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 406 of file gnsrecord_misc.c.

416{
417 struct GNUNET_TIME_Absolute now;
418 struct GNUNET_TIME_Absolute minimum_expiration;
419 int have_zone_delegation = GNUNET_NO;
420 int have_gns2dns = GNUNET_NO;
421 int have_other = GNUNET_NO;
422 int have_redirect = GNUNET_NO;
423 int have_empty_label = (0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT, label));
424 unsigned int rd_count_tmp;
425
426 minimum_expiration = GNUNET_TIME_UNIT_ZERO_ABS;
428 rd_count_tmp = 0;
429 for (unsigned int i = 0; i < rd_count; i++)
430 {
431 /* Ignore private records for public record set */
433 (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE)))
434 {
436 "Filtering private record filter=%u...\n", filter);
437 continue;
438 }
439 /* Skip expired records */
440 if ((0 == (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) &&
441 (rd[i].expiration_time < now.abs_value_us))
442 {
444 "Filtering expired record...\n");
445 continue; /* record already expired, skip it */
446 }
447 /* Ignore the maintenance record (e.g. tombstone) unless filter permits explicitly.
448 * Remember expiration time. */
449 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_MAINTENANCE))
450 {
452 {
453 rd_public[rd_count_tmp] = rd[i];
454 rd_count_tmp++;
455 }
456 continue;
457 }
458 /* No NICK records unless empty label */
459 if (have_empty_label &&
460 (GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type))
461 continue;
462
472 if (GNUNET_YES == GNUNET_GNSRECORD_is_zonekey_type (rd[i].record_type))
473 {
474 /* No delegation records under empty label*/
475 if (have_empty_label)
476 {
477 *emsg = GNUNET_strdup (_ (
478 "Zone delegation record not allowed in apex."));
479 return GNUNET_SYSERR;
480 }
481 if ((GNUNET_YES == have_other) ||
482 (GNUNET_YES == have_redirect) ||
483 (GNUNET_YES == have_gns2dns))
484 {
485 *emsg = GNUNET_strdup (_ (
486 "Zone delegation record set contains mutually exclusive records."));
487 return GNUNET_SYSERR;
488 }
489 have_zone_delegation = GNUNET_YES;
490 }
491 else if (GNUNET_GNSRECORD_TYPE_REDIRECT == rd[i].record_type)
492 {
493 if (GNUNET_YES == have_redirect)
494 {
495 *emsg = GNUNET_strdup (_ (
496 "Multiple REDIRECT records."));
497 return GNUNET_SYSERR;
498
499 }
500 if ((GNUNET_YES == have_other) ||
501 (GNUNET_YES == have_zone_delegation) ||
502 (GNUNET_YES == have_gns2dns))
503 {
504 *emsg = GNUNET_strdup (_ (
505 "Redirection record set contains mutually exclusive records."));
506 return GNUNET_SYSERR;
507 }
508 /* No redirection records under empty label*/
509 if (have_empty_label)
510 {
511 *emsg = GNUNET_strdup (_ (
512 "Redirection records not allowed in apex."));
513 return GNUNET_SYSERR;
514 }
515 have_redirect = GNUNET_YES;
516 }
517 else if (GNUNET_GNSRECORD_TYPE_GNS2DNS == rd[i].record_type)
518 {
519 /* No gns2dns records under empty label*/
520 if (have_empty_label)
521 {
522 *emsg = GNUNET_strdup (_ (
523 "Redirection records not allowed in apex.."));
524 return GNUNET_SYSERR;
525 }
526 if ((GNUNET_YES == have_other) ||
527 (GNUNET_YES == have_redirect) ||
528 (GNUNET_YES == have_zone_delegation))
529 {
530 *emsg = GNUNET_strdup (_ (
531 "Redirection record set contains mutually exclusive records."));
532 return GNUNET_SYSERR;
533 }
534 have_gns2dns = GNUNET_YES;
535 }
536 else
537 {
538 /* Some other record.
539 * Not allowed for zone delegations or redirections */
540 if ((GNUNET_YES == have_zone_delegation) ||
541 (GNUNET_YES == have_redirect) ||
542 (GNUNET_YES == have_gns2dns))
543 {
544 *emsg = GNUNET_strdup (_ (
545 "Mutually exclusive records."));
546 return GNUNET_SYSERR;
547 }
548 have_other = GNUNET_YES;
549 }
550
551 rd_public[rd_count_tmp] = rd[i];
552 /* Make sure critical record types are marked as such */
553 if (GNUNET_YES == GNUNET_GNSRECORD_is_critical (rd[i].record_type))
554 rd_public[rd_count_tmp].flags |= GNUNET_GNSRECORD_RF_CRITICAL;
555 rd_count_tmp++;
556 }
557
558 *expiry = GNUNET_GNSRECORD_record_get_expiration_time (rd_count_tmp,
559 rd_public,
560 minimum_expiration);
561 *rd_count_public = rd_count_tmp;
562 return GNUNET_OK;
563}
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:247
#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 47 of file gnsrecord_misc.c.

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

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 166 of file gnsrecord_pow.c.

169{
170 char buf[sizeof(struct GNUNET_CRYPTO_PublicKey)
171 + sizeof (struct GNUNET_TIME_AbsoluteNBO)
172 + sizeof (uint64_t)] GNUNET_ALIGN;
173 struct GNUNET_HashCode result;
174 struct GNUNET_TIME_Absolute ts;
175 struct GNUNET_TIME_Absolute exp;
177 struct GNUNET_TIME_Relative buffer;
178 /* LSD0001: D' */
179 unsigned int score = 0;
180 unsigned int tmp_score = 0;
181 unsigned int epochs;
182 uint64_t pow_val;
183 ssize_t pklen;
184 const struct GNUNET_CRYPTO_PublicKey *pk;
185
186 pk = (const struct GNUNET_CRYPTO_PublicKey *) &pow[1];
187
191 if (GNUNET_OK != check_signature (pow))
192 {
194 "Proof of work signature invalid!\n");
195 return GNUNET_SYSERR;
196 }
197
201 for (unsigned int i = 0; i < POW_COUNT - 1; i++)
202 {
203 if (GNUNET_ntohll (pow->pow[i]) >= GNUNET_ntohll (pow->pow[i + 1]))
204 return GNUNET_NO;
205 }
206 GNUNET_memcpy (&buf[sizeof(uint64_t)],
207 &pow->timestamp,
208 sizeof (uint64_t));
210 if (0 > pklen)
211 {
212 GNUNET_break (0);
213 return GNUNET_NO;
214 }
215 GNUNET_memcpy (&buf[sizeof(uint64_t) * 2],
216 pk,
217 pklen);
218 for (unsigned int i = 0; i < POW_COUNT; i++)
219 {
220 pow_val = GNUNET_ntohll (pow->pow[i]);
221 GNUNET_memcpy (buf, &pow->pow[i], sizeof(uint64_t));
223 buf,
224 sizeof(buf),
225 &result);
228 "Score %u with %" PRIu64 " (#%u)\n",
229 tmp_score, pow_val, i);
230
231 score += tmp_score;
232
233 }
234 score = score / POW_COUNT;
235 if (score < difficulty)
236 return GNUNET_NO;
237 /* LSD0001: (D'-D+1) */
238 epochs = score - difficulty + 1;
239
245 epochs);
250 10);
251 exp = GNUNET_TIME_absolute_add (ts, ttl);
252 exp = GNUNET_TIME_absolute_add (exp,
253 buffer);
254
255 if (0 != GNUNET_TIME_absolute_get_remaining (ts).rel_value_us)
256 return GNUNET_NO; /* Not yet valid. */
257 /* Revert to actual start time */
259 buffer);
260
261 if (0 == GNUNET_TIME_absolute_get_remaining (exp).rel_value_us)
262 return GNUNET_NO; /* expired */
263 return GNUNET_YES;
264}
enum GNUNET_GenericReturnValue check_signature(const struct GNUNET_GNSRECORD_PowP *pow)
static struct GNUNET_CRYPTO_PowSalt salt
Definition: gnsrecord_pow.c:85
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:177
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:484
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:450
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:550
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 318 of file gnsrecord_pow.c.

320{
322}
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 326 of file gnsrecord_pow.c.

329{
332
333
335 pc->pow = pow;
337 epochs);
338 pc->pow->ttl = GNUNET_TIME_relative_hton (ttl);
340 UINT64_MAX);
341 pc->difficulty = difficulty;
342 pc->epochs = epochs;
343 return pc;
344}
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:618
#define GNUNET_TIME_UNIT_YEARS
One year (365 days).
The handle to a PoW calculation.
Definition: gnsrecord_pow.c:56

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 372 of file gnsrecord_pow.c.

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

435{
436 size_t size;
437 size_t ksize;
438 const struct GNUNET_CRYPTO_PublicKey *pk;
439
440 size = sizeof (struct GNUNET_GNSRECORD_PowP);
441 pk = (const struct GNUNET_CRYPTO_PublicKey *) &pow[1];
443 size += ksize;
445 return size;
446}
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:225
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 457 of file gnsrecord_pow.c.

458{
459 GNUNET_free (pc);
460}

References GNUNET_free, and pc.

Referenced by calculate_pow_shutdown().

Here is the caller graph for this function: