diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-04-29 08:35:52 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-04-29 08:35:52 +0000 |
commit | efab0ade0d318534457fd2b2e829f2129fdc2eb7 (patch) | |
tree | 8862f04e54c56ca09de2abca5b6a31d16b4e0534 /src/dht | |
parent | 4221441f74e1fcdf87ee9811b6f97d0cfd6799a4 (diff) | |
download | gnunet-efab0ade0d318534457fd2b2e829f2129fdc2eb7.tar.gz gnunet-efab0ade0d318534457fd2b2e829f2129fdc2eb7.zip |
adding API to get random key from datacache
Diffstat (limited to 'src/dht')
-rw-r--r-- | src/dht/gnunet-service-wdht_datacache.c | 56 | ||||
-rw-r--r-- | src/dht/gnunet-service-wdht_datacache.h | 27 |
2 files changed, 76 insertions, 7 deletions
diff --git a/src/dht/gnunet-service-wdht_datacache.c b/src/dht/gnunet-service-wdht_datacache.c index 42fa884cf..6bf68028a 100644 --- a/src/dht/gnunet-service-wdht_datacache.c +++ b/src/dht/gnunet-service-wdht_datacache.c | |||
@@ -368,6 +368,62 @@ GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *key, | |||
368 | 368 | ||
369 | 369 | ||
370 | /** | 370 | /** |
371 | * Function called with a random element from the datacache. | ||
372 | * Stores the key in the closure. | ||
373 | * | ||
374 | * @param cls a `struct GNUNET_HashCode *`, where to store the @a key | ||
375 | * @param key key for the content | ||
376 | * @param data_size number of bytes in @a data | ||
377 | * @param data content stored | ||
378 | * @param type type of the content | ||
379 | * @param exp when will the content expire? | ||
380 | * @param path_info_len number of entries in @a path_info | ||
381 | * @param path_info a path through the network | ||
382 | * @return #GNUNET_OK to continue iterating, #GNUNET_SYSERR to abort | ||
383 | */ | ||
384 | static int | ||
385 | datacache_random_iterator (void *cls, | ||
386 | const struct GNUNET_HashCode *key, | ||
387 | size_t data_size, | ||
388 | const char *data, | ||
389 | enum GNUNET_BLOCK_Type type, | ||
390 | struct GNUNET_TIME_Absolute exp, | ||
391 | unsigned int path_info_len, | ||
392 | const struct GNUNET_PeerIdentity *path_info) | ||
393 | { | ||
394 | struct GNUNET_HashCode *dest = cls; | ||
395 | |||
396 | *dest = *key; | ||
397 | return GNUNET_OK; /* should actually not matter which we return */ | ||
398 | } | ||
399 | |||
400 | |||
401 | /** | ||
402 | * Obtain a random key from the datacache. | ||
403 | * Used by Whanau for load-balancing. | ||
404 | * | ||
405 | * @param[out] key where to store the key of a random element, | ||
406 | * randomized by PRNG if datacache is empty | ||
407 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the datacache is empty | ||
408 | */ | ||
409 | int | ||
410 | GDS_DATACACHE_get_random_key (struct GNUNET_HashCode *key) | ||
411 | { | ||
412 | if (0 == | ||
413 | GNUNET_DATACACHE_get_random (datacache, | ||
414 | &datacache_random_iterator, | ||
415 | key)) | ||
416 | { | ||
417 | /* randomize key in this case */ | ||
418 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_NONCE, | ||
419 | key); | ||
420 | return GNUNET_SYSERR; | ||
421 | } | ||
422 | return GNUNET_OK; | ||
423 | } | ||
424 | |||
425 | |||
426 | /** | ||
371 | * Initialize datacache subsystem. | 427 | * Initialize datacache subsystem. |
372 | */ | 428 | */ |
373 | void | 429 | void |
diff --git a/src/dht/gnunet-service-wdht_datacache.h b/src/dht/gnunet-service-wdht_datacache.h index a8f37fa63..0b28477c1 100644 --- a/src/dht/gnunet-service-wdht_datacache.h +++ b/src/dht/gnunet-service-wdht_datacache.h | |||
@@ -36,15 +36,15 @@ | |||
36 | * | 36 | * |
37 | * @param expiration when will the reply expire | 37 | * @param expiration when will the reply expire |
38 | * @param key the query this reply is for | 38 | * @param key the query this reply is for |
39 | * @param put_path_length number of peers in 'put_path' | 39 | * @param put_path_length number of peers in @a put_path |
40 | * @param put_path path the reply took on put | 40 | * @param put_path path the reply took on put |
41 | * @param type type of the reply | 41 | * @param type type of the reply |
42 | * @param data_size number of bytes in 'data' | 42 | * @param data_size number of bytes in @a data |
43 | * @param data application payload data | 43 | * @param data application payload data |
44 | */ | 44 | */ |
45 | void | 45 | void |
46 | GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration, | 46 | GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration, |
47 | const struct GNUNET_HashCode * key, | 47 | const struct GNUNET_HashCode *key, |
48 | unsigned int put_path_length, | 48 | unsigned int put_path_length, |
49 | const struct GNUNET_PeerIdentity *put_path, | 49 | const struct GNUNET_PeerIdentity *put_path, |
50 | enum GNUNET_BLOCK_Type type, size_t data_size, | 50 | enum GNUNET_BLOCK_Type type, size_t data_size, |
@@ -57,14 +57,15 @@ GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration, | |||
57 | * @param key the query | 57 | * @param key the query |
58 | * @param type requested data type | 58 | * @param type requested data type |
59 | * @param xquery extended query | 59 | * @param xquery extended query |
60 | * @param xquery_size number of bytes in xquery | 60 | * @param xquery_size number of bytes in @a xquery |
61 | * @param reply_bf where the reply bf is (to be) stored, possibly updated!, can be NULL | 61 | * @param reply_bf where the reply bf is (to be) stored, possibly updated!, can be NULL |
62 | * @param reply_bf_mutator mutation value for reply_bf | 62 | * @param reply_bf_mutator mutation value for @a reply_bf |
63 | * @return evaluation result for the local replies | 63 | * @return evaluation result for the local replies |
64 | */ | 64 | */ |
65 | enum GNUNET_BLOCK_EvaluationResult | 65 | enum GNUNET_BLOCK_EvaluationResult |
66 | GDS_DATACACHE_handle_get (const struct GNUNET_HashCode * key, | 66 | GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *key, |
67 | enum GNUNET_BLOCK_Type type, const void *xquery, | 67 | enum GNUNET_BLOCK_Type type, |
68 | const void *xquery, | ||
68 | size_t xquery_size, | 69 | size_t xquery_size, |
69 | struct GNUNET_CONTAINER_BloomFilter **reply_bf, | 70 | struct GNUNET_CONTAINER_BloomFilter **reply_bf, |
70 | uint32_t reply_bf_mutator, | 71 | uint32_t reply_bf_mutator, |
@@ -75,6 +76,18 @@ GDS_DATACACHE_handle_get (const struct GNUNET_HashCode * key, | |||
75 | 76 | ||
76 | 77 | ||
77 | /** | 78 | /** |
79 | * Obtain a random key from the datacache. | ||
80 | * Used by Whanau for load-balancing. | ||
81 | * | ||
82 | * @param[out] key where to store the key of a random element, | ||
83 | * randomized by PRNG if datacache is empty | ||
84 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the datacache is empty | ||
85 | */ | ||
86 | int | ||
87 | GDS_DATACACHE_get_random_key (struct GNUNET_HashCode *key); | ||
88 | |||
89 | |||
90 | /** | ||
78 | * Initialize datacache subsystem. | 91 | * Initialize datacache subsystem. |
79 | */ | 92 | */ |
80 | void | 93 | void |