aboutsummaryrefslogtreecommitdiff
path: root/src/dht/gnunet-service-dht_datacache.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-01-15 19:24:33 +0100
committerChristian Grothoff <christian@grothoff.org>2022-02-19 12:39:55 +0100
commitb0abdf7127f2403ff583d224e0d9d4e68c1c5bfc (patch)
tree47df762cdbcce501ec5536c8963b5c9ee55da31d /src/dht/gnunet-service-dht_datacache.c
parent3a71153405e8fc26712807b4bdb5987fb3bf2b9e (diff)
downloadgnunet-b0abdf7127f2403ff583d224e0d9d4e68c1c5bfc.tar.gz
gnunet-b0abdf7127f2403ff583d224e0d9d4e68c1c5bfc.zip
-more work on DHTU integration
Diffstat (limited to 'src/dht/gnunet-service-dht_datacache.c')
-rw-r--r--src/dht/gnunet-service-dht_datacache.c124
1 files changed, 42 insertions, 82 deletions
diff --git a/src/dht/gnunet-service-dht_datacache.c b/src/dht/gnunet-service-dht_datacache.c
index cb778717b..880c72cb2 100644
--- a/src/dht/gnunet-service-dht_datacache.c
+++ b/src/dht/gnunet-service-dht_datacache.c
@@ -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,
@@ -231,7 +231,15 @@ GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *key,
231 GDS_DATACACHE_GetCallback gc, 231 GDS_DATACACHE_GetCallback gc,
232 void *gc_cls) 232 void *gc_cls)
233{ 233{
234 struct GetRequestContext ctx; 234 struct GetRequestContext ctx = {
235 .eval = GNUNET_BLOCK_EVALUATION_REQUEST_VALID,
236 .key = *key,
237 .xquery = xquery,
238 .xquery_size = xquery_size,
239 .bg = bg,
240 .gc = gc,
241 .gc_cls = gc_cls
242 };
235 unsigned int r; 243 unsigned int r;
236 244
237 if (NULL == datacache) 245 if (NULL == datacache)
@@ -240,13 +248,6 @@ GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *key,
240 "# GET requests given to datacache", 248 "# GET requests given to datacache",
241 1, 249 1,
242 GNUNET_NO); 250 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, 251 r = GNUNET_DATACACHE_get (datacache,
251 key, 252 key,
252 type, 253 type,
@@ -261,85 +262,44 @@ GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *key,
261} 262}
262 263
263 264
264/** 265enum GNUNET_BLOCK_EvaluationResult
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, 266GDS_DATACACHE_get_closest (const struct GNUNET_HashCode *key,
267 enum GNUNET_BLOCK_Type type,
268 const void *xquery,
269 size_t xquery_size,
270 struct GNUNET_BLOCK_Group *bg,
330 GDS_DATACACHE_GetCallback cb, 271 GDS_DATACACHE_GetCallback cb,
331 void *cb_cls) 272 void *cb_cls)
332{ 273{
333 struct SuccContext sc = { 274 struct GetRequestContext ctx = {
334 .cb = cb, 275 .eval = GNUNET_BLOCK_EVALUATION_REQUEST_VALID,
335 .cb_cls = cb_cls 276 .key = *key,
277 .xquery = xquery,
278 .xquery_size = xquery_size,
279 .bg = bg,
280 .gc = cb,
281 .gc_cls = cb_cls
336 }; 282 };
283 unsigned int r;
337 284
338 (void) GNUNET_DATACACHE_get_closest (datacache, 285 if (NULL == datacache)
339 key, 286 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
340 NUM_CLOSEST, 287 GNUNET_STATISTICS_update (GDS_stats,
341 &datacache_get_successors_iterator, 288 "# GET closest requests given to datacache",
342 &sc); 289 1,
290 GNUNET_NO);
291 r = GNUNET_DATACACHE_get_closest (datacache,
292 key,
293 type,
294 NUM_CLOSEST,
295 &datacache_get_iterator,
296 &ctx);
297 LOG (GNUNET_ERROR_TYPE_DEBUG,
298 "DATACACHE approximate GET for key %s completed (%d). %u results found.\n",
299 GNUNET_h2s (key),
300 ctx.eval,
301 r);
302 return ctx.eval;
343} 303}
344 304
345 305