GNUnet 0.22.2
Data Cache library

Simple, transient hash table of bounded size with content expiration. More...

Collaboration diagram for Data Cache library:

Data Structures

struct  GNUNET_DATACACHE_Block
 Information about a block stored in the datacache. More...
 

Typedefs

typedef enum GNUNET_GenericReturnValue(* GNUNET_DATACACHE_Iterator) (void *cls, const struct GNUNET_DATACACHE_Block *block)
 An iterator over a set of items stored in the datacache. More...
 

Functions

struct GNUNET_DATACACHE_HandleGNUNET_DATACACHE_create (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
 Create a data cache. More...
 
void GNUNET_DATACACHE_destroy (struct GNUNET_DATACACHE_Handle *h)
 Destroy a data cache (and free associated resources). More...
 
enum GNUNET_GenericReturnValue GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h, uint32_t xor_distance, const struct GNUNET_DATACACHE_Block *block)
 Store an item in the datacache. More...
 
unsigned int GNUNET_DATACACHE_get (struct GNUNET_DATACACHE_Handle *h, 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 datacache. More...
 
unsigned int GNUNET_DATACACHE_get_closest (struct GNUNET_DATACACHE_Handle *h, 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...
 

Detailed Description

Simple, transient hash table of bounded size with content expiration.

In contrast to the sqstore there is no prioritization, deletion or iteration. All of the data is discarded when the peer shuts down!

Typedef Documentation

◆ GNUNET_DATACACHE_Iterator

typedef enum GNUNET_GenericReturnValue(* GNUNET_DATACACHE_Iterator) (void *cls, const struct GNUNET_DATACACHE_Block *block)

An iterator over a set of items stored in the datacache.

Parameters
clsclosure
blocka block from the datacache
Returns
GNUNET_OK to continue iterating, GNUNET_SYSERR to abort

Definition at line 134 of file gnunet_datacache_lib.h.

Function Documentation

◆ GNUNET_DATACACHE_create()

struct GNUNET_DATACACHE_Handle * GNUNET_DATACACHE_create ( const struct GNUNET_CONFIGURATION_Handle cfg,
const char *  section 
)

Create a data cache.

Parameters
cfgconfiguration to use
sectionsection in the configuration that contains our options
Returns
handle to use to access the service

Definition at line 128 of file datacache.c.

130{
131 unsigned int bf_size;
132 unsigned long long quota;
134 char *libname;
135 char *name;
136
137 if (GNUNET_OK !=
139 section,
140 "QUOTA",
141 &quota))
142 {
144 section,
145 "QUOTA");
146 return NULL;
147 }
148 if (GNUNET_OK !=
150 section,
151 "DATABASE",
152 &name))
153 {
155 section,
156 "DATABASE");
157 return NULL;
158 }
159 bf_size = quota / 32; /* 8 bit per entry, 1 bit per 32 kb in DB */
160
162
163 if (GNUNET_YES !=
165 section,
166 "DISABLE_BF"))
167 {
168 if (GNUNET_YES !=
170 section,
171 "DISABLE_BF_RC"))
172 {
173 ret->bloom_name = GNUNET_DISK_mktemp ("gnunet-datacachebloom");
174 }
175 if (NULL != ret->bloom_name)
176 {
178 ret->bloom_name,
179 quota / 1024, /* 8 bit per entry in DB, expect 1k entries */
180 5);
181 }
182 if (NULL == ret->filter)
183 {
184 ret->filter =
186 bf_size,
187 5); /* approx. 3% false positives at max use */
188 }
189 }
190 ret->stats = GNUNET_STATISTICS_create ("datacache",
191 cfg);
192 ret->section = GNUNET_strdup (section);
193 ret->env.cfg = cfg;
194 ret->env.delete_notify = &env_delete_notify;
195 ret->env.section = ret->section;
196 ret->env.cls = ret;
197 ret->env.delete_notify = &env_delete_notify;
198 ret->env.quota = quota;
200 "Loading `%s' datacache plugin\n",
201 name);
202 GNUNET_asprintf (&libname,
203 "libgnunet_plugin_datacache_%s",
204 name);
205 ret->short_name = name;
206 ret->lib_name = libname;
207 /* Load the plugin within GNUnet's default context */
209 libname,
210 &ret->env);
211 if (NULL == ret->api)
212 {
214 "Failed to load datacache plugin for `%s'\n",
215 name);
217 return NULL;
218 }
219 return ret;
220}
static void env_delete_notify(void *cls, const struct GNUNET_HashCode *key, size_t size)
Function called by plugins to notify the datacache about content deletions.
Definition: datacache.c:104
#define LOG(kind,...)
Definition: datacache.c:32
static int ret
Final status code.
Definition: gnunet-arm.c:93
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
static char * name
Name (label) of the records to list.
static unsigned long long quota
How much space are we allowed to use?
struct GNUNET_CONTAINER_BloomFilter * GNUNET_CONTAINER_bloomfilter_init(const char *data, size_t size, unsigned int k)
Create a Bloom filter from raw bits.
struct GNUNET_CONTAINER_BloomFilter * GNUNET_CONTAINER_bloomfilter_load(const char *filename, size_t size, unsigned int k)
Load a Bloom filter from a file.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_size(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *size)
Get a configuration value that should be a size in bytes.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
const struct GNUNET_OS_ProjectData * GNUNET_CONFIGURATION_get_project_data(const struct GNUNET_CONFIGURATION_Handle *cfg)
Return the project data associated with this configuration.
void GNUNET_DATACACHE_destroy(struct GNUNET_DATACACHE_Handle *h)
Destroy a data cache (and free associated resources).
Definition: datacache.c:224
char * GNUNET_DISK_mktemp(const char *t)
Create an (empty) temporary file on disk.
Definition: disk.c:418
@ GNUNET_OK
@ GNUNET_YES
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_INFO
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void * GNUNET_PLUGIN_load(const struct GNUNET_OS_ProjectData *pd, const char *library_name, void *arg)
Setup plugin (runs the "init" callback and returns whatever "init" returned).
Definition: plugin.c:221
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
Internal state of the datacache library.
Definition: datacache.c:41
char * section
Configuration section to use.
Definition: datacache.c:60

References cfg, env_delete_notify(), GNUNET_asprintf(), GNUNET_CONFIGURATION_get_project_data(), GNUNET_CONFIGURATION_get_value_size(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_CONTAINER_bloomfilter_init(), GNUNET_CONTAINER_bloomfilter_load(), GNUNET_DATACACHE_destroy(), GNUNET_DISK_mktemp(), GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_log_config_missing(), GNUNET_new, GNUNET_OK, GNUNET_PLUGIN_load(), GNUNET_STATISTICS_create(), GNUNET_strdup, GNUNET_YES, LOG, name, quota, ret, and GNUNET_DATACACHE_Handle::section.

Referenced by GDS_DATACACHE_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DATACACHE_destroy()

void GNUNET_DATACACHE_destroy ( struct GNUNET_DATACACHE_Handle h)

Destroy a data cache (and free associated resources).

Parameters
hhandle to the datastore

Definition at line 224 of file datacache.c.

225{
226 if (NULL != h->filter)
228 if (NULL != h->api)
229 GNUNET_break (NULL ==
230 GNUNET_PLUGIN_unload (h->lib_name,
231 h->api));
232 GNUNET_free (h->lib_name);
233 GNUNET_free (h->short_name);
234 GNUNET_free (h->section);
235 if (NULL != h->bloom_name)
236 {
237 if (0 != unlink (h->bloom_name))
239 "datacache",
240 "unlink",
241 h->bloom_name);
242 GNUNET_free (h->bloom_name);
243 }
245 GNUNET_free (h);
246}
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:98
void GNUNET_CONTAINER_bloomfilter_free(struct GNUNET_CONTAINER_BloomFilter *bf)
Free the space associated with a filter in memory, flush to drive if needed (do not free the space on...
@ GNUNET_NO
#define GNUNET_log_from_strerror_file(level, component, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_WARNING
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_PLUGIN_unload(const char *library_name, void *arg)
Unload plugin (runs the "done" callback and returns whatever "done" returned).
Definition: plugin.c:277
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).

References GNUNET_break, GNUNET_CONTAINER_bloomfilter_free(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log_from_strerror_file, GNUNET_NO, GNUNET_PLUGIN_unload(), GNUNET_STATISTICS_destroy(), and h.

Referenced by GDS_DATACACHE_done(), and GNUNET_DATACACHE_create().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DATACACHE_put()

enum GNUNET_GenericReturnValue GNUNET_DATACACHE_put ( struct GNUNET_DATACACHE_Handle h,
uint32_t  xor_distance,
const struct GNUNET_DATACACHE_Block block 
)

Store an item in the datacache.

Parameters
hhandle to the datacache
xor_distancehow close is the block's key to our pid?
blockactual block data to store
Returns
GNUNET_OK on success, GNUNET_SYSERR on error, GNUNET_NO if duplicate

Definition at line 250 of file datacache.c.

253{
254 ssize_t used;
255
256 used = h->api->put (h->api->cls,
257 xor_distance,
258 block);
259 if (-1 == used)
260 {
261 GNUNET_break (0);
262 return GNUNET_SYSERR;
263 }
264 if (0 == used)
265 {
266 /* duplicate */
267 return GNUNET_NO;
268 }
270 "Stored data under key `%s' in cache\n",
271 GNUNET_h2s (&block->key));
272 if (NULL != h->filter)
274 &block->key);
276 "# bytes stored",
277 used,
278 GNUNET_NO);
280 "# items stored",
281 1,
282 GNUNET_NO);
283 while (h->utilization + used > h->env.quota)
285 h->api->del (h->api->cls));
286 h->utilization += used;
287 return GNUNET_OK;
288}
void GNUNET_CONTAINER_bloomfilter_add(struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Add an element to the filter.
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_DEBUG
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
struct GNUNET_HashCode key
Key of the block.

References GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_bloomfilter_add(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_SYSERR, h, GNUNET_DATACACHE_Block::key, and LOG.

Referenced by GDS_DATACACHE_handle_put().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DATACACHE_get()

unsigned int GNUNET_DATACACHE_get ( struct GNUNET_DATACACHE_Handle h,
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 datacache.

Parameters
hhandle to the datacache
keywhat to look up
typeentries of which type are relevant?
itermaybe NULL (to just count)
iter_clsclosure for iter
Returns
the number of results found

Definition at line 292 of file datacache.c.

297{
299 "# requests received",
300 1,
301 GNUNET_NO);
303 "Processing request for key `%s'\n",
304 GNUNET_h2s (key));
305 if ( (NULL != h->filter) &&
306 (GNUNET_OK !=
308 key)) )
309 {
311 "# requests filtered by bloom filter",
312 1,
313 GNUNET_NO);
315 "Bloomfilter filters request for key `%s'\n",
316 GNUNET_h2s (key));
317 return 0; /* can not be present */
318 }
319 return h->api->get (h->api->cls,
320 key,
321 type,
322 iter, iter_cls);
323}
struct GNUNET_HashCode key
The key used in the DHT.
static uint32_t type
Type string converted to DNS type value.
bool GNUNET_CONTAINER_bloomfilter_test(const struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Test if an element is in the filter.

References GNUNET_CONTAINER_bloomfilter_test(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), h, key, LOG, and type.

Referenced by GDS_DATACACHE_handle_get().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DATACACHE_get_closest()

unsigned int GNUNET_DATACACHE_get_closest ( struct GNUNET_DATACACHE_Handle h,
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.

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

Parameters
hhandle to the datacache
keyarea of the keyspace to look into
typeentries of which type are relevant?
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 327 of file datacache.c.

333{
335 "# proximity search requests received",
336 1,
337 GNUNET_NO);
339 "Processing proximity search at `%s'\n",
340 GNUNET_h2s (key));
341 return h->api->get_closest (h->api->cls,
342 key,
343 type,
344 num_results,
345 iter,
346 iter_cls);
347}

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_NO, GNUNET_STATISTICS_update(), h, key, LOG, and type.

Referenced by GDS_DATACACHE_get_closest().

Here is the call graph for this function:
Here is the caller graph for this function: