GNUnet 0.22.2
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, uint32_t xor_distance, const struct GNUNET_DATACACHE_Block *block)
 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 enum GNUNET_GenericReturnValue 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_closest (void *cls, const struct GNUNET_HashCode *key, enum GNUNET_BLOCK_Type type, 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,
uint32_t  xor_distance,
const struct GNUNET_DATACACHE_Block block 
)
static

Store an item in the datastore.

Parameters
clsclosure (our struct Plugin)
xor_distancedistance of key to our PID
blockdata to store
Returns
0 if duplicate, -1 on error, number of bytes used otherwise

Definition at line 52 of file plugin_datacache_template.c.

55{
56 GNUNET_break (0);
57 return -1;
58}
#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_datacache_template_init().

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

78{
79 GNUNET_break (0);
80 return 0;
81}

References GNUNET_break.

Referenced by libgnunet_plugin_datacache_template_init().

Here is the caller graph for this function:

◆ template_plugin_del()

static enum GNUNET_GenericReturnValue 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 92 of file plugin_datacache_template.c.

93{
94 GNUNET_break (0);
95 return GNUNET_SYSERR;
96}
@ GNUNET_SYSERR

References GNUNET_break, and GNUNET_SYSERR.

Referenced by libgnunet_plugin_datacache_template_init().

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,
enum GNUNET_BLOCK_Type  type,
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
typedesired block type for the replies
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 114 of file plugin_datacache_template.c.

120{
121 GNUNET_break (0);
122 return 0;
123}

References GNUNET_break.

Referenced by libgnunet_plugin_datacache_template_init().

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

136{
139 struct Plugin *plugin;
140
141 plugin = GNUNET_new (struct Plugin);
142 plugin->env = env;
144 api->cls = plugin;
145 api->get = &template_plugin_get;
146 api->put = &template_plugin_put;
147 api->del = &template_plugin_del;
148 api->get_closest = &template_plugin_get_closest;
150 "template",
151 "Template datacache running\n");
152 return api;
153}
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.
static enum GNUNET_GenericReturnValue template_plugin_del(void *cls)
Delete the entry with the lowest expiration value from the datacache right now.
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.
static unsigned int template_plugin_get_closest(void *cls, const struct GNUNET_HashCode *key, enum GNUNET_BLOCK_Type type, 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.
static ssize_t template_plugin_put(void *cls, uint32_t xor_distance, const struct GNUNET_DATACACHE_Block *block)
Store an item in the datastore.
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 ...
void * cls
Closure to use for callbacks.
struct returned by the initialization function of the plugin
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_DATACACHE_PluginEnvironment::cls, env, GNUNET_ERROR_TYPE_INFO, GNUNET_log_from, GNUNET_new, plugin, template_plugin_del(), template_plugin_get(), template_plugin_get_closest(), and template_plugin_put().

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

166{
168 struct Plugin *plugin = api->cls;
169
172 return NULL;
173}
#define GNUNET_free(ptr)
Wrapper around free.
void * cls
Closure to pass to all plugin functions.

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