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

template for an implementation of a database backend for the datacache More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_datacache_plugin.h"
Include dependency graph for plugin_datacache_template.c:

Go to the source code of this file.

Data Structures

struct  Plugin
 Handle for a plugin. More...
 

Functions

static ssize_t template_plugin_put (void *cls, const struct GNUNET_HashCode *key, uint32_t xor_distance, size_t size, const char *data, enum GNUNET_BLOCK_Type type, struct GNUNET_TIME_Absolute discard_time, unsigned int path_info_len, const struct GNUNET_PeerIdentity *path_info)
 Store an item in the datastore. More...
 
static unsigned int template_plugin_get (void *cls, const struct GNUNET_HashCode *key, enum GNUNET_BLOCK_Type type, GNUNET_DATACACHE_Iterator iter, void *iter_cls)
 Iterate over the results for a particular key in the datastore. More...
 
static int template_plugin_del (void *cls)
 Delete the entry with the lowest expiration value from the datacache right now. More...
 
static unsigned int template_plugin_get_random (void *cls, GNUNET_DATACACHE_Iterator iter, void *iter_cls)
 Return a random value from the datastore. More...
 
static unsigned int template_plugin_get_closest (void *cls, const struct GNUNET_HashCode *key, unsigned int num_results, GNUNET_DATACACHE_Iterator iter, void *iter_cls)
 Iterate over the results that are "close" to a particular key in the datacache. More...
 
void * libgnunet_plugin_datacache_template_init (void *cls)
 Entry point for the plugin. More...
 
void * libgnunet_plugin_datacache_template_done (void *cls)
 Exit point from the plugin. More...
 

Detailed Description

template for an implementation of a database backend for the datacache

Author
Christian Grothoff

Definition in file plugin_datacache_template.c.

Function Documentation

◆ template_plugin_put()

static ssize_t template_plugin_put ( void *  cls,
const struct GNUNET_HashCode key,
uint32_t  xor_distance,
size_t  size,
const char *  data,
enum GNUNET_BLOCK_Type  type,
struct GNUNET_TIME_Absolute  discard_time,
unsigned int  path_info_len,
const struct GNUNET_PeerIdentity path_info 
)
static

Store an item in the datastore.

Parameters
clsclosure (our struct Plugin)
keykey to store data under
xor_distancedistance of key to our PID
sizenumber of bytes in data
datadata to store
typetype of the value
discard_timewhen to discard the value in any case
path_info_lennumber of entries in path_info
path_infoa path through the network
Returns
0 if duplicate, -1 on error, number of bytes used otherwise

Definition at line 57 of file plugin_datacache_template.c.

References GNUNET_break.

Referenced by libgnunet_plugin_datacache_template_init().

66 {
67  GNUNET_break(0);
68  return -1;
69 }
#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()

static unsigned int template_plugin_get ( void *  cls,
const struct GNUNET_HashCode key,
enum GNUNET_BLOCK_Type  type,
GNUNET_DATACACHE_Iterator  iter,
void *  iter_cls 
)
static

Iterate over the results for a particular key in the datastore.

Parameters
clsclosure (our struct Plugin)
key
typeentries of which type are relevant?
itermaybe NULL (to just count)
iter_clsclosure for iter
Returns
the number of results found

Definition at line 84 of file plugin_datacache_template.c.

References GNUNET_break.

Referenced by libgnunet_plugin_datacache_template_init().

89 {
90  GNUNET_break(0);
91  return 0;
92 }
#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_del()

static int template_plugin_del ( void *  cls)
static

Delete the entry with the lowest expiration value from the datacache right now.

Parameters
clsclosure (our struct Plugin)
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 103 of file plugin_datacache_template.c.

References GNUNET_break, and GNUNET_SYSERR.

Referenced by libgnunet_plugin_datacache_template_init().

104 {
105  GNUNET_break(0);
106  return GNUNET_SYSERR;
107 }
#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:76
Here is the caller graph for this function:

◆ template_plugin_get_random()

static unsigned int template_plugin_get_random ( void *  cls,
GNUNET_DATACACHE_Iterator  iter,
void *  iter_cls 
)
static

Return a random value from the datastore.

Parameters
clsclosure (internal context for the plugin)
itermaybe NULL (to just count)
iter_clsclosure for iter
Returns
the number of results found (zero or one)

Definition at line 119 of file plugin_datacache_template.c.

References GNUNET_break.

Referenced by libgnunet_plugin_datacache_template_init().

122 {
123  GNUNET_break(0);
124  return 0;
125 }
#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_closest()

static unsigned int template_plugin_get_closest ( void *  cls,
const struct GNUNET_HashCode key,
unsigned int  num_results,
GNUNET_DATACACHE_Iterator  iter,
void *  iter_cls 
)
static

Iterate over the results that are "close" to a particular key in the datacache.

"close" is defined as numerically larger than key (when interpreted as a circular address space), with small distance.

