GNUnet  0.11.x
Typedefs | Functions
Data Cache library

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

Typedefs

typedef int(* GNUNET_DATACACHE_Iterator) (void *cls, const struct GNUNET_HashCode *key, size_t data_size, const char *data, enum GNUNET_BLOCK_Type type, struct GNUNET_TIME_Absolute exp, unsigned int path_info_len, const struct GNUNET_PeerIdentity *path_info)
 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...
 
int GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h, const struct GNUNET_HashCode *key, uint32_t xor_distance, size_t data_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 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_random (struct GNUNET_DATACACHE_Handle *h, GNUNET_DATACACHE_Iterator iter, void *iter_cls)
 Obtain a random element from the datacache. More...
 
unsigned int GNUNET_DATACACHE_get_closest (struct GNUNET_DATACACHE_Handle *h, 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...
 

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 int(* GNUNET_DATACACHE_Iterator) (void *cls, const struct GNUNET_HashCode *key, size_t data_size, const char *data, enum GNUNET_BLOCK_Type type, struct GNUNET_TIME_Absolute exp, unsigned int path_info_len, const struct GNUNET_PeerIdentity *path_info)

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

Parameters
clsclosure
keykey for the content
data_sizenumber of bytes in data
datacontent stored
typetype of the content
expwhen will the content expire?
path_info_lennumber of entries in path_info
path_infoa path through the network
Returns
GNUNET_OK to continue iterating, GNUNET_SYSERR to abort

Definition at line 93 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 133 of file datacache.c.

References _, GNUNET_DATACACHE_Handle::api, GNUNET_DATACACHE_Handle::bloom_name, GNUNET_DATACACHE_Handle::cfg, GNUNET_DATACACHE_PluginEnvironment::cfg, GNUNET_DATACACHE_PluginEnvironment::cls, GNUNET_DATACACHE_PluginEnvironment::delete_notify, GNUNET_DATACACHE_Handle::env, env_delete_notify(), GNUNET_DATACACHE_Handle::filter, GNUNET_asprintf(), 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, GNUNET_DATACACHE_Handle::lib_name, LOG, name, GNUNET_DATACACHE_PluginEnvironment::quota, quota, ret, GNUNET_DATACACHE_Handle::section, GNUNET_DATACACHE_PluginEnvironment::section, GNUNET_DATACACHE_Handle::short_name, and GNUNET_DATACACHE_Handle::stats.

Referenced by GDS_DATACACHE_init().

135 {
136  unsigned int bf_size;
137  unsigned long long quota;
139  char *libname;
140  char *name;
141 
142  if (GNUNET_OK !=
143  GNUNET_CONFIGURATION_get_value_size (cfg, section, "QUOTA", &quota))
144  {
146  return NULL;
147  }
148  if (GNUNET_OK !=
149  GNUNET_CONFIGURATION_get_value_string (cfg, section, "DATABASE", &name))
150  {
152  return NULL;
153  }
154  bf_size = quota / 32; /* 8 bit per entry, 1 bit per 32 kb in DB */
155 
156  ret = GNUNET_new (struct GNUNET_DATACACHE_Handle);
157 
158  if (GNUNET_YES !=
159  GNUNET_CONFIGURATION_get_value_yesno (cfg, section, "DISABLE_BF"))
160  {
161  if (GNUNET_YES !=
162  GNUNET_CONFIGURATION_get_value_yesno (cfg, section, "DISABLE_BF_RC"))
163  {
164  ret->bloom_name = GNUNET_DISK_mktemp ("gnunet-datacachebloom");
165  }
166  if (NULL != ret->bloom_name)
167  {
169  ret->bloom_name,
170  quota / 1024, /* 8 bit per entry in DB, expect 1k entries */
171  5);
172  }
173  if (NULL == ret->filter)
174  {
175  ret->filter =
177  bf_size,
178  5); /* approx. 3% false positives at max use */
179  }
180  }
181  ret->stats = GNUNET_STATISTICS_create ("datacache", cfg);
182  ret->section = GNUNET_strdup (section);
183  ret->env.cfg = cfg;
185  ret->env.section = ret->section;
186  ret->env.cls = ret;
188  ret->env.quota = quota;
189  LOG (GNUNET_ERROR_TYPE_INFO, _ ("Loading `%s' datacache plugin\n"), name);
190  GNUNET_asprintf (&libname, "libgnunet_plugin_datacache_%s", name);
191  ret->short_name = name;
192  ret->lib_name = libname;
193  ret->api = GNUNET_PLUGIN_load (libname, &ret->env);
194  if (ret->api == NULL)
195  {
197  _ ("Failed to load datacache plugin for `%s'\n"),
198  name);
200  return NULL;
201  }
202  return ret;
203 }
const char * section
Configuration section 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_DATACACHE_PluginEnvironment env
Environment provided to our plugin.
Definition: datacache.c:86
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
void GNUNET_DATACACHE_destroy(struct GNUNET_DATACACHE_Handle *h)
Destroy a data cache (and free associated resources).
Definition: datacache.c:212
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
GNUNET_DATACACHE_DeleteNotifyCallback delete_notify
Function to call whenever the plugin needs to discard content that it was asked to store...
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static char * section
Name of the section.
Definition: gnunet-config.c:33
struct GNUNET_STATISTICS_Handle * stats
Opaque handle for the statistics service.
Definition: datacache.c:55
char * short_name
Short name for the plugin (i.e.
Definition: datacache.c:71
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
char * GNUNET_DISK_mktemp(const char *t)
Create an (empty) temporary file on disk.
Definition: disk.c:468
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
struct GNUNET_CONTAINER_BloomFilter * filter
Bloomfilter to quickly tell if we don't have the content.
Definition: datacache.c:45
char * lib_name
Name of the library (i.e.
Definition: datacache.c:76
struct GNUNET_CONTAINER_BloomFilter * GNUNET_CONTAINER_bloomfilter_load(const char *filename, size_t size, unsigned int k)
Load a Bloom filter from a file.
int 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.
int 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.
#define LOG(kind,...)
Definition: datacache.c:32
static unsigned long long quota
How much space are we allowed to use?
struct GNUNET_DATACACHE_PluginFunctions * api
API of the transport as returned by the plugin's initialization function.
Definition: datacache.c:66
Internal state of the datacache library.
Definition: datacache.c:40
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
const char * name
void * cls
Closure to use for callbacks.
#define GNUNET_YES
Definition: gnunet_common.h:77
void * GNUNET_PLUGIN_load(const char *library_name, void *arg)
Setup plugin (runs the "init" callback and returns whatever "init" returned).
Definition: plugin.c:207
unsigned long long quota
How much space are we allowed to use?
int 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".
char * section
Configuration section to use.
Definition: datacache.c:60
char * bloom_name
Name for the bloom filter file.
Definition: datacache.c:81
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 212 of file datacache.c.

References GNUNET_DATACACHE_Handle::api, GNUNET_DATACACHE_Handle::bloom_name, GNUNET_DATACACHE_Handle::filter, 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(), GNUNET_DATACACHE_Handle::lib_name, GNUNET_DATACACHE_Handle::section, GNUNET_DATACACHE_Handle::short_name, and GNUNET_DATACACHE_Handle::stats.

Referenced by GDS_DATACACHE_done(), and GNUNET_DATACACHE_create().

213 {
214  if (NULL != h->filter)
216  if (NULL != h->api)
217  GNUNET_break (NULL == GNUNET_PLUGIN_unload (h->lib_name, h->api));
218  GNUNET_free (h->lib_name);
219  GNUNET_free (h->short_name);
220  GNUNET_free (h->section);
221  if (NULL != h->bloom_name)
222  {
223  if (0 != unlink (h->bloom_name))
225  "datacache",
226  "unlink",
227  h->bloom_name);
228  GNUNET_free (h->bloom_name);
229  }
231  GNUNET_free (h);
232 }
#define GNUNET_NO
Definition: gnunet_common.h:78
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
void * GNUNET_PLUGIN_unload(const char *library_name, void *arg)
Unload plugin (runs the "done" callback and returns whatever "done" returned).
Definition: plugin.c:256
struct GNUNET_STATISTICS_Handle * stats
Opaque handle for the statistics service.
Definition: datacache.c:55
#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...
char * short_name
Short name for the plugin (i.e.
Definition: datacache.c:71
struct GNUNET_CONTAINER_BloomFilter * filter
Bloomfilter to quickly tell if we don't have the content.
Definition: datacache.c:45
char * lib_name
Name of the library (i.e.
Definition: datacache.c:76
struct GNUNET_DATACACHE_PluginFunctions * api
API of the transport as returned by the plugin's initialization function.
Definition: datacache.c:66
char * section
Configuration section to use.
Definition: datacache.c:60
void GNUNET_CONTAINER_bloomfilter_free(struct GNUNET_CONTAINER_BloomFilter *bf)
Free the space associcated with a filter in memory, flush to drive if needed (do not free the space o...
char * bloom_name
Name for the bloom filter file.
Definition: datacache.c:81
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DATACACHE_put()

int GNUNET_DATACACHE_put ( struct GNUNET_DATACACHE_Handle h,
const struct GNUNET_HashCode key,
uint32_t  xor_distance,
size_t  data_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 datacache.

Parameters
hhandle to the datacache
keykey to store data under
howclose is key to our pid?
data_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
GNUNET_OK on success, GNUNET_SYSERR on error, GNUNET_NO if duplicate

Store an item in the datacache.

Parameters
hhandle to the datacache
keykey to store data under
xor_distancedistance of key to our PID
data_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
GNUNET_OK on success, GNUNET_SYSERR on error, GNUNET_NO if duplicate

Definition at line 250 of file datacache.c.

References GNUNET_DATACACHE_Handle::api, GNUNET_DATACACHE_PluginFunctions::cls, GNUNET_DATACACHE_PluginFunctions::del, GNUNET_DATACACHE_Handle::env, GNUNET_DATACACHE_Handle::filter, gettext_noop, GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_bloomfilter_add(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_SYSERR, LOG, GNUNET_DATACACHE_PluginFunctions::put, GNUNET_DATACACHE_PluginEnvironment::quota, GNUNET_DATACACHE_Handle::stats, and GNUNET_DATACACHE_Handle::utilization.

Referenced by GDS_DATACACHE_handle_put().

259 {
260  ssize_t used;
261 
262  used = h->api->put (h->api->cls,
263  key,
264  xor_distance,
265  data_size,
266  data,
267  type,
268  discard_time,
269  path_info_len,
270  path_info);
271  if (-1 == used)
272  {
273  GNUNET_break (0);
274  return GNUNET_SYSERR;
275  }
276  if (0 == used)
277  {
278  /* duplicate */
279  return GNUNET_NO;
280  }
282  "Stored data under key `%s' in cache\n",
283  GNUNET_h2s (key));
284  if (NULL != h->filter)
287  gettext_noop ("# bytes stored"),
288  used,
289  GNUNET_NO);
291  gettext_noop ("# items stored"),
292  1,
293  GNUNET_NO);
294  while (h->utilization + used > h->env.quota)
295  GNUNET_assert (GNUNET_OK == h->api->del (h->api->cls));
296  h->utilization += used;
297  return GNUNET_OK;
298 }
void * cls
Closure to pass to all plugin functions.
struct GNUNET_DATACACHE_PluginEnvironment env
Environment provided to our plugin.
Definition: datacache.c:86
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.
void GNUNET_CONTAINER_bloomfilter_add(struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Add an element to the filter.
int(* del)(void *cls)
Delete the entry with the lowest expiration value from the datacache right now.
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_STATISTICS_Handle * stats
Opaque handle for the statistics service.
Definition: datacache.c:55
unsigned long long utilization
How much space is in use right now?
Definition: datacache.c:91
struct GNUNET_CONTAINER_BloomFilter * filter
Bloomfilter to quickly tell if we don't have the content.
Definition: datacache.c:45
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
#define LOG(kind,...)
Definition: datacache.c:32
struct GNUNET_DATACACHE_PluginFunctions * api
API of the transport as returned by the plugin's initialization function.
Definition: datacache.c:66
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
unsigned long long quota
How much space are we allowed to use?
uint32_t data
The data value.
#define gettext_noop(String)
Definition: gettext.h:69
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 313 of file datacache.c.

References GNUNET_DATACACHE_Handle::api, GNUNET_DATACACHE_PluginFunctions::cls, GNUNET_DATACACHE_Handle::filter, GNUNET_DATACACHE_PluginFunctions::get, gettext_noop, GNUNET_CONTAINER_bloomfilter_test(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), LOG, and GNUNET_DATACACHE_Handle::stats.

Referenced by GDS_DATACACHE_handle_get().

318 {
320  gettext_noop ("# requests received"),
321  1,
322  GNUNET_NO);
324  "Processing request for key `%s'\n",
325  GNUNET_h2s (key));
326  if ((NULL != h->filter) &&
328  {
330  gettext_noop (
331  "# requests filtered by bloom filter"),
332  1,
333  GNUNET_NO);
335  "Bloomfilter filters request for key `%s'\n",
336  GNUNET_h2s (key));
337  return 0; /* can not be present */
338  }
339  return h->api->get (h->api->cls, key, type, iter, iter_cls);
340 }
void * cls
Closure to pass to all plugin functions.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
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_STATISTICS_Handle * stats
Opaque handle for the statistics service.
Definition: datacache.c:55
int GNUNET_CONTAINER_bloomfilter_test(const struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Test if an element is in the filter.
struct GNUNET_CONTAINER_BloomFilter * filter
Bloomfilter to quickly tell if we don't have the content.
Definition: datacache.c:45
#define LOG(kind,...)
Definition: datacache.c:32
struct GNUNET_DATACACHE_PluginFunctions * api
API of the transport as returned by the plugin's initialization function.
Definition: datacache.c:66
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
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.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_DATACACHE_get_random()

unsigned int GNUNET_DATACACHE_get_random ( struct GNUNET_DATACACHE_Handle h,
GNUNET_DATACACHE_Iterator  iter,
void *  iter_cls 
)

Obtain a random element from the datacache.

Parameters
hhandle to the datacache
itermaybe NULL (to just count)
iter_clsclosure for iter
Returns
the number of results found (zero or 1)

Definition at line 352 of file datacache.c.

References GNUNET_DATACACHE_Handle::api, GNUNET_DATACACHE_PluginFunctions::cls, GNUNET_DATACACHE_PluginFunctions::get_random, gettext_noop, GNUNET_ERROR_TYPE_DEBUG, GNUNET_NO, GNUNET_STATISTICS_update(), LOG, and GNUNET_DATACACHE_Handle::stats.

Referenced by GDS_DATACACHE_get_random_key().

355 {
357  gettext_noop (
358  "# requests for random value received"),
359  1,
360  GNUNET_NO);
361  LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing request for random value\n");
362  return h->api->get_random (h->api->cls, iter, iter_cls);
363 }
void * cls
Closure to pass to all plugin functions.
#define GNUNET_NO
Definition: gnunet_common.h:78
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_STATISTICS_Handle * stats
Opaque handle for the statistics service.
Definition: datacache.c:55
#define LOG(kind,...)
Definition: datacache.c:32
struct GNUNET_DATACACHE_PluginFunctions * api
API of the transport as returned by the plugin's initialization function.
Definition: datacache.c:66
unsigned int(* get_random)(void *cls, GNUNET_DATACACHE_Iterator iter, void *iter_cls)
Return a random value from the datastore.
#define gettext_noop(String)
Definition: gettext.h:69
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,
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
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 380 of file datacache.c.

References GNUNET_DATACACHE_Handle::api, GNUNET_DATACACHE_PluginFunctions::cls, GNUNET_DATACACHE_PluginFunctions::get_closest, gettext_noop, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_NO, GNUNET_STATISTICS_update(), LOG, and GNUNET_DATACACHE_Handle::stats.

Referenced by GDS_DATACACHE_get_successors().

385 {
387  gettext_noop (
388  "# proximity search requests received"),
389  1,
390  GNUNET_NO);
392  "Processing proximity search at `%s'\n",
393  GNUNET_h2s (key));
394  return h->api->get_closest (h->api->cls, key, num_results, iter, iter_cls);
395 }
void * cls
Closure to pass to all plugin functions.
#define GNUNET_NO
Definition: gnunet_common.h:78
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
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_STATISTICS_Handle * stats
Opaque handle for the statistics service.
Definition: datacache.c:55
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.
#define LOG(kind,...)
Definition: datacache.c:32
struct GNUNET_DATACACHE_PluginFunctions * api
API of the transport as returned by the plugin's initialization function.
Definition: datacache.c:66
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function: