GNUnet  0.16.x
Data Structures | Typedefs | Functions
gnunet-service-dht_datacache.h File Reference

GNUnet DHT service's datacache integration. More...

#include "gnunet_util_lib.h"
#include "gnunet_block_lib.h"
#include "gnunet_dht_service.h"
Include dependency graph for gnunet-service-dht_datacache.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

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

Typedefs

typedef void(* GDS_DATACACHE_GetCallback) (void *cls, const struct GDS_DATACACHE_BlockData *bd)
 Handle a result for a GET operation. More...
 

Functions

void GDS_DATACACHE_handle_put (const struct GDS_DATACACHE_BlockData *bd)
 Handle a datum we've received from another peer. More...
 
enum GNUNET_BLOCK_ReplyEvaluationResult GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *key, enum GNUNET_BLOCK_Type type, const void *xquery, size_t xquery_size, struct GNUNET_BLOCK_Group *bg, GDS_DATACACHE_GetCallback gc, void *gc_cls)
 Handle a GET request we've received from another peer. More...
 
enum GNUNET_BLOCK_ReplyEvaluationResult GDS_DATACACHE_get_closest (const struct GNUNET_HashCode *key, enum GNUNET_BLOCK_Type type, const void *xquery, size_t xquery_size, struct GNUNET_BLOCK_Group *bg, GDS_DATACACHE_GetCallback cb, void *cb_cls)
 Handle a request for data close to a key that we have received from another peer. More...
 
void GDS_DATACACHE_init (void)
 Initialize datacache subsystem. More...
 
void GDS_DATACACHE_done (void)
 Shutdown datacache subsystem. More...
 

Detailed Description

GNUnet DHT service's datacache integration.

Author
Christian Grothoff
Nathan Evans

Definition in file gnunet-service-dht_datacache.h.

Typedef Documentation

◆ GDS_DATACACHE_GetCallback

typedef void(* GDS_DATACACHE_GetCallback) (void *cls, const struct GDS_DATACACHE_BlockData *bd)

Handle a result for a GET operation.

Parameters
clsclosure
bdblock details

Definition at line 93 of file gnunet-service-dht_datacache.h.

Function Documentation

◆ GDS_DATACACHE_handle_put()

void GDS_DATACACHE_handle_put ( const struct GDS_DATACACHE_BlockData bd)

Handle a datum we've received from another peer.

Cache if possible.

Parameters
bdblock data to cache

Definition at line 49 of file gnunet-service-dht_datacache.c.

50 {
51  struct GNUNET_HashCode xor;
53 
54  if (NULL == datacache)
55  {
57  "PUT request received, but have no datacache!\n");
58  return;
59  }
61  {
62  GNUNET_break (0);
63  return;
64  }
65  /* Put size is actual data size plus struct overhead plus path length (if any) */
67  "# ITEMS stored in datacache",
68  1,
69  GNUNET_NO);
72  &xor);
74  &bd->key,
76  bd->data_size,
77  bd->data,
78  bd->type,
79  bd->expiration_time,
80  bd->put_path_length,
81  bd->put_path);
83  "DATACACHE PUT for key %s [%lu] completed (%d) after %u hops\n",
84  GNUNET_h2s (&bd->key),
85  (unsigned long) bd->data_size,
86  r,
87  bd->put_path_length);
88 }
struct GNUNET_HashCode GDS_my_identity_hash
Hash of the identity of this peer.
struct GNUNET_STATISTICS_Handle * GDS_stats
Handle for the statistics service.
#define LOG(kind,...)
static struct GNUNET_DATACACHE_Handle * datacache
Handle to the datacache service (for inserting/retrieving data)
#define GNUNET_log(kind,...)
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:92
@ GNUNET_NO
Definition: gnunet_common.h:94
unsigned int GNUNET_CRYPTO_hash_count_leading_zeros(const struct GNUNET_HashCode *h)
Count the number of leading 0 bits in h.
Definition: crypto_hash.c:176
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...
enum GNUNET_GenericReturnValue 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_DHT_PathElement *path_info)
Store an item in the datacache.
Definition: datacache.c:261
void GNUNET_CRYPTO_hash_xor(const struct GNUNET_HashCode *a, const struct GNUNET_HashCode *b, struct GNUNET_HashCode *result)
compute result = a ^ b
Definition: crypto_hash.c:135
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_WARNING
@ 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.
const void * data
Actual block data.
size_t data_size
Number of bytes in data.
const struct GNUNET_DHT_PathElement * put_path
PUT path taken by the block, array of peer identities.
enum GNUNET_BLOCK_Type type
Type of the block.
struct GNUNET_TIME_Absolute expiration_time
When does the block expire?
unsigned int put_path_length
Length of the put_path array.
struct GNUNET_HashCode key
Key of the block.
A 512-bit hashcode.

Referenced by check_dht_p2p_result(), handle_dht_local_put(), and handle_dht_p2p_put().

Here is the caller graph for this function:

◆ GDS_DATACACHE_handle_get()

enum GNUNET_BLOCK_ReplyEvaluationResult GDS_DATACACHE_handle_get ( const struct GNUNET_HashCode key,
enum GNUNET_BLOCK_Type  type,
const void *  xquery,
size_t  xquery_size,
struct GNUNET_BLOCK_Group bg,
GDS_DATACACHE_GetCallback  gc,
void *  gc_cls 
)

Handle a GET request we've received from another peer.

Parameters
keythe query
typerequested data type
xqueryextended query
xquery_sizenumber of bytes in xquery
bgblock group to use for evaluation of replies
gcfunction to call on the results
gc_clsclosure for gc
Returns
evaluation result for the local replies

Definition at line 49 of file gnunet-service-dht_datacache.c.

226 {
227  struct GetRequestContext ctx = {
229  .key = *key,
230  .xquery = xquery,
231  .xquery_size = xquery_size,
232  .bg = bg,
233  .gc = gc,
234  .gc_cls = gc_cls
235  };
236  unsigned int r;
237 
238  if (NULL == datacache)
241  "# GET requests given to datacache",
242  1,
243  GNUNET_NO);
245  key,
246  type,
248  &ctx);
250  "DATACACHE GET for key %s completed (%d). %u results found.\n",
251  GNUNET_h2s (key),
252  ctx.eval,
253  r);
254  return ctx.eval;
255 }
struct GNUNET_HashCode key
The key used in the DHT.
static enum GNUNET_GenericReturnValue datacache_get_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 put_path_length, const struct GNUNET_DHT_PathElement *put_path)
Iterator for local get request results,.
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
@ GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED
Specified block type not supported by any plugin.
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.
Definition: datacache.c:315
Context containing information about a GET request.
struct GNUNET_BLOCK_Group * bg
Block group to use to evaluate replies (updated)
GDS_DATACACHE_GetCallback gc
Function to call on results.
const void * xquery
extended query (see gnunet_block_lib.h).
void * gc_cls
Closure for gc.
size_t xquery_size
Number of bytes in xquery.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model

Referenced by check_dht_local_get_result_seen(), and handle_dht_p2p_get().

Here is the caller graph for this function:

◆ GDS_DATACACHE_get_closest()

enum GNUNET_BLOCK_ReplyEvaluationResult GDS_DATACACHE_get_closest ( const struct GNUNET_HashCode key,
enum GNUNET_BLOCK_Type  type,
const void *  xquery,
size_t  xquery_size,
struct GNUNET_BLOCK_Group bg,
GDS_DATACACHE_GetCallback  cb,
void *  cb_cls 
)

Handle a request for data close to a key that we have received from another peer.

Parameters
keythe location at which the peer is looking for data that is close
typerequested data type
xqueryextended query
xquery_sizenumber of bytes in xquery
bgblock group to use for evaluation of replies
cbfunction to call with the result
cb_clsclosure for cb
Returns
evaluation result for the local replies

Definition at line 49 of file gnunet-service-dht_datacache.c.

266 {
267  struct GetRequestContext ctx = {
269  .key = *key,
270  .xquery = xquery,
271  .xquery_size = xquery_size,
272  .bg = bg,
273  .gc = cb,
274  .gc_cls = cb_cls
275  };
276  unsigned int r;
277 
278  if (NULL == datacache)
281  "# GET closest requests given to datacache",
282  1,
283  GNUNET_NO);
285  key,
286  type,
287  NUM_CLOSEST,
289  &ctx);
291  "DATACACHE approximate GET for key %s completed (%d). %u results found.\n",
292  GNUNET_h2s (key),
293  ctx.eval,
294  r);
295  return ctx.eval;
296 }
#define NUM_CLOSEST
How many "closest" results to we return for migration when asked (at most)?
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.
Definition: datacache.c:349

Referenced by handle_dht_p2p_get().

Here is the caller graph for this function:

◆ GDS_DATACACHE_init()

void GDS_DATACACHE_init ( void  )

Initialize datacache subsystem.

Definition at line 300 of file gnunet-service-dht_datacache.c.

301 {
303  "dhtcache");
304 }
const struct GNUNET_CONFIGURATION_Handle * GDS_cfg
Configuration we use.
struct GNUNET_DATACACHE_Handle * GNUNET_DATACACHE_create(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
Create a data cache.
Definition: datacache.c:128

References datacache, GDS_cfg, and GNUNET_DATACACHE_create().

Referenced by run().

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

◆ GDS_DATACACHE_done()

void GDS_DATACACHE_done ( void  )

Shutdown datacache subsystem.

Definition at line 308 of file gnunet-service-dht_datacache.c.

309 {
310  if (NULL != datacache)
311  {
313  datacache = NULL;
314  }
315 }
void GNUNET_DATACACHE_destroy(struct GNUNET_DATACACHE_Handle *h)
Destroy a data cache (and free associated resources).
Definition: datacache.c:235

References datacache, and GNUNET_DATACACHE_destroy().

Referenced by shutdown_task().

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