Parameters
clsclosure (internal context for the plugin)
keyarea of the keyspace to look into
num_resultsnumber of results that should be returned to iter
itermaybe NULL (to just count)
iter_clsclosure for iter
Returns
the number of results found

Definition at line 143 of file plugin_datacache_template.c.

References GNUNET_break.

Referenced by libgnunet_plugin_datacache_template_init().

148 {
149  GNUNET_break(0);
150  return 0;
151 }
#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:

◆ libgnunet_plugin_datacache_template_init()

void* libgnunet_plugin_datacache_template_init ( void *  cls)

Entry point for the plugin.

Parameters
clsclosure (the struct GNUNET_DATACACHE_PluginEnvironmnet)
Returns
the plugin's closure (our struct Plugin)

Definition at line 161 of file plugin_datacache_template.c.

References Plugin::api, GNUNET_DATACACHE_PluginEnvironment::cls, GNUNET_DATACACHE_PluginFunctions::cls, GNUNET_DATACACHE_PluginFunctions::del, Plugin::env, GNUNET_DATACACHE_PluginFunctions::get, GNUNET_DATACACHE_PluginFunctions::get_closest, GNUNET_DATACACHE_PluginFunctions::get_random, GNUNET_ERROR_TYPE_INFO, GNUNET_log_from, GNUNET_new, plugin, GNUNET_DATACACHE_PluginFunctions::put, template_plugin_del(), template_plugin_get(), template_plugin_get_closest(), template_plugin_get_random(), and template_plugin_put().

162 {
165  struct Plugin *plugin;
166 
167  plugin = GNUNET_new(struct Plugin);
168  plugin->env = env;
170  api->cls = plugin;
171  api->get = &template_plugin_get;
172  api->put = &template_plugin_put;
173  api->del = &template_plugin_del;
177  "template",
178  "Template datacache running\n");
179  return api;
180 }
static unsigned int template_plugin_get_closest(void *cls, const struct GNUNET_HashCode *key, unsigned int num_results, GNUNET_DATACACHE_Iterator iter, void *iter_cls)
Iterate over the results that are "close" to a particular key in the datacache.
void * cls
Closure to pass to all plugin functions.
ssize_t(* put)(void *cls, const struct GNUNET_HashCode *key, uint32_t xor_distance, size_t size, const char *data, enum GNUNET_BLOCK_Type type, struct GNUNET_TIME_Absolute discard_time, unsigned int path_info_len, const struct GNUNET_PeerIdentity *path_info)
Store an item in the datastore.
int(* del)(void *cls)
Delete the entry with the lowest expiration value from the datacache right now.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:46
static ssize_t template_plugin_put(void *cls, const struct GNUNET_HashCode *key, uint32_t xor_distance, size_t size, const char *data, enum GNUNET_BLOCK_Type type, struct GNUNET_TIME_Absolute discard_time, unsigned int path_info_len, const struct GNUNET_PeerIdentity *path_info)
Store an item in the datastore.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
unsigned int(* get_closest)(void *cls, const struct GNUNET_HashCode *key, unsigned int num_results, GNUNET_DATACACHE_Iterator iter, void *iter_cls)
Iterate over the results that are "close" to a particular key in the datacache.
struct returned by the initialization function of the plugin
static unsigned int template_plugin_get(void *cls, const struct GNUNET_HashCode *key, enum GNUNET_BLOCK_Type type, GNUNET_DATACACHE_Iterator iter, void *iter_cls)
Iterate over the results for a particular key in the datastore.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static int template_plugin_del(void *cls)
Delete the entry with the lowest expiration value from the datacache right now.
Handle for a plugin.
Definition: block.c:37
void * cls
Closure to use for callbacks.
unsigned int(* get_random)(void *cls, GNUNET_DATACACHE_Iterator iter, void *iter_cls)
Return a random value from the datastore.
#define GNUNET_log_from(kind, comp,...)
The datastore service will pass a pointer to a struct of this type as the first and only argument to ...
unsigned int(* get)(void *cls, const struct GNUNET_HashCode *key, enum GNUNET_BLOCK_Type type, GNUNET_DATACACHE_Iterator iter, void *iter_cls)
Iterate over the results for a particular key in the datastore.
static unsigned int template_plugin_get_random(void *cls, GNUNET_DATACACHE_Iterator iter, void *iter_cls)
Return a random value from the datastore.
Here is the call graph for this function:

◆ libgnunet_plugin_datacache_template_done()

void* libgnunet_plugin_datacache_template_done ( void *  cls)

Exit point from the plugin.

Parameters
clsclosure (our struct Plugin)
Returns
NULL

Definition at line 190 of file plugin_datacache_template.c.

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

191 {
193  struct Plugin *plugin = api->cls;
194 
195  GNUNET_free(plugin);
196  GNUNET_free(api);
197  return NULL;
198 }
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_free(ptr)
Wrapper around free.