GNUnet  0.11.x
Data Structures | Functions
plugin_namestore_flat.c File Reference

file-based namestore backend More...

#include "platform.h"
#include "gnunet_namestore_plugin.h"
#include "gnunet_namestore_service.h"
#include "gnunet_gnsrecord_lib.h"
#include "namestore.h"
Include dependency graph for plugin_namestore_flat.c:

Go to the source code of this file.

Data Structures

struct  Plugin
 Handle for a plugin. More...
 
struct  FlatFileEntry
 
struct  IterateContext
 Closure for iterate_zones. More...
 
struct  ZoneToNameContext
 Closure for zone_to_name. More...
 

Functions

static void hash_pkey_and_label (const struct GNUNET_IDENTITY_PrivateKey *pkey, const char *label, struct GNUNET_HashCode *h)
 Hash contactenation of pkey and label into h. More...
 
static int database_setup (struct Plugin *plugin)
 Initialize the database connections and associated data structures (create tables and indices as needed as well). More...
 
static int store_and_free_entries (void *cls, const struct GNUNET_HashCode *key, void *value)
 Store values in hashmap in file and free data. More...
 
static void database_shutdown (struct Plugin *plugin)
 Shutdown database connection and associate data structures. More...
 
static int namestore_flat_store_records (void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone_key, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
 Store a record in the datastore. More...
 
static int namestore_flat_lookup_records (void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone, const char *label, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
 Lookup records in the datastore for which we are the authority. More...
 
static int iterate_zones (void *cls, const struct GNUNET_HashCode *key, void *value)
 Helper function for namestore_flat_iterate_records(). More...
 
static int namestore_flat_iterate_records (void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone, uint64_t serial, uint64_t limit, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
 Iterate over the results for a particular key and zone in the datastore. More...
 
static int zone_to_name (void *cls, const struct GNUNET_HashCode *key, void *value)
 
static int namestore_flat_zone_to_name (void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone, const struct GNUNET_IDENTITY_PublicKey *value_zone, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
 Look for an existing PKEY delegation record for a given public key. More...
 
void * libgnunet_plugin_namestore_flat_init (void *cls)
 Entry point for the plugin. More...
 
void * libgnunet_plugin_namestore_flat_done (void *cls)
 Exit point from the plugin. More...
 

Detailed Description

file-based namestore backend

Author
Martin Schanzenbach
Christian Grothoff

Definition in file plugin_namestore_flat.c.

Function Documentation

◆ hash_pkey_and_label()

static void hash_pkey_and_label ( const struct GNUNET_IDENTITY_PrivateKey pkey,
const char *  label,
struct GNUNET_HashCode h 
)
static

Hash contactenation of pkey and label into h.

Parameters
pkeya key
labela label
h[out]initialized hash

Definition at line 89 of file plugin_namestore_flat.c.

92 {
93  char *key;
94  size_t label_len;
95  size_t key_len;
96 
97  label_len = strlen (label);
98  key_len = label_len + sizeof(struct GNUNET_IDENTITY_PrivateKey);
99  key = GNUNET_malloc (key_len);
101  label,
102  label_len);
103  GNUNET_memcpy (key + label_len,
104  pkey,
105  sizeof(struct GNUNET_IDENTITY_PrivateKey));
107  key_len,
108  h);
109  GNUNET_free (key);
110 }
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
struct GNUNET_HashCode key
The key used in the DHT.
static char * pkey
Public key of the zone to look in, in ASCII.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
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
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
A private key for an identity as per LSD0001.

References GNUNET_CRYPTO_hash(), GNUNET_free, GNUNET_malloc, GNUNET_memcpy, h, key, and pkey.

Referenced by database_setup(), namestore_flat_lookup_records(), and namestore_flat_store_records().

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

◆ database_setup()

static int database_setup ( struct Plugin plugin)
static

Initialize the database connections and associated data structures (create tables and indices as needed as well).

Parameters
pluginthe plugin context (state for this module)
Returns
GNUNET_OK on success

Definition at line 122 of file plugin_namestore_flat.c.

123 {
124  char *flatdbfile;
125  char *record_data;
126  char *zone_private_key;
127  char *record_data_b64;
128  char *buffer;
129  char *line;
130  char *label;
131  char *rvalue;
132  char *record_count;
133  size_t record_data_size;
134  uint64_t size;
135  struct GNUNET_HashCode hkey;
136  struct GNUNET_DISK_FileHandle *fh;
137  struct FlatFileEntry *entry;
138  struct GNUNET_DISK_MapHandle *mh;
139 
140  if (GNUNET_OK !=
142  "namestore-flat",
143  "FILENAME",
144  &flatdbfile))
145  {
147  "namestore-flat",
148  "FILENAME");
149  return GNUNET_SYSERR;
150  }
151  if (GNUNET_OK !=
152  GNUNET_DISK_file_test (flatdbfile))
153  {
154  if (GNUNET_OK !=
156  {
157  GNUNET_break (0);
158  GNUNET_free (flatdbfile);
159  return GNUNET_SYSERR;
160  }
161  }
162  /* flatdbfile should be UTF-8-encoded. If it isn't, it's a bug */
163  plugin->fn = flatdbfile;
164 
165  /* Load data from file into hashmap */
167  GNUNET_NO);
168  fh = GNUNET_DISK_file_open (flatdbfile,
173  if (NULL == fh)
174  {
176  _ ("Unable to initialize file: %s.\n"),
177  flatdbfile);
178  return GNUNET_SYSERR;
179  }
180  if (GNUNET_SYSERR ==
181  GNUNET_DISK_file_size (flatdbfile,
182  &size,
183  GNUNET_YES,
184  GNUNET_YES))
185  {
187  _ ("Unable to get filesize: %s.\n"),
188  flatdbfile);
190  return GNUNET_SYSERR;
191  }
192  if (size > SIZE_MAX)
193  {
195  _ ("File too big to map: %llu bytes.\n"),
196  (unsigned long long) size);
198  return GNUNET_SYSERR;
199  }
200  if (0 == size)
201  {
203  return GNUNET_OK;
204  }
205  buffer = GNUNET_DISK_file_map (fh,
206  &mh,
208  size);
209  if (NULL == buffer)
210  {
212  "mmap");
214  return GNUNET_SYSERR;
215  }
216  if ('\0' != buffer[size - 1])
217  {
219  _ ("Namestore database file `%s' malformed\n"),
220  flatdbfile);
223  return GNUNET_SYSERR;
224  }
225 
226  line = strtok (buffer, "\n");
227  while (NULL != line)
228  {
229  zone_private_key = strtok (line, ",");
230  if (NULL == zone_private_key)
231  break;
232  rvalue = strtok (NULL, ",");
233  if (NULL == rvalue)
234  break;
235  record_count = strtok (NULL, ",");
236  if (NULL == record_count)
237  break;
238  record_data_b64 = strtok (NULL, ",");
239  if (NULL == record_data_b64)
240  break;
241  label = strtok (NULL, ",");
242  if (NULL == label)
243  break;
244  line = strtok (NULL, "\n");
245  entry = GNUNET_new (struct FlatFileEntry);
246  {
247  unsigned long long ll;
248 
249  if (1 != sscanf (rvalue,
250  "%llu",
251  &ll))
252  {
254  "Error parsing entry\n");
255  GNUNET_free (entry);
256  break;
257  }
258  entry->rvalue = (uint64_t) ll;
259  }
260  {
261  unsigned int ui;
262 
263  if (1 != sscanf (record_count,
264  "%u",
265  &ui))
266  {
268  "Error parsing entry\n");
269  GNUNET_free (entry);
270  break;
271  }
272  entry->record_count = (uint32_t) ui;
273  }
274  entry->label = GNUNET_strdup (label);
275  record_data_size
276  = GNUNET_STRINGS_base64_decode (record_data_b64,
277  strlen (record_data_b64),
278  (void **) &record_data);
279  entry->record_data =
281  struct GNUNET_GNSRECORD_Data);
282  if (GNUNET_OK !=
283  GNUNET_GNSRECORD_records_deserialize (record_data_size,
284  record_data,
285  entry->record_count,
286  entry->record_data))
287  {
289  "Unable to deserialize record %s\n",
290  label);
291  GNUNET_free (entry->label);
292  GNUNET_free (entry);
293  GNUNET_free (record_data);
294  break;
295  }
296  GNUNET_free (record_data);
297 
298  {
299  struct GNUNET_IDENTITY_PrivateKey *private_key;
300 
301  GNUNET_STRINGS_base64_decode (zone_private_key,
302  strlen (zone_private_key),
303  (void **) &private_key);
304  entry->private_key = *private_key;
305  GNUNET_free (private_key);
306  }
307 
309  label,
310  &hkey);
311  if (GNUNET_OK !=
313  &hkey,
314  entry,
316  {
317  GNUNET_free (entry);
318  GNUNET_break (0);
319  }
320  }
323  return GNUNET_OK;
324 }
static struct GNUNET_CADET_Handle * mh
Cadet handle.
Definition: gnunet-cadet.c:92
struct Plugin * plugin
The process handle to the testbed service.
static char * line
Desired phone line (string to be converted to a hash).
static uint64_t record_count
Record count.
#define GNUNET_log(kind,...)
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_YES
Definition: gnunet_common.h:97
@ GNUNET_NO
Definition: gnunet_common.h:94
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
static int fh
Handle to the unique file.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1235
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
Definition: disk.c:482
enum GNUNET_GenericReturnValue GNUNET_DISK_file_size(const char *filename, uint64_t *size, int include_symbolic_links, int single_file_mode)
Get the size of the file (or directory) of the given file (in bytes).
Definition: disk.c:222
void * GNUNET_DISK_file_map(const struct GNUNET_DISK_FileHandle *h, struct GNUNET_DISK_MapHandle **m, enum GNUNET_DISK_MapType access, size_t len)
Map a file into memory.
Definition: disk.c:1378
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1306
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:582
enum GNUNET_GenericReturnValue GNUNET_DISK_file_unmap(struct GNUNET_DISK_MapHandle *h)
Unmap a file.
Definition: disk.c:1409
@ GNUNET_DISK_OPEN_CREATE
Create file if it doesn't exist.
@ GNUNET_DISK_OPEN_READWRITE
Open the file for both reading and writing.
@ GNUNET_DISK_PERM_USER_READ
Owner can read.
@ GNUNET_DISK_PERM_USER_WRITE
Owner can write.
@ GNUNET_DISK_MAP_TYPE_READ
Read-only memory map.
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.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
int GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY
There must only be one value per key; storing a value should fail if a value under the same key alrea...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
size_t GNUNET_STRINGS_base64_decode(const char *data, size_t len, void **output)
Decode from Base64.
Definition: strings.c:1682
static unsigned int size
Size of the "table".
Definition: peer.c:67
#define _(String)
GNU gettext support macro.
Definition: platform.h:177
#define SIZE_MAX
Definition: platform.h:207
static void hash_pkey_and_label(const struct GNUNET_IDENTITY_PrivateKey *pkey, const char *label, struct GNUNET_HashCode *h)
Hash contactenation of pkey and label into h.
uint64_t rvalue
Rvalue.
uint32_t record_count
Record count.
struct GNUNET_GNSRECORD_Data * record_data
Record data.
struct GNUNET_IDENTITY_PrivateKey private_key
Entry zone.
Handle used to access files (and pipes).
Handle for a memory-mapping operation.
Definition: disk.c:1359
A 512-bit hashcode.
struct GNUNET_CONTAINER_MultiHashMap * hm
HashMap.
char * fn
Filename used for the DB.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.

References _, Plugin::cfg, fh, Plugin::fn, GNUNET_break, GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CONTAINER_multihashmap_create(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_DISK_directory_create_for_file(), GNUNET_DISK_file_close(), GNUNET_DISK_file_map(), GNUNET_DISK_file_open(), GNUNET_DISK_file_size(), GNUNET_DISK_file_test(), GNUNET_DISK_file_unmap(), GNUNET_DISK_MAP_TYPE_READ, GNUNET_DISK_OPEN_CREATE, GNUNET_DISK_OPEN_READWRITE, GNUNET_DISK_PERM_USER_READ, GNUNET_DISK_PERM_USER_WRITE, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_GNSRECORD_records_deserialize(), GNUNET_log, GNUNET_log_config_missing(), GNUNET_log_strerror, GNUNET_new, GNUNET_new_array, GNUNET_NO, GNUNET_OK, GNUNET_strdup, GNUNET_STRINGS_base64_decode(), GNUNET_SYSERR, GNUNET_YES, hash_pkey_and_label(), Plugin::hm, FlatFileEntry::label, line, mh, plugin, FlatFileEntry::private_key, record_count, FlatFileEntry::record_count, FlatFileEntry::record_data, FlatFileEntry::rvalue, size, and SIZE_MAX.

Referenced by libgnunet_plugin_namestore_flat_init().

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

◆ store_and_free_entries()

static int store_and_free_entries ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Store values in hashmap in file and free data.

Parameters
pluginthe plugin context
keykey in the map
valuea struct FlatFileEntry

Definition at line 335 of file plugin_namestore_flat.c.

338 {
339  struct GNUNET_DISK_FileHandle *fh = cls;
340  struct FlatFileEntry *entry = value;
341  char *line;
342  char *zone_private_key;
343  char *record_data_b64;
344  ssize_t data_size;
345 
346  (void) key;
348  sizeof(struct GNUNET_IDENTITY_PrivateKey),
349  &zone_private_key);
351  entry->record_data);
352  if (data_size < 0)
353  {
354  GNUNET_break (0);
355  GNUNET_free (zone_private_key);
356  return GNUNET_SYSERR;
357  }
358  if (data_size >= UINT16_MAX)
359  {
360  GNUNET_break (0);
361  GNUNET_free (zone_private_key);
362  return GNUNET_SYSERR;
363  }
364  {
365  char data[data_size];
366  ssize_t ret;
367 
369  entry->record_data,
370  data_size,
371  data);
372  if ((ret < 0) ||
373  (data_size != ret))
374  {
375  GNUNET_break (0);
376  GNUNET_free (zone_private_key);
377  return GNUNET_SYSERR;
378  }
380  data_size,
381  &record_data_b64);
382  }
384  "%s,%llu,%u,%s,%s\n",
385  zone_private_key,
386  (unsigned long long) entry->rvalue,
387  (unsigned int) entry->record_count,
388  record_data_b64,
389  entry->label);
390  GNUNET_free (record_data_b64);
391  GNUNET_free (zone_private_key);
392 
394  line,
395  strlen (line));
396 
397  GNUNET_free (line);
398  GNUNET_free (entry->label);
399  GNUNET_free (entry->record_data);
400  GNUNET_free (entry);
401  return GNUNET_YES;
402 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
uint32_t data
The data value.
static char * value
Value of the record to add/remove.
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: disk.c:686
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.
GNUNET_NETWORK_STRUCT_END 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.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
size_t GNUNET_STRINGS_base64_encode(const void *in, size_t len, char **output)
Encode into Base64.
Definition: strings.c:1594

References data, data_size, fh, GNUNET_asprintf(), GNUNET_break, GNUNET_DISK_file_write(), GNUNET_free, GNUNET_GNSRECORD_records_get_size(), GNUNET_GNSRECORD_records_serialize(), GNUNET_STRINGS_base64_encode(), GNUNET_SYSERR, GNUNET_YES, key, FlatFileEntry::label, line, FlatFileEntry::private_key, FlatFileEntry::record_count, FlatFileEntry::record_data, ret, FlatFileEntry::rvalue, and value.

Referenced by database_shutdown().

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

◆ database_shutdown()

static void database_shutdown ( struct Plugin plugin)
static

Shutdown database connection and associate data structures.

Parameters
pluginthe plugin context (state for this module)

Definition at line 411 of file plugin_namestore_flat.c.

412 {
413  struct GNUNET_DISK_FileHandle *fh;
414 
421  if (NULL == fh)
422  {
424  _ ("Unable to initialize file: %s.\n"),
425  plugin->fn);
426  return;
427  }
428 
431  fh);
433  /* append 0-terminator */
435  "",
436  1);
438 }
@ GNUNET_DISK_OPEN_TRUNCATE
Truncate file if it exists.
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
static int store_and_free_entries(void *cls, const struct GNUNET_HashCode *key, void *value)
Store values in hashmap in file and free data.

References _, fh, Plugin::fn, GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_DISK_file_close(), GNUNET_DISK_file_open(), GNUNET_DISK_file_write(), GNUNET_DISK_OPEN_CREATE, GNUNET_DISK_OPEN_READWRITE, GNUNET_DISK_OPEN_TRUNCATE, GNUNET_DISK_PERM_USER_READ, GNUNET_DISK_PERM_USER_WRITE, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, Plugin::hm, plugin, and store_and_free_entries().

Referenced by libgnunet_plugin_namestore_flat_done(), and libgnunet_plugin_namestore_flat_init().

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

◆ namestore_flat_store_records()

static int namestore_flat_store_records ( void *  cls,
const struct GNUNET_IDENTITY_PrivateKey zone_key,
const char *  label,
unsigned int  rd_count,
const struct GNUNET_GNSRECORD_Data rd 
)
static

Store a record in the datastore.

Removes any existing record in the same zone with the same name.

Parameters
clsclosure (internal context for the plugin)
zone_keyprivate key of the zone
labelname that is being mapped (at most 255 characters long)
rd_countnumber of entries in rd array
rdarray of records with data to store
Returns
GNUNET_OK on success, else GNUNET_SYSERR

Definition at line 453 of file plugin_namestore_flat.c.

459 {
460  struct Plugin *plugin = cls;
461  uint64_t rvalue;
462  struct GNUNET_HashCode hkey;
463  struct FlatFileEntry *entry;
464 
466  UINT64_MAX);
468  label,
469  &hkey);
471  &hkey);
472  if (0 == rd_count)
473  {
475  "sqlite",
476  "Record deleted\n");
477  return GNUNET_OK;
478  }
479  entry = GNUNET_new (struct FlatFileEntry);
480  GNUNET_asprintf (&entry->label,
481  label,
482  strlen (label));
483  GNUNET_memcpy (&entry->private_key,
484  zone_key,
485  sizeof(struct GNUNET_IDENTITY_PrivateKey));
486  entry->rvalue = rvalue;
487  entry->record_count = rd_count;
488  entry->record_data = GNUNET_new_array (rd_count,
489  struct GNUNET_GNSRECORD_Data);
490  for (unsigned int i = 0; i < rd_count; i++)
491  {
492  entry->record_data[i].expiration_time = rd[i].expiration_time;
493  entry->record_data[i].record_type = rd[i].record_type;
494  entry->record_data[i].flags = rd[i].flags;
495  entry->record_data[i].data_size = rd[i].data_size;
496  entry->record_data[i].data = GNUNET_malloc (rd[i].data_size);
497  GNUNET_memcpy ((char *) entry->record_data[i].data,
498  rd[i].data,
499  rd[i].data_size);
500  }
502  &hkey,
503  entry,
505 }
static const struct GNUNET_IDENTITY_PrivateKey * zone_key
Private key of the zone.
#define GNUNET_log_from(kind, comp,...)
uint64_t GNUNET_CRYPTO_random_u64(enum GNUNET_CRYPTO_Quality mode, uint64_t max)
Random on unsigned 64-bit values.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
int GNUNET_CONTAINER_multihashmap_remove_all(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Remove all entries for the given key from the map.
@ GNUNET_ERROR_TYPE_DEBUG
uint32_t record_type
Type of the GNS/DNS record.
const void * data
Binary value stored in the DNS record.
size_t data_size
Number of bytes in data.
enum GNUNET_GNSRECORD_Flags flags
Flags for the record.
uint64_t expiration_time
Expiration time for the DNS record.
Handle for a plugin.
Definition: block.c:38

References GNUNET_GNSRECORD_Data::data, data_size, GNUNET_GNSRECORD_Data::data_size, GNUNET_GNSRECORD_Data::expiration_time, GNUNET_GNSRECORD_Data::flags, GNUNET_asprintf(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_multihashmap_remove_all(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u64(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log_from, GNUNET_malloc, GNUNET_memcpy, GNUNET_new, GNUNET_new_array, GNUNET_OK, hash_pkey_and_label(), Plugin::hm, FlatFileEntry::label, plugin, FlatFileEntry::private_key, FlatFileEntry::record_count, FlatFileEntry::record_data, GNUNET_GNSRECORD_Data::record_type, FlatFileEntry::rvalue, and zone_key.

Referenced by libgnunet_plugin_namestore_flat_init().

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

◆ namestore_flat_lookup_records()

static int namestore_flat_lookup_records ( void *  cls,
const struct GNUNET_IDENTITY_PrivateKey zone,
const char *  label,
GNUNET_NAMESTORE_RecordIterator  iter,
void *  iter_cls 
)
static

Lookup records in the datastore for which we are the authority.

Parameters
clsclosure (internal context for the plugin)
zoneprivate key of the zone
labelname of the record in the zone
iterfunction to call with the result
iter_clsclosure for iter
Returns
GNUNET_OK on success, GNUNET_NO for no results, else GNUNET_SYSERR

Definition at line 519 of file plugin_namestore_flat.c.

524 {
525  struct Plugin *plugin = cls;
526  struct FlatFileEntry *entry;
527  struct GNUNET_HashCode hkey;
528 
529  if (NULL == zone)
530  {
531  GNUNET_break (0);
532  return GNUNET_SYSERR;
533  }
535  label,
536  &hkey);
538  &hkey);
539 
540  if (NULL == entry)
541  return GNUNET_NO;
542  if (NULL != iter)
543  iter (iter_cls,
544  1, /* zero is illegal */
545  &entry->private_key,
546  entry->label,
547  entry->record_count,
548  entry->record_data);
549  return GNUNET_YES;
550 }
static char * zone
Name of the zone being managed.
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.

References GNUNET_break, GNUNET_CONTAINER_multihashmap_get(), GNUNET_NO, GNUNET_SYSERR, GNUNET_YES, hash_pkey_and_label(), Plugin::hm, FlatFileEntry::label, plugin, FlatFileEntry::private_key, FlatFileEntry::record_count, FlatFileEntry::record_data, and zone.

Referenced by libgnunet_plugin_namestore_flat_init().

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

◆ iterate_zones()

static int iterate_zones ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Helper function for namestore_flat_iterate_records().

Parameters
clsa struct IterateContext
keyunused
valuea struct FlatFileEntry
Returns
GNUNET_YES to continue the iteration

Definition at line 600 of file plugin_namestore_flat.c.

603 {
604  struct IterateContext *ic = cls;
605  struct FlatFileEntry *entry = value;
606 
607  (void) key;
608  if (0 == ic->limit)
609  return GNUNET_NO;
610  if ((NULL != ic->zone) &&
611  (0 != GNUNET_memcmp (&entry->private_key,
612  ic->zone)))
613  return GNUNET_YES;
614  ic->pos++;
615  if (ic->offset > 0)
616  {
617  ic->offset--;
618  return GNUNET_YES;
619  }
620  ic->iter (ic->iter_cls,
621  ic->pos,
622  (NULL == ic->zone)
623  ? &entry->private_key
624  : ic->zone,
625  entry->label,
626  entry->record_count,
627  entry->record_data);
628  ic->limit--;
629  if (0 == ic->limit)
630  return GNUNET_NO;
631  return GNUNET_YES;
632 }
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
Closure for iterate_zones.
void * iter_cls
Closure for iter.
uint64_t pos
What is the position of the current entry, counting starts from 1.
const struct GNUNET_IDENTITY_PrivateKey * zone
Target zone.
uint64_t offset
How many more records should we skip before returning results?
GNUNET_NAMESTORE_RecordIterator iter
Function to call on each record.
uint64_t limit
How many more records should we return?

References GNUNET_memcmp, GNUNET_NO, GNUNET_YES, IterateContext::iter, IterateContext::iter_cls, key, FlatFileEntry::label, IterateContext::limit, IterateContext::offset, IterateContext::pos, FlatFileEntry::private_key, FlatFileEntry::record_count, FlatFileEntry::record_data, value, and IterateContext::zone.

Referenced by namestore_flat_iterate_records().

Here is the caller graph for this function:

◆ namestore_flat_iterate_records()

static int namestore_flat_iterate_records ( void *  cls,
const struct GNUNET_IDENTITY_PrivateKey zone,
uint64_t  serial,
uint64_t  limit,
GNUNET_NAMESTORE_RecordIterator  iter,
void *  iter_cls 
)
static

Iterate over the results for a particular key and zone in the datastore.

Will return at most one result to the iterator.

Parameters
clsclosure (internal context for the plugin)
zonehash of public key of the zone, NULL to iterate over all zones
serialserial number to exclude in the list of all matching records
limitmaximum number of results to return to iter
iterfunction to call with the result
iter_clsclosure for iter
Returns
GNUNET_OK on success, GNUNET_NO if there were no more results, GNUNET_SYSERR on error

Definition at line 648 of file plugin_namestore_flat.c.

655 {
656  struct Plugin *plugin = cls;
657  struct IterateContext ic;
658 
659  ic.offset = serial;
660  ic.pos = 0;
661  ic.limit = limit;
662  ic.iter = iter;
663  ic.iter_cls = iter_cls;
664  ic.zone = zone;
666  &iterate_zones,
667  &ic);
668  return (0 == ic.limit) ? GNUNET_OK : GNUNET_NO;
669 }
static int iterate_zones(void *cls, const struct GNUNET_HashCode *key, void *value)
Helper function for namestore_flat_iterate_records().

References GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_NO, GNUNET_OK, Plugin::hm, IterateContext::iter, IterateContext::iter_cls, iterate_zones(), IterateContext::limit, IterateContext::offset, plugin, IterateContext::pos, zone, and IterateContext::zone.

Referenced by libgnunet_plugin_namestore_flat_init().

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

◆ zone_to_name()

static int zone_to_name ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Definition at line 687 of file plugin_namestore_flat.c.

690 {
691  struct ZoneToNameContext *ztn = cls;
692  struct FlatFileEntry *entry = value;
693 
694  (void) key;
695  if (0 != GNUNET_memcmp (&entry->private_key,
696  ztn->zone))
697  return GNUNET_YES;
698 
699  for (unsigned int i = 0; i < entry->record_count; i++)
700  {
701  if (GNUNET_NO ==
703  continue;
704  if (ztn->value_zone->type != entry->record_data[i].record_type)
705  continue;
706  if (0 == memcmp (ztn->value_zone,
707  entry->record_data[i].data,
708  entry->record_data[i].data_size))
709  {
710  ztn->iter (ztn->iter_cls,
711  i + 1, /* zero is illegal! */
712  &entry->private_key,
713  entry->label,
714  entry->record_count,
715  entry->record_data);
716  ztn->result_found = GNUNET_YES;
717  }
718  }
719  return GNUNET_YES;
720 }
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_is_zonekey_type(uint32_t type)
Check if this type is one of the supported GNS zone types.
uint32_t type
Type of public key.
Closure for zone_to_name.
const struct GNUNET_IDENTITY_PrivateKey * zone
GNUNET_NAMESTORE_RecordIterator iter
const struct GNUNET_IDENTITY_PublicKey * value_zone

References GNUNET_GNSRECORD_Data::data, GNUNET_GNSRECORD_Data::data_size, GNUNET_GNSRECORD_is_zonekey_type(), GNUNET_memcmp, GNUNET_NO, GNUNET_YES, ZoneToNameContext::iter, ZoneToNameContext::iter_cls, key, FlatFileEntry::label, FlatFileEntry::private_key, FlatFileEntry::record_count, FlatFileEntry::record_data, GNUNET_GNSRECORD_Data::record_type, ZoneToNameContext::result_found, GNUNET_IDENTITY_PublicKey::type, value, ZoneToNameContext::value_zone, and ZoneToNameContext::zone.

Referenced by namestore_flat_zone_to_name().

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

◆ namestore_flat_zone_to_name()

static int namestore_flat_zone_to_name ( void *  cls,
const struct GNUNET_IDENTITY_PrivateKey zone,
const struct GNUNET_IDENTITY_PublicKey value_zone,
GNUNET_NAMESTORE_RecordIterator  iter,
void *  iter_cls 
)
static

Look for an existing PKEY delegation record for a given public key.

Returns at most one result to the iterator.

Parameters
clsclosure (internal context for the plugin)
zoneprivate key of the zone to look up in, never NULL
value_zonepublic key of the target zone (value), never NULL
iterfunction to call with the result
iter_clsclosure for iter
Returns
GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error

Definition at line 735 of file plugin_namestore_flat.c.

741 {
742  struct Plugin *plugin = cls;
743  struct ZoneToNameContext ztn = {
744  .iter = iter,
745  .iter_cls = iter_cls,
746  .zone = zone,
747  .value_zone = value_zone,
748  .result_found = GNUNET_NO
749  };
750 
752  "Performing reverse lookup for `%s'\n",
755  &zone_to_name,
756  &ztn);
757  return ztn.result_found;
758 }
const char * GNUNET_GNSRECORD_z2s(const struct GNUNET_IDENTITY_PublicKey *z)
Convert a zone key to a string (for printing debug messages).
static int zone_to_name(void *cls, const struct GNUNET_HashCode *key, void *value)

References GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_GNSRECORD_z2s(), GNUNET_log, GNUNET_NO, Plugin::hm, ZoneToNameContext::iter, ZoneToNameContext::iter_cls, plugin, ZoneToNameContext::result_found, ZoneToNameContext::value_zone, zone, and zone_to_name().

Referenced by libgnunet_plugin_namestore_flat_init().

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

◆ libgnunet_plugin_namestore_flat_init()

void* libgnunet_plugin_namestore_flat_init ( void *  cls)

Entry point for the plugin.

Parameters
clsthe "struct GNUNET_NAMESTORE_PluginEnvironment*"
Returns
NULL on error, otherwise the plugin context

Definition at line 768 of file plugin_namestore_flat.c.

769 {
770  static struct Plugin plugin;
771  const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
773 
774  if (NULL != plugin.cfg)
775  return NULL; /* can only initialize once! */
776  memset (&plugin,
777  0,
778  sizeof(struct Plugin));
779  plugin.cfg = cfg;
780  if (GNUNET_OK != database_setup (&plugin))
781  {
783  return NULL;
784  }
786  api->cls = &plugin;
792  _ ("Flat file database running\n"));
793  return api;
794 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
@ GNUNET_ERROR_TYPE_INFO
static int namestore_flat_zone_to_name(void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone, const struct GNUNET_IDENTITY_PublicKey *value_zone, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
Look for an existing PKEY delegation record for a given public key.
static int namestore_flat_store_records(void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone_key, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Store a record in the datastore.
static void database_shutdown(struct Plugin *plugin)
Shutdown database connection and associate data structures.
static int namestore_flat_lookup_records(void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone, const char *label, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
Lookup records in the datastore for which we are the authority.
static int database_setup(struct Plugin *plugin)
Initialize the database connections and associated data structures (create tables and indices as need...
static int namestore_flat_iterate_records(void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone, uint64_t serial, uint64_t limit, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
Iterate over the results for a particular key and zone in the datastore.
struct returned by the initialization function of the plugin
int(* lookup_records)(void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone, const char *label, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
Lookup records in the datastore for which we are the authority.
int(* zone_to_name)(void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone, const struct GNUNET_IDENTITY_PublicKey *value_zone, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
Look for an existing PKEY delegation record for a given public key.
int(* iterate_records)(void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone, uint64_t serial, uint64_t limit, GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
Iterate over the results for a particular zone in the datastore.
int(* store_records)(void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Store a record in the datastore for which we are the authority.
void * cls
Closure to pass to all plugin functions.

References _, cfg, Plugin::cfg, GNUNET_NAMESTORE_PluginFunctions::cls, database_setup(), database_shutdown(), GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_new, GNUNET_OK, GNUNET_NAMESTORE_PluginFunctions::iterate_records, GNUNET_NAMESTORE_PluginFunctions::lookup_records, namestore_flat_iterate_records(), namestore_flat_lookup_records(), namestore_flat_store_records(), namestore_flat_zone_to_name(), plugin, GNUNET_NAMESTORE_PluginFunctions::store_records, and GNUNET_NAMESTORE_PluginFunctions::zone_to_name.

Here is the call graph for this function:

◆ libgnunet_plugin_namestore_flat_done()

void* libgnunet_plugin_namestore_flat_done ( void *  cls)

Exit point from the plugin.

Parameters
clsthe plugin context (as returned by "init")
Returns
always NULL

Definition at line 804 of file plugin_namestore_flat.c.

805 {
807  struct Plugin *plugin = api->cls;
808 
810  plugin->cfg = NULL;
811  GNUNET_free (api);
813  "Flat file plugin is finished\n");
814  return NULL;
815 }
void * cls
Closure for all of the callbacks.
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:47

References Plugin::api, Plugin::cfg, GNUNET_BLOCK_PluginFunctions::cls, GNUNET_NAMESTORE_PluginFunctions::cls, database_shutdown(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, and plugin.

Here is the call graph for this function: