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 58 of file plugin_datacache_template.c.

References GNUNET_break.

Referenced by libgnunet_plugin_datacache_template_init().

67 {
68  GNUNET_break (0);
69  return -1;
70 }
#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 85 of file plugin_datacache_template.c.

References GNUNET_break.

Referenced by libgnunet_plugin_datacache_template_init().

90 {
91  GNUNET_break (0);
92  return 0;
93 }
#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 104 of file plugin_datacache_template.c.

References GNUNET_break, and GNUNET_SYSERR.

Referenced by libgnunet_plugin_datacache_template_init().

105 {
106  GNUNET_break (0);
107  return GNUNET_SYSERR;
108 }
#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
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 120 of file plugin_datacache_template.c.

References GNUNET_break.

Referenced by libgnunet_plugin_datacache_template_init().

123 {
124  GNUNET_break (0);
125  return 0;
126 }
#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 144 of file plugin_datacache_template.c.

References GNUNET_break.

Referenced by libgnunet_plugin_datacache_template_init().

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

163 {
166  struct Plugin *plugin;
167 
168  plugin = GNUNET_new (struct Plugin);
169  plugin->env = env;
171  api->cls = plugin;
172  api->get = &template_plugin_get;
173  api->put = &template_plugin_put;
174  api->del = &template_plugin_del;
178  "template",
179  "Template datacache running\n");
180  return api;
181 }
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:47
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 191 of file plugin_datacache_template.c.

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

192 {
194  struct Plugin *plugin = api->cls;
195 
196  GNUNET_free (plugin);
197  GNUNET_free (api);
198  return NULL;
199 }
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.