diff options
author | Christian Grothoff <christian@grothoff.org> | 2022-02-23 00:30:36 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2022-02-23 00:30:36 +0100 |
commit | 0209b47aeddf61686fe08e946d8909860cfb161a (patch) | |
tree | 5e683a11dbb6698d97ed6363ab80fe36c3fef38b /src/datacache/plugin_datacache_heap.c | |
parent | 020df0bf2999e990806b72356c9a477b31b0142c (diff) | |
download | gnunet-0209b47aeddf61686fe08e946d8909860cfb161a.tar.gz gnunet-0209b47aeddf61686fe08e946d8909860cfb161a.zip |
-fix datacache to return 2x num_closest in both directions
Diffstat (limited to 'src/datacache/plugin_datacache_heap.c')
-rw-r--r-- | src/datacache/plugin_datacache_heap.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/datacache/plugin_datacache_heap.c b/src/datacache/plugin_datacache_heap.c index 09e66d892..5b50468a5 100644 --- a/src/datacache/plugin_datacache_heap.c +++ b/src/datacache/plugin_datacache_heap.c | |||
@@ -427,15 +427,16 @@ struct GetClosestContext | |||
427 | { | 427 | { |
428 | struct Value **values; | 428 | struct Value **values; |
429 | 429 | ||
430 | const struct GNUNET_HashCode *key; | ||
431 | |||
430 | enum GNUNET_BLOCK_Type type; | 432 | enum GNUNET_BLOCK_Type type; |
431 | 433 | ||
432 | unsigned int num_results; | 434 | unsigned int num_results; |
433 | 435 | ||
434 | const struct GNUNET_HashCode *key; | ||
435 | }; | 436 | }; |
436 | 437 | ||
437 | 438 | ||
438 | static int | 439 | static enum GNUNET_GenericReturnValue |
439 | find_closest (void *cls, | 440 | find_closest (void *cls, |
440 | const struct GNUNET_HashCode *key, | 441 | const struct GNUNET_HashCode *key, |
441 | void *value) | 442 | void *value) |
@@ -458,8 +459,9 @@ find_closest (void *cls, | |||
458 | j = i; | 459 | j = i; |
459 | break; | 460 | break; |
460 | } | 461 | } |
461 | if (1 == GNUNET_CRYPTO_hash_cmp (&gcc->values[i]->key, | 462 | if (1 == |
462 | key)) | 463 | GNUNET_CRYPTO_hash_cmp (&gcc->values[i]->key, |
464 | key)) | ||
463 | { | 465 | { |
464 | j = i; | 466 | j = i; |
465 | break; | 467 | break; |
@@ -499,14 +501,14 @@ heap_plugin_get_closest (void *cls, | |||
499 | struct GetClosestContext gcc = { | 501 | struct GetClosestContext gcc = { |
500 | .values = values, | 502 | .values = values, |
501 | .type = type, | 503 | .type = type, |
502 | .num_results = num_results, | 504 | .num_results = num_results * 2, |
503 | .key = key | 505 | .key = key |
504 | }; | 506 | }; |
505 | 507 | ||
506 | GNUNET_CONTAINER_multihashmap_iterate (plugin->map, | 508 | GNUNET_CONTAINER_multihashmap_iterate (plugin->map, |
507 | &find_closest, | 509 | &find_closest, |
508 | &gcc); | 510 | &gcc); |
509 | for (unsigned int i = 0; i < num_results; i++) | 511 | for (unsigned int i = 0; i < num_results * 2; i++) |
510 | { | 512 | { |
511 | if (NULL == values[i]) | 513 | if (NULL == values[i]) |
512 | return i; | 514 | return i; |
@@ -519,7 +521,7 @@ heap_plugin_get_closest (void *cls, | |||
519 | values[i]->path_info_len, | 521 | values[i]->path_info_len, |
520 | values[i]->path_info); | 522 | values[i]->path_info); |
521 | } | 523 | } |
522 | return num_results; | 524 | return num_results * 2; |
523 | } | 525 | } |
524 | 526 | ||
525 | 527 | ||