From 65b243be0941da4896afd842deda48cd0ce488e2 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 27 Sep 2011 21:06:11 +0000 Subject: [PATCH] DHT api switch adjustments --- src/fs/gnunet-service-fs_pr.c | 21 ++++---- src/fs/gnunet-service-fs_put.c | 2 +- src/include/gnunet_dht_service.h | 7 +++ src/mesh/gnunet-service-mesh.c | 90 +++++++++++++------------------- src/vpn/gnunet-service-dns.c | 15 +++--- 5 files changed, 65 insertions(+), 70 deletions(-) diff --git a/src/fs/gnunet-service-fs_pr.c b/src/fs/gnunet-service-fs_pr.c index d47d28ce6..dd59170a2 100644 --- a/src/fs/gnunet-service-fs_pr.c +++ b/src/fs/gnunet-service-fs_pr.c @@ -941,10 +941,10 @@ test_put_load_too_high (uint32_t priority) * @param cls closure * @param exp when will this value expire * @param key key of the result - * @param get_path NULL-terminated array of pointers - * to the peers on reverse GET path (or NULL if not recorded) - * @param put_path NULL-terminated array of pointers - * to the peers on the PUT path (or NULL if not recorded) + * @param get_path peers on reply path (or NULL if not recorded) + * @param get_path_length number of entries in get_path + * @param put_path peers on the PUT path (or NULL if not recorded) + * @param put_path_length number of entries in get_path * @param type type of the result * @param size number of bytes in data * @param data pointer to the result data @@ -952,8 +952,10 @@ test_put_load_too_high (uint32_t priority) static void handle_dht_reply (void *cls, struct GNUNET_TIME_Absolute exp, const GNUNET_HashCode * key, - const struct GNUNET_PeerIdentity *const *get_path, - const struct GNUNET_PeerIdentity *const *put_path, + const struct GNUNET_PeerIdentity *get_path, + unsigned int get_path_length, + const struct GNUNET_PeerIdentity *put_path, + unsigned int put_path_length, enum GNUNET_BLOCK_Type type, size_t size, const void *data) { struct GSF_PendingRequest *pr = cls; @@ -1032,9 +1034,10 @@ GSF_dht_lookup_ (struct GSF_PendingRequest *pr) pr->gh = GNUNET_DHT_get_start (GSF_dht, GNUNET_TIME_UNIT_FOREVER_REL, pr->public_data.type, &pr->public_data.query, - DEFAULT_GET_REPLICATION, - GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, pr->bf, - pr->mingle, xquery, xquery_size, &handle_dht_reply, + 5 /* DEFAULT_GET_REPLICATION */, + GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, + /* FIXME: can no longer pass pr->bf/pr->mingle... */ + xquery, xquery_size, &handle_dht_reply, pr); } diff --git a/src/fs/gnunet-service-fs_put.c b/src/fs/gnunet-service-fs_put.c index 5771b5665..4910144d1 100644 --- a/src/fs/gnunet-service-fs_put.c +++ b/src/fs/gnunet-service-fs_put.c @@ -161,7 +161,7 @@ process_dht_put_content (void *cls, const GNUNET_HashCode * key, size_t size, "Retrieved block `%s' of type %u for DHT PUT\n", GNUNET_h2s (key), type); #endif - GNUNET_DHT_put (GSF_dht, key, DEFAULT_PUT_REPLICATION, GNUNET_DHT_RO_NONE, + GNUNET_DHT_put (GSF_dht, key, 5 /* DEFAULT_PUT_REPLICATION */, GNUNET_DHT_RO_NONE, type, size, data, expiration, GNUNET_TIME_UNIT_FOREVER_REL, &delay_dht_put_blocks, po); } diff --git a/src/include/gnunet_dht_service.h b/src/include/gnunet_dht_service.h index 904357c92..fcbc8df47 100644 --- a/src/include/gnunet_dht_service.h +++ b/src/include/gnunet_dht_service.h @@ -40,6 +40,13 @@ extern "C" #endif +/** + * Default republication frequency for stored data in the DHT. + */ +#define GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 60) + + + /** * Connection to the DHT service. */ diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index c90cada1b..e26cf666e 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c @@ -577,10 +577,6 @@ announce_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) * @param cls closure * @param exp when will this value expire * @param key key of the result - * @param get_path NULL-terminated array of pointers - * to the peers on reverse GET path (or NULL if not recorded) - * @param put_path NULL-terminated array of pointers - * to the peers on the PUT path (or NULL if not recorded) * @param type type of the result * @param size number of bytes in data * @param data pointer to the result data @@ -588,8 +584,10 @@ announce_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) static void dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp, const GNUNET_HashCode * key, - const struct GNUNET_PeerIdentity *const *get_path, - const struct GNUNET_PeerIdentity *const *put_path, + const struct GNUNET_PeerIdentity *get_path, + unsigned int get_path_length, + const struct GNUNET_PeerIdentity *put_path, + unsigned int put_path_length, enum GNUNET_BLOCK_Type type, size_t size, const void *data); @@ -759,11 +757,9 @@ path_remove_from_peer (struct MeshPeerInfo *peer, &id.hashPubKey, /*key to search */ 4, /* replication level */ GNUNET_DHT_RO_RECORD_ROUTE, - NULL, /* bloom filter */ - 0, /* mutator */ NULL, /* xquery */ 0, /* xquery bits */ - dht_get_id_handler, + &dht_get_id_handler, (void *) path_info); } } @@ -839,27 +835,24 @@ path_add_to_origin (struct MeshPeerInfo *peer_info, struct MeshPeerPath *path) * Build a PeerPath from the paths returned from the DHT, reversing the paths * to obtain a local peer -> destination path and interning the peer ids. * - * @param get_path NULL-terminated array of pointers - * to the peers on reverse GET path (or NULL if not recorded) - * @param put_path NULL-terminated array of pointers - * to the peers on the PUT path (or NULL if not recorded) - * * @return Newly allocated and created path */ static struct MeshPeerPath * -path_build_from_dht (const struct GNUNET_PeerIdentity *const *get_path, - const struct GNUNET_PeerIdentity *const *put_path) +path_build_from_dht (const struct GNUNET_PeerIdentity *get_path, + unsigned int get_path_length, + const struct GNUNET_PeerIdentity *put_path, + unsigned int put_path_length) { struct MeshPeerPath *p; GNUNET_PEER_Id id; int i; p = path_new (0); - for (i = 0; get_path[i] != NULL; i++) ; + i = get_path_length; GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: GET has %d hops.\n", i); for (i--; i >= 0; i--) { - id = GNUNET_PEER_intern (get_path[i]); + id = GNUNET_PEER_intern (&get_path[i]); if (p->length > 0 && id == p->peers[p->length - 1]) { GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: Optimizing 1 hop out.\n"); @@ -873,11 +866,11 @@ path_build_from_dht (const struct GNUNET_PeerIdentity *const *get_path, p->length++; } } - for (i = 0; put_path[i] != NULL; i++) ; + i = put_path_length; GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: PUT has %d hops.\n", i); for (i--; i >= 0; i--) { - id = GNUNET_PEER_intern (put_path[i]); + id = GNUNET_PEER_intern (&put_path[i]); if (p->length > 0 && id == p->peers[p->length - 1]) { GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: Optimizing 1 hop out.\n"); @@ -894,10 +887,10 @@ path_build_from_dht (const struct GNUNET_PeerIdentity *const *get_path, #if MESH_DEBUG GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: (first of GET: %s)\n", - GNUNET_h2s_full(&get_path[0]->hashPubKey)); + GNUNET_h2s_full(&get_path[0].hashPubKey)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: (first of PUT: %s)\n", - GNUNET_h2s_full(&put_path[0]->hashPubKey)); + GNUNET_h2s_full(&put_path[0].hashPubKey)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: In total: %d hops\n", p->length); @@ -2046,10 +2039,6 @@ notify_client_connection_failure (void *cls, size_t size, void *buf) * @param cls closure * @param exp when will this value expire * @param key key of the result - * @param get_path NULL-terminated array of pointers - * to the peers on reverse GET path (or NULL if not recorded) - * @param put_path NULL-terminated array of pointers - * to the peers on the PUT path (or NULL if not recorded) * @param type type of the result * @param size number of bytes in data * @param data pointer to the result data @@ -2059,8 +2048,10 @@ notify_client_connection_failure (void *cls, size_t size, void *buf) static void dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp, const GNUNET_HashCode * key, - const struct GNUNET_PeerIdentity *const *get_path, - const struct GNUNET_PeerIdentity *const *put_path, + const struct GNUNET_PeerIdentity *get_path, + unsigned int get_path_length, + const struct GNUNET_PeerIdentity *put_path, + unsigned int put_path_length, enum GNUNET_BLOCK_Type type, size_t size, const void *data) { struct MeshPathInfo *path_info = cls; @@ -2080,17 +2071,16 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp, GNUNET_BLOCK_TYPE_TEST, /* type */ &pi.hashPubKey, /*key to search */ 4, /* replication level */ - GNUNET_DHT_RO_RECORD_ROUTE, NULL, /* bloom filter */ - 0, /* mutator */ + GNUNET_DHT_RO_RECORD_ROUTE, NULL, /* xquery */ 0, /* xquery bits */ - dht_get_id_handler, + &dht_get_id_handler, (void *) path_info); return; } } - p = path_build_from_dht (get_path, put_path); + p = path_build_from_dht (get_path, get_path_length, put_path, put_path_length); path_add_to_peer (path_info->peer, p); for (i = 0; i < path_info->peer->ntunnels; i++) { @@ -2110,10 +2100,6 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp, * @param cls closure * @param exp when will this value expire * @param key key of the result - * @param get_path NULL-terminated array of pointers - * to the peers on reverse GET path (or NULL if not recorded) - * @param put_path NULL-terminated array of pointers - * to the peers on the PUT path (or NULL if not recorded) * @param type type of the result * @param size number of bytes in data * @param data pointer to the result data @@ -2121,8 +2107,10 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp, static void dht_get_type_handler (void *cls, struct GNUNET_TIME_Absolute exp, const GNUNET_HashCode * key, - const struct GNUNET_PeerIdentity *const *get_path, - const struct GNUNET_PeerIdentity *const *put_path, + const struct GNUNET_PeerIdentity *get_path, + unsigned int get_path_length, + const struct GNUNET_PeerIdentity *put_path, + unsigned int put_path_length, enum GNUNET_BLOCK_Type type, size_t size, const void *data) { @@ -2162,8 +2150,6 @@ dht_get_type_handler (void *cls, struct GNUNET_TIME_Absolute exp, /* replication level */ GNUNET_DHT_RO_RECORD_ROUTE, /* option to dht: record route */ - NULL, /* bloom filter */ - 0, /* mutator */ NULL, /* xquery */ 0, /* xquery bits */ dht_get_id_handler, @@ -2171,7 +2157,7 @@ dht_get_type_handler (void *cls, struct GNUNET_TIME_Absolute exp, peer_info); /* closure */ } - p = path_build_from_dht (get_path, put_path); + p = path_build_from_dht (get_path, get_path_length, put_path, put_path_length); path_add_to_peer (peer_info, p); tunnel_add_peer(t, peer_info); p = tree_get_path_to_peer(t->tree, peer_info->id); @@ -2595,17 +2581,15 @@ handle_local_connect_add (void *cls, struct GNUNET_SERVER_Client *client, path_info->peer = peer_info; path_info->t = t; peer_info->dhtget = GNUNET_DHT_get_start(dht_handle, /* handle */ - GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ - GNUNET_BLOCK_TYPE_TEST, /* type */ - &peer_msg->peer.hashPubKey, /*key to search */ - 4, /* replication level */ - GNUNET_DHT_RO_RECORD_ROUTE, - NULL, /* bloom filter */ - 0, /* mutator */ - NULL, /* xquery */ - 0, /* xquery bits */ - dht_get_id_handler, - (void *) path_info); + GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ + GNUNET_BLOCK_TYPE_TEST, /* type */ + &peer_msg->peer.hashPubKey, /*key to search */ + 4, /* replication level */ + GNUNET_DHT_RO_RECORD_ROUTE, + NULL, /* xquery */ + 0, /* xquery bits */ + &dht_get_id_handler, + (void *) path_info); } if (NULL != peer_info->path_head) { @@ -2761,7 +2745,7 @@ handle_local_connect_by_type (void *cls, struct GNUNET_SERVER_Client *client, c->dht_get_type = GNUNET_DHT_get_start (dht_handle, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_BLOCK_TYPE_TEST, &hash, 10U, - GNUNET_DHT_RO_RECORD_ROUTE, NULL, 0, NULL, 0, + GNUNET_DHT_RO_RECORD_ROUTE, NULL, 0, &dht_get_type_handler, t); GNUNET_SERVER_receive_done (client, GNUNET_OK); diff --git a/src/vpn/gnunet-service-dns.c b/src/vpn/gnunet-service-dns.c index e97da1921..fc65cf608 100644 --- a/src/vpn/gnunet-service-dns.c +++ b/src/vpn/gnunet-service-dns.c @@ -641,10 +641,11 @@ static void receive_dht (void *cls, struct GNUNET_TIME_Absolute exp __attribute__ ((unused)), const GNUNET_HashCode * key __attribute__ ((unused)), - const struct GNUNET_PeerIdentity *const *get_path - __attribute__ ((unused)), - const struct GNUNET_PeerIdentity *const *put_path - __attribute__ ((unused)), enum GNUNET_BLOCK_Type type, size_t size, + const struct GNUNET_PeerIdentity *get_path __attribute__ ((unused)), + unsigned int get_path_length __attribute__ ((unused)), + const struct GNUNET_PeerIdentity *put_path __attribute__ ((unused)), + unsigned int put_path_length __attribute__ ((unused)), + enum GNUNET_BLOCK_Type type, size_t size, const void *data) { @@ -806,8 +807,8 @@ receive_query (void *cls cls->handle = GNUNET_DHT_get_start (dht, GNUNET_TIME_UNIT_MINUTES, GNUNET_BLOCK_TYPE_DNS, &key, - DEFAULT_GET_REPLICATION, GNUNET_DHT_RO_NONE, NULL, - 0, NULL, 0, receive_dht, cls); + 5 /* DEFAULT_GET_REPLICATION */, GNUNET_DHT_RO_NONE, NULL, + 0, &receive_dht, cls); goto outfree; } @@ -1251,7 +1252,7 @@ publish_name (const char *name, uint64_t ports, uint32_t service_type, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Putting with key %08x, size = %d\n", *((unsigned int *) &data.service_descriptor), size); - GNUNET_DHT_put (dht, &data.service_descriptor, DEFAULT_PUT_REPLICATION, + GNUNET_DHT_put (dht, &data.service_descriptor, 5 /* DEFAULT_PUT_REPLICATION */, GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_DNS, size, (char *) &data, GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS), -- 2.25.1