GNUnet  0.11.x
Data Structures | Macros | Typedefs | Enumerations | Functions
GNS Record library

Manipulate GNS record data. More...

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_ReverseRecord
 Record type used internally to keep track of reverse mappings into a namespace. 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...
 

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 , GNUNET_GNSRECORD_RF_SHADOW_RECORD = 2 , GNUNET_GNSRECORD_RF_SUPPLEMENTAL = 4 ,
  GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION = 16384 , GNUNET_GNSRECORD_RF_PRIVATE = 32768
}
 Include the record types generated from GANA. 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_IDENTITY_PublicKey *z)
 Convert a zone to a string (for printing debug messages). More...
 
const char * GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_IDENTITY_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_IDENTITY_PublicKey *pkey)
 Convert an absolute domain name to the respective public key. More...
 
void GNUNET_GNSRECORD_query_from_private_key (const struct GNUNET_IDENTITY_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_IDENTITY_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_IDENTITY_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_create (const struct GNUNET_IDENTITY_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_create2 (const struct GNUNET_IDENTITY_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...
 
int GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block)
 Check if a signature is valid. More...
 
int GNUNET_GNSRECORD_block_decrypt (const struct GNUNET_GNSRECORD_Block *block, const struct GNUNET_IDENTITY_PublicKey *zone_key, const char *label, GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls)
 Decrypt block. More...
 
int 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_IDENTITY_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_IDENTITY_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, int include_private, char **emsg)
 Normalize namestore records: Check for consistency and expirations. More...
 
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_convert_records_for_export (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 *expiry, char **emsg)
 Convert namestore records from the internal format to that suitable for publication (removes private records). More...
 
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_label_check (const char *label, char **emsg)
 Check label for invalid characters. 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 50 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 55 of file gnunet_gnsrecord_lib.h.

◆ GNUNET_GNSRECORD_TYPE_ANY

#define GNUNET_GNSRECORD_TYPE_ANY   0

Record type indicating any record/'*'.

Definition at line 61 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 316 of file gnunet_gnsrecord_lib.h.

Enumeration Type Documentation

◆ GNUNET_GNSRECORD_Flags

Include the record types generated from GANA.

Flags that can be set for a record. MUST fit into 16 bit.

Enumerator
GNUNET_GNSRECORD_RF_NONE 

No special options.

GNUNET_GNSRECORD_RF_CRITICAL 

This record is critical.

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

GNUNET_GNSRECORD_RF_SHADOW_RECORD 

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

GNUNET_GNSRECORD_RF_SUPPLEMENTAL 

This is a supplemental record.

GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION 

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

GNUNET_GNSRECORD_RF_PRIVATE 

This is a private record of this peer and it should thus not be handed out to other peers.

Definition at line 72 of file gnunet_gnsrecord_lib.h.

73 {
78 
85 
91 
96 
101  GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION = 16384, /* 2^14 */
102 
107  GNUNET_GNSRECORD_RF_PRIVATE = 32768, /* 2^15 */
108 
109 
121 #define GNUNET_GNSRECORD_RF_RCMP_FLAGS (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)
122 };
@ 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_SHADOW_RECORD
This record should not be used unless all (other) records with an absolute expiration time have expir...
@ GNUNET_GNSRECORD_RF_PRIVATE
This is a private record of this peer and it should thus not be handed out to other peers.
@ GNUNET_GNSRECORD_RF_NONE
No special options.

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

265 {
266  struct GnsRecordInfo *gnsrecord_info = GNUNET_new (struct GnsRecordInfo);
267 
268  gnsrecord_info->rd = rd;
269  gnsrecord_info->name = name;
270  gnsrecord_info->rd_count = rd_count;
272  .cleaner = &clean_gnsrecordobject,
273  .cls = NULL,
274  .field = NULL,
275  .ptr = (struct GnsRecordInfo *)
276  gnsrecord_info,
277  .ptr_size = 0,
278  .size_ptr = NULL };
279  return ret;
280 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#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)
const char * name
Entry in parser specification for GNUNET_JSON_parse().
struct GNUNET_GNSRECORD_Data ** rd
unsigned int * rd_count

Referenced by namestore_add_or_update().

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 291 of file json_gnsrecord.c.

294 {
295  struct GNUNET_TIME_Absolute abs_exp;
296  struct GNUNET_TIME_Relative rel_exp;
297  const char *expiration_time_str;
298  const char *record_type_str;
299  char *value_str;
300  json_t *data;
301  json_t *record;
302  json_t *records;
303 
304  data = json_object ();
305  if (NULL == data)
306  {
307  GNUNET_break (0);
308  return NULL;
309  }
310  if (0 !=
311  json_object_set_new (data,
312  "record_name",
313  json_string (rname)))
314  {
315  GNUNET_break (0);
316  json_decref (data);
317  return NULL;
318  }
319  records = json_array ();
320  if (NULL == records)
321  {
322  GNUNET_break (0);
323  json_decref (data);
324  return NULL;
325  }
326  for (int i = 0; i < rd_count; i++)
327  {
328  value_str = GNUNET_GNSRECORD_value_to_string (rd[i].record_type,
329  rd[i].data,
330  rd[i].data_size);
331  if (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION & rd[i].flags)
332  {
333  rel_exp.rel_value_us = rd[i].expiration_time;
334  expiration_time_str = GNUNET_STRINGS_relative_time_to_string (rel_exp,
335  GNUNET_NO);
336  }
337  else
338  {
339  abs_exp.abs_value_us = rd[i].expiration_time;
340  expiration_time_str = GNUNET_STRINGS_absolute_time_to_string (abs_exp);
341  }
342  record_type_str = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type);
344  "Packing %s %s %s %d\n",
345  value_str, record_type_str, expiration_time_str, rd[i].flags);
346  record = json_pack ("{s:s,s:s,s:s,s:b,s:b,s:b,s:b}",
347  "value",
348  value_str,
349  "record_type",
350  record_type_str,
351  "expiration_time",
352  expiration_time_str,
353  "private",
354  rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE,
355  "relative_expiration",
357  "supplemental",
358  rd[i].flags & GNUNET_GNSRECORD_RF_SUPPLEMENTAL,
359  "shadow",
360  rd[i].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD);
361  GNUNET_free (value_str);
362  if (NULL == record)
363  {
364  GNUNET_break (0);
365  json_decref (records);
366  json_decref (data);
367  return NULL;
368  }
369  if (0 !=
370  json_array_append_new (records,
371  record))
372  {
373  GNUNET_break (0);
374  json_decref (records);
375  json_decref (data);
376  return NULL;
377  }
378  }
379  if (0 !=
380  json_object_set_new (data,
381  "data",
382  records))
383  {
384  GNUNET_break (0);
385  json_decref (data);
386  return NULL;
387  }
388  return data;
389 }
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
uint32_t data
The data value.
static unsigned int records
Number of records we found.
#define GNUNET_log(kind,...)
@ GNUNET_NO
Definition: gnunet_common.h:94
const char * GNUNET_GNSRECORD_number_to_typename(uint32_t type)
Convert a type number to the corresponding type string (e.g.
Definition: gnsrecord.c:244
char * GNUNET_GNSRECORD_value_to_string(uint32_t type, const void *data, size_t data_size)
Convert the 'value' of a record to a string.
Definition: gnsrecord.c:156
#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.
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:617
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:570
uint64_t expiration_time
Expiration time for the DNS record.
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.

References GNUNET_TIME_Absolute::abs_value_us, data, data_size, GNUNET_GNSRECORD_Data::expiration_time, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_GNSRECORD_number_to_typename(), GNUNET_GNSRECORD_RF_PRIVATE, GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION, GNUNET_GNSRECORD_RF_SHADOW_RECORD, GNUNET_GNSRECORD_RF_SUPPLEMENTAL, GNUNET_GNSRECORD_value_to_string(), GNUNET_log, GNUNET_NO, GNUNET_STRINGS_absolute_time_to_string(), GNUNET_STRINGS_relative_time_to_string(), record(), records, and GNUNET_TIME_Relative::rel_value_us.

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

159 {
160  struct Plugin *plugin;
161  char *ret;
162 
163  init ();
164  for (unsigned int i = 0; i < num_plugins; i++)
165  {
166  plugin = gns_plugins[i];
167  if (NULL != (ret = plugin->api->value_to_string (plugin->api->cls,
168  type,
169  data,
170  data_size)))
171  return ret;
172  }
173  return NULL;
174 }
static unsigned int num_plugins
Size of the 'plugins' array.
Definition: gnsrecord.c:63
static struct Plugin ** gns_plugins
Array of our plugins.
Definition: gnsrecord.c:58
static void init()
Loads all plugins (lazy initialization).
Definition: gnsrecord.c:100
struct Plugin * plugin
The process handle to the testbed service.
void * cls
Closure for all of the callbacks.
Handle for a plugin.
Definition: block.c:38
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:47
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model

References Plugin::api, GNUNET_BLOCK_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

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

192 {
193  struct Plugin *plugin;
194 
195  init ();
196  for (unsigned int i = 0; i < num_plugins; i++)
197  {
198  plugin = gns_plugins[i];
199  if (GNUNET_OK == plugin->api->string_to_value (plugin->api->cls,
200  type,
201  s,
202  data,
203  data_size))
204  return GNUNET_OK;
205  }
206  return GNUNET_SYSERR;
207 }
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_SYSERR
Definition: gnunet_common.h:93

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

Referenced by gns_string_to_value(), multirecord_option(), parse_record(), 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

Convert a type name (e.g.

Parameters
dns_typenamename to convert
Returns
corresponding number, UINT32_MAX on error

Definition at line 217 of file gnsrecord.c.

218 {
219  struct Plugin *plugin;
220  uint32_t ret;
221 
222  if (0 == strcasecmp (dns_typename,
223  "ANY"))
225  init ();
226  for (unsigned int i = 0; i < num_plugins; i++)
227  {
228  plugin = gns_plugins[i];
229  if (UINT32_MAX != (ret = plugin->api->typename_to_number (plugin->api->cls,
230  dns_typename)))
231  return ret;
232  }
233  return UINT32_MAX;
234 }
#define GNUNET_GNSRECORD_TYPE_ANY
Record type indicating any record/'*'.

References Plugin::api, GNUNET_BLOCK_PluginFunctions::cls, gns_plugins, GNUNET_GNSRECORD_TYPE_ANY, init(), num_plugins, plugin, and ret.

Referenced by create_did_store(), del_monitor(), display_record(), get_gns_cont(), multirecord_option(), namestore_get(), parse_record(), 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 244 of file gnsrecord.c.

245 {
246  struct Plugin *plugin;
247  const char *ret;
248 
250  return "ANY";
251  init ();
252  for (unsigned int i = 0; i < num_plugins; i++)
253  {
254  plugin = gns_plugins[i];
255  if (NULL != (ret = plugin->api->number_to_typename (plugin->api->cls,
256  type)))
257  return ret;
258  }
259  return NULL;
260 }

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

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
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 89 of file gnsrecord_serialization.c.

91 {
92  size_t ret;
93 
94  if (0 == rd_count)
95  return 0;
96 
97  ret = sizeof(struct NetworkRecord) * rd_count;
98  for (unsigned int i = 0; i < rd_count; i++)
99  {
100  if ((ret + rd[i].data_size) < ret)
101  {
102  GNUNET_break (0);
103  return -1;
104  }
105  ret += rd[i].data_size;
106 #if DEBUG_GNSRECORDS
107  {
108  char *str;
109 
111  rd[i].data,
112  rd[i].data_size);
113  if (NULL == str)
114  {
115  GNUNET_break_op (0);
116  return -1;
117  }
118  GNUNET_free (str);
119  }
120 #endif
121  }
122  if (ret > SSIZE_MAX)
123  {
124  GNUNET_break (0);
125  return -1;
126  }
127  // Do not pad PKEY
130  return ret;ret--;
136  ret |= ret >> 1;
137  ret |= ret >> 2;
138  ret |= ret >> 4;
139  ret |= ret >> 8;
140  ret |= ret >> 16;
141  ret++;
142  return (ssize_t) ret;
143 }
#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
Record type for EDKEY zone delegations.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
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(), NetworkRecord::record_type, GNUNET_GNSRECORD_Data::record_type, and ret.

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(), 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
Parameters
rd_countnumber of records in the rd array
rdarray of GNUNET_GNSRECORD_Data with rd_count elements
dest_sizesize of the destination array
destwhere to write the result
Returns
the size of serialized records, -1 if records do not fit

Definition at line 156 of file gnsrecord_serialization.c.

160 {
161  struct NetworkRecord rec;
162  size_t off;
163 
164  off = 0;
165  for (unsigned int i = 0; i < rd_count; i++)
166  {
168  "Serializing record %u with flags %d and expiration time %llu\n",
169  i,
170  rd[i].flags,
171  (unsigned long long) rd[i].expiration_time);
172  rec.expiration_time = GNUNET_htonll (rd[i].expiration_time);
173  rec.data_size = htons ((uint16_t) rd[i].data_size);
174  rec.record_type = htonl (rd[i].record_type);
175  rec.flags = htons (rd[i].flags);
176  if ((off + sizeof(rec) > dest_size) ||
177  (off + sizeof(rec) < off))
178  {
179  GNUNET_break (0);
180  return -1;
181  }
182  GNUNET_memcpy (&dest[off],
183  &rec,
184  sizeof(rec));
185  off += sizeof(rec);
186  if ((off + rd[i].data_size > dest_size) ||
187  (off + rd[i].data_size < off))
188  {
189  GNUNET_break (0);
190  return -1;
191  }
192  GNUNET_memcpy (&dest[off],
193  rd[i].data,
194  rd[i].data_size);
195  off += rd[i].data_size;
196 #if DEBUG_GNSRECORDS
197  {
198  char *str;
199 
201  rd[i].data,
202  rd[i].data_size);
203  if (NULL == str)
204  {
205  GNUNET_break_op (0);
206  return -1;
207  }
208  GNUNET_free (str);
209  }
210 #endif
211  }
212  memset (&dest[off],
213  0,
214  dest_size - off);
215  return dest_size;
216 }
#define LOG(kind,...)
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:36
#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, NetworkRecord::data_size, GNUNET_GNSRECORD_Data::data_size, 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, and NetworkRecord::record_type.

Referenced by 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(), 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 219 of file gnsrecord_serialization.c.

221 {
222  struct NetworkRecord rec;
223  struct NetworkRecord rec_zero;
224  size_t off;
225  unsigned int rd_count = 0;
226 
227  memset (&rec_zero, 0, sizeof (rec_zero));
228 
229  off = 0;
230  for (off = 0; (off + sizeof(rec) <= len) && (off + sizeof(rec) >= off);)
231  {
232  /*
233  * If we have found a byte string of zeroes, we have reached
234  * the padding
235  */
236  if (0 == GNUNET_memcmp (&rec, &rec_zero))
237  break;
238  GNUNET_memcpy (&rec,
239  &src[off],
240  sizeof(rec));
241  off += sizeof(rec);
242  if ((off + ntohs ((uint16_t) rec.data_size) > len) ||
243  (off + ntohs ((uint16_t) rec.data_size) < off))
244  {
245  GNUNET_break_op (0);
246  return 0;
247  }
248  off += ntohs ((uint16_t) rec.data_size);
249  rd_count++;
250  }
251  return rd_count;
252 }
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
#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 len.

◆ 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 264 of file gnsrecord_serialization.c.

268 {
269  struct NetworkRecord rec;
270  size_t off;
271 
272  off = 0;
273  for (unsigned int i = 0; i < rd_count; i++)
274  {
275  if ((off + sizeof(rec) > len) ||
276  (off + sizeof(rec) < off))
277  {
278  GNUNET_break_op (0);
279  return GNUNET_SYSERR;
280  }
281  GNUNET_memcpy (&rec,
282  &src[off],
283  sizeof(rec));
284  dest[i].expiration_time = GNUNET_ntohll (rec.expiration_time);
285  dest[i].data_size = ntohs ((uint16_t) rec.data_size);
286  dest[i].record_type = ntohl (rec.record_type);
287  dest[i].flags = ntohs (rec.flags);
288  off += sizeof(rec);
289  if ((off + dest[i].data_size > len) ||
290  (off + dest[i].data_size < off))
291  {
292  GNUNET_break_op (0);
293  return GNUNET_SYSERR;
294  }
295  dest[i].data = &src[off];
296  off += dest[i].data_size;
297 #if GNUNET_EXTRA_LOGGING
298  {
299  char *str;
300 
302  dest[i].data,
303  dest[i].data_size);
304  if (NULL == str)
305  {
306  GNUNET_break_op (0);
307  return GNUNET_SYSERR;
308  }
309  GNUNET_free (str);
310  }
311 #endif
313  "Deserialized record %u with flags %d and expiration time %llu\n",
314  i,
315  dest[i].flags,
316  (unsigned long long) dest[i].expiration_time);
317  }
318  return GNUNET_OK;
319 }
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:53
const void * data
Binary value stored in the DNS record.
enum GNUNET_GNSRECORD_Flags flags
Flags for the record.

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

Referenced by check_rd(), check_result(), continue_store_activity(), database_setup(), get_records_and_call_iterator(), handle_lookup_result(), handle_record_result(), handle_record_store(), handle_result(), handle_zone_to_name_response(), parse_result_call_iterator(), process_tickets(), 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 216 of file gnsrecord_misc.c.

217 {
218  struct GNUNET_TIME_Absolute at;
219 
221  return GNUNET_NO;
222  at.abs_value_us = rd->expiration_time;
223  return (0 == GNUNET_TIME_absolute_get_remaining (at).rel_value_us) ?
225 }
@ GNUNET_YES
Definition: gnunet_common.h:97
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:404

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(), and GNUNET_YES.

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

42 {
43  /*FIXME: We may want to follow RFC5890/RFC5891 */
44  return GNUNET_STRINGS_utf8_normalize (src);
45 }
char * GNUNET_STRINGS_utf8_normalize(const char *input)
Normalize the utf-8 input string to NFC.
Definition: strings.c:430

Referenced by GNUNET_GNSRECORD_query_from_private_key(), handle_record_lookup(), handle_record_store(), run_edkey(), and run_pkey().

Here is the caller graph for this function:

◆ GNUNET_GNSRECORD_z2s()

const char* GNUNET_GNSRECORD_z2s ( const struct GNUNET_IDENTITY_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.

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
zthe zone key
Returns
string form; will be overwritten by next call to GNUNET_GNSRECORD_z2s

Definition at line 72 of file gnsrecord_misc.c.

73 {
74  static char buf[sizeof(struct GNUNET_IDENTITY_PublicKey) * 8];
75  char *end;
76 
77  end = GNUNET_STRINGS_data_to_string ((const unsigned char *) z,
78  sizeof(struct
80  buf, sizeof(buf));
81  if (NULL == end)
82  {
83  GNUNET_break (0);
84  return NULL;
85  }
86  *end = '\0';
87  return buf;
88 }
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
static char buf[2048]
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
An identity key as per LSD0001.

References buf, 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(), recursive_gns_resolution_revocation(), and refresh_block().

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_IDENTITY_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 eliptic 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 eliptic curve
Returns
string "X.zkey" where X is the public key in an encoding suitable for DNS labels.

Definition at line 239 of file gnsrecord_misc.c.

240 {
241  static char ret[128];
242  char *pkeys;
243 
246  sizeof(ret),
247  "%s",
248  pkeys);
249  GNUNET_free (pkeys);
250  return ret;
251 }
static char * pkey
Public key of the zone to look in, in ASCII.
char * GNUNET_IDENTITY_public_key_to_string(const struct GNUNET_IDENTITY_PublicKey *key)
Creates a (Base32) string representation of the public key.
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_free, GNUNET_IDENTITY_public_key_to_string(), 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_IDENTITY_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 eliptic 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 eliptic curve
Returns
GNUNET_SYSERR if zkey has the wrong syntax

Definition at line 264 of file gnsrecord_misc.c.

266 {
267  if (GNUNET_OK !=
269  pkey))
270  return GNUNET_SYSERR;
271  return GNUNET_OK;
272 }
enum GNUNET_GenericReturnValue GNUNET_IDENTITY_public_key_from_string(const char *str, struct GNUNET_IDENTITY_PublicKey *key)
Parses a (Base32) string representation of the public key.

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

