aboutsummaryrefslogtreecommitdiff
path: root/src/dht/gnunet-service-dht_datacache.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dht/gnunet-service-dht_datacache.c')
-rw-r--r--src/dht/gnunet-service-dht_datacache.c139
1 files changed, 46 insertions, 93 deletions
diff --git a/src/dht/gnunet-service-dht_datacache.c b/src/dht/gnunet-service-dht_datacache.c
index cb778717b..be0a6db81 100644
--- a/src/dht/gnunet-service-dht_datacache.c
+++ b/src/dht/gnunet-service-dht_datacache.c
@@ -36,7 +36,7 @@
36 * How many "closest" results to we return for migration when 36 * How many "closest" results to we return for migration when
37 * asked (at most)? 37 * asked (at most)?
38 */ 38 */
39#define NUM_CLOSEST 42 39#define NUM_CLOSEST 4
40 40
41 41
42/** 42/**
@@ -68,7 +68,7 @@ GDS_DATACACHE_handle_put (const struct GDS_DATACACHE_BlockData *bd)
68 1, 68 1,
69 GNUNET_NO); 69 GNUNET_NO);
70 GNUNET_CRYPTO_hash_xor (&bd->key, 70 GNUNET_CRYPTO_hash_xor (&bd->key,
71 &my_identity_hash, 71 &GDS_my_identity_hash,
72 &xor); 72 &xor);
73 r = GNUNET_DATACACHE_put (datacache, 73 r = GNUNET_DATACACHE_put (datacache,
74 &bd->key, 74 &bd->key,
@@ -126,7 +126,7 @@ struct GetRequestContext
126 /** 126 /**
127 * Return value to give back. 127 * Return value to give back.
128 */ 128 */
129 enum GNUNET_BLOCK_EvaluationResult eval; 129 enum GNUNET_BLOCK_ReplyEvaluationResult eval;
130}; 130};
131 131
132 132
@@ -204,13 +204,6 @@ datacache_get_iterator (void *cls,
204 1, 204 1,
205 GNUNET_NO); 205 GNUNET_NO);
206 break; 206 break;
207 case GNUNET_BLOCK_REPLY_INVALID:
208 /* maybe it expired? */
209 GNUNET_STATISTICS_update (GDS_stats,
210 "# Invalid RESULTS found in datacache",
211 1,
212 GNUNET_NO);
213 break;
214 case GNUNET_BLOCK_REPLY_IRRELEVANT: 207 case GNUNET_BLOCK_REPLY_IRRELEVANT:
215 GNUNET_STATISTICS_update (GDS_stats, 208 GNUNET_STATISTICS_update (GDS_stats,
216 "# Irrelevant RESULTS found in datacache", 209 "# Irrelevant RESULTS found in datacache",
@@ -222,7 +215,7 @@ datacache_get_iterator (void *cls,
222} 215}
223 216
224 217
225enum GNUNET_BLOCK_EvaluationResult 218enum GNUNET_BLOCK_ReplyEvaluationResult
226GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *key, 219GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *key,
227 enum GNUNET_BLOCK_Type type, 220 enum GNUNET_BLOCK_Type type,
228 const void *xquery, 221 const void *xquery,
@@ -231,22 +224,23 @@ GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *key,
231 GDS_DATACACHE_GetCallback gc, 224 GDS_DATACACHE_GetCallback gc,
232 void *gc_cls) 225 void *gc_cls)
233{ 226{
234 struct GetRequestContext ctx; 227 struct GetRequestContext ctx = {
228 .eval = GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED,
229 .key = *key,
230 .xquery = xquery,
231 .xquery_size = xquery_size,
232 .bg = bg,
233 .gc = gc,
234 .gc_cls = gc_cls
235 };
235 unsigned int r; 236 unsigned int r;
236 237
237 if (NULL == datacache) 238 if (NULL == datacache)
238 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; 239 return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED;
239 GNUNET_STATISTICS_update (GDS_stats, 240 GNUNET_STATISTICS_update (GDS_stats,
240 "# GET requests given to datacache", 241 "# GET requests given to datacache",
241 1, 242 1,
242 GNUNET_NO); 243 GNUNET_NO);
243 ctx.eval = GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
244 ctx.key = *key;
245 ctx.xquery = xquery;
246 ctx.xquery_size = xquery_size;
247 ctx.bg = bg;
248 ctx.gc = gc;
249 ctx.gc_cls = gc_cls;
250 r = GNUNET_DATACACHE_get (datacache, 244 r = GNUNET_DATACACHE_get (datacache,
251 key, 245 key,
252 type, 246 type,
@@ -261,85 +255,44 @@ GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *key,
261} 255}
262 256
263 257
264/** 258enum GNUNET_BLOCK_ReplyEvaluationResult
265 * Closure for #datacache_get_successors_iterator().
266 */
267struct SuccContext
268{
269 /**
270 * Function to call on the result
271 */
272 GDS_DATACACHE_GetCallback cb;
273
274 /**
275 * Closure for @e cb.
276 */
277 void *cb_cls;
278
279};
280
281
282/**
283 * Iterator for local get request results,
284 *
285 * @param cls closure with the `struct GNUNET_HashCode *` with the trail ID
286 * @param key the key this data is stored under
287 * @param size the size of the data identified by key
288 * @param data the actual data
289 * @param type the type of the data
290 * @param exp when does this value expire?
291 * @param put_path_length number of peers in @a put_path
292 * @param put_path path the reply took on put
293 * @return #GNUNET_OK to continue iteration, anything else
294 * to stop iteration.
295 */
296static enum GNUNET_GenericReturnValue
297datacache_get_successors_iterator (void *cls,
298 const struct GNUNET_HashCode *key,
299 size_t size,
300 const char *data,
301 enum GNUNET_BLOCK_Type type,
302 struct GNUNET_TIME_Absolute exp,
303 unsigned int put_path_length,
304 const struct
305 GNUNET_DHT_PathElement *put_path)
306{
307 const struct SuccContext *sc = cls;
308 struct GDS_DATACACHE_BlockData bd = {
309 .key = *key,
310 .expiration_time = exp,
311 .put_path = put_path,
312 .data = data,
313 .data_size = size,
314 .put_path_length = put_path_length,
315 .type = type
316 };
317
318 /* NOTE: The datacache currently does not store the RO from
319 the original 'put', so we don't know the 'correct' option
320 at this point anymore. Thus, we conservatively assume
321 that recording is desired (for now). */
322 sc->cb (sc->cb_cls,
323 &bd);
324 return GNUNET_OK;
325}
326
327
328void
329GDS_DATACACHE_get_closest (const struct GNUNET_HashCode *key, 259GDS_DATACACHE_get_closest (const struct GNUNET_HashCode *key,
260 enum GNUNET_BLOCK_Type type,
261 const void *xquery,
262 size_t xquery_size,
263 struct GNUNET_BLOCK_Group *bg,
330 GDS_DATACACHE_GetCallback cb, 264 GDS_DATACACHE_GetCallback cb,
331 void *cb_cls) 265 void *cb_cls)
332{ 266{
333 struct SuccContext sc = { 267 struct GetRequestContext ctx = {
334 .cb = cb, 268 .eval = GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED,
335 .cb_cls = cb_cls 269 .key = *key,
270 .xquery = xquery,
271 .xquery_size = xquery_size,
272 .bg = bg,
273 .gc = cb,
274 .gc_cls = cb_cls
336 }; 275 };
276 unsigned int r;
337 277
338 (void) GNUNET_DATACACHE_get_closest (datacache, 278 if (NULL == datacache)
339 key, 279 return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED;
340 NUM_CLOSEST, 280 GNUNET_STATISTICS_update (GDS_stats,
341 &datacache_get_successors_iterator, 281 "# GET closest requests given to datacache",
342 &sc); 282 1,
283 GNUNET_NO);
284 r = GNUNET_DATACACHE_get_closest (datacache,
285 key,
286 type,
287 NUM_CLOSEST,
288 &datacache_get_iterator,
289 &ctx);
290 LOG (GNUNET_ERROR_TYPE_DEBUG,
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;
343} 296}
344 297
345 298