GNUnet  0.10.x
Data Structures | Functions
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 99 of file plugin_peerstore_flat.c.

References Plugin::deleted_entries, GNUNET_CONTAINER_multihashmap_remove(), GNUNET_YES, Plugin::hm, Plugin::iter_key, Plugin::iter_peer, Plugin::iter_sub_system, GNUNET_PEERSTORE_Record::key, GNUNET_PEERSTORE_Record::peer, plugin, GNUNET_PEERSTORE_Record::sub_system, and value.

Referenced by peerstore_flat_delete_records().

102 {
103  struct Plugin *plugin = cls;
104  struct GNUNET_PEERSTORE_Record *entry = value;
105 
106  if (0 != strcmp(plugin->iter_key, entry->key))
107  return GNUNET_YES;
108  if (0 != memcmp(plugin->iter_peer,
109  &entry->peer,
110  sizeof(struct GNUNET_PeerIdentity)))
111  return GNUNET_YES;
112  if (0 != strcmp(plugin->iter_sub_system, entry->sub_system))
113  return GNUNET_YES;
114 
116  plugin->deleted_entries++;
117  return GNUNET_YES;
118 }
struct GNUNET_PeerIdentity peer
Peer Identity.
char * key
Record key string.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
uint64_t deleted_entries
Deleted entries.
static char * value
Value of the record to add/remove.
const struct GNUNET_PeerIdentity * iter_peer
Iterator peer.
int 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.
struct GNUNET_CONTAINER_MultiHashMap * hm
HashMap.
The identity of the host (wraps the signing key of the peer).
char * sub_system
Responsible sub system string.
Handle for a plugin.
Definition: block.c:37
Single PEERSTORE record.
const char * iter_sub_system
Iterator subsystem.
#define GNUNET_YES
Definition: gnunet_common.h:77
const char * iter_key
iterator key
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 131 of file plugin_peerstore_flat.c.

References delete_entries(), Plugin::deleted_entries, GNUNET_CONTAINER_multihashmap_iterate(), Plugin::hm, Plugin::iter_key, Plugin::iter_peer, Plugin::iter_sub_system, Plugin::key, peer, and plugin.

Referenced by peerstore_flat_store_record().

134 {
135  struct Plugin *plugin = cls;
136 
137  plugin->iter_sub_system = sub_system;
138  plugin->iter_peer = peer;
139  plugin->iter_key = key;
140  plugin->deleted_entries = 0;
141 
144  plugin);
145  return plugin->deleted_entries;
146 }
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
uint64_t deleted_entries
Deleted entries.
static int delete_entries(void *cls, const struct GNUNET_HashCode *key, void *value)
const struct GNUNET_PeerIdentity * iter_peer
Iterator peer.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct GNUNET_HashCode key
The key used in the DHT.
struct GNUNET_CONTAINER_MultiHashMap * hm
HashMap.
Handle for a plugin.
Definition: block.c:37
const char * iter_sub_system
Iterator subsystem.
const char * iter_key
iterator key
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
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 149 of file plugin_peerstore_flat.c.

References GNUNET_TIME_Absolute::abs_value_us, Plugin::exp_changes, GNUNET_PEERSTORE_Record::expiry, GNUNET_CONTAINER_multihashmap_remove(), GNUNET_YES, Plugin::hm, Plugin::iter_now, plugin, and value.

Referenced by peerstore_flat_expire_records().

152 {
153  struct Plugin *plugin = cls;
154  struct GNUNET_PEERSTORE_Record *entry = value;
155 
156  if (entry->expiry.abs_value_us < plugin->iter_now.abs_value_us)
157  {
159  plugin->exp_changes++;
160  }
161  return GNUNET_YES;
162 }
struct GNUNET_TIME_Absolute iter_now
Iterator time.
uint64_t abs_value_us
The actual value.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
static char * value
Value of the record to add/remove.
int 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.
struct GNUNET_CONTAINER_MultiHashMap * hm
HashMap.
uint64_t exp_changes
Expired entries.
struct GNUNET_TIME_Absolute expiry
Expiry time of entry.
Handle for a plugin.
Definition: block.c:37
Single PEERSTORE record.
#define GNUNET_YES
Definition: gnunet_common.h:77
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 177 of file plugin_peerstore_flat.c.

References Plugin::exp_changes, expire_entries(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_OK, Plugin::hm, Plugin::iter_now, and plugin.

Referenced by libgnunet_plugin_peerstore_flat_init().

180 {
181  struct Plugin *plugin = cls;
182 
183  plugin->exp_changes = 0;
184  plugin->iter_now = now;
185 
188  plugin);
189  if (NULL != cont)
190  {
191  cont(cont_cls, plugin->exp_changes);
192  }
193  return GNUNET_OK;
194 }
struct GNUNET_TIME_Absolute iter_now
Iterator time.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
static int expire_entries(void *cls, const struct GNUNET_HashCode *key, void *value)
struct GNUNET_CONTAINER_MultiHashMap * hm
HashMap.
uint64_t exp_changes
Expired entries.
Handle for a plugin.
Definition: block.c:37
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
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 198 of file plugin_peerstore_flat.c.

References GNUNET_YES, Plugin::iter, Plugin::iter_cls, Plugin::iter_key, Plugin::iter_peer, Plugin::iter_result_found, GNUNET_PEERSTORE_Record::key, GNUNET_PEERSTORE_Record::peer, plugin, and value.

Referenced by peerstore_flat_iterate_records().

201 {
202  struct Plugin *plugin = cls;
203  struct GNUNET_PEERSTORE_Record *entry = value;
204 
205  if ((NULL != plugin->iter_peer) &&
206  (0 != memcmp(plugin->iter_peer,
207  &entry->peer,
208  sizeof(struct GNUNET_PeerIdentity))))
209  {
210  return GNUNET_YES;
211  }
212  if ((NULL != plugin->iter_key) &&
213  (0 != strcmp(plugin->iter_key,
214  entry->key)))
215  {
216  return GNUNET_YES;
217  }
218  if (NULL != plugin->iter)
219  plugin->iter(plugin->iter_cls, entry, NULL);
220  plugin->iter_result_found = GNUNET_YES;
221  return GNUNET_YES;
222 }
struct GNUNET_PeerIdentity peer
Peer Identity.
char * key
Record key string.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
static char * value
Value of the record to add/remove.
const struct GNUNET_PeerIdentity * iter_peer
Iterator peer.
void * iter_cls
Iterator cls.
The identity of the host (wraps the signing key of the peer).
Handle for a plugin.
Definition: block.c:37
Single PEERSTORE record.
int iter_result_found
Result found bool.
#define GNUNET_YES
Definition: gnunet_common.h:77
const char * iter_key
iterator key
GNUNET_PEERSTORE_Processor iter
Iterator.
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 239 of file plugin_peerstore_flat.c.

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

Referenced by libgnunet_plugin_peerstore_flat_init().

244 {
245  struct Plugin *plugin = cls;
246 
247  plugin->iter = iter;
248  plugin->iter_cls = iter_cls;
249  plugin->iter_peer = peer;
250  plugin->iter_sub_system = sub_system;
251  plugin->iter_key = key;
252 
255  plugin);
256  if (NULL != iter)
257  iter(iter_cls, NULL, NULL);
258  return GNUNET_OK;
259 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static int iterate_entries(void *cls, const struct GNUNET_HashCode *key, void *value)
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
const struct GNUNET_PeerIdentity * iter_peer
Iterator peer.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct GNUNET_HashCode key
The key used in the DHT.
struct GNUNET_CONTAINER_MultiHashMap * hm
HashMap.
void * iter_cls
Iterator cls.
Handle for a plugin.
Definition: block.c:37
const char * iter_sub_system
Iterator subsystem.
const char * iter_key
iterator key
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
GNUNET_PEERSTORE_Processor iter
Iterator.
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 280 of file plugin_peerstore_flat.c.

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, Plugin::hm, GNUNET_PEERSTORE_Record::key, GNUNET_PEERSTORE_Record::peer, peer, peer_id, peerstore_flat_delete_records(), plugin, Plugin::size, GNUNET_PEERSTORE_Record::sub_system, GNUNET_PEERSTORE_Record::value, and GNUNET_PEERSTORE_Record::value_size.

Referenced by libgnunet_plugin_peerstore_flat_init().

287 {
288  struct Plugin *plugin = cls;
289  struct GNUNET_HashCode hkey;
290  struct GNUNET_PEERSTORE_Record *entry;
291  const char *peer_id;
292 
293 
294  entry = GNUNET_new(struct GNUNET_PEERSTORE_Record);
296  entry->key = GNUNET_strdup(key);
297  entry->value = GNUNET_malloc(size);
298  GNUNET_memcpy(entry->value, value, size);
299  entry->value_size = size;
300  entry->peer = *peer;
301  entry->expiry = expiry;
302 
303  peer_id = GNUNET_i2s(peer);
304  GNUNET_CRYPTO_hash(peer_id,
305  strlen(peer_id),
306  &hkey);
307 
309  {
311  }
312 
314  &hkey,
315  entry,
317  if (NULL != cont)
318  {
319  cont(cont_cls, GNUNET_OK);
320  }
321  return GNUNET_OK;
322 }
struct GNUNET_PeerIdentity peer
Peer Identity.
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
Delete any previous values for the given key before storing the given value.
size_t value_size
Size of value BLOB.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
static char * peer_id
Option –peer.
Definition: gnunet-cadet.c:42
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
char * key
Record key string.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
void * value
Record value BLOB.
static char * value
Value of the record to add/remove.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:44
A 512-bit hashcode.
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.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct GNUNET_HashCode key
The key used in the DHT.
static unsigned int size
Size of the "table".
Definition: peer.c:66
struct GNUNET_CONTAINER_MultiHashMap * hm
HashMap.
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.
Allow multiple values with the same key.
struct GNUNET_TIME_Absolute expiry
Expiry time of entry.
char * sub_system
Responsible sub system string.
Handle for a plugin.
Definition: block.c:37
Single PEERSTORE record.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_malloc(size)
Wrapper around malloc.
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 334 of file plugin_peerstore_flat.c.

References _, Plugin::cfg, GNUNET_PEERSTORE_Record::expiry, fh, Plugin::fn, 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_free_non_null, 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, Plugin::hm, GNUNET_PEERSTORE_Record::key, Plugin::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().

335 {
336  char *afsdir;
337  char *key;
338  char *sub_system;
339  const char *peer_id;
340  char *peer;
341  char *value;
342  char *expiry;
343  struct GNUNET_DISK_FileHandle *fh;
344  struct GNUNET_PEERSTORE_Record *entry;
345  struct GNUNET_HashCode hkey;
346  size_t size;
347  char *buffer;
348  char *line;
349 
350  if (GNUNET_OK !=
351  GNUNET_CONFIGURATION_get_value_filename(plugin->cfg, "peerstore-flat",
352  "FILENAME", &afsdir))
353  {
355  "FILENAME");
356  return GNUNET_SYSERR;
357  }
358  if (GNUNET_OK != GNUNET_DISK_file_test(afsdir))
359  {
361  {
362  GNUNET_break(0);
363  GNUNET_free(afsdir);
364  return GNUNET_SYSERR;
365  }
366  }
367  /* afsdir should be UTF-8-encoded. If it isn't, it's a bug */
368  plugin->fn = afsdir;
369 
370  fh = GNUNET_DISK_file_open(afsdir,
375  if (NULL == fh)
376  {
378  _("Unable to initialize file: %s.\n"),
379  afsdir);
380  return GNUNET_SYSERR;
381  }
382 
383  /* Load data from file into hashmap */
385  GNUNET_NO);
386 
387  if (GNUNET_SYSERR == GNUNET_DISK_file_size(afsdir,
388  &size,
389  GNUNET_YES,
390  GNUNET_YES))
391  {
393  _("Unable to get filesize: %s.\n"),
394  afsdir);
395  return GNUNET_SYSERR;
396  }
397 
398  buffer = GNUNET_malloc(size + 1);
399 
401  buffer,
402  size))
403  {
405  _("Unable to read file: %s.\n"),
406  afsdir);
408  GNUNET_free(buffer);
409  return GNUNET_SYSERR;
410  }
411 
412  buffer[size] = '\0';
414  if (0 < size)
415  {
416  line = strtok(buffer, "\n");
417  while (line != NULL)
418  {
419  sub_system = strtok(line, ",");
420  if (NULL == sub_system)
421  break;
422  peer = strtok(NULL, ",");
423  if (NULL == peer)
424  break;
425  key = strtok(NULL, ",");
426  if (NULL == key)
427  break;
428  value = strtok(NULL, ",");
429  if (NULL == value)
430  break;
431  expiry = strtok(NULL, ",");
432  if (NULL == expiry)
433  break;
434  entry = GNUNET_new(struct GNUNET_PEERSTORE_Record);
435  entry->sub_system = GNUNET_strdup(sub_system);
436  entry->key = GNUNET_strdup(key);
437  {
438  size_t s;
439  char *o;
440 
441  o = NULL;
443  strlen(peer),
444  (void**)&o);
445  if (sizeof(struct GNUNET_PeerIdentity) == s)
446  GNUNET_memcpy(&entry->peer,
447  o,
448  s);
449  else
450  GNUNET_break(0);
452  }
454  strlen(value),
455  (void**)&entry->value);
456  if (GNUNET_SYSERR ==
458  &entry->expiry))
459  {
460  GNUNET_free(entry->sub_system);
461  GNUNET_free(entry->key);
462  GNUNET_free(entry);
463  break;
464  }
465  peer_id = GNUNET_i2s(&entry->peer);
466  GNUNET_CRYPTO_hash(peer_id,
467  strlen(peer_id),
468  &hkey);
469 
471  &hkey,
472  entry,
474  }
475  }
476  GNUNET_free(buffer);
477  return GNUNET_OK;
478 }
int 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:541
Create file if it doesn&#39;t exist.
int GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1339
struct GNUNET_PeerIdentity peer
Peer Identity.
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:729
size_t value_size
Size of value BLOB.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
int 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:401
int GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:681
static char * peer_id
Option –peer.
Definition: gnunet-cadet.c:42
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
char * key
Record key string.
void * value
Record value BLOB.
static char * line
Desired phone line (string to be converted to a hash).
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
static char * value
Value of the record to add/remove.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:44
static int fh
Handle to the unique file.
A 512-bit hashcode.
size_t GNUNET_STRINGS_base64_decode(const char *data, size_t len, void **output)
Decode from Base64.
Definition: strings.c:1920
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct GNUNET_HashCode key
The key used in the DHT.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static unsigned int size
Size of the "table".
Definition: peer.c:66
struct GNUNET_CONTAINER_MultiHashMap * hm
HashMap.
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.
int 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:254
char * fn
Filename used for the DB.
Allow multiple values with the same key.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_TIME_Absolute expiry
Expiry time of entry.
char * sub_system
Responsible sub system string.
Single PEERSTORE record.
#define GNUNET_log(kind,...)
Open the file for both reading and writing.
int 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_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
#define GNUNET_YES
Definition: gnunet_common.h:77
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:1262
Handle used to access files (and pipes).
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
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 481 of file plugin_peerstore_flat.c.

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().

484 {
485  struct GNUNET_DISK_FileHandle *fh = cls;
486  struct GNUNET_PEERSTORE_Record *entry = value;
487  char *line;
488  char *peer;
489  const char *expiry;
490  char *val;
491 
493  entry->value_size,
494  &val);
496  GNUNET_STRINGS_base64_encode((char*)&entry->peer,
497  sizeof(struct GNUNET_PeerIdentity),
498  &peer);
499  GNUNET_asprintf(&line,
500  "%s,%s,%s,%s,%s",
501  entry->sub_system,
502  peer,
503  entry->key,
504  val,
505  expiry);
506  GNUNET_free(val);
507  GNUNET_free(peer);
509  line,
510  strlen(line));
511  GNUNET_free(entry->sub_system);
512  GNUNET_free(entry->key);
513  GNUNET_free(entry->value);
514  GNUNET_free(entry);
515  GNUNET_free(line);
516  return GNUNET_YES;
517 }
struct GNUNET_PeerIdentity peer
Peer Identity.
size_t value_size
Size of value BLOB.
char * key
Record key string.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
void * value
Record value BLOB.
static char * line
Desired phone line (string to be converted to a hash).
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:817
static int fh
Handle to the unique file.
size_t GNUNET_STRINGS_base64_encode(const void *in, size_t len, char **output)
Encode into Base64.
Definition: strings.c:1856
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_TIME_Absolute expiry
Expiry time of entry.
char * sub_system
Responsible sub system string.
Single PEERSTORE record.
#define GNUNET_YES
Definition: gnunet_common.h:77
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:741
Handle used to access files (and pipes).
#define GNUNET_free(ptr)
Wrapper around free.
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 525 of file plugin_peerstore_flat.c.

References _, fh, Plugin::fn, 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::hm, and store_and_free_entries().

Referenced by libgnunet_plugin_peerstore_flat_done(), and libgnunet_plugin_peerstore_flat_init().

526 {
527  struct GNUNET_DISK_FileHandle *fh;
528 
529  fh = GNUNET_DISK_file_open(plugin->fn,
535  if (NULL == fh)
536  {
538  _("Unable to initialize file: %s.\n"),
539  plugin->fn);
540  return;
541  }
544  fh);
547 }
Create file if it doesn&#39;t exist.
int GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1339
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static int store_and_free_entries(void *cls, const struct GNUNET_HashCode *key, void *value)
Truncate file if it exists.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
static int fh
Handle to the unique file.
struct GNUNET_CONTAINER_MultiHashMap * hm
HashMap.
char * fn
Filename used for the DB.
#define GNUNET_log(kind,...)
Open the file for both reading and writing.
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
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:1262
Handle used to access files (and pipes).
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 557 of file plugin_peerstore_flat.c.

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

558 {
559  static struct Plugin plugin;
560  const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
562 
563  if (NULL != plugin.cfg)
564  return NULL; /* can only initialize once! */
565  memset(&plugin, 0, sizeof(struct Plugin));
566  plugin.cfg = cfg;
568  {
570  return NULL;
571  }
573  api->cls = &plugin;
577  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Flat plugin is running\n");
578  return api;
579 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
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.
static void database_shutdown(struct Plugin *plugin)
Shutdown database connection and associate data structures.
void * cls
Closure to pass to all plugin functions.
int(* expire_records)(void *cls, struct GNUNET_TIME_Absolute now, GNUNET_PEERSTORE_Continuation cont, void *cont_cls)
Delete expired records (expiry < now)
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
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)
struct returned by the initialization function of the plugin
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:104
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.
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.
configuration data
Definition: configuration.c:83
Handle for a plugin.
Definition: block.c:37
#define GNUNET_log(kind,...)
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 database_setup(struct Plugin *plugin)
Initialize the database connections and associated data structures (create tables and indices as need...
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 589 of file plugin_peerstore_flat.c.

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

590 {
592  struct Plugin *plugin = api->cls;
593 
594  database_shutdown(plugin);
595  plugin->cfg = NULL;
596  GNUNET_free(api);
597  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Flat plugin is finished\n");
598  return NULL;
599 }
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static void database_shutdown(struct Plugin *plugin)
Shutdown database connection and associate data structures.
void * cls
Closure to pass to all plugin functions.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
struct returned by the initialization function of the plugin
Handle for a plugin.
Definition: block.c:37
#define GNUNET_log(kind,...)
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function: