GNUnet 0.21.2
plugin_datastore_template.c File Reference

template-based datastore backend More...

#include "platform.h"
#include "gnunet_datastore_plugin.h"
Include dependency graph for plugin_datastore_template.c:

Go to the source code of this file.

Data Structures

struct  Plugin
 Handle for a plugin. More...
 

Functions

static void template_plugin_estimate_size (void *cls, unsigned long long *estimate)
 Get an estimate of how much space the database is currently using. More...
 
static void template_plugin_put (void *cls, const struct GNUNET_HashCode *key, bool absent, uint32_t size, const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, uint32_t replication, struct GNUNET_TIME_Absolute expiration, PluginPutCont cont, void *cont_cls)
 Store an item in the datastore. More...
 
static void template_plugin_get_key (void *cls, uint64_t next_uid, bool random, const struct GNUNET_HashCode *key, enum GNUNET_BLOCK_Type type, PluginDatumProcessor proc, void *proc_cls)
 Get one of the results for a particular key in the datastore. More...
 
static void template_plugin_get_replication (void *cls, PluginDatumProcessor proc, void *proc_cls)
 Get a random item for replication. More...
 
static void template_plugin_get_expiration (void *cls, PluginDatumProcessor proc, void *proc_cls)
 Get a random item for expiration. More...
 
static void template_plugin_get_zero_anonymity (void *cls, uint64_t next_uid, enum GNUNET_BLOCK_Type type, PluginDatumProcessor proc, void *proc_cls)
 Call the given processor on an item with zero anonymity. More...
 
static void template_plugin_drop (void *cls)
 Drop database. More...
 
static void template_get_keys (void *cls, PluginKeyProcessor proc, void *proc_cls)
 Get all of the keys in the datastore. More...
 
static void template_plugin_remove_key (void *cls, const struct GNUNET_HashCode *key, uint32_t size, const void *data, PluginRemoveCont cont, void *cont_cls)
 Remove a particular key in the datastore. More...
 
void * libgnunet_plugin_datastore_template_init (void *cls)
 Entry point for the plugin. More...
 
void * libgnunet_plugin_datastore_template_done (void *cls)
 Exit point from the plugin. More...
 

Detailed Description

template-based datastore backend

Author
Christian Grothoff

Definition in file plugin_datastore_template.c.

Function Documentation

◆ template_plugin_estimate_size()

static void template_plugin_estimate_size ( void *  cls,
unsigned long long *  estimate 
)
static

Get an estimate of how much space the database is currently using.

Parameters
clsour "struct Plugin*"
Returns
number of bytes used on disk

Definition at line 51 of file plugin_datastore_template.c.

52{
53 if (NULL == estimate)
54 return;
55 GNUNET_break (0);
56 *estimate = 0;
57}
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.

References GNUNET_break.

Referenced by libgnunet_plugin_datastore_template_init().

Here is the caller graph for this function:

◆ template_plugin_put()

static void template_plugin_put ( void *  cls,
const struct GNUNET_HashCode key,
bool  absent,
uint32_t  size,
const void *  data,
enum GNUNET_BLOCK_Type  type,
uint32_t  priority,
uint32_t  anonymity,
uint32_t  replication,
struct GNUNET_TIME_Absolute  expiration,
PluginPutCont  cont,
void *  cont_cls 
)
static

Store an item in the datastore.

Parameters
clsclosure
keykey for the item
absenttrue if the key was not found in the bloom filter
sizenumber of bytes in data
datacontent stored
typetype of the content
prioritypriority of the content
anonymityanonymity-level for the content
replicationreplication-level for the content
expirationexpiration time for the content
contcontinuation called with success or failure status
cont_clscontinuation closure

Definition at line 77 of file plugin_datastore_template.c.

89{
90 GNUNET_break (0);
91 cont (cont_cls, key, size, GNUNET_SYSERR, "not implemented");
92}
struct GNUNET_HashCode key
The key used in the DHT.
@ GNUNET_SYSERR
static unsigned int size
Size of the "table".
Definition: peer.c:68

References GNUNET_break, GNUNET_SYSERR, key, and size.

Referenced by libgnunet_plugin_datastore_template_init().

Here is the caller graph for this function:

◆ template_plugin_get_key()

static void template_plugin_get_key ( void *  cls,
uint64_t  next_uid,
bool  random,
const struct GNUNET_HashCode key,
enum GNUNET_BLOCK_Type  type,
PluginDatumProcessor  proc,
void *  proc_cls 
)
static

Get one of the results for a particular key in the datastore.

Parameters
clsclosure
next_uidreturn the result with lowest uid >= next_uid
randomif true, return a random result instead of using next_uid
keymaybe NULL (to match all entries)
typeentries of which type are relevant? Use 0 for any type.
procfunction to call on each matching value; will be called with NULL if nothing matches
proc_clsclosure for proc

Definition at line 109 of file plugin_datastore_template.c.

116{
117 GNUNET_break (0);
118}

References GNUNET_break.

Referenced by libgnunet_plugin_datastore_template_init().

Here is the caller graph for this function:

◆ template_plugin_get_replication()

static void template_plugin_get_replication ( void *  cls,
PluginDatumProcessor  proc,
void *  proc_cls 
)
static

Get a random item for replication.

Returns a single, not expired, random item from those with the highest replication counters. The item's replication counter is decremented by one IF it was positive before. Call 'proc' with all values ZERO or NULL if the datastore is empty.

Parameters
clsclosure
procfunction to call the value (once only).
proc_clsclosure for proc

Definition at line 133 of file plugin_datastore_template.c.

135{
136 GNUNET_break (0);
137}

References GNUNET_break.

Referenced by libgnunet_plugin_datastore_template_init().

Here is the caller graph for this function:

◆ template_plugin_get_expiration()

static void template_plugin_get_expiration ( void *  cls,
PluginDatumProcessor  proc,
void *  proc_cls 
)
static

Get a random item for expiration.

Call 'proc' with all values ZERO or NULL if the datastore is empty.

Parameters
clsclosure
procfunction to call the value (once only).
proc_clsclosure for proc

Definition at line 149 of file plugin_datastore_template.c.

151{
152 GNUNET_break (0);
153}

References GNUNET_break.

Referenced by libgnunet_plugin_datastore_template_init().

Here is the caller graph for this function:

◆ template_plugin_get_zero_anonymity()

static void template_plugin_get_zero_anonymity ( void *  cls,
uint64_t  next_uid,
enum GNUNET_BLOCK_Type  type,
PluginDatumProcessor  proc,
void *  proc_cls 
)
static

Call the given processor on an item with zero anonymity.

Parameters
clsour "struct Plugin*"
next_uidreturn the result with lowest uid >= next_uid
typeentries of which type should be considered? Must not be zero (ANY).
procfunction to call on the matching value; will be called with NULL if no value matches
proc_clsclosure for proc

Definition at line 168 of file plugin_datastore_template.c.

171{
172 GNUNET_break (0);
173}

References GNUNET_break.

Referenced by libgnunet_plugin_datastore_template_init().

Here is the caller graph for this function:

◆ template_plugin_drop()

static void template_plugin_drop ( void *  cls)
static

Drop database.

Definition at line 180 of file plugin_datastore_template.c.

181{
182 GNUNET_break (0);
183}

References GNUNET_break.

Referenced by libgnunet_plugin_datastore_template_init().

Here is the caller graph for this function:

◆ template_get_keys()

static void template_get_keys ( void *  cls,
PluginKeyProcessor  proc,
void *  proc_cls 
)
static

Get all of the keys in the datastore.

Parameters
clsclosure
procfunction to call on each key
proc_clsclosure for proc

Definition at line 194 of file plugin_datastore_template.c.

197{
198 proc (proc_cls, NULL, 0);
199}

Referenced by libgnunet_plugin_datastore_template_init().

Here is the caller graph for this function:

◆ template_plugin_remove_key()

static void template_plugin_remove_key ( void *  cls,
const struct GNUNET_HashCode key,
uint32_t  size,
const void *  data,
PluginRemoveCont  cont,
void *  cont_cls 
)
static

Remove a particular key in the datastore.

Parameters
clsclosure
keykey for the content
sizenumber of bytes in data
datacontent stored
contcontinuation called with success or failure status
cont_clscontinuation closure for cont

Definition at line 213 of file plugin_datastore_template.c.

219{
220 GNUNET_break (0);
221 cont (cont_cls, key, size, GNUNET_SYSERR, "not implemented");
222}

References GNUNET_break, GNUNET_SYSERR, key, and size.

Referenced by libgnunet_plugin_datastore_template_init().

Here is the caller graph for this function:

◆ libgnunet_plugin_datastore_template_init()

void * libgnunet_plugin_datastore_template_init ( void *  cls)

Entry point for the plugin.

Parameters
clsthe "struct GNUNET_DATASTORE_PluginEnvironment*"
Returns
our "struct Plugin*"

Definition at line 232 of file plugin_datastore_template.c.

233{
236 struct Plugin *plugin;
237
238 plugin = GNUNET_new (struct Plugin);
239 plugin->env = env;
241 api->cls = plugin;
242 api->estimate_size = &template_plugin_estimate_size;
243 api->put = &template_plugin_put;
245 api->get_replication = &template_plugin_get_replication;
246 api->get_expiration = &template_plugin_get_expiration;
247 api->get_zero_anonymity = &template_plugin_get_zero_anonymity;
248 api->drop = &template_plugin_drop;
249 api->get_keys = &template_get_keys;
250 api->remove_key = &template_plugin_remove_key;
252 _ ("Template database running\n"));
253 return api;
254}
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static struct GNUNET_TESTING_PluginFunctions * plugin
Plugin to dynamically load a test case.
#define GNUNET_log_from(kind, comp,...)
@ GNUNET_ERROR_TYPE_INFO
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
static void template_plugin_get_zero_anonymity(void *cls, uint64_t next_uid, enum GNUNET_BLOCK_Type type, PluginDatumProcessor proc, void *proc_cls)
Call the given processor on an item with zero anonymity.
static void template_plugin_estimate_size(void *cls, unsigned long long *estimate)
Get an estimate of how much space the database is currently using.
static void template_plugin_remove_key(void *cls, const struct GNUNET_HashCode *key, uint32_t size, const void *data, PluginRemoveCont cont, void *cont_cls)
Remove a particular key in the datastore.
static void template_get_keys(void *cls, PluginKeyProcessor proc, void *proc_cls)
Get all of the keys in the datastore.
static void template_plugin_get_expiration(void *cls, PluginDatumProcessor proc, void *proc_cls)
Get a random item for expiration.
static void template_plugin_drop(void *cls)
Drop database.
static void template_plugin_get_key(void *cls, uint64_t next_uid, bool random, const struct GNUNET_HashCode *key, enum GNUNET_BLOCK_Type type, PluginDatumProcessor proc, void *proc_cls)
Get one of the results for a particular key in the datastore.
static void template_plugin_get_replication(void *cls, PluginDatumProcessor proc, void *proc_cls)
Get a random item for replication.
static void template_plugin_put(void *cls, const struct GNUNET_HashCode *key, bool absent, uint32_t size, const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, uint32_t replication, struct GNUNET_TIME_Absolute expiration, PluginPutCont cont, void *cont_cls)
Store an item in the datastore.
GNUNET_BLOCK_GetKeyFunction get_key
Obtain the key for a given block (if possible).
void * cls
Closure for all of the callbacks.
The datastore service will pass a pointer to a struct of this type as the first and only argument to ...
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
Handle for a plugin.
Definition: block.c:38
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:47

References _, Plugin::api, GNUNET_BLOCK_PluginFunctions::cls, GNUNET_DATASTORE_PluginEnvironment::cls, env, GNUNET_BLOCK_PluginFunctions::get_key, GNUNET_ERROR_TYPE_INFO, GNUNET_log_from, GNUNET_new, plugin, template_get_keys(), template_plugin_drop(), template_plugin_estimate_size(), template_plugin_get_expiration(), template_plugin_get_key(), template_plugin_get_replication(), template_plugin_get_zero_anonymity(), template_plugin_put(), and template_plugin_remove_key().

Here is the call graph for this function:

◆ libgnunet_plugin_datastore_template_done()

void * libgnunet_plugin_datastore_template_done ( void *  cls)

Exit point from the plugin.

Parameters
clsour "struct Plugin*"
Returns
always NULL

Definition at line 263 of file plugin_datastore_template.c.

264{
266 struct Plugin *plugin = api->cls;
267
270 return NULL;
271}
#define GNUNET_free(ptr)
Wrapper around free.
void * cls
Closure to use for all of the following callbacks (except "next_request").

References Plugin::api, GNUNET_BLOCK_PluginFunctions::cls, GNUNET_DATASTORE_PluginFunctions::cls, GNUNET_free, and plugin.