diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-05-30 18:47:17 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-05-30 18:47:17 +0200 |
commit | adef29b3ed00afd42669ae35a73951c59f08a41b (patch) | |
tree | c8d6c7f60716c551b587aed7a1efe0d6e756833f | |
parent | f5a18b7466f342ac9624adcdb65f104aef8ecb5e (diff) |
add proximity considerations to datacache
-rw-r--r-- | src/datacache/datacache.c | 3 | ||||
-rw-r--r-- | src/datacache/plugin_datacache_heap.c | 117 | ||||
-rw-r--r-- | src/datacache/plugin_datacache_postgres.c | 2 | ||||
-rw-r--r-- | src/datacache/plugin_datacache_sqlite.c | 61 | ||||
-rw-r--r-- | src/datacache/plugin_datacache_template.c | 2 | ||||
-rw-r--r-- | src/datacache/test_datacache.c | 10 | ||||
-rw-r--r-- | src/datacache/test_datacache_quota.c | 10 | ||||
-rw-r--r-- | src/dht/gnunet-dht-get.c | 22 | ||||
-rw-r--r-- | src/dht/gnunet-dht-monitor.c | 27 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_datacache.c | 6 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_neighbours.c | 12 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_neighbours.h | 16 | ||||
-rw-r--r-- | src/gns/gnunet-gns-benchmark.c | 2 | ||||
-rw-r--r-- | src/gns/gnunet-service-gns_resolver.c | 2 | ||||
-rw-r--r-- | src/include/gnunet_datacache_lib.h | 2 | ||||
-rw-r--r-- | src/include/gnunet_datacache_plugin.h | 2 |
16 files changed, 245 insertions, 51 deletions
diff --git a/src/datacache/datacache.c b/src/datacache/datacache.c index 0646019bd7..18a2ed228e 100644 --- a/src/datacache/datacache.c +++ b/src/datacache/datacache.c @@ -260,6 +260,7 @@ GNUNET_DATACACHE_destroy (struct GNUNET_DATACACHE_Handle *h) * * @param h handle to the datacache * @param key key to store data under + * @param am_closest are we the closest peer? * @param data_size number of bytes in @a data * @param data data to store * @param type type of the value @@ -271,6 +272,7 @@ GNUNET_DATACACHE_destroy (struct GNUNET_DATACACHE_Handle *h) int GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h, const struct GNUNET_HashCode *key, + int am_closest, size_t data_size, const char *data, enum GNUNET_BLOCK_Type type, @@ -282,6 +284,7 @@ GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h, used = h->api->put (h->api->cls, key, + am_closest, data_size, data, type, diff --git a/src/datacache/plugin_datacache_heap.c b/src/datacache/plugin_datacache_heap.c index 49e60bca1d..c32edf8e2e 100644 --- a/src/datacache/plugin_datacache_heap.c +++ b/src/datacache/plugin_datacache_heap.c @@ -53,6 +53,11 @@ struct Plugin */ struct GNUNET_CONTAINER_Heap *heap; + /** + * Heap from the plugin for "closest" values. + */ + struct GNUNET_CONTAINER_Heap *cheap; + }; @@ -92,6 +97,11 @@ struct Value unsigned int path_info_len; /** + * Am I the closest peer? Determines which heap we are in! + */ + int am_closest; + + /** * Type of the block. */ enum GNUNET_BLOCK_Type type; @@ -118,6 +128,11 @@ struct PutContext const char *data; /** + * Heap from the plugin for "closest" values. + */ + struct GNUNET_CONTAINER_Heap *cheap; + + /** * Heap from the plugin. */ struct GNUNET_CONTAINER_Heap *heap; @@ -168,7 +183,9 @@ put_cb (void *cls, if ( (val->size == put_ctx->size) && (val->type == put_ctx->type) && - (0 == memcmp (&val[1], put_ctx->data, put_ctx->size)) ) + (0 == memcmp (&val[1], + put_ctx->data, + put_ctx->size)) ) { put_ctx->found = GNUNET_YES; val->discard_time = GNUNET_TIME_absolute_max (val->discard_time, @@ -199,6 +216,7 @@ put_cb (void *cls, * * @param cls closure (our `struct Plugin`) * @param key key to store data under + * @param am_closest are we the closest peer? * @param size number of bytes in @a data * @param data data to store * @param type type of the value @@ -210,6 +228,7 @@ put_cb (void *cls, static ssize_t heap_plugin_put (void *cls, const struct GNUNET_HashCode *key, + int am_closest, size_t size, const char *data, enum GNUNET_BLOCK_Type type, @@ -223,6 +242,7 @@ heap_plugin_put (void *cls, put_ctx.found = GNUNET_NO; put_ctx.heap = plugin->heap; + put_ctx.cheap = plugin->cheap; put_ctx.data = data; put_ctx.size = size; put_ctx.path_info = path_info; @@ -241,17 +261,20 @@ heap_plugin_put (void *cls, val->type = type; val->discard_time = discard_time; val->size = size; + val->am_closest = am_closest; GNUNET_array_grow (val->path_info, val->path_info_len, path_info_len); GNUNET_memcpy (val->path_info, - path_info, - path_info_len * sizeof (struct GNUNET_PeerIdentity)); + path_info, + path_info_len * sizeof (struct GNUNET_PeerIdentity)); (void) GNUNET_CONTAINER_multihashmap_put (plugin->map, &val->key, val, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); - val->hn = GNUNET_CONTAINER_heap_insert (plugin->heap, + val->hn = GNUNET_CONTAINER_heap_insert (am_closest + ? plugin->cheap + : plugin->heap, val, val->discard_time.abs_value_us); return size + OVERHEAD; @@ -371,6 +394,8 @@ heap_plugin_del (void *cls) val = GNUNET_CONTAINER_heap_remove_root (plugin->heap); if (NULL == val) + val = GNUNET_CONTAINER_heap_remove_root (plugin->cheap); + if (NULL == val) return GNUNET_SYSERR; GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (plugin->map, @@ -413,6 +438,53 @@ heap_plugin_get_random (void *cls, /** + * Closure for #find_closest(). + */ +struct GetClosestContext +{ + struct Value **values; + + unsigned int num_results; + + const struct GNUNET_HashCode *key; +}; + + +static int +find_closest (void *cls, + const struct GNUNET_HashCode *key, + void *value) +{ + struct GetClosestContext *gcc = cls; + struct Value *val = value; + unsigned int j; + + if (1 != GNUNET_CRYPTO_hash_cmp (key, + gcc->key)) + return GNUNET_OK; /* useless */ + j = gcc->num_results; + for (unsigned int i=0;i<gcc->num_results;i++) + { + if (NULL == gcc->values[i]) + { + j = i; + break; + } + if (1 == GNUNET_CRYPTO_hash_cmp (&gcc->values[i]->key, + key)) + { + j = i; + break; + } + } + if (j == gcc->num_results) + return GNUNET_OK; + gcc->values[j] = val; + return GNUNET_OK; +} + + +/** * Iterate over the results that are "close" to a particular key in * the datacache. "close" is defined as numerically larger than @a * key (when interpreted as a circular address space), with small @@ -432,8 +504,30 @@ heap_plugin_get_closest (void *cls, GNUNET_DATACACHE_Iterator iter, void *iter_cls) { - GNUNET_break (0); // not implemented! - return 0; + struct Plugin *plugin = cls; + struct Value *values[num_results]; + struct GetClosestContext gcc = { + .values = values, + .num_results = num_results, + .key = key + }; + GNUNET_CONTAINER_multihashmap_iterate (plugin->map, + &find_closest, + &gcc); + for (unsigned int i=0;i<num_results;i++) + { + if (NULL == values[i]) + return i; + iter (iter_cls, + &values[i]->key, + values[i]->size, + (void *) &values[i][1], + values[i]->type, + values[i]->discard_time, + values[i]->path_info_len, + values[i]->path_info); + } + return num_results; } @@ -454,6 +548,7 @@ libgnunet_plugin_datacache_heap_init (void *cls) plugin->map = GNUNET_CONTAINER_multihashmap_create (1024, /* FIXME: base on quota! */ GNUNET_YES); plugin->heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); + plugin->cheap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); plugin->env = env; api = GNUNET_new (struct GNUNET_DATACACHE_PluginFunctions); api->cls = plugin; @@ -490,7 +585,17 @@ libgnunet_plugin_datacache_heap_done (void *cls) GNUNET_free_non_null (val->path_info); GNUNET_free (val); } + while (NULL != (val = GNUNET_CONTAINER_heap_remove_root (plugin->cheap))) + { + GNUNET_assert (GNUNET_YES == + GNUNET_CONTAINER_multihashmap_remove (plugin->map, + &val->key, + val)); + GNUNET_free_non_null (val->path_info); + GNUNET_free (val); + } GNUNET_CONTAINER_heap_destroy (plugin->heap); + GNUNET_CONTAINER_heap_destroy (plugin->cheap); GNUNET_CONTAINER_multihashmap_destroy (plugin->map); GNUNET_free (plugin); GNUNET_free (api); diff --git a/src/datacache/plugin_datacache_postgres.c b/src/datacache/plugin_datacache_postgres.c index 2c233c4c21..c6ccfb2109 100644 --- a/src/datacache/plugin_datacache_postgres.c +++ b/src/datacache/plugin_datacache_postgres.c @@ -141,6 +141,7 @@ init_connection (struct Plugin *plugin) * * @param cls closure (our `struct Plugin`) * @param key key to store @a data under + * @param am_closest are we the closest peer? * @param data_size number of bytes in @a data * @param data data to store * @param type type of the value @@ -152,6 +153,7 @@ init_connection (struct Plugin *plugin) static ssize_t postgres_plugin_put (void *cls, const struct GNUNET_HashCode *key, + int am_closest, size_t data_size, const char *data, enum GNUNET_BLOCK_Type type, diff --git a/src/datacache/plugin_datacache_sqlite.c b/src/datacache/plugin_datacache_sqlite.c index 15438b29b8..455dcab0b3 100644 --- a/src/datacache/plugin_datacache_sqlite.c +++ b/src/datacache/plugin_datacache_sqlite.c @@ -38,7 +38,7 @@ * How much overhead do we assume per entry in the * datacache? */ -#define OVERHEAD (sizeof(struct GNUNET_HashCode) + 32) +#define OVERHEAD (sizeof(struct GNUNET_HashCode) + 36) /** * Context for all functions in this plugin. @@ -150,6 +150,7 @@ sq_prepare (sqlite3 *dbh, * * @param cls closure (our `struct Plugin`) * @param key key to store @a data under + * @param am_closest are we the closest peer? * @param size number of bytes in @a data * @param data data to store * @param type type of the value @@ -161,6 +162,7 @@ sq_prepare (sqlite3 *dbh, static ssize_t sqlite_plugin_put (void *cls, const struct GNUNET_HashCode *key, + int am_closest, size_t size, const char *data, enum GNUNET_BLOCK_Type type, @@ -170,10 +172,12 @@ sqlite_plugin_put (void *cls, { struct Plugin *plugin = cls; uint32_t type32 = type; + uint32_t prox = am_closest; struct GNUNET_SQ_QueryParam params[] = { GNUNET_SQ_query_param_uint32 (&type32), GNUNET_SQ_query_param_absolute_time (&discard_time), GNUNET_SQ_query_param_auto_from_type (key), + GNUNET_SQ_query_param_uint32 (&prox), GNUNET_SQ_query_param_fixed_size (data, size), GNUNET_SQ_query_param_fixed_size (path_info, path_info_len * sizeof (struct GNUNET_PeerIdentity)), @@ -386,6 +390,7 @@ sqlite_plugin_del (void *cls) uint64_t rowid; void *data; size_t dsize; + uint32_t prox; struct GNUNET_HashCode hc; struct GNUNET_SQ_ResultSpec rs[] = { GNUNET_SQ_result_spec_uint64 (&rowid), @@ -398,9 +403,26 @@ sqlite_plugin_del (void *cls) GNUNET_SQ_query_param_uint64 (&rowid), GNUNET_SQ_query_param_end }; + struct GNUNET_SQ_QueryParam prox_params[] = { + GNUNET_SQ_query_param_uint32 (&prox), + GNUNET_SQ_query_param_end + }; LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing DEL\n"); + prox = GNUNET_NO; + again: + if (GNUNET_OK != + GNUNET_SQ_bind (plugin->del_select_stmt, + prox_params)) + { + LOG_SQLITE (plugin->dbh, + GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + "sqlite3_bind"); + GNUNET_SQ_reset (plugin->dbh, + plugin->del_stmt); + return GNUNET_SYSERR; + } if (SQLITE_ROW != sqlite3_step (plugin->del_select_stmt)) { @@ -409,15 +431,25 @@ sqlite_plugin_del (void *cls) "sqlite3_step"); GNUNET_SQ_reset (plugin->dbh, plugin->del_select_stmt); + if (GNUNET_NO == prox) + { + prox = GNUNET_YES; + goto again; + } return GNUNET_SYSERR; } if (GNUNET_OK != GNUNET_SQ_extract_result (plugin->del_select_stmt, rs)) { - GNUNET_break (0); GNUNET_SQ_reset (plugin->dbh, plugin->del_select_stmt); + if (GNUNET_NO == prox) + { + prox = GNUNET_YES; + goto again; + } + GNUNET_break (0); return GNUNET_SYSERR; } GNUNET_SQ_cleanup_result (rs); @@ -709,13 +741,14 @@ libgnunet_plugin_datacache_sqlite_init (void *cls) SQLITE3_EXEC (dbh, "PRAGMA sqlite_temp_store=3"); SQLITE3_EXEC (dbh, - "CREATE TABLE ds090 (" " type INTEGER NOT NULL DEFAULT 0," - " expire INTEGER NOT NULL DEFAULT 0," + "CREATE TABLE ds091 (" " type INTEGER NOT NULL DEFAULT 0," + " expire INTEGER NOT NULL," " key BLOB NOT NULL DEFAULT ''," - " value BLOB NOT NULL DEFAULT ''," + " prox INTEGER NOT NULL," + " value BLOB NOT NULL," " path BLOB DEFAULT '')"); SQLITE3_EXEC (dbh, "CREATE INDEX idx_hashidx ON ds090 (key,type,expire)"); - SQLITE3_EXEC (dbh, "CREATE INDEX idx_expire ON ds090 (expire)"); + SQLITE3_EXEC (dbh, "CREATE INDEX idx_expire ON ds090 (prox,expire)"); plugin = GNUNET_new (struct Plugin); plugin->env = env; plugin->dbh = dbh; @@ -723,35 +756,35 @@ libgnunet_plugin_datacache_sqlite_init (void *cls) if ( (SQLITE_OK != sq_prepare (plugin->dbh, - "INSERT INTO ds090 (type, expire, key, value, path) " - "VALUES (?, ?, ?, ?, ?)", + "INSERT INTO ds091 (type, expire, key, prox, value, path) " + "VALUES (?, ?, ?, ?, ?, ?)", &plugin->insert_stmt)) || (SQLITE_OK != sq_prepare (plugin->dbh, - "SELECT count(*) FROM ds090 " + "SELECT count(*) FROM ds091 " "WHERE key=? AND type=? AND expire >= ?", &plugin->get_count_stmt)) || (SQLITE_OK != sq_prepare (plugin->dbh, - "SELECT value,expire,path FROM ds090 " + "SELECT value,expire,path FROM ds091 " "WHERE key=? AND type=? AND expire >= ? LIMIT 1 OFFSET ?", &plugin->get_stmt)) || (SQLITE_OK != sq_prepare (plugin->dbh, - "SELECT _ROWID_,key,value FROM ds090 ORDER BY expire ASC LIMIT 1", + "SELECT _ROWID_,key,value FROM ds091 WHERE prox=? ORDER BY expire ASC LIMIT 1", &plugin->del_select_stmt)) || (SQLITE_OK != sq_prepare (plugin->dbh, - "DELETE FROM ds090 WHERE _ROWID_=?", + "DELETE FROM ds091 WHERE _ROWID_=?", &plugin->del_stmt)) || (SQLITE_OK != sq_prepare (plugin->dbh, - "SELECT value,expire,path,key,type FROM ds090 " + "SELECT value,expire,path,key,type FROM ds091 " "ORDER BY key LIMIT 1 OFFSET ?", &plugin->get_random_stmt)) || (SQLITE_OK != sq_prepare (plugin->dbh, - "SELECT value,expire,path,type,key FROM ds090 " + "SELECT value,expire,path,type,key FROM ds091 " "WHERE key>=? AND expire >= ? ORDER BY KEY ASC LIMIT ?", &plugin->get_closest_stmt)) ) diff --git a/src/datacache/plugin_datacache_template.c b/src/datacache/plugin_datacache_template.c index b9baa64d34..28bcbcd26a 100644 --- a/src/datacache/plugin_datacache_template.c +++ b/src/datacache/plugin_datacache_template.c @@ -45,6 +45,7 @@ struct Plugin * * @param cls closure (our `struct Plugin`) * @param key key to store @a data under + * @param am_closest are we the closest peer? * @param size number of bytes in @a data * @param data data to store * @param type type of the value @@ -56,6 +57,7 @@ struct Plugin static ssize_t template_plugin_put (void *cls, const struct GNUNET_HashCode *key, + int am_closest, size_t size, const char *data, enum GNUNET_BLOCK_Type type, diff --git a/src/datacache/test_datacache.c b/src/datacache/test_datacache.c index 79e6b6d749..c4d59c3cc6 100644 --- a/src/datacache/test_datacache.c +++ b/src/datacache/test_datacache.c @@ -87,7 +87,10 @@ run (void *cls, char *const *args, const char *cfgfile, { GNUNET_CRYPTO_hash (&k, sizeof (struct GNUNET_HashCode), &n); ASSERT (GNUNET_OK == - GNUNET_DATACACHE_put (h, &k, sizeof (struct GNUNET_HashCode), + GNUNET_DATACACHE_put (h, + &k, + GNUNET_YES, + sizeof (struct GNUNET_HashCode), (const char *) &n, 1 + i % 16, exp, 0, NULL)); k = n; @@ -103,7 +106,10 @@ run (void *cls, char *const *args, const char *cfgfile, memset (&k, 42, sizeof (struct GNUNET_HashCode)); GNUNET_CRYPTO_hash (&k, sizeof (struct GNUNET_HashCode), &n); ASSERT (GNUNET_OK == - GNUNET_DATACACHE_put (h, &k, sizeof (struct GNUNET_HashCode), + GNUNET_DATACACHE_put (h, + &k, + GNUNET_YES, + sizeof (struct GNUNET_HashCode), (const char *) &n, 792, GNUNET_TIME_UNIT_FOREVER_ABS, 0, NULL)); diff --git a/src/datacache/test_datacache_quota.c b/src/datacache/test_datacache_quota.c index 78b56ce425..35357a8d28 100644 --- a/src/datacache/test_datacache_quota.c +++ b/src/datacache/test_datacache_quota.c @@ -73,7 +73,15 @@ run (void *cls, char *const *args, const char *cfgfile, { exp.abs_value_us++; buf[j] = i; - ASSERT (GNUNET_OK == GNUNET_DATACACHE_put (h, &k, j, buf, 1 + i, exp, 0, NULL)); + ASSERT (GNUNET_OK == GNUNET_DATACACHE_put (h, + &k, + GNUNET_YES, + j, + buf, + 1 + i, + exp, + 0, + NULL)); ASSERT (0 < GNUNET_DATACACHE_get (h, &k, 1 + i, NULL, NULL)); } k = n; diff --git a/src/dht/gnunet-dht-get.c b/src/dht/gnunet-dht-get.c index 842ec6270e..afcd5422cc 100644 --- a/src/dht/gnunet-dht-get.c +++ b/src/dht/gnunet-dht-get.c @@ -154,7 +154,9 @@ get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, const void *data) { FPRINTF (stdout, - _("Result %d, type %d:\n%.*s\n"), + (GNUNET_BLOCK_TYPE_TEST == type) + ? _("Result %d, type %d:\n%.*s\n") + : _("Result %d, type %d:\n"), result_count, type, (unsigned int) size, @@ -196,8 +198,6 @@ run (void *cls, char *const *args, const char *cfgfile, { struct GNUNET_HashCode key; - - cfg = c; if (NULL == query_key) { @@ -215,17 +215,22 @@ run (void *cls, char *const *args, const char *cfgfile, query_type = GNUNET_BLOCK_TYPE_TEST; GNUNET_CRYPTO_hash (query_key, strlen (query_key), &key); if (verbose) - FPRINTF (stderr, "%s `%s' \n", _("Issueing DHT GET with key"), GNUNET_h2s_full (&key)); + FPRINTF (stderr, "%s `%s' \n", + _("Issueing DHT GET with key"), + GNUNET_h2s_full (&key)); GNUNET_SCHEDULER_add_shutdown (&cleanup_task, NULL); tt = GNUNET_SCHEDULER_add_delayed (timeout_request, - &timeout_task, NULL); + &timeout_task, + NULL); get_handle = GNUNET_DHT_get_start (dht_handle, query_type, &key, replication, (demultixplex_everywhere) ? GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE : GNUNET_DHT_RO_NONE, - NULL, 0, &get_result_iterator, NULL); - + NULL, 0, + &get_result_iterator, + NULL); } + /** * Entry point for gnunet-dht-get * @@ -236,15 +241,12 @@ run (void *cls, char *const *args, const char *cfgfile, int main (int argc, char *const *argv) { - struct GNUNET_GETOPT_CommandLineOption options[] = { - GNUNET_GETOPT_option_string ('k', "key", "KEY", gettext_noop ("the query key"), &query_key), - GNUNET_GETOPT_option_uint ('r', "replication", "LEVEL", diff --git a/src/dht/gnunet-dht-monitor.c b/src/dht/gnunet-dht-monitor.c index b7360bbabc..a699b3d175 100644 --- a/src/dht/gnunet-dht-monitor.c +++ b/src/dht/gnunet-dht-monitor.c @@ -141,7 +141,8 @@ get_callback (void *cls, const struct GNUNET_PeerIdentity *path, const struct GNUNET_HashCode * key) { - FPRINTF (stdout, "GET #%u: type %d, key `%s'\n", + FPRINTF (stdout, + "GET #%u: type %d, key `%s'\n", result_count, (int) type, GNUNET_h2s_full(key)); @@ -176,8 +177,11 @@ get_resp_callback (void *cls, size_t size) { FPRINTF (stdout, - "RESPONSE #%u: type %d, key `%s', data `%.*s'\n", + (GNUNET_BLOCK_TYPE_TEST == type) + ? "RESPONSE #%u (%s): type %d, key `%s', data `%.*s'\n" + : "RESPONSE #%u (%s): type %d, key `%s'\n", result_count, + GNUNET_STRINGS_absolute_time_to_string (exp), (int) type, GNUNET_h2s_full (key), (unsigned int) size, @@ -215,8 +219,11 @@ put_callback (void *cls, size_t size) { FPRINTF (stdout, - "PUT %u: type %d, key `%s', data `%.*s'\n", + (GNUNET_BLOCK_TYPE_TEST == type) + ? "PUT %u (%s): type %d, key `%s', data `%.*s'\n" + : "PUT %u (%s): type %d, key `%s'\n", result_count, + GNUNET_STRINGS_absolute_time_to_string (exp), (int) type, GNUNET_h2s_full(key), (unsigned int) size, @@ -234,7 +241,9 @@ put_callback (void *cls, * @param c configuration */ static void -run (void *cls, char *const *args, const char *cfgfile, +run (void *cls, + char *const *args, + const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) { struct GNUNET_HashCode *key; @@ -291,30 +300,30 @@ int main (int argc, char *const *argv) { struct GNUNET_GETOPT_CommandLineOption options[] = { - + GNUNET_GETOPT_option_string ('k', "key", "KEY", gettext_noop ("the query key"), &query_key), - + GNUNET_GETOPT_option_uint ('t', "type", "TYPE", gettext_noop ("the type of data to look for"), &block_type), - + GNUNET_GETOPT_option_relative_time ('T', "timeout", "TIMEOUT", gettext_noop ("how long should the monitor command run"), &timeout_request), - + GNUNET_GETOPT_option_flag ('V', "verbose", gettext_noop ("be verbose (print progress information)"), &verbose), - + GNUNET_GETOPT_OPTION_END }; diff --git a/src/dht/gnunet-service-dht_datacache.c b/src/dht/gnunet-service-dht_datacache.c index 36047d5619..81b7184edb 100644 --- a/src/dht/gnunet-service-dht_datacache.c +++ b/src/dht/gnunet-service-dht_datacache.c @@ -26,6 +26,7 @@ #include "platform.h" #include "gnunet_datacache_lib.h" #include "gnunet-service-dht_datacache.h" +#include "gnunet-service-dht_neighbours.h" #include "gnunet-service-dht_routing.h" #include "gnunet-service-dht.h" @@ -79,10 +80,13 @@ GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration, } /* Put size is actual data size plus struct overhead plus path length (if any) */ GNUNET_STATISTICS_update (GDS_stats, - gettext_noop ("# ITEMS stored in datacache"), 1, + gettext_noop ("# ITEMS stored in datacache"), + 1, GNUNET_NO); r = GNUNET_DATACACHE_put (datacache, key, + GDS_am_closest_peer (key, + NULL), data_size, data, type, diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c index 0309bea880..b120091af2 100644 --- a/src/dht/gnunet-service-dht_neighbours.c +++ b/src/dht/gnunet-service-dht_neighbours.c @@ -421,7 +421,7 @@ static struct GNUNET_ATS_ConnectivityHandle *ats_ch; * Find the optimal bucket for this key. * * @param hc the hashcode to compare our identity to - * @return the proper bucket index, or GNUNET_SYSERR + * @return the proper bucket index, or #GNUNET_SYSERR * on error (same hashcode) */ static int @@ -941,9 +941,9 @@ get_distance (const struct GNUNET_HashCode *target, * @return #GNUNET_YES if node location is closest, * #GNUNET_NO otherwise. */ -static int -am_closest_peer (const struct GNUNET_HashCode *key, - const struct GNUNET_CONTAINER_BloomFilter *bloom) +int +GDS_am_closest_peer (const struct GNUNET_HashCode *key, + const struct GNUNET_CONTAINER_BloomFilter *bloom) { int bits; int other_bits; @@ -1803,7 +1803,7 @@ handle_dht_p2p_put (void *cls, payload); /* store locally */ if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || - (am_closest_peer (&put->key, bf))) + (GDS_am_closest_peer (&put->key, bf))) GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (put->expiration_time), &put->key, putlen, @@ -2122,7 +2122,7 @@ handle_dht_p2p_get (void *cls, (unsigned int) ntohl (get->hop_count)); /* local lookup (this may update the reply_bf) */ if ((0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || - (am_closest_peer (&get->key, + (GDS_am_closest_peer (&get->key, peer_bf))) { if ((0 != (options & GNUNET_DHT_RO_FIND_PEER))) diff --git a/src/dht/gnunet-service-dht_neighbours.h b/src/dht/gnunet-service-dht_neighbours.h index 34b76ee8a2..bb1867fe9f 100644 --- a/src/dht/gnunet-service-dht_neighbours.h +++ b/src/dht/gnunet-service-dht_neighbours.h @@ -123,6 +123,22 @@ GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target, /** + * Check whether my identity is closer than any known peers. If a + * non-null bloomfilter is given, check if this is the closest peer + * that hasn't already been routed to. + * + * @param key hash code to check closeness to + * @param bloom bloomfilter, exclude these entries from the decision + * @return #GNUNET_YES if node location is closest, + * #GNUNET_NO otherwise. + */ +int +GDS_am_closest_peer (const struct GNUNET_HashCode *key, + const struct GNUNET_CONTAINER_BloomFilter *bloom); + + + +/** * Initialize neighbours subsystem. * * @return #GNUNET_OK on success, #GNUNET_SYSERR on error diff --git a/src/gns/gnunet-gns-benchmark.c b/src/gns/gnunet-gns-benchmark.c index 0ab6cefd53..414c844952 100644 --- a/src/gns/gnunet-gns-benchmark.c +++ b/src/gns/gnunet-gns-benchmark.c @@ -294,7 +294,7 @@ process_queue (void *cls) active_cnt); req->lr = GNUNET_GNS_lookup_with_tld (gns, req->hostname, - GNUNET_GNSRECORD_TYPE_ANY, + GNUNET_GNSRECORD_TYPE_GNS2DNS, GNUNET_GNS_LO_DEFAULT, &process_result, req); diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c index 8b20f2ae36..0d04fc6b9c 100644 --- a/src/gns/gnunet-service-gns_resolver.c +++ b/src/gns/gnunet-service-gns_resolver.c @@ -60,7 +60,7 @@ /** * DHT replication level */ -#define DHT_GNS_REPLICATION_LEVEL 5 +#define DHT_GNS_REPLICATION_LEVEL 10 /** * How deep do we allow recursions to go before we abort? diff --git a/src/include/gnunet_datacache_lib.h b/src/include/gnunet_datacache_lib.h index 39a312b17a..066b02ca91 100644 --- a/src/include/gnunet_datacache_lib.h +++ b/src/include/gnunet_datacache_lib.h @@ -105,6 +105,7 @@ typedef int * * @param h handle to the datacache * @param key key to store data under + * @param am_closest am I the closest peer? * @param data_size number of bytes in @a data * @param data data to store * @param type type of the value @@ -116,6 +117,7 @@ typedef int int GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h, const struct GNUNET_HashCode *key, + int am_closest, size_t data_size, const char *data, enum GNUNET_BLOCK_Type type, diff --git a/src/include/gnunet_datacache_plugin.h b/src/include/gnunet_datacache_plugin.h index 166c7bc3b6..9746b6493e 100644 --- a/src/include/gnunet_datacache_plugin.h +++ b/src/include/gnunet_datacache_plugin.h @@ -109,6 +109,7 @@ struct GNUNET_DATACACHE_PluginFunctions * * @param cls closure (internal context for the plugin) * @param key key to store the value under + * @param am_closest are we the closest peer? * @param size number of bytes in @a data * @param data data to store * @param type type of the value @@ -119,6 +120,7 @@ struct GNUNET_DATACACHE_PluginFunctions */ ssize_t (*put) (void *cls, const struct GNUNET_HashCode *key, + int am_closest, size_t size, const char *data, enum GNUNET_BLOCK_Type type, |