GNUnet  0.20.0
plugin_peerstore_flat.c File Reference

flat file-based peerstore backend More...

#include "platform.h"
#include "gnunet_peerstore_plugin.h"
#include "gnunet_peerstore_service.h"
#include "peerstore.h"
Include dependency graph for plugin_peerstore_flat.c:

Go to the source code of this file.

Data Structures

struct  Plugin
 Handle for a plugin. More...
 

Functions

static int delete_entries (void *cls, const struct GNUNET_HashCode *key, void *value)
 
static int peerstore_flat_delete_records (void *cls, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key)
 Delete records with the given key. More...
 
static int expire_entries (void *cls, const struct GNUNET_HashCode *key, void *value)
 
static int peerstore_flat_expire_records (void *cls, struct GNUNET_TIME_Absolute now, GNUNET_PEERSTORE_Continuation cont, void *cont_cls)
 Delete expired records (expiry < now) More...
 
static int iterate_entries (void *cls, const struct GNUNET_HashCode *key, void *value)
 
static int peerstore_flat_iterate_records (void *cls, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, GNUNET_PEERSTORE_Processor iter, void *iter_cls)
 Iterate over the records given an optional peer id and/or key. More...
 
static int peerstore_flat_store_record (void *cls, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, const void *value, size_t size, struct GNUNET_TIME_Absolute expiry, enum GNUNET_PEERSTORE_StoreOption options, GNUNET_PEERSTORE_Continuation cont, void *cont_cls)
 Store a record in the peerstore. 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)
 
static void database_shutdown (struct Plugin *plugin)
 Shutdown database connection and associate data structures. More...
 
void * libgnunet_plugin_peerstore_flat_init (void *cls)
 Entry point for the plugin. More...
 
void * libgnunet_plugin_peerstore_flat_done (void *cls)
 Exit point from the plugin. More...
 

Detailed Description

flat file-based peerstore backend

Author
Martin Schanzenbach

Definition in file plugin_peerstore_flat.c.

Function Documentation

◆ delete_entries()

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

Definition at line 100 of file plugin_peerstore_flat.c.

103 {
104  struct Plugin *plugin = cls;
105  struct GNUNET_PEERSTORE_Record *entry = value;
106 
107  if (0 != strcmp (plugin->iter_key, entry->key))
108  return GNUNET_YES;
109  if (0 != memcmp (plugin->iter_peer,
110  &entry->peer,
111  sizeof(struct GNUNET_PeerIdentity)))
112  return GNUNET_YES;
113  if (0 != strcmp (plugin->iter_sub_system, entry->sub_system))
114  return GNUNET_YES;
115 
117  plugin->deleted_entries++;
118  return GNUNET_YES;
119 }
struct TestcasePlugin * plugin
The process handle to the testbed service.
struct GNUNET_HashCode key
The key used in the DHT.
static char * value
Value of the record to add/remove.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_remove(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
Remove the given key-value pair from the map.
@ GNUNET_YES
Single PEERSTORE record.
struct GNUNET_PeerIdentity peer
Peer Identity.
char * sub_system
Responsible sub system string.
char * key
Record key string.
The identity of the host (wraps the signing key of the peer).
Handle for a plugin.
Definition: block.c:38

References GNUNET_CONTAINER_multihashmap_remove(), GNUNET_YES, key, GNUNET_PEERSTORE_Record::key, GNUNET_PEERSTORE_Record::peer, plugin, GNUNET_PEERSTORE_Record::sub_system, and value.

Referenced by peerstore_flat_delete_records().

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

◆ peerstore_flat_delete_records()

static int peerstore_flat_delete_records ( void *  cls,
const char *  sub_system,
const struct GNUNET_PeerIdentity peer,
const char *  key 
)
static

Delete records with the given key.

Parameters
clsclosure (internal context for the plugin)
sub_systemname of sub system
peerPeer identity (can be NULL)
keyentry key string (can be NULL)
Returns
number of deleted records

Definition at line 132 of file plugin_peerstore_flat.c.

135 {
136  struct Plugin *plugin = cls;
137 
138  plugin->iter_sub_system = sub_system;
139  plugin->iter_peer = peer;
140  plugin->iter_key = key;
141  plugin->deleted_entries = 0;
142 
145  plugin);
146  return plugin->deleted_entries;
147 }
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
static int delete_entries(void *cls, const struct GNUNET_HashCode *key, void *value)
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.

References delete_entries(), GNUNET_CONTAINER_multihashmap_iterate(), key, peer, and plugin.

Referenced by peerstore_flat_store_record().

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

◆ expire_entries()

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

Definition at line 151 of file plugin_peerstore_flat.c.

154 {
155  struct Plugin *plugin = cls;
156  struct GNUNET_PEERSTORE_Record *entry = value;
157 
158  if (entry->expiry.abs_value_us < plugin->iter_now.abs_value_us)
159  {
161  plugin->exp_changes++;
162  }
163  return GNUNET_YES;
164 }
struct GNUNET_TIME_Absolute expiry
Expiry time of entry.
uint64_t abs_value_us
The actual value.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_PEERSTORE_Record::expiry, GNUNET_CONTAINER_multihashmap_remove(), GNUNET_YES, key, plugin, and value.

Referenced by peerstore_flat_expire_records().

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

◆ peerstore_flat_expire_records()

static int peerstore_flat_expire_records ( void *  cls,
struct GNUNET_TIME_Absolute  now,
GNUNET_PEERSTORE_Continuation  cont,
void *  cont_cls 
)
static

Delete expired records (expiry < now)

Parameters
clsclosure (internal context for the plugin)
nowtime to use as reference
contcontinuation called with the number of records expired
cont_clscontinuation closure
Returns
GNUNET_OK on success, GNUNET_SYSERR on error and cont is not called

Definition at line 178 of file plugin_peerstore_flat.c.

181 {
182  struct Plugin *plugin = cls;
183 
184  plugin->exp_changes = 0;
185  plugin->iter_now = now;
186 
189  plugin);
190  if (NULL != cont)
191  {
192  cont (cont_cls, plugin->exp_changes);
193  }
194  return GNUNET_OK;
195 }
@ GNUNET_OK
static int expire_entries(void *cls, const struct GNUNET_HashCode *key, void *value)

References expire_entries(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_OK, and plugin.

Referenced by libgnunet_plugin_peerstore_flat_init().

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

◆ iterate_entries()

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

Definition at line 199 of file plugin_peerstore_flat.c.

202 {
203  struct Plugin *plugin = cls;
204  struct GNUNET_PEERSTORE_Record *entry = value;
205 
206  if ((NULL != plugin->iter_peer) &&
207  (0 != memcmp (plugin->iter_peer,
208  &entry->peer,
209  sizeof(struct GNUNET_PeerIdentity))))
210  {
211  return GNUNET_YES;
212  }
213  if ((NULL != plugin->iter_key) &&
214  (0 != strcmp (plugin->iter_key,
215  entry->key)))
216  {
217  return GNUNET_YES;
218  }
219  if (NULL != plugin->iter)
220  plugin->iter (plugin->iter_cls, entry, NULL);
221  plugin->iter_result_found = GNUNET_YES;
222  return GNUNET_YES;
223 }

References GNUNET_YES, GNUNET_PEERSTORE_Record::key, GNUNET_PEERSTORE_Record::peer, plugin, and value.

Referenced by peerstore_flat_iterate_records().

Here is the caller graph for this function:

◆ peerstore_flat_iterate_records()

static int peerstore_flat_iterate_records ( void *  cls,
const char *  sub_system,
const struct GNUNET_PeerIdentity peer,
const char *  key,
GNUNET_PEERSTORE_Processor  iter,
void *  iter_cls 
)
static

Iterate over the records given an optional peer id and/or key.

Parameters
clsclosure (internal context for the plugin)
sub_systemname of sub system
peerPeer identity (can be NULL)
keyentry key string (can be NULL)
iterfunction to call asynchronously with the results, terminated by a NULL result
iter_clsclosure for iter
Returns
GNUNET_OK on success, GNUNET_SYSERR on error and iter is not called

Definition at line 241 of file plugin_peerstore_flat.c.

246 {
247  struct Plugin *plugin = cls;
248 
249  plugin->iter = iter;
250  plugin->iter_cls = iter_cls;
251  plugin->iter_peer = peer;
252  plugin->iter_sub_system = sub_system;
253  plugin->iter_key = key;
254 
257  plugin);
258  if (NULL != iter)
259  iter (iter_cls, NULL, NULL);
260  return GNUNET_OK;
261 }
static int iterate_entries(void *cls, const struct GNUNET_HashCode *key, void *value)
void * iter_cls
Iterator cls.
GNUNET_PEERSTORE_Processor iter
Iterator.

References GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_OK, Plugin::iter, Plugin::iter_cls, iterate_entries(), key, peer, and plugin.

Referenced by libgnunet_plugin_peerstore_flat_init().

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

◆ peerstore_flat_store_record()

static int peerstore_flat_store_record ( void *  cls,
const char *  sub_system,
const struct GNUNET_PeerIdentity peer,
const char *  key,
const void *  value,
size_t  size,
struct GNUNET_TIME_Absolute  expiry,
enum GNUNET_PEERSTORE_StoreOption  options,
GNUNET_PEERSTORE_Continuation  cont,
void *  cont_cls 
)
static

Store a record in the peerstore.

Key is the combination of sub system and peer identity. One key can store multiple values.

Parameters
clsclosure (internal context for the plugin)
sub_systemname of the GNUnet sub system responsible
peerpeer identity
keyrecord key string
valuevalue to be stored
sizesize of value to be stored
expiryabsolute time after which the record is (possibly) deleted
optionsoptions related to the store operation
contcontinuation called when record is stored
cont_clscontinuation closure
Returns
GNUNET_OK on success, else GNUNET_SYSERR and cont is not called

Definition at line 282 of file plugin_peerstore_flat.c.

289 {
290  struct Plugin *plugin = cls;
291  struct GNUNET_HashCode hkey;
292  struct GNUNET_PEERSTORE_Record *entry;
293  const char *peer_id;
294 
295 
296  entry = GNUNET_new (struct GNUNET_PEERSTORE_Record);
298  entry->key = GNUNET_strdup (key);
299  entry->value = GNUNET_malloc (size);
300  GNUNET_memcpy (entry->value, value, size);
301  entry->value_size = size;
302  entry->peer = *peer;
303  entry->expiry = expiry;
304 
305  peer_id = GNUNET_i2s (peer);
307  strlen (peer_id),
308  &hkey);
309 
311  {
313  }
314 
316  &hkey,
317  entry,
319  if (NULL != cont)
320  {
321  cont (cont_cls, GNUNET_OK);
322  }
323  return GNUNET_OK;
324 }
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
static char * peer_id
Option –peer.
Definition: gnunet-cadet.c:42
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
enum GNUNET_GenericReturnValue 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_MULTIPLE
Allow multiple values with the same key.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
@ GNUNET_PEERSTORE_STOREOPTION_REPLACE
Delete any previous values for the given key before storing the given value.
static unsigned int size
Size of the "table".
Definition: peer.c:68
static int peerstore_flat_delete_records(void *cls, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key)
Delete records with the given key.
A 512-bit hashcode.
size_t value_size
Size of value BLOB.
void * value
Record value BLOB.

References GNUNET_PEERSTORE_Record::expiry, GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CRYPTO_hash(), GNUNET_i2s(), GNUNET_malloc, GNUNET_memcpy, GNUNET_new, GNUNET_OK, GNUNET_PEERSTORE_STOREOPTION_REPLACE, GNUNET_strdup, key, GNUNET_PEERSTORE_Record::key, options, GNUNET_PEERSTORE_Record::peer, peer, peer_id, peerstore_flat_delete_records(), plugin, size, GNUNET_PEERSTORE_Record::sub_system, GNUNET_PEERSTORE_Record::value, value, and GNUNET_PEERSTORE_Record::value_size.

Referenced by libgnunet_plugin_peerstore_flat_init().

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 336 of file plugin_peerstore_flat.c.

337 {
338  char *afsdir;
339  char *key;
340  char *sub_system;
341  const char *peer_id;
342  char *peer;
343  char *value;
344  char *expiry;
345  struct GNUNET_DISK_FileHandle *fh;
346  struct GNUNET_PEERSTORE_Record *entry;
347  struct GNUNET_HashCode hkey;
348  uint64_t size;
349  char *buffer;
350  char *line;
351 
352  if (GNUNET_OK !=
353  GNUNET_CONFIGURATION_get_value_filename (plugin->cfg, "peerstore-flat",
354  "FILENAME", &afsdir))
355  {
357  "FILENAME");
358  return GNUNET_SYSERR;
359  }
360  if (GNUNET_OK != GNUNET_DISK_file_test (afsdir))
361  {
363  {
364  GNUNET_break (0);
365  GNUNET_free (afsdir);
366  return GNUNET_SYSERR;
367  }
368  }
369  /* afsdir should be UTF-8-encoded. If it isn't, it's a bug */
370  plugin->fn = afsdir;
371 
372  fh = GNUNET_DISK_file_open (afsdir,
377  if (NULL == fh)
378  {
380  _ ("Unable to initialize file: %s.\n"),
381  afsdir);
382  return GNUNET_SYSERR;
383  }
384 
385  /* Load data from file into hashmap */
387  GNUNET_NO);
388 
389  if (GNUNET_SYSERR == GNUNET_DISK_file_size (afsdir,
390  &size,
391  GNUNET_YES,
392  GNUNET_YES))
393  {
395  _ ("Unable to get filesize: %s.\n"),
396  afsdir);
397  return GNUNET_SYSERR;
398  }
399 
400  buffer = GNUNET_malloc (size + 1);
401 
403  buffer,
404  size))
405  {
407  _ ("Unable to read file: %s.\n"),
408  afsdir);
410  GNUNET_free (buffer);
411  return GNUNET_SYSERR;
412  }
413 
414  buffer[size] = '\0';
416  if (0 < size)
417  {
418  line = strtok (buffer, "\n");
419  while (line != NULL)
420  {
421  sub_system = strtok (line, ",");
422  if (NULL == sub_system)
423  break;
424  peer = strtok (NULL, ",");
425  if (NULL == peer)
426  break;
427  key = strtok (NULL, ",");
428  if (NULL == key)
429  break;
430  value = strtok (NULL, ",");
431  if (NULL == value)
432  break;
433  expiry = strtok (NULL, ",");
434  if (NULL == expiry)
435  break;
436  entry = GNUNET_new (struct GNUNET_PEERSTORE_Record);
437  entry->sub_system = GNUNET_strdup (sub_system);
438  entry->key = GNUNET_strdup (key);
439  {
440  size_t s;
441  char *o;
442 
443  o = NULL;
445  strlen (peer),
446  (void **) &o);
447  if (sizeof(struct GNUNET_PeerIdentity) == s)
448  GNUNET_memcpy (&entry->peer,
449  o,
450  s);
451  else
452  GNUNET_break (0);
453  GNUNET_free (o);
454  }
456  strlen (value),
457  (void **) &entry->value);
458  if (GNUNET_SYSERR ==
460  &entry->expiry))
461  {
462  GNUNET_free (entry->sub_system);
463  GNUNET_free (entry->key);
464  GNUNET_free (entry);
465  break;
466  }
467  peer_id = GNUNET_i2s (&entry->peer);
469  strlen (peer_id),
470  &hkey);
471 
473  &hkey,
474  entry,
476  }
477  }
478  GNUNET_free (buffer);
479  return GNUNET_OK;
480 }
static char * line
Desired phone line (string to be converted to a hash).
static struct GNUNET_DISK_FileHandle * fh
File handle to STDIN, for reading restart/quit commands.
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:1237
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:221
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1308
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:582
ssize_t GNUNET_DISK_file_read(const struct GNUNET_DISK_FileHandle *h, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: disk.c:622
@ 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.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
#define GNUNET_log(kind,...)
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#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.
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_free(ptr)
Wrapper around free.
size_t GNUNET_STRINGS_base64_decode(const char *data, size_t len, void **output)
Decode from Base64.
Definition: strings.c:1695
enum GNUNET_GenericReturnValue GNUNET_STRINGS_fancy_time_to_absolute(const char *fancy_time, struct GNUNET_TIME_Absolute *atime)
Convert a given fancy human-readable time to our internal representation.
Definition: strings.c:302
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
Handle used to access files (and pipes).

References _, GNUNET_PEERSTORE_Record::expiry, fh, GNUNET_assert, GNUNET_break, GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CONTAINER_multihashmap_create(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CRYPTO_hash(), GNUNET_DISK_directory_create_for_file(), GNUNET_DISK_file_close(), GNUNET_DISK_file_open(), GNUNET_DISK_file_read(), GNUNET_DISK_file_size(), GNUNET_DISK_file_test(), 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_i2s(), GNUNET_log, GNUNET_log_config_missing(), GNUNET_malloc, GNUNET_memcpy, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_strdup, GNUNET_STRINGS_base64_decode(), GNUNET_STRINGS_fancy_time_to_absolute(), GNUNET_SYSERR, GNUNET_YES, key, GNUNET_PEERSTORE_Record::key, line, GNUNET_PEERSTORE_Record::peer, peer, peer_id, plugin, size, GNUNET_PEERSTORE_Record::sub_system, GNUNET_PEERSTORE_Record::value, value, and GNUNET_PEERSTORE_Record::value_size.

Referenced by libgnunet_plugin_peerstore_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

Definition at line 484 of file plugin_peerstore_flat.c.

487 {
488  struct GNUNET_DISK_FileHandle *fh = cls;
489  struct GNUNET_PEERSTORE_Record *entry = value;
490  char *line;
491  char *peer;
492  const char *expiry;
493  char *val;
494 
496  entry->value_size,
497  &val);
499  GNUNET_STRINGS_base64_encode ((char *) &entry->peer,
500  sizeof(struct GNUNET_PeerIdentity),
501  &peer);
503  "%s,%s,%s,%s,%s",
504  entry->sub_system,
505  peer,
506  entry->key,
507  val,
508  expiry);
509  GNUNET_free (val);
510  GNUNET_free (peer);
512  line,
513  strlen (line));
514  GNUNET_free (entry->sub_system);
515  GNUNET_free (entry->key);
516  GNUNET_free (entry->value);
517  GNUNET_free (entry);
518  GNUNET_free (line);
519  return GNUNET_YES;
520 }
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
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:1607
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:616

References GNUNET_PEERSTORE_Record::expiry, fh, GNUNET_asprintf(), GNUNET_DISK_file_write(), GNUNET_free, GNUNET_STRINGS_absolute_time_to_string(), GNUNET_STRINGS_base64_encode(), GNUNET_YES, GNUNET_PEERSTORE_Record::key, line, GNUNET_PEERSTORE_Record::peer, peer, GNUNET_PEERSTORE_Record::sub_system, GNUNET_PEERSTORE_Record::value, value, and GNUNET_PEERSTORE_Record::value_size.

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 529 of file plugin_peerstore_flat.c.

530 {
531  struct GNUNET_DISK_FileHandle *fh;
532 
539  if (NULL == fh)
540  {
542  _ ("Unable to initialize file: %s.\n"),
543  plugin->fn);
544  return;
545  }
548  fh);
551 }
@ GNUNET_DISK_OPEN_TRUNCATE
Truncate file if it exists.
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)

References _, fh, GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_DISK_file_close(), GNUNET_DISK_file_open(), 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, and store_and_free_entries().

Referenced by libgnunet_plugin_peerstore_flat_done(), and libgnunet_plugin_peerstore_flat_init().

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

◆ libgnunet_plugin_peerstore_flat_init()

void* libgnunet_plugin_peerstore_flat_init ( void *  cls)

Entry point for the plugin.

Parameters
clsThe struct GNUNET_CONFIGURATION_Handle.
Returns
NULL on error, otherwise the plugin context

Definition at line 561 of file plugin_peerstore_flat.c.

562 {
563  static struct Plugin plugin;
564  const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
566 
567  if (NULL != plugin.cfg)
568  return NULL; /* can only initialize once! */
569  memset (&plugin, 0, sizeof(struct Plugin));
570  plugin.cfg = cfg;
571  if (GNUNET_OK != database_setup (&plugin))
572  {
574  return NULL;
575  }
577  api->cls = &plugin;
581  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Flat plugin is running\n");
582  return api;
583 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
@ GNUNET_ERROR_TYPE_DEBUG
static void database_shutdown(struct Plugin *plugin)
Shutdown database connection and associate data structures.
static int peerstore_flat_iterate_records(void *cls, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, GNUNET_PEERSTORE_Processor iter, void *iter_cls)
Iterate over the records given an optional peer id and/or key.
static int peerstore_flat_expire_records(void *cls, struct GNUNET_TIME_Absolute now, GNUNET_PEERSTORE_Continuation cont, void *cont_cls)
Delete expired records (expiry < now)
static int database_setup(struct Plugin *plugin)
Initialize the database connections and associated data structures (create tables and indices as need...
static int peerstore_flat_store_record(void *cls, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, const void *value, size_t size, struct GNUNET_TIME_Absolute expiry, enum GNUNET_PEERSTORE_StoreOption options, GNUNET_PEERSTORE_Continuation cont, void *cont_cls)
Store a record in the peerstore.
struct returned by the initialization function of the plugin
void * cls
Closure to pass to all plugin functions.
int(* store_record)(void *cls, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, const void *value, size_t size, struct GNUNET_TIME_Absolute expiry, enum GNUNET_PEERSTORE_StoreOption options, GNUNET_PEERSTORE_Continuation cont, void *cont_cls)
Store a record in the peerstore.
int(* expire_records)(void *cls, struct GNUNET_TIME_Absolute now, GNUNET_PEERSTORE_Continuation cont, void *cont_cls)
Delete expired records (expiry < now)
int(* iterate_records)(void *cls, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, GNUNET_PEERSTORE_Processor iter, void *iter_cls)
Iterate over the records given an optional peer id and/or key.

References cfg, GNUNET_PEERSTORE_PluginFunctions::cls, database_setup(), database_shutdown(), GNUNET_PEERSTORE_PluginFunctions::expire_records, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_new, GNUNET_OK, GNUNET_PEERSTORE_PluginFunctions::iterate_records, peerstore_flat_expire_records(), peerstore_flat_iterate_records(), peerstore_flat_store_record(), plugin, and GNUNET_PEERSTORE_PluginFunctions::store_record.

Here is the call graph for this function:

◆ libgnunet_plugin_peerstore_flat_done()

void* libgnunet_plugin_peerstore_flat_done ( void *  cls)

Exit point from the plugin.

Parameters
clsThe plugin context (as returned by "init")
Returns
Always NULL

Definition at line 593 of file plugin_peerstore_flat.c.

594 {
596  struct Plugin *plugin = api->cls;
597 
599  plugin->cfg = NULL;
600  GNUNET_free (api);
601  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Flat plugin is finished\n");
602  return NULL;
603 }
void * cls
Closure for all of the callbacks.
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:47

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

Here is the call graph for this function: