GNUnet  0.10.x
Data Structures | Functions
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.

References GNUNET_break.

Referenced by libgnunet_plugin_datastore_template_init().

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

References GNUNET_break, and GNUNET_SYSERR.

Referenced by libgnunet_plugin_datastore_template_init().

89 {
90  GNUNET_break (0);
91  cont (cont_cls, key, size, GNUNET_SYSERR, "not implemented");
92 }
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
static unsigned int size
Size of the "table".
Definition: peer.c:67
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.

References GNUNET_break.

Referenced by libgnunet_plugin_datastore_template_init().

116 {
117  GNUNET_break (0);
118 }
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
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 134 of file plugin_datastore_template.c.

References GNUNET_break.

Referenced by libgnunet_plugin_datastore_template_init().

136 {
137  GNUNET_break (0);
138 }
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
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 150 of file plugin_datastore_template.c.

References GNUNET_break.

Referenced by libgnunet_plugin_datastore_template_init().

152 {
153  GNUNET_break (0);
154 }
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
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 169 of file plugin_datastore_template.c.

References GNUNET_break.

Referenced by libgnunet_plugin_datastore_template_init().

172 {
173  GNUNET_break (0);
174 }
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
Here is the caller graph for this function:

◆ template_plugin_drop()

static void template_plugin_drop ( void *  cls)
static

Drop database.

Definition at line 181 of file plugin_datastore_template.c.

References GNUNET_break.

Referenced by libgnunet_plugin_datastore_template_init().

182 {
183  GNUNET_break (0);
184 }
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
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 195 of file plugin_datastore_template.c.

Referenced by libgnunet_plugin_datastore_template_init().

198 {
199  proc (proc_cls, NULL, 0);
200 }
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 214 of file plugin_datastore_template.c.

References GNUNET_break, and GNUNET_SYSERR.

Referenced by libgnunet_plugin_datastore_template_init().

220 {
221  GNUNET_break (0);
222  cont (cont_cls, key, size, GNUNET_SYSERR, "not implemented");
223 }
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
static unsigned int size
Size of the "table".
Definition: peer.c:67
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 233 of file plugin_datastore_template.c.

References _, Plugin::api, GNUNET_DATASTORE_PluginEnvironment::cls, GNUNET_DATASTORE_PluginFunctions::cls, GNUNET_DATASTORE_PluginFunctions::drop, Plugin::env, GNUNET_DATASTORE_PluginFunctions::estimate_size, GNUNET_DATASTORE_PluginFunctions::get_expiration, GNUNET_DATASTORE_PluginFunctions::get_key, GNUNET_DATASTORE_PluginFunctions::get_keys, GNUNET_DATASTORE_PluginFunctions::get_replication, GNUNET_DATASTORE_PluginFunctions::get_zero_anonymity, GNUNET_ERROR_TYPE_INFO, GNUNET_log_from, GNUNET_new, plugin, GNUNET_DATASTORE_PluginFunctions::put, GNUNET_DATASTORE_PluginFunctions::remove_key, 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().

234 {
237  struct Plugin *plugin;
238 
239  plugin = GNUNET_new (struct Plugin);
240  plugin->env = env;
242  api->cls = plugin;
244  api->put = &template_plugin_put;
249  api->drop = &template_plugin_drop;
250  api->get_keys = &template_get_keys;
253  _("Template database running\n"));
254  return api;
255 }
static void template_plugin_get_expiration(void *cls, PluginDatumProcessor proc, void *proc_cls)
Get a random item for expiration.
PluginGetKeys get_keys
Iterate over all keys in the database.
PluginPut put
Function to store an item in the datastore.
PluginGetType get_zero_anonymity
Get datum (of the specified type) with anonymity level zero.
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_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.
PluginRemoveKey remove_key
Function to remove an item from the database.
PluginEstimateSize estimate_size
Calculate the current on-disk size of the SQ store.
static void template_plugin_estimate_size(void *cls, unsigned long long *estimate)
Get an estimate of how much space the database is currently using.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
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.
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:47
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
PluginGetRandom get_replication
Function to get a random item with high replication score from the database, lowering the item's repl...
static void template_plugin_get_replication(void *cls, PluginDatumProcessor proc, void *proc_cls)
Get a random item for replication.
PluginDrop drop
Delete the database.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
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.
PluginGetRandom get_expiration
Function to get a random expired item or, if none are expired, either the oldest entry or one with a ...
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
The datastore service will pass a pointer to a struct of this type as the first and only argument to ...
static void template_plugin_drop(void *cls)
Drop database.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
void * cls
Closure to use for all of the following callbacks (except "next_request").
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.
Handle for a plugin.
Definition: block.c:37
#define GNUNET_log_from(kind, comp,...)
PluginGetKey get_key
Get a particular datum matching a given hash from the datastore.
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 264 of file plugin_datastore_template.c.

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

265 {
267  struct Plugin *plugin = api->cls;
268 
269  GNUNET_free (plugin);
270  GNUNET_free (api);
271  return NULL;
272 }
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
void * cls
Closure to use for all of the following callbacks (except "next_request").
Handle for a plugin.
Definition: block.c:37
#define GNUNET_free(ptr)
Wrapper around free.