GNUnet 0.22.2
gnunet-service-dht_datacache.c File Reference

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

Include dependency graph for gnunet-service-dht_datacache.c:

Go to the source code of this file.

Data Structures

struct  GetRequestContext
 Context containing information about a GET request. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "dht-dhtcache", __VA_ARGS__)
 
#define NUM_CLOSEST   4
 How many "closest" results to we return for migration when asked (at most)? More...
 

Functions

void GDS_DATACACHE_handle_put (const struct GNUNET_DATACACHE_Block *bd)
 Handle a datum we've received from another peer. More...
 
static enum GNUNET_GenericReturnValue datacache_get_iterator (void *cls, const struct GNUNET_DATACACHE_Block *bd)
 Iterator for local get request results,. 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 ()
 Initialize datacache subsystem. More...
 
void GDS_DATACACHE_done ()
 Shutdown datacache subsystem. More...
 

Variables

static struct GNUNET_DATACACHE_Handledatacache
 Handle to the datacache service (for inserting/retrieving data) More...
 

Detailed Description

GNUnet DHT service's datacache integration.

Author
Christian Grothoff
Nathan Evans

Definition in file gnunet-service-dht_datacache.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "dht-dhtcache", __VA_ARGS__)

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

◆ NUM_CLOSEST

#define NUM_CLOSEST   4

How many "closest" results to we return for migration when asked (at most)?

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

Function Documentation

◆ GDS_DATACACHE_handle_put()

void GDS_DATACACHE_handle_put ( const struct GNUNET_DATACACHE_Block 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);
75 bd);
77 "DATACACHE PUT for key %s [%lu] completed (%d) after %u hops\n",
78 GNUNET_h2s (&bd->key),
79 (unsigned long) bd->data_size,
80 r,
81 bd->put_path_length);
82}
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_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, uint32_t xor_distance, const struct GNUNET_DATACACHE_Block *block)
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:132
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:174
#define GNUNET_log(kind,...)
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_NO
#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.
struct GNUNET_HashCode key
Key of the block.
size_t data_size
Number of bytes in data.
unsigned int put_path_length
Length of the put_path array.
A 512-bit hashcode.

References GNUNET_DATACACHE_Block::data_size, datacache, GDS_my_identity_hash, GDS_stats, GNUNET_break, GNUNET_CRYPTO_hash_count_leading_zeros(), GNUNET_CRYPTO_hash_xor(), GNUNET_DATACACHE_put(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_h2s(), GNUNET_log, GNUNET_MAX_MESSAGE_SIZE, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_DATACACHE_Block::key, LOG, and GNUNET_DATACACHE_Block::put_path_length.

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

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

◆ datacache_get_iterator()

static enum GNUNET_GenericReturnValue datacache_get_iterator ( void *  cls,
const struct GNUNET_DATACACHE_Block bd 
)
static

Iterator for local get request results,.

Parameters
clsclosure for iterator, a struct GetRequestContext
bdblock data
Returns
GNUNET_OK to continue iteration, anything else to stop iteration.

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

138{
139 struct GetRequestContext *ctx = cls;
141
143 {
144 GNUNET_break (0); /* why does datacache return expired values? */
145 return GNUNET_OK; /* skip expired record */
146 }
147 eval
149 bd->type,
150 ctx->bg,
151 &bd->key,
152 ctx->xquery,
153 ctx->xquery_size,
154 bd->data,
155 bd->data_size);
157 "Evaluated reply for query %s in datacache, result is %d\n",
158 GNUNET_h2s (&bd->key),
159 (int) eval);
160 ctx->eval = eval;
161 switch (eval)
162 {
166 /* forward to initiator */
168 "# Good RESULTS found in datacache",
169 1,
170 GNUNET_NO);
171 ctx->gc (ctx->gc_cls,
172 bd);
173 break;
176 "# Duplicate RESULTS found in datacache",
177 1,
178 GNUNET_NO);
179 break;
182 "# Irrelevant RESULTS found in datacache",
183 1,
184 GNUNET_NO);
185 break;
186 }
188}
static struct GNUNET_FS_Handle * ctx
struct GNUNET_BLOCK_Context * GDS_block_context
Our handle to the BLOCK library.
enum GNUNET_BLOCK_ReplyEvaluationResult GNUNET_BLOCK_check_reply(struct GNUNET_BLOCK_Context *ctx, enum GNUNET_BLOCK_Type type, struct GNUNET_BLOCK_Group *group, const struct GNUNET_HashCode *query, const void *xquery, size_t xquery_size, const void *reply_block, size_t reply_block_size)
Function called to validate if a reply is good for a particular query.
Definition: block.c:337
GNUNET_BLOCK_ReplyEvaluationResult
Possible ways for how a block may relate to a query.
@ GNUNET_BLOCK_REPLY_OK_MORE
Valid result, and there may be more.
@ GNUNET_BLOCK_REPLY_OK_DUPLICATE
Valid result, but suppressed because it is a duplicate.
@ GNUNET_BLOCK_REPLY_OK_LAST
Last possible valid result.
@ GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED
Specified block type not supported by any plugin.
@ GNUNET_BLOCK_REPLY_IRRELEVANT
Block does not match xquery (valid result, not relevant for the request)
@ GNUNET_OK
bool GNUNET_TIME_absolute_is_past(struct GNUNET_TIME_Absolute abs)
Test if abs is truly in the past (excluding now).
Definition: time.c:671
enum GNUNET_BLOCK_Type type
Type of the block.
const void * data
Actual block data.
struct GNUNET_TIME_Absolute expiration_time
When does the block expire?
Context containing information about a GET request.
enum GNUNET_BLOCK_ReplyEvaluationResult eval
Return value to give back.

References ctx, GNUNET_DATACACHE_Block::data, GNUNET_DATACACHE_Block::data_size, GetRequestContext::eval, GNUNET_DATACACHE_Block::expiration_time, GDS_block_context, GDS_stats, GNUNET_BLOCK_check_reply(), GNUNET_BLOCK_REPLY_IRRELEVANT, GNUNET_BLOCK_REPLY_OK_DUPLICATE, GNUNET_BLOCK_REPLY_OK_LAST, GNUNET_BLOCK_REPLY_OK_MORE, GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_is_past(), GNUNET_DATACACHE_Block::key, LOG, and GNUNET_DATACACHE_Block::type.

Referenced by GDS_DATACACHE_get_closest(), and GDS_DATACACHE_handle_get().

Here is the call graph for this function:
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 192 of file gnunet-service-dht_datacache.c.

199{
200 struct GetRequestContext ctx = {
202 .key = *key,
203 .xquery = xquery,
204 .xquery_size = xquery_size,
205 .bg = bg,
206 .gc = gc,
207 .gc_cls = gc_cls
208 };
209 unsigned int r;
210
211 if (NULL == datacache)
214 "# GET requests given to datacache",
215 1,
216 GNUNET_NO);
218 key,
219 type,
221 &ctx);
223 "DATACACHE GET for key %s completed (%d). %u results found.\n",
224 GNUNET_h2s (key),
225 ctx.eval,
226 r);
227 return ctx.eval;
228}
struct GNUNET_HashCode key
The key used in the DHT.
static uint32_t type
Type string converted to DNS type value.
static enum GNUNET_GenericReturnValue datacache_get_iterator(void *cls, const struct GNUNET_DATACACHE_Block *bd)
Iterator for local get request results,.
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:303
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.

References GetRequestContext::bg, ctx, datacache, datacache_get_iterator(), GetRequestContext::gc, GetRequestContext::gc_cls, GDS_stats, GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED, GNUNET_DATACACHE_get(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_NO, GNUNET_STATISTICS_update(), key, LOG, type, GetRequestContext::xquery, and GetRequestContext::xquery_size.

Referenced by handle_dht_local_get(), and handle_dht_p2p_get().

Here is the call graph for this function:
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 232 of file gnunet-service-dht_datacache.c.

239{
240 struct GetRequestContext ctx = {
242 .key = *key,
243 .xquery = xquery,
244 .xquery_size = xquery_size,
245 .bg = bg,
246 .gc = cb,
247 .gc_cls = cb_cls
248 };
249 unsigned int r;
250
251 if (NULL == datacache)
254 "# GET closest requests given to datacache",
255 1,
256 GNUNET_NO);
258 key,
259 type,
262 &ctx);
264 "DATACACHE approximate GET for key %s completed (%d). %u results found.\n",
265 GNUNET_h2s (key),
266 ctx.eval,
267 r);
268 return ctx.eval;
269}
#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:338

References GetRequestContext::bg, ctx, datacache, datacache_get_iterator(), GDS_stats, GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED, GNUNET_DATACACHE_get_closest(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_NO, GNUNET_STATISTICS_update(), key, LOG, NUM_CLOSEST, type, GetRequestContext::xquery, and GetRequestContext::xquery_size.

Referenced by handle_dht_p2p_get().

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

◆ GDS_DATACACHE_init()

void GDS_DATACACHE_init ( void  )

Initialize datacache subsystem.

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

274{
276 "dhtcache");
277}
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 281 of file gnunet-service-dht_datacache.c.

282{
283 if (NULL != datacache)
284 {
286 datacache = NULL;
287 }
288}
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:

Variable Documentation

◆ datacache

struct GNUNET_DATACACHE_Handle* datacache
static

Handle to the datacache service (for inserting/retrieving data)

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

Referenced by GDS_DATACACHE_done(), GDS_DATACACHE_get_closest(), GDS_DATACACHE_handle_get(), GDS_DATACACHE_handle_put(), and GDS_DATACACHE_init().