Here is the caller graph for this function:

◆ GNUNET_GNSRECORD_query_from_private_key()

void GNUNET_GNSRECORD_query_from_private_key ( const struct GNUNET_IDENTITY_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 922 of file gnsrecord_crypto.c.

926 {
927  char *norm_label;
929 
930  norm_label = GNUNET_GNSRECORD_string_normalize (label);
931  switch (ntohl (zone->type))
932  {
935 
937  &pub);
939  norm_label,
940  query);
941  break;
942  default:
943  GNUNET_assert (0);
944  }
945  GNUNET_free (norm_label);
946 }
static char * zone
Name of the zone being managed.
static struct GNUNET_CRYPTO_EddsaPublicKey pub
Definition: gnunet-scrypt.c:46
char * GNUNET_GNSRECORD_string_normalize(const char *src)
Normalize a UTF-8 string to a GNS name.
void GNUNET_GNSRECORD_query_from_public_key(const struct GNUNET_IDENTITY_PublicKey *pub, const char *label, struct GNUNET_HashCode *query)
Calculate the DHT query for a given label in a given zone.
enum GNUNET_GenericReturnValue GNUNET_IDENTITY_key_get_public(const struct GNUNET_IDENTITY_PrivateKey *privkey, struct GNUNET_IDENTITY_PublicKey *key)
Retrieves the public key representation of a private key.
Definition: identity_api.c:175
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.

References GNUNET_assert, GNUNET_free, GNUNET_GNSRECORD_query_from_public_key(), GNUNET_GNSRECORD_string_normalize(), GNUNET_GNSRECORD_TYPE_EDKEY, GNUNET_GNSRECORD_TYPE_PKEY, GNUNET_IDENTITY_key_get_public(), pub, and zone.

Referenced by perform_dht_put().

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_IDENTITY_PublicKey pub,
const char *  label,
struct GNUNET_HashCode query 
)

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

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

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

962 {
963  char *norm_label;
964  struct GNUNET_IDENTITY_PublicKey pd;
965 
966  norm_label = GNUNET_GNSRECORD_string_normalize (label);
967 
968  switch (ntohl (pub->type))
969  {
971  pd.type = pub->type;
973  norm_label,
974  "gns",
975  &pd.ecdsa_key);
976  GNUNET_CRYPTO_hash (&pd.ecdsa_key,
977  sizeof (pd.ecdsa_key),
978  query);
979  break;
981  pd.type = pub->type;
983  norm_label,
984  "gns",
985  &(pd.eddsa_key));
986  GNUNET_CRYPTO_hash (&pd.eddsa_key,
987  sizeof (pd.eddsa_key),
988  query);
989  break;
990  default:
991  GNUNET_assert (0);
992  }
993  GNUNET_free (norm_label);
994 }
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

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 caller graph for this function:

◆ GNUNET_GNSRECORD_block_calculate_size()

ssize_t GNUNET_GNSRECORD_block_calculate_size ( const struct GNUNET_IDENTITY_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 430 of file gnsrecord_crypto.c.

434 {
436  ssize_t res = -1;
437 
439  &pkey);
440  switch (ntohl (key->type))
441  {
443  res = block_get_size_ecdsa (rd, rd_count);
444  break;
446  res = block_get_size_eddsa (rd, rd_count);
447  break;
448  default:
449  GNUNET_assert (0);
450  }
451  return res;
452 
453 }
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)
static int res
struct GNUNET_HashCode key
The key used in the DHT.

◆ GNUNET_GNSRECORD_block_create()

enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_block_create ( const struct GNUNET_IDENTITY_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 430 of file gnsrecord_crypto.c.

462 {
465  char *norm_label;
466 
468  &pkey);
469  norm_label = GNUNET_GNSRECORD_string_normalize (label);
470 
471  switch (ntohl (key->type))
472  {
474  res = block_create_ecdsa (&key->ecdsa_key,
475  &pkey.ecdsa_key,
476  expire,
477  norm_label,
478  rd,
479  rd_count,
480  result);
481  break;
483  res = block_create_eddsa (&key->eddsa_key,
484  &pkey.eddsa_key,
485  expire,
486  norm_label,
487  rd,
488  rd_count,
489  result);
490  break;
491  default:
492  GNUNET_assert (0);
493  }
494  GNUNET_free (norm_label);
495  return res;
496 }
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)
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)
Sign name and records.
static char * expire
DID Document expiration Date Attribut String.
Definition: gnunet-did.c:99
static int result
Global testing status.
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:92

Referenced by perform_dht_put(), refresh_block(), run_edkey(), and run_pkey().

Here is the caller graph for this function:

◆ GNUNET_GNSRECORD_block_create2()

enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_block_create2 ( const struct GNUNET_IDENTITY_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 430 of file gnsrecord_crypto.c.

523 {
524  const struct GNUNET_CRYPTO_EcdsaPrivateKey *key;
525  struct GNUNET_CRYPTO_EddsaPublicKey edpubkey;
527  char *norm_label;
528 
529  norm_label = GNUNET_GNSRECORD_string_normalize (label);
530 
531  if (GNUNET_IDENTITY_TYPE_ECDSA == ntohl (pkey->type))
532  {
533  key = &pkey->ecdsa_key;
534 #define CSIZE 64
535  static struct KeyCacheLine cache[CSIZE];
536  struct KeyCacheLine *line;
537 
538  line = &cache[(*(unsigned int *) key) % CSIZE];
539  if (0 != memcmp (&line->key,
540  key,
541  sizeof(*key)))
542  {
543  /* cache miss, recompute */
544  line->key = *key;
546  &line->pkey);
547  }
548 #undef CSIZE
550  &line->pkey,
551  expire,
552  norm_label,
553  rd,
554  rd_count,
555  result);
556  }
557  else if (GNUNET_IDENTITY_TYPE_EDDSA == ntohl (pkey->type))
558  {
560  &edpubkey);
561  res = block_create_eddsa (&pkey->eddsa_key,
562  &edpubkey,
563  expire,
564  norm_label,
565  rd,
566  rd_count,
567  result);
568  }
569  GNUNET_free (norm_label);
570  return res;
571 }
#define CSIZE
static char * line
Desired phone line (string to be converted to a hash).
static struct GNUNET_CONTAINER_MultiHashMap32 * cache
Hashmap to maintain cache.
void GNUNET_CRYPTO_eddsa_key_get_public(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:197
void GNUNET_CRYPTO_ecdsa_key_get_public(const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:186
@ GNUNET_IDENTITY_TYPE_ECDSA
The identity type.
@ GNUNET_IDENTITY_TYPE_EDDSA
EDDSA identity.
Private ECC key encoded for transmission.
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...
Line in cache mapping private keys to public keys.

Referenced by perform_dht_put(), and refresh_block().

Here is the caller graph for this function:

◆ GNUNET_GNSRECORD_block_verify()

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

583 {
584  struct GNRBlockPS *purp;
585  size_t payload_len = ntohl (block->size)
586  - sizeof (struct GNUNET_GNSRECORD_Block);
588  purp = GNUNET_malloc (sizeof (struct GNRBlockPS) + payload_len);
589  purp->purpose.size = htonl (sizeof (struct GNRBlockPS) + payload_len);
591  GNUNET_memcpy (&purp[1],
592  &block[1],
593  payload_len);
594  switch (ntohl (block->type))
595  {
600  &purp->purpose,
601  &block->ecdsa_block.signature,
602  &block->ecdsa_block.derived_key);
603  break;
608  &purp->purpose,
609  &block->eddsa_block.signature,
610  &block->eddsa_block.derived_key);
611  break;
612  default:
613  res = GNUNET_NO;
614  }
615  GNUNET_free (purp);
616  return res;
617 }
#define GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN
Signature of a gnunet naming system record block (GNUnet-GNSRECORD)
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:623
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:682
#define GNUNET_malloc(size)
Wrapper around malloc.
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.

Referenced by handle_lookup_block_response().

Here is the caller graph for this function:

◆ GNUNET_GNSRECORD_block_decrypt()

int GNUNET_GNSRECORD_block_decrypt ( const struct GNUNET_GNSRECORD_Block block,
const struct GNUNET_IDENTITY_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
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 430 of file gnsrecord_crypto.c.

889 {
891  char *norm_label;
892 
893  norm_label = GNUNET_GNSRECORD_string_normalize (label);
894  switch (ntohl (zone_key->type))
895  {
897  res = block_decrypt_ecdsa (block,
898  &zone_key->ecdsa_key, norm_label, proc,
899  proc_cls);
900  break;
902  res = block_decrypt_eddsa (block,
903  &zone_key->eddsa_key, norm_label, proc,
904  proc_cls);
905  break;
906  default:
907  res = GNUNET_SYSERR;
908  }
909  GNUNET_free (norm_label);
910  return res;
911 }
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)
static const struct GNUNET_IDENTITY_PrivateKey * zone_key
Private key of the zone.
uint32_t type
Type of public key.
struct GNUNET_CRYPTO_EcdsaPrivateKey ecdsa_key
An ECDSA identity key.
struct GNUNET_CRYPTO_EddsaPrivateKey eddsa_key
AN EdDSA identtiy key.

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

Here is the caller graph for this function:

◆ GNUNET_GNSRECORD_records_cmp()

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

103 {
105  "Comparing records\n");
106  if (a->record_type != b->record_type)
107  {
109  "Record type %u != %u\n", a->record_type, b->record_type);
110  return GNUNET_NO;
111  }
112  if ((a->expiration_time != b->expiration_time) &&
113  ((a->expiration_time != 0) && (b->expiration_time != 0)))
114  {
116  "Expiration time %llu != %llu\n",
117  (unsigned long long) a->expiration_time,
118  (unsigned long long) b->expiration_time);
119  return GNUNET_NO;
120  }
123  {
125  "Flags %u (%u) != %u (%u)\n", a->flags,
128  return GNUNET_NO;
129  }
130  if (a->data_size != b->data_size)
131  {
133  "Data size %lu != %lu\n",
134  a->data_size,
135  b->data_size);
136  return GNUNET_NO;
137  }
138  if (0 != memcmp (a->data, b->data, a->data_size))
139  {
141  "Data contents do not match\n");
142  return GNUNET_NO;
143  }
145  "Records are equal\n");
146  return GNUNET_YES;
147 }
#define LOG(kind,...)
#define GNUNET_GNSRECORD_RF_RCMP_FLAGS
When comparing flags for record equality for removal, which flags should must match (in addition to t...

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

155 {
157  struct GNUNET_TIME_Absolute at;
158  struct GNUNET_TIME_Relative rt;
159  struct GNUNET_TIME_Absolute at_shadow;
160  struct GNUNET_TIME_Relative rt_shadow;
161 
162  if (0 == rd_count)
165  for (unsigned int c = 0; c < rd_count; c++)
166  {
167  if (0 != (rd[c].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
168  {
169  rt.rel_value_us = rd[c].expiration_time;
171  }
172  else
173  {
174  at.abs_value_us = rd[c].expiration_time;
175  }
176 
177  for (unsigned int c2 = 0; c2 < rd_count; c2++)
178  {
179  /* Check for shadow record */
180  if ((c == c2) ||
181  (rd[c].record_type != rd[c2].record_type) ||
182  (0 == (rd[c2].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD)))
183  continue;
184  /* We have a shadow record */
185  if (0 != (rd[c2].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
186  {
187  rt_shadow.rel_value_us = rd[c2].expiration_time;
188  at_shadow = GNUNET_TIME_relative_to_absolute (rt_shadow);
189  }
190  else
191  {
192  at_shadow.abs_value_us = rd[c2].expiration_time;
193  }
194  at = GNUNET_TIME_absolute_max (at,
195  at_shadow);
196  }
198  expire);
199  }
202  "Determined expiration time for block with %u records to be %s\n",
203  rd_count,
205  return expire;
206 }
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:366
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:315
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:358
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
#define min(x, y)

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.

Referenced by refresh_block(), run_edkey(), and run_pkey().

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

339 {
340  return ntohl (block->size);
341 }

Referenced by GNUNET_NAMECACHE_block_cache(), handle_dht_response(), handle_lookup_block_it(), namecache_cache_block(), namecache_postgres_cache_block(), namecache_sqlite_cache_block(), perform_dht_put(), 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 338 of file gnsrecord_misc.c.

347 {
348 
349  switch (ntohl (block->type))
350  {
355  default:
356  GNUNET_break (0); /* Hopefully we never get here, but we might */
357  }
359 
360 }
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_zero_(void)
Return absolute time of 0ms.
Definition: time.c:141
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:736

References GNUNET_GNSRECORD_Block::size.

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

366 {
367  switch (ntohl (block->type))
368  {
371  sizeof (block->ecdsa_block.derived_key),
372  query);
373  return GNUNET_OK;
376  sizeof (block->eddsa_block.derived_key),
377  query);
378  return GNUNET_OK;
379  default:
380  return GNUNET_SYSERR;
381  }
382  return GNUNET_SYSERR;
383 
384 }

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

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

280 {
282  return GNUNET_SYSERR;
283  switch (type)
284  {
286  if (data_size > sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))
287  return GNUNET_SYSERR;
288  memcpy (&key->ecdsa_key, data, data_size);
289  break;
291  if (data_size > sizeof (struct GNUNET_CRYPTO_EddsaPublicKey))
292  return GNUNET_SYSERR;
293  memcpy (&key->eddsa_key, data, data_size);
294  break;
295  default:
296  return GNUNET_NO;
297  }
298  key->type = htonl (type);
299 
300  return GNUNET_YES;
301 }
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...

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 caller graph for this function:

◆ GNUNET_GNSRECORD_data_from_identity()

enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_data_from_identity ( const struct GNUNET_IDENTITY_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 264 of file gnsrecord_misc.c.

310 {
311  char *tmp;
312  *type = ntohl (key->type);
313  *data_size = GNUNET_IDENTITY_key_get_length (key) - sizeof (key->type);
314  if (0 == *data_size)
315  return GNUNET_SYSERR;
316  tmp = GNUNET_malloc (*data_size);
317  memcpy (tmp, ((char*) key) + sizeof (key->type), *data_size);
318  *data = tmp;
319  return GNUNET_OK;
320 }
ssize_t GNUNET_IDENTITY_key_get_length(const struct GNUNET_IDENTITY_PublicKey *key)
Get the compacted length of a GNUNET_IDENTITY_PublicKey.
Definition: identity_api.c:991

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

Referenced by gns_string_to_value(), and register_do_cb().

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

325 {
326  switch (type)
327  {
330  return GNUNET_YES;
331  default:
332  return GNUNET_NO;
333  }
334 }

Referenced by 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 244 of file gnsrecord.c.

265 {
266  struct Plugin *plugin;
267 
269  return GNUNET_NO;
270  init ();
271  for (unsigned int i = 0; i < num_plugins; i++)
272  {
273  plugin = gns_plugins[i];
274  if (NULL == plugin->api->is_critical)
275  continue;
276  if (GNUNET_NO == plugin->api->is_critical (plugin->api->cls, type))
277  continue;
278  return GNUNET_YES;
279  }
280  return GNUNET_NO;
281 }

References Plugin::api, GNUNET_BLOCK_PluginFunctions::cls, gns_plugins, GNUNET_GNSRECORD_TYPE_ANY, init(), num_plugins, plugin, ret, and type.

Referenced by 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,
int  include_private,
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_public_countnumber of records written to rd_public
min_expirythe minimum expiration of this set
include_privateGNUNET_YES if private records should be included.
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 338 of file gnsrecord_misc.c.

423 {
424  struct GNUNET_TIME_Absolute now;
425  struct GNUNET_TIME_Absolute minimum_expiration;
426  int have_zone_delegation = GNUNET_NO;
427  int have_gns2dns = GNUNET_NO;
428  int have_other = GNUNET_NO;
429  int have_redirect = GNUNET_NO;
430  int have_empty_label = (0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT, label));
431  unsigned int rd_count_tmp;
432 
433  minimum_expiration = GNUNET_TIME_UNIT_ZERO_ABS;
434  now = GNUNET_TIME_absolute_get ();
435  rd_count_tmp = 0;
436  for (unsigned int i = 0; i < rd_count; i++)
437  {
438  /* Ignore the tombstone. For maintenance only. Remember expiration time. */
439  if (GNUNET_GNSRECORD_TYPE_TOMBSTONE == rd[i].record_type)
440  {
441  minimum_expiration.abs_value_us = rd[i].expiration_time;
442  continue;
443  }
444  /* No NICK records unless empty label */
445  if (have_empty_label &&
446  (GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type))
447  continue;
448 
458  if (GNUNET_YES == GNUNET_GNSRECORD_is_zonekey_type (rd[i].record_type))
459  {
460  /* No delegation records under empty label*/
461  if (have_empty_label)
462  {
463  *emsg = GNUNET_strdup (_ (
464  "Zone delegation record not allowed in apex."));
465  return GNUNET_SYSERR;
466  }
467  if ((GNUNET_YES == have_other) ||
468  (GNUNET_YES == have_redirect) ||
469  (GNUNET_YES == have_gns2dns))
470  {
471  *emsg = GNUNET_strdup (_ (
472  "Zone delegation record set contains mutually exclusive records."));
473  return GNUNET_SYSERR;
474  }
475  have_zone_delegation = GNUNET_YES;
476  }
477  else if (GNUNET_GNSRECORD_TYPE_REDIRECT == rd[i].record_type)
478  {
479  if (GNUNET_YES == have_redirect)
480  {
481  *emsg = GNUNET_strdup (_ (
482  "Multiple REDIRECT records."));
483  return GNUNET_SYSERR;
484 
485  }
486  if ((GNUNET_YES == have_other) ||
487  (GNUNET_YES == have_zone_delegation) ||
488  (GNUNET_YES == have_gns2dns))
489  {
490  *emsg = GNUNET_strdup (_ (
491  "Redirection record set conains mutually exclusive records."));
492  return GNUNET_SYSERR;
493  }
494  /* No redirection records under empty label*/
495  if (have_empty_label)
496  {
497  *emsg = GNUNET_strdup (_ (
498  "Redirection records not allowed in apex."));
499  return GNUNET_SYSERR;
500  }
501  have_redirect = GNUNET_YES;
502  }
503  else if (GNUNET_GNSRECORD_TYPE_GNS2DNS == rd[i].record_type)
504  {
505  /* No gns2dns records under empty label*/
506  if (have_empty_label)
507  {
508  *emsg = GNUNET_strdup (_ (
509  "Redirection records not allowed in apex.."));
510  return GNUNET_SYSERR;
511  }
512  if ((GNUNET_YES == have_other) ||
513  (GNUNET_YES == have_redirect) ||
514  (GNUNET_YES == have_zone_delegation))
515  {
516  *emsg = GNUNET_strdup (_ (
517  "Redirection record set conains mutually exclusive records."));
518  return GNUNET_SYSERR;
519  }
520  have_gns2dns = GNUNET_YES;
521  }
522  else
523  {
524  /* Some other record.
525  * Not allowed for zone delegations or redirections */
526  if ((GNUNET_YES == have_zone_delegation) ||
527  (GNUNET_YES == have_redirect) ||
528  (GNUNET_YES == have_gns2dns))
529  {
530  *emsg = GNUNET_strdup (_ (
531  "Mutually exclusive records."));
532  return GNUNET_SYSERR;
533  }
534  have_other = GNUNET_YES;
535  }
536 
537  /* Ignore private records for public record set */
538 
539  if ((GNUNET_NO == include_private) &&
540  (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE)))
541  continue;
542  /* Skip expired records */
543  if ((0 == (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) &&
544  (rd[i].expiration_time < now.abs_value_us))
545  continue; /* record already expired, skip it */
546  rd_public[rd_count_tmp] = rd[i];
547  /* Make sure critical record types are marked as such */
548  if (GNUNET_YES == GNUNET_GNSRECORD_is_critical (rd[i].record_type))
549  rd_public[rd_count_tmp].flags |= GNUNET_GNSRECORD_RF_CRITICAL;
550  rd_count_tmp++;
551  }
552 
553  *expiry = GNUNET_GNSRECORD_record_get_expiration_time (rd_count_tmp,
554  rd_public,
555  minimum_expiration);
556  *rd_count_public = rd_count_tmp;
557  return GNUNET_OK;
558 }
#define GNUNET_GNSRECORD_TYPE_NICK
GNS nick names.
#define GNUNET_GNSRECORD_TYPE_TOMBSTONE
Record type to indicate a previously delete record (PRIVATE only)
#define GNUNET_GNSRECORD_TYPE_GNS2DNS
Delegation to DNS.
#define GNUNET_GNSRECORD_TYPE_REDIRECT
Resolver redirects.
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:264
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:110
#define _(String)
GNU gettext support macro.
Definition: platform.h:177

Referenced by handle_record_store().

Here is the caller graph for this function:

◆ GNUNET_GNSRECORD_convert_records_for_export()

enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_convert_records_for_export ( 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 expiry,
char **  emsg 
)

Convert namestore records from the internal format to that suitable for publication (removes private records).

Parameters
labelthe label under which this set is (supposed to be) published.
rdinput records
rd_countsize of the rd and rd_public arrays
rd_publicwhere to write the converted records
rd_public_countnumber of records written to rd_public
expirythe expiration of the block
emsgthe error message if something went wrong
Returns
GNUNET_OK if set is consistent and can be exported

Definition at line 338 of file gnsrecord_misc.c.

570 {
572  rd,
573  rd_count,
574  rd_public,
575  rd_count_public,
576  expiry,
577  GNUNET_NO,
578  emsg);
579 
580 }
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 *expiry, int include_private, char **emsg)
Normalize namestore records: Check for consistency and expirations.

Referenced by get_block_exp_existing(), handle_monitor_event(), and put_gns_record().

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

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

References GNUNET_STRINGS_utf8_normalize().

Referenced by handle_record_store().

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