GNUnet  0.10.x
Data Structures | Functions
plugin_namecache_flat.c File Reference

flat file-based namecache backend More...

#include "platform.h"
#include "gnunet_namecache_plugin.h"
#include "gnunet_namecache_service.h"
#include "gnunet_gnsrecord_lib.h"
#include "namecache.h"
Include dependency graph for plugin_namecache_flat.c:

Go to the source code of this file.

Data Structures

struct  Plugin
 Handle for a plugin. More...
 
struct  FlatFileEntry
 

Functions

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 expire_blocks (void *cls, const struct GNUNET_HashCode *key, void *value)
 
static void namecache_expire_blocks (struct Plugin *plugin)
 Removes any expired block. More...
 
static int namecache_cache_block (void *cls, const struct GNUNET_GNSRECORD_Block *block)
 Cache a block in the datastore. More...
 
static int namecache_lookup_block (void *cls, const struct GNUNET_HashCode *query, GNUNET_NAMECACHE_BlockCallback iter, void *iter_cls)
 Get the block for a particular zone and label in the datastore. More...
 
void * libgnunet_plugin_namecache_flat_init (void *cls)
 Entry point for the plugin. More...
 
void * libgnunet_plugin_namecache_flat_done (void *cls)
 Exit point from the plugin. More...
 

Detailed Description

flat file-based namecache backend

Author
Martin Schanzenbach

Definition in file plugin_namecache_flat.c.

Function Documentation

◆ 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 76 of file plugin_namecache_flat.c.

References _, FlatFileEntry::block, Plugin::cfg, fh, Plugin::fn, GNUNET_assert, GNUNET_break, GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CONTAINER_multihashmap_create(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CRYPTO_hash_from_string, 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_log, GNUNET_log_config_missing(), GNUNET_malloc, GNUNET_NO, GNUNET_OK, GNUNET_STRINGS_base64_decode(), GNUNET_SYSERR, GNUNET_YES, Plugin::hm, line, FlatFileEntry::query, and Plugin::size.

Referenced by libgnunet_plugin_namecache_flat_init().

77 {
78  char *afsdir;
79  char* block_buffer;
80  char* buffer;
81  char* line;
82  char* query;
83  char* block;
84  size_t size;
85  struct FlatFileEntry *entry;
86  struct GNUNET_DISK_FileHandle *fh;
87 
88  if (GNUNET_OK !=
90  "namecache-flat",
91  "FILENAME",
92  &afsdir))
93  {
95  "namecache-flat", "FILENAME");
96  return GNUNET_SYSERR;
97  }
98  if (GNUNET_OK != GNUNET_DISK_file_test (afsdir))
99  {
101  {
102  GNUNET_break (0);
103  GNUNET_free (afsdir);
104  return GNUNET_SYSERR;
105  }
106  }
107  /* afsdir should be UTF-8-encoded. If it isn't, it's a bug */
108  plugin->fn = afsdir;
109 
110  /* Load data from file into hashmap */
112  GNUNET_NO);
113  fh = GNUNET_DISK_file_open (afsdir,
118  if (NULL == fh)
119  {
121  _("Unable to initialize file: %s.\n"),
122  afsdir);
123  return GNUNET_SYSERR;
124  }
125 
126  if (GNUNET_SYSERR == GNUNET_DISK_file_size (afsdir,
127  &size,
128  GNUNET_YES,
129  GNUNET_YES))
130  {
132  _("Unable to get filesize: %s.\n"),
133  afsdir);
135  return GNUNET_SYSERR;
136  }
137 
138  if (0 == size)
139  {
141  return GNUNET_OK;
142  }
143 
144  buffer = GNUNET_malloc (size + 1);
145 
147  buffer,
148  size))
149  {
151  _("Unable to read file: %s.\n"),
152  afsdir);
153  GNUNET_free (buffer);
155  return GNUNET_SYSERR;
156  }
157  buffer[size] = '\0';
158 
160  if (0 < size)
161  {
162  line = strtok (buffer, "\n");
163  while (line != NULL) {
164  query = strtok (line, ",");
165  if (NULL == query)
166  break;
167  block = strtok (NULL, ",");
168  if (NULL == block)
169  break;
170  line = strtok (NULL, "\n");
171  entry = GNUNET_malloc (sizeof (struct FlatFileEntry));
173  &entry->query));
175  strlen (block),
176  (void**)&block_buffer);
177  entry->block = (struct GNUNET_GNSRECORD_Block *) block_buffer;
178  if (GNUNET_OK !=
180  &entry->query,
181  entry,
183  {
184  GNUNET_free (entry);
185  GNUNET_break (0);
186  }
187  }
188  }
189  GNUNET_free (buffer);
190  return GNUNET_OK;
191 }
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:669
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:1817
struct GNUNET_GNSRECORD_Block * block
Block.
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:881
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_HashCode query
query
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
int GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:833
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
Information we have in an encrypted block with record data (i.e.
#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:208
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 int fh
Handle to the unique file.
size_t GNUNET_STRINGS_base64_decode(const char *data, size_t len, void **output)
Decode from Base64.
Definition: strings.c:2067
There must only be one value per key; storing a value should fail if a value under the same key alrea...
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
static unsigned int size
Size of the "table".
Definition: peer.c:67
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:289
char * fn
Filename used for the DB.
#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:80
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:1673
#define GNUNET_CRYPTO_hash_from_string(enc, result)
Convert ASCII encoding back to struct GNUNET_HashCode
Handle used to access files (and pipes).
#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

Store values in hashmap in file and free data.

Parameters
pluginthe plugin context

Definition at line 199 of file plugin_namecache_flat.c.

References FlatFileEntry::block, fh, GNUNET_asprintf(), GNUNET_CRYPTO_hash_to_enc(), GNUNET_DISK_file_write(), GNUNET_free, GNUNET_STRINGS_base64_encode(), GNUNET_YES, line, GNUNET_GNSRECORD_Block::purpose, FlatFileEntry::query, GNUNET_CRYPTO_EccSignaturePurpose::size, and value.

Referenced by database_shutdown().

202 {
203  struct GNUNET_DISK_FileHandle *fh = cls;
204  struct FlatFileEntry *entry = value;
205 
206  char *line;
207  char *block_b64;
208  struct GNUNET_CRYPTO_HashAsciiEncoded query;
209  size_t block_size;
210 
211  block_size = ntohl (entry->block->purpose.size) +
212  sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) +
213  sizeof (struct GNUNET_CRYPTO_EcdsaSignature);
214 
215  GNUNET_STRINGS_base64_encode ((char*)entry->block,
216  block_size,
217  &block_b64);
219  &query);
220  GNUNET_asprintf (&line,
221  "%s,%s\n",
222  (char*)&query,
223  block_b64);
224 
225  GNUNET_free (block_b64);
226 
228  line,
229  strlen (line));
230 
231  GNUNET_free (entry->block);
232  GNUNET_free (entry);
233  GNUNET_free (line);
234  return GNUNET_YES;
235 }
struct GNUNET_GNSRECORD_Block * block
Block.
struct GNUNET_HashCode query
query
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
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:1049
an ECC signature using ECDSA
static int fh
Handle to the unique file.
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!)...
size_t GNUNET_STRINGS_base64_encode(const void *in, size_t len, char **output)
Encode into Base64.
Definition: strings.c:2004
void GNUNET_CRYPTO_hash_to_enc(const struct GNUNET_HashCode *block, struct GNUNET_CRYPTO_HashAsciiEncoded *result)
Convert hash to ASCII encoding.
Definition: crypto_hash.c:69
0-terminated ASCII encoding of a struct GNUNET_HashCode.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
#define GNUNET_YES
Definition: gnunet_common.h:80
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Number of bytes signed; also specifies the number of bytes of encrypted data that follow...
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 243 of file plugin_namecache_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_namecache_flat_done(), and libgnunet_plugin_namecache_flat_init().

244 {
245  struct GNUNET_DISK_FileHandle *fh;
246  fh = GNUNET_DISK_file_open (plugin->fn,
252  if (NULL == fh)
253  {
255  _("Unable to initialize file: %s.\n"),
256  plugin->fn);
257  return;
258  }
259 
262  fh);
265 
266 }
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:1817
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_HashMapIterator it, void *it_cls)
Iterate over all entries in the map.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
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.
static int store_and_free_entries(void *cls, const struct GNUNET_HashCode *key, void *value)
Store values in hashmap in file and free data.
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.
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:1673
Handle used to access files (and pipes).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ expire_blocks()

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

Definition at line 269 of file plugin_namecache_flat.c.

References FlatFileEntry::block, GNUNET_GNSRECORD_Block::expiration_time, GNUNET_CONTAINER_multihashmap_remove_all(), GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_get_difference(), GNUNET_TIME_absolute_ntoh(), GNUNET_YES, Plugin::hm, plugin, and value.

272 {
273  struct Plugin *plugin = cls;
274  struct FlatFileEntry *entry = value;
275  struct GNUNET_TIME_Absolute now;
277 
278  now = GNUNET_TIME_absolute_get ();
280 
282  expiration).rel_value_us)
283  {
285  }
286  return GNUNET_YES;
287 }
struct GNUNET_TIME_AbsoluteNBO expiration_time
Expiration time of the block.
static char * expiration
Credential TTL.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:670
struct GNUNET_GNSRECORD_Block * block
Block.
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.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
static char * value
Value of the record to add/remove.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
struct GNUNET_CONTAINER_MultiHashMap * hm
HashMap.
Handle for a plugin.
Definition: block.c:37
Time for absolute times used by GNUnet, in microseconds.
#define GNUNET_YES
Definition: gnunet_common.h:80
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_difference(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Absolute end)
Compute the time difference between the given start and end times.
Definition: time.c:353
Here is the call graph for this function:

◆ namecache_expire_blocks()

static void namecache_expire_blocks ( struct Plugin plugin)
static

Removes any expired block.

Parameters
pluginthe plugin

Definition at line 297 of file plugin_namecache_flat.c.

References Plugin::expire_blocks, GNUNET_CONTAINER_multihashmap_iterate(), and Plugin::hm.

Referenced by namecache_cache_block().

298 {
300  &expire_blocks,
301  plugin);
302 }
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_HashMapIterator it, void *it_cls)
Iterate over all entries in the map.
struct GNUNET_CONTAINER_MultiHashMap * hm
HashMap.
static int expire_blocks(void *cls, const struct GNUNET_HashCode *key, void *value)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ namecache_cache_block()

static int namecache_cache_block ( void *  cls,
const struct GNUNET_GNSRECORD_Block block 
)
static

Cache a block in the datastore.

Parameters
clsclosure (internal context for the plugin)
blockblock to cache
Returns
GNUNET_OK on success, else GNUNET_SYSERR

Definition at line 313 of file plugin_namecache_flat.c.

References FlatFileEntry::block, GNUNET_GNSRECORD_Block::derived_key, GNUNET_break, GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_multihashmap_remove_all(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_h2s_full(), GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_OK, GNUNET_SYSERR, Plugin::hm, namecache_expire_blocks(), plugin, GNUNET_GNSRECORD_Block::purpose, and GNUNET_CRYPTO_EccSignaturePurpose::size.

Referenced by libgnunet_plugin_namecache_flat_init().

315 {
316  struct Plugin *plugin = cls;
317  struct GNUNET_HashCode query;
318  struct FlatFileEntry *entry;
319  size_t block_size;
320 
321  namecache_expire_blocks (plugin);
323  sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey),
324  &query);
325  block_size = ntohl (block->purpose.size) +
326  sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) +
327  sizeof (struct GNUNET_CRYPTO_EcdsaSignature);
328  if (block_size > 64 * 65536)
329  {
330  GNUNET_break (0);
331  return GNUNET_SYSERR;
332  }
333  entry = GNUNET_malloc (sizeof (struct FlatFileEntry));
334  entry->block = GNUNET_malloc (block_size);
335  GNUNET_memcpy (entry->block, block, block_size);
337  if (GNUNET_OK !=
339  &query,
340  entry,
342  {
343  GNUNET_free (entry);
344  GNUNET_break (0);
345  return GNUNET_SYSERR;
346  }
348  "Caching block under derived key `%s'\n",
349  GNUNET_h2s_full (&query));
350  return GNUNET_OK;
351 }
struct GNUNET_GNSRECORD_Block * block
Block.
struct GNUNET_HashCode query
query
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
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.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
#define GNUNET_memcpy(dst, src, n)
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
an ECC signature using ECDSA
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!)...
static void namecache_expire_blocks(struct Plugin *plugin)
Removes any expired block.
A 512-bit hashcode.
There must only be one value per key; storing a value should fail if a value under the same key alrea...
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
struct GNUNET_CONTAINER_MultiHashMap * hm
HashMap.
const char * GNUNET_h2s_full(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
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.
Handle for a plugin.
Definition: block.c:37
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
#define GNUNET_log(kind,...)
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Number of bytes signed; also specifies the number of bytes of encrypted data that follow...
struct GNUNET_CRYPTO_EcdsaPublicKey derived_key
Derived key used for signing; hash of this is the query.
#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:

◆ namecache_lookup_block()

static int namecache_lookup_block ( void *  cls,
const struct GNUNET_HashCode query,
GNUNET_NAMECACHE_BlockCallback  iter,
void *  iter_cls 
)
static

Get the block for a particular zone and label in the datastore.

Will return at most one result to the iterator.

Parameters
clsclosure (internal context for the plugin)
queryhash of public key derived from the zone and the label
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 365 of file plugin_namecache_flat.c.

References GNUNET_CONTAINER_multihashmap_get(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s_full(), GNUNET_log, GNUNET_NO, GNUNET_YES, Plugin::hm, Plugin::iter, and plugin.

Referenced by libgnunet_plugin_namecache_flat_init().

368 {
369  struct Plugin *plugin = cls;
370  const struct GNUNET_GNSRECORD_Block *block;
371 
372  block = GNUNET_CONTAINER_multihashmap_get (plugin->hm, query);
373  if (NULL == block)
374  return GNUNET_NO;
376  "Found block under derived key `%s'\n",
377  GNUNET_h2s_full (query));
378  iter (iter_cls, block);
379  return GNUNET_YES;
380 }
#define GNUNET_NO
Definition: gnunet_common.h:81
Information we have in an encrypted block with record data (i.e.
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.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
struct GNUNET_CONTAINER_MultiHashMap * hm
HashMap.
const char * GNUNET_h2s_full(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
Handle for a plugin.
Definition: block.c:37
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:80
Here is the call graph for this function:
Here is the caller graph for this function:

◆ libgnunet_plugin_namecache_flat_init()

void* libgnunet_plugin_namecache_flat_init ( void *  cls)

Entry point for the plugin.

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

Definition at line 390 of file plugin_namecache_flat.c.

References _, Plugin::api, GNUNET_NAMECACHE_PluginFunctions::cache_block, Plugin::cfg, GNUNET_NAMECACHE_PluginFunctions::cls, database_setup(), database_shutdown(), GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_new, GNUNET_OK, GNUNET_NAMECACHE_PluginFunctions::lookup_block, namecache_cache_block(), namecache_lookup_block(), and plugin.

391 {
392  static struct Plugin plugin;
393  const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
395 
396  if (NULL != plugin.cfg)
397  return NULL; /* can only initialize once! */
398  memset (&plugin, 0, sizeof (struct Plugin));
399  plugin.cfg = cfg;
400  if (GNUNET_OK != database_setup (&plugin))
401  {
403  return NULL;
404  }
406  api->cls = &plugin;
410  _("flat plugin running\n"));
411  return api;
412 }
void * cls
Closure to pass to all plugin functions.
static int namecache_cache_block(void *cls, const struct GNUNET_GNSRECORD_Block *block)
Cache a block in the datastore.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
int(* cache_block)(void *cls, const struct GNUNET_GNSRECORD_Block *block)
Cache a block in the datastore.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
int(* lookup_block)(void *cls, const struct GNUNET_HashCode *query, GNUNET_NAMECACHE_BlockCallback iter, void *iter_cls)
Get the block for a particular zone and label in the datastore.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:104
struct returned by the initialization function of the plugin
static void database_shutdown(struct Plugin *plugin)
Shutdown database connection and associate data structures.
configuration data
Definition: configuration.c:85
Handle for a plugin.
Definition: block.c:37
#define GNUNET_log(kind,...)
static int namecache_lookup_block(void *cls, const struct GNUNET_HashCode *query, GNUNET_NAMECACHE_BlockCallback iter, void *iter_cls)
Get the block for a particular zone and label in the datastore.
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_namecache_flat_done()

void* libgnunet_plugin_namecache_flat_done ( void *  cls)

Exit point from the plugin.

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

Definition at line 422 of file plugin_namecache_flat.c.

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

423 {
425  struct Plugin *plugin = api->cls;
426 
427  database_shutdown (plugin);
428  plugin->cfg = NULL;
429  GNUNET_free (api);
431  "flat plugin is finished\n");
432  return NULL;
433 }
void * cls
Closure to pass to all plugin functions.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
struct returned by the initialization function of the plugin
static void database_shutdown(struct Plugin *plugin)
Shutdown database connection and associate data structures.
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: