aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-02-23 00:30:36 +0100
committerChristian Grothoff <christian@grothoff.org>2022-02-23 00:30:36 +0100
commit0209b47aeddf61686fe08e946d8909860cfb161a (patch)
tree5e683a11dbb6698d97ed6363ab80fe36c3fef38b /src
parent020df0bf2999e990806b72356c9a477b31b0142c (diff)
downloadgnunet-0209b47aeddf61686fe08e946d8909860cfb161a.tar.gz
gnunet-0209b47aeddf61686fe08e946d8909860cfb161a.zip
-fix datacache to return 2x num_closest in both directions
Diffstat (limited to 'src')
-rw-r--r--src/datacache/plugin_datacache_heap.c16
-rw-r--r--src/datacache/plugin_datacache_postgres.c12
-rw-r--r--src/datacache/plugin_datacache_sqlite.c12
-rw-r--r--src/dht/gnunet-service-dht_datacache.c2
-rw-r--r--src/include/gnunet_datacache_plugin.h11
5 files changed, 35 insertions, 18 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
438static int 439static enum GNUNET_GenericReturnValue
439find_closest (void *cls, 440find_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
diff --git a/src/datacache/plugin_datacache_postgres.c b/src/datacache/plugin_datacache_postgres.c
index 4e48d89df..1a83cda86 100644
--- a/src/datacache/plugin_datacache_postgres.c
+++ b/src/datacache/plugin_datacache_postgres.c
@@ -108,14 +108,20 @@ init_connection (struct Plugin *plugin)
108 "SELECT length(value) AS len,oid,key FROM gn011dc" 108 "SELECT length(value) AS len,oid,key FROM gn011dc"
109 " ORDER BY prox ASC, discard_time ASC LIMIT 1", 109 " ORDER BY prox ASC, discard_time ASC LIMIT 1",
110 0), 110 0),
111 /* FIXME: do key >= ASC + UNION key <= DESC! */
112 GNUNET_PQ_make_prepare ("get_closest", 111 GNUNET_PQ_make_prepare ("get_closest",
113 "SELECT discard_time,type,value,path,key FROM gn011dc" 112 "(SELECT discard_time,type,value,path,key FROM gn011dc"
114 " WHERE key >= $1" 113 " WHERE key >= $1"
115 " AND discard_time >= $2" 114 " AND discard_time >= $2"
116 " AND ( (type = $3) OR ( 0 = $3) )" 115 " AND ( (type = $3) OR ( 0 = $3) )"
117 " ORDER BY key ASC" 116 " ORDER BY key ASC"
118 " LIMIT $4", 117 " LIMIT $4)"
118 " UNION "
119 "(SELECT discard_time,type,value,path,key FROM gn011dc"
120 " WHERE key <= $1"
121 " AND discard_time >= $2"
122 " AND ( (type = $3) OR ( 0 = $3) )"
123 " ORDER BY key DESC"
124 " LIMIT $4)",
119 4), 125 4),
120 GNUNET_PQ_make_prepare ("delrow", 126 GNUNET_PQ_make_prepare ("delrow",
121 "DELETE FROM gn011dc WHERE oid=$1", 127 "DELETE FROM gn011dc WHERE oid=$1",
diff --git a/src/datacache/plugin_datacache_sqlite.c b/src/datacache/plugin_datacache_sqlite.c
index 46ff66dce..e5ee3e5a8 100644
--- a/src/datacache/plugin_datacache_sqlite.c
+++ b/src/datacache/plugin_datacache_sqlite.c
@@ -651,11 +651,19 @@ libgnunet_plugin_datacache_sqlite_init (void *cls)
651 &plugin->del_stmt)) || 651 &plugin->del_stmt)) ||
652 (SQLITE_OK != 652 (SQLITE_OK !=
653 sq_prepare (plugin->dbh, 653 sq_prepare (plugin->dbh,
654 "SELECT value,expire,path,type,key FROM ds091 " 654 "SELECT * FROM ("
655 " SELECT value,expire,path,type,key FROM ds091 "
655 " WHERE key>=?1 " 656 " WHERE key>=?1 "
656 " AND expire >= ?2" 657 " AND expire >= ?2"
657 " AND ( (type=?3) or (0 == ?3) )" 658 " AND ( (type=?3) or (0 == ?3) )"
658 " ORDER BY KEY ASC LIMIT ?4", 659 " ORDER BY KEY ASC LIMIT ?4)"
660 "UNION "
661 "SELECT * FROM ("
662 " SELECT value,expire,path,type,key FROM ds091 "
663 " WHERE key>=?1 "
664 " AND expire >= ?2"
665 " AND ( (type=?3) or (0 == ?3) )"
666 " ORDER BY KEY ASC LIMIT ?4)",
659 &plugin->get_closest_stmt))) 667 &plugin->get_closest_stmt)))
660 { 668 {
661 LOG_SQLITE (plugin->dbh, 669 LOG_SQLITE (plugin->dbh,
diff --git a/src/dht/gnunet-service-dht_datacache.c b/src/dht/gnunet-service-dht_datacache.c
index 880c72cb2..91bdfe3da 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/**
diff --git a/src/include/gnunet_datacache_plugin.h b/src/include/gnunet_datacache_plugin.h
index 914aaf15c..34bf5f277 100644
--- a/src/include/gnunet_datacache_plugin.h
+++ b/src/include/gnunet_datacache_plugin.h
@@ -158,15 +158,16 @@ struct GNUNET_DATACACHE_PluginFunctions
158 158
159 159
160 /** 160 /**
161 * Iterate over the results that are "close" to a particular key in 161 * Iterate over the results that are "close" to a particular key in the
162 * the datacache. "close" is defined as numerically larger than @a 162 * datacache. "close" is defined as returning the @a num_results that are
163 * key (when interpreted as a circular address space), with small 163 * numerically closest and larger than @a key and also @a num_results that
164 * distance. 164 * are numerically lower than @a key. Thus, the maximum number of results
165 * returned is actually twice @a num_results.
165 * 166 *
166 * @param cls closure (internal context for the plugin) 167 * @param cls closure (internal context for the plugin)
167 * @param key area of the keyspace to look into 168 * @param key area of the keyspace to look into
168 * @param type desired block type for the replies 169 * @param type desired block type for the replies
169 * @param num_results number of results that should be returned to @a iter 170 * @param num_results half the number of results that should be returned to @a iter
170 * @param iter maybe NULL (to just count) 171 * @param iter maybe NULL (to just count)
171 * @param iter_cls closure for @a iter 172 * @param iter_cls closure for @a iter
172 * @return the number of results found 173 * @return the number of results found