GNUnet  0.18.1
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_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...
 
#define GNUNET_GNSRECORD_RF_RCMP_FLAGS   (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)
 Include the record types generated from GANA. 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_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_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_sign (const struct GNUNET_IDENTITY_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_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_create_unsigned (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)
 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_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, 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...
 

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 53 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 58 of file gnunet_gnsrecord_lib.h.

◆ GNUNET_GNSRECORD_TYPE_ANY

#define GNUNET_GNSRECORD_TYPE_ANY   0

Record type indicating any record/'*'.

Definition at line 64 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.

Include the record flags 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 87 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 310 of file gnunet_gnsrecord_lib.h.

Enumeration Type Documentation

◆ 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 92 of file gnunet_gnsrecord_lib.h.

93 {
100 
105 
110 
115  // GNUNET_NAMESTORE_FILTER_OMIT_PUBLIC = 4,
116 };
@ 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 256 of file json_gnsrecord.c.

274 {
275  struct GnsRecordInfo *gnsrecord_info = GNUNET_new (struct GnsRecordInfo);
276 
277  gnsrecord_info->rd = rd;
278  gnsrecord_info->name = name;
279  gnsrecord_info->rd_count = rd_count;
281  .cleaner = &clean_gnsrecordobject,
282  .cls = NULL,
283  .field = NULL,
284  .ptr = (struct GnsRecordInfo *)
285  gnsrecord_info,
286  .ptr_size = 0,
287  .size_ptr = NULL };
288  return ret;
289 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
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)
const char * name
Entry in parser specification for GNUNET_JSON_parse().
struct GNUNET_GNSRECORD_Data ** rd
unsigned int * rd_count

Referenced by bulk_tx_start(), and 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 300 of file json_gnsrecord.c.

303 {
304  const char *record_type_str;
305  char *value_str;
306  json_t *data;
307  json_t *record;
308  json_t *records;
309 
310  data = json_object ();
311  if (NULL == data)
312  {
313  GNUNET_break (0);
314  return NULL;
315  }
316  if (0 !=
317  json_object_set_new (data,
318  "record_name",
319  json_string (rname)))
320  {
321  GNUNET_break (0);
322  json_decref (data);
323  return NULL;
324  }
325  records = json_array ();
326  if (NULL == records)
327  {
328  GNUNET_break (0);
329  json_decref (data);
330  return NULL;
331  }
332  for (int i = 0; i < rd_count; i++)
333  {
334  value_str = GNUNET_GNSRECORD_value_to_string (rd[i].record_type,
335  rd[i].data,
336  rd[i].data_size);
337  record_type_str = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type);
339  "Packing %s %s %lu %d\n",
340  value_str, record_type_str, rd[i].expiration_time, rd[i].flags);
341  record = json_pack ("{s:s,s:s,s:I,s:b,s:b,s:b,s:b}",
343  value_str,
345  record_type_str,
348  rd[i].expiration_time,
350  rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE,
356  rd[i].flags & GNUNET_GNSRECORD_RF_SHADOW);
357  GNUNET_free (value_str);
358  if (NULL == record)
359  {
360  GNUNET_break (0);
361  json_decref (records);
362  json_decref (data);
363  return NULL;
364  }
365  if (0 !=
366  json_array_append_new (records,
367  record))
368  {
369  GNUNET_break (0);
370  json_decref (records);
371  json_decref (data);
372  return NULL;
373  }
374  }
375  if (0 !=
376  json_object_set_new (data,
377  "data",
378  records))
379  {
380  GNUNET_break (0);
381  json_decref (data);
382  return NULL;
383  }
384  return data;
385 }
@ GNUNET_GNSRECORD_RF_SUPPLEMENTAL
This is a supplemental record.
@ GNUNET_GNSRECORD_RF_PRIVATE
This is a private record of this peer and it should thus not be published.
@ 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_RELATIVE_EXPIRATION
This expiration time of the record is a relative time (not an absolute time).
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.
const char * GNUNET_GNSRECORD_number_to_typename(uint32_t type)
Convert a type number to the corresponding type string (e.g.
Definition: gnsrecord.c:228
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_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_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_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_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 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

Definition at line 178 of file gnsrecord.c.

182 {
183  struct Plugin *plugin;
184 
185  init ();
186  for (unsigned int i = 0; i < num_plugins; i++)
187  {
188  plugin = gns_plugins[i];
189  if (GNUNET_OK == plugin->api->string_to_value (plugin->api->cls,
190  type,
191  s,
192  data,
193  data_size))
194  return GNUNET_OK;
195  }
196  return GNUNET_SYSERR;
197 }
@ GNUNET_OK
Definition: gnunet_common.h:99
@ GNUNET_SYSERR
Definition: gnunet_common.h:97

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(), 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 201 of file gnsrecord.c.

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

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

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

83 {
84  size_t ret;
85 
86  if (0 == rd_count)
87  return 0;
88 
89  ret = sizeof(struct NetworkRecord) * rd_count;
90  for (unsigned int i = 0; i < rd_count; i++)
91  {
92  if ((ret + rd[i].data_size) < ret)
93  {
94  GNUNET_break (0);
95  return -1;
96  }
97  ret += rd[i].data_size;
98 #if DEBUG_GNSRECORDS
99  {
100  char *str;
101 
103  rd[i].data,
104  rd[i].data_size);
105  if (NULL == str)
106  {
107  GNUNET_break_op (0);
108  return -1;
109  }
110  GNUNET_free (str);
111  }
112 #endif
113  }
114  if (ret > SSIZE_MAX)
115  {
116  GNUNET_break (0);
117  return -1;
118  }
119  // Do not pad PKEY
122  return ret;ret--;
128  ret |= ret >> 1;
129  ret |= ret >> 2;
130  ret |= ret >> 4;
131  ret |= ret >> 8;
132  ret |= ret >> 16;
133  ret++;
134  return (ssize_t) ret;
135 }
#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(), rd, rd_count, NetworkRecord::record_type, GNUNET_GNSRECORD_Data::record_type, and ret.

Referenced by block_create_ecdsa(), block_create_eddsa(), check_zone_to_name(), consistency_iter(), GNUNET_NAMESTORE_records_store2(), lookup_it(), 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 139 of file gnsrecord_serialization.c.

143 {
144  struct NetworkRecord rec;
145  size_t off;
146 
147  off = 0;
148  for (unsigned int i = 0; i < rd_count; i++)
149  {
151  "Serializing record %u with flags %d and expiration time %llu\n",
152  i,
153  rd[i].flags,
154  (unsigned long long) rd[i].expiration_time);
155  rec.expiration_time = GNUNET_htonll (rd[i].expiration_time);
156  rec.data_size = htons ((uint16_t) rd[i].data_size);
157  rec.record_type = htonl (rd[i].record_type);
158  rec.flags = htons (rd[i].flags);
159  if ((off + sizeof(rec) > dest_size) ||
160  (off + sizeof(rec) < off))
161  {
162  GNUNET_break (0);
163  return -1;
164  }
165  GNUNET_memcpy (&dest[off],
166  &rec,
167  sizeof(rec));
168  off += sizeof(rec);
169  if ((off + rd[i].data_size > dest_size) ||
170  (off + rd[i].data_size < off))
171  {
172  GNUNET_break (0);
173  return -1;
174  }
175  GNUNET_memcpy (&dest[off],
176  rd[i].data,
177  rd[i].data_size);
178  off += rd[i].data_size;
179 #if DEBUG_GNSRECORDS
180  {
181  char *str;
182 
184  rd[i].data,
185  rd[i].data_size);
186  if (NULL == str)
187  {
188  GNUNET_break_op (0);
189  return -1;
190  }
191  GNUNET_free (str);
192  }
193 #endif
194  }
195  memset (&dest[off],
196  0,
197  dest_size - off);
198  return dest_size;
199 }
#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, 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 check_zone_to_name(), consistency_iter(), GNUNET_NAMESTORE_records_store2(), lookup_it(), 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 202 of file gnsrecord_serialization.c.

204 {
205  struct NetworkRecord rec;
206  struct NetworkRecord rec_zero;
207  size_t off;
208  unsigned int rd_count = 0;
209 
210  memset (&rec_zero, 0, sizeof (rec_zero));
211 
212  off = 0;
213  for (off = 0; (off + sizeof(rec) <= len) && (off + sizeof(rec) >= off);)
214  {
215  GNUNET_memcpy (&rec,
216  &src[off],
217  sizeof(rec));
218  /*
219  * If we have found a byte string of zeroes, we have reached
220  * the padding
221  */
222  if (0 == GNUNET_memcmp (&rec, &rec_zero))
223  break;
224  off += sizeof(rec);
225  if ((off + ntohs ((uint16_t) rec.data_size) > len) ||
226  (off + ntohs ((uint16_t) rec.data_size) < off))
227  {
228  GNUNET_break_op (0);
229  return 0;
230  }
231  off += ntohs ((uint16_t) rec.data_size);
232  rd_count++;
233  }
234  return rd_count;
235 }
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, len, and rd_count.

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

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

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, len, LOG, rd_count, and NetworkRecord::record_type.

Referenced by check_rd(), check_result(), continue_store_activity(), database_setup(), handle_lookup_result(), handle_record_result(), handle_result(), handle_zone_to_name_response(), lookup_records(), 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 210 of file gnsrecord_misc.c.

211 {
212  struct GNUNET_TIME_Absolute at;
213 
215  return GNUNET_NO;
216  at.abs_value_us = rd->expiration_time;
217  return (0 == GNUNET_TIME_absolute_get_remaining (at).rel_value_us) ?
219 }
@ GNUNET_YES
@ GNUNET_NO
Definition: gnunet_common.h:98
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
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 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 continue_store_activity(), GNUNET_GNSRECORD_query_from_private_key(), handle_record_lookup(), 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.

Definition at line 66 of file gnsrecord_misc.c.

67 {
68  static char buf[sizeof(struct GNUNET_IDENTITY_PublicKey) * 8];
69  char *end;
70 
71  end = GNUNET_STRINGS_data_to_string ((const unsigned char *) z,
72  sizeof(struct
74  buf, sizeof(buf));
75  if (NULL == end)
76  {
77  GNUNET_break (0);
78  return NULL;
79  }
80  *end = '\0';
81  return buf;
82 }
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(), 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_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 233 of file gnsrecord_misc.c.

234 {
235  static char ret[128];
236  char *pkeys;
237 
240  sizeof(ret),
241  "%s",
242  pkeys);
243  GNUNET_free (pkeys);
244  return ret;
245 }
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 258 of file gnsrecord_misc.c.

260 {
261  if (GNUNET_OK !=
263  pkey))
264  return GNUNET_SYSERR;
265  return GNUNET_OK;
266 }
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 1020 of file gnsrecord_crypto.c.

1024 {
1025  char *norm_label;
1027 
1028  norm_label = GNUNET_GNSRECORD_string_normalize (label);
1029  switch (ntohl (zone->type))
1030  {
1033 
1035  &pub);
1037  norm_label,
1038  query);
1039  break;
1040  default:
1041  GNUNET_assert (0);
1042  }
1043  GNUNET_free (norm_label);
1044 }
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:179
#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 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_IDENTITY_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 1048 of file gnsrecord_crypto.c.

1052 {
1053  char *norm_label;
1054  struct GNUNET_IDENTITY_PublicKey pd;
1055 
1056  norm_label = GNUNET_GNSRECORD_string_normalize (label);
1057 
1058  switch (ntohl (pub->type))
1059  {
1061  pd.type = pub->type;
1063  norm_label,
1064  "gns",
1065  &pd.ecdsa_key);
1066  GNUNET_CRYPTO_hash (&pd.ecdsa_key,
1067  sizeof (pd.ecdsa_key),
1068  query);
1069  break;
1071  pd.type = pub->type;
1073  norm_label,
1074  "gns",
1075  &(pd.eddsa_key));
1076  GNUNET_CRYPTO_hash (&pd.eddsa_key,
1077  sizeof (pd.eddsa_key),
1078  query);
1079  break;
1080  default:
1081  GNUNET_assert (0);
1082  }
1083  GNUNET_free (norm_label);
1084 }
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 508 of file gnsrecord_crypto.c.

512 {
514  ssize_t res = -1;
515 
517  &pkey);
518  switch (ntohl (key->type))
519  {
522  break;
525  break;
526  default:
527  GNUNET_assert (0);
528  }
529  return res;
530 
531 }
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_sign()

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

277 {
280  char *norm_label;
281 
283  &pkey);
284  norm_label = GNUNET_GNSRECORD_string_normalize (label);
285 
286  switch (ntohl (key->type))
287  {
289  res = block_sign_ecdsa (&key->ecdsa_key,
290  &pkey.ecdsa_key,
291  norm_label,
292  block);
293  break;
295  res = block_sign_eddsa (&key->eddsa_key,
296  &pkey.eddsa_key,
297  norm_label,
298  block);
299  break;
300  default:
301  GNUNET_assert (0);
302  }
303  GNUNET_free (norm_label);
304  return res;
305 }
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.
Definition: gnunet_common.h:96

Referenced by sign_worker().

Here is the caller graph for this function:

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

540 {
543  char *norm_label;
544 
546  &pkey);
547  norm_label = GNUNET_GNSRECORD_string_normalize (label);
548 
549  switch (ntohl (key->type))
550  {
552  res = block_create_ecdsa (&key->ecdsa_key,
553  &pkey.ecdsa_key,
554  expire,
555  norm_label,
556  rd,
557  rd_count,
558  result,
559  GNUNET_YES);
560  break;
562  res = block_create_eddsa (&key->eddsa_key,
563  &pkey.eddsa_key,
564  expire,
565  norm_label,
566  rd,
567  rd_count,
568  result,
569  GNUNET_YES);
570  break;
571  default:
572  GNUNET_assert (0);
573  }
574  GNUNET_free (norm_label);
575  return res;
576 }
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 Attribut String.
Definition: gnunet-did.c:101
static int result
Global testing status.

Referenced by run_edkey(), and run_pkey().

Here is the caller graph for this function:

◆ GNUNET_GNSRECORD_block_create_unsigned()

enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_block_create_unsigned ( 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 
)

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

666 {
667  return block_create2 (pkey, expire, label, rd, rd_count, result, GNUNET_NO);
668 }
static enum GNUNET_GenericReturnValue block_create2(const struct GNUNET_IDENTITY_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)

Referenced by dispatch_job(), and dispatch_job_monitor().

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

679 {
680  return block_create2 (pkey, expire, label, rd, rd_count, result, GNUNET_YES);
681 }

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

692 {
693  struct GNRBlockPS *purp;
694  size_t payload_len = ntohl (block->size)
695  - sizeof (struct GNUNET_GNSRECORD_Block);
697  purp = GNUNET_malloc (sizeof (struct GNRBlockPS) + payload_len);
698  purp->purpose.size = htonl (sizeof (struct GNRBlockPS) + payload_len);
700  GNUNET_memcpy (&purp[1],
701  &block[1],
702  payload_len);
703  switch (ntohl (block->type))
704  {
709  &purp->purpose,
710  &block->ecdsa_block.signature,
711  &block->ecdsa_block.derived_key);
712  break;
717  &purp->purpose,
718  &block->eddsa_block.signature,
719  &block->eddsa_block.derived_key);
720  break;
721  default:
722  res = GNUNET_NO;
723  }
724  GNUNET_free (purp);
725  return res;
726 }
#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:643
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:702
#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

Definition at line 508 of file gnsrecord_crypto.c.

987 {
989  char *norm_label;
990 
991  norm_label = GNUNET_GNSRECORD_string_normalize (label);
992  switch (ntohl (zone_key->type))
993  {
995  res = block_decrypt_ecdsa (block,
996  &zone_key->ecdsa_key, norm_label, proc,
997  proc_cls);
998  break;
1000  res = block_decrypt_eddsa (block,
1001  &zone_key->eddsa_key, norm_label, proc,
1002  proc_cls);
1003  break;
1004  default:
1005  res = GNUNET_SYSERR;
1006  }
1007  GNUNET_free (norm_label);
1008  return res;
1009 }
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.
@ GNUNET_IDENTITY_TYPE_ECDSA
The identity type.
@ GNUNET_IDENTITY_TYPE_EDDSA
EDDSA identity.
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 95 of file gnsrecord_misc.c.

97 {
99  "Comparing records\n");
100  if (a->record_type != b->record_type)
101  {
103  "Record type %u != %u\n", a->record_type, b->record_type);
104  return GNUNET_NO;
105  }
106  if ((a->expiration_time != b->expiration_time) &&
107  ((a->expiration_time != 0) && (b->expiration_time != 0)))
108  {
110  "Expiration time %llu != %llu\n",
111  (unsigned long long) a->expiration_time,
112  (unsigned long long) b->expiration_time);
113  return GNUNET_NO;
114  }
117  {
119  "Flags %u (%u) != %u (%u)\n", a->flags,
122  return GNUNET_NO;
123  }
124  if (a->data_size != b->data_size)
125  {
127  "Data size %lu != %lu\n",
128  a->data_size,
129  b->data_size);
130  return GNUNET_NO;
131  }
132  if (0 != memcmp (a->data, b->data, a->data_size))
133  {
135  "Data contents do not match\n");
136  return GNUNET_NO;
137  }
139  "Records are equal\n");
140  return GNUNET_YES;
141 }
#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.

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

149 {
151  struct GNUNET_TIME_Absolute at;
152  struct GNUNET_TIME_Relative rt;
153  struct GNUNET_TIME_Absolute at_shadow;
154  struct GNUNET_TIME_Relative rt_shadow;
155 
156  if (0 == rd_count)
159  for (unsigned int c = 0; c < rd_count; c++)
160  {
161  if (0 != (rd[c].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
162  {
163  rt.rel_value_us = rd[c].expiration_time;
165  }
166  else
167  {
168  at.abs_value_us = rd[c].expiration_time;
169  }
170 
171  for (unsigned int c2 = 0; c2 < rd_count; c2++)
172  {
173  /* Check for shadow record */
174  if ((c == c2) ||
175  (rd[c].record_type != rd[c2].record_type) ||
176  (0 == (rd[c2].flags & GNUNET_GNSRECORD_RF_SHADOW)))
177  continue;
178  /* We have a shadow record */
179  if (0 != (rd[c2].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
180  {
181  rt_shadow.rel_value_us = rd[c2].expiration_time;
182  at_shadow = GNUNET_TIME_relative_to_absolute (rt_shadow);
183  }
184  else
185  {
186  at_shadow.abs_value_us = rd[c2].expiration_time;
187  }
188  at = GNUNET_TIME_absolute_max (at,
189  at_shadow);
190  }
192  expire);
193  }
196  "Determined expiration time for block with %u records to be %s\n",
197  rd_count,
199  return expire;
200 }
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
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:617
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)
Time for relative time used by GNUnet, in microseconds.

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

333 {
334  return ntohl (block->size);
335 }

Referenced by dispatch_job(), dispatch_job_monitor(), GNUNET_NAMECACHE_block_cache(), handle_dht_response(), handle_lookup_block_it(), namecache_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 332 of file gnsrecord_misc.c.

341 {
342 
343  switch (ntohl (block->type))
344  {
349  default:
350  GNUNET_break (0); /* Hopefully we never get here, but we might */
351  }
353 
354 }
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(), 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 332 of file gnsrecord_misc.c.

360 {
361  switch (ntohl (block->type))
362  {
365  sizeof (block->ecdsa_block.derived_key),
366  query);
367  return GNUNET_OK;
370  sizeof (block->eddsa_block.derived_key),
371  query);
372  return GNUNET_OK;
373  default:
374  return GNUNET_SYSERR;
375  }
376  return GNUNET_SYSERR;
377 
378 }

Referenced by namecache_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 258 of file gnsrecord_misc.c.

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

Referenced by check_pkey(), gns_value_to_string(), handle_gns_resolution_result(), 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 258 of file gnsrecord_misc.c.

304 {
305  char *tmp;
306  *type = ntohl (key->type);
308  if (0 == *data_size)
309  return GNUNET_SYSERR;
310  tmp = GNUNET_malloc (*data_size);
311  memcpy (tmp, ((char*) key) + sizeof (key->type), *data_size);
312  *data = tmp;
313  return GNUNET_OK;
314 }
ssize_t GNUNET_IDENTITY_public_key_get_length(const struct GNUNET_IDENTITY_PublicKey *key)
Get the compacted length of a GNUNET_IDENTITY_PublicKey.
Definition: identity_api.c:830

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

319 {
320  switch (type)
321  {
324  return GNUNET_YES;
325  default:
326  return GNUNET_NO;
327  }
328 }

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

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

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

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

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.

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

References GNUNET_STRINGS_utf8_normalize().

Here is the call graph for this function: