From 0bf8817f025818c83d31eea23203a2c99ba83f7e Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 26 Sep 2016 21:35:46 +0000 Subject: [PATCH] -migrating wdht to new service API --- src/dht/Makefile.am | 3 +- src/dht/gnunet-service-dht.h | 2 +- src/dht/gnunet-service-wdht.c | 66 +++------- src/dht/gnunet-service-wdht_clients.h | 149 ----------------------- src/dht/gnunet-service-wdht_neighbours.c | 81 +++++++----- src/dht/gnunet-service-wdht_neighbours.h | 121 ------------------ src/dht/gnunet-service-xdht.c | 6 +- 7 files changed, 77 insertions(+), 351 deletions(-) delete mode 100644 src/dht/gnunet-service-wdht_clients.h delete mode 100644 src/dht/gnunet-service-wdht_neighbours.h diff --git a/src/dht/Makefile.am b/src/dht/Makefile.am index 10aeae175..f91917768 100644 --- a/src/dht/Makefile.am +++ b/src/dht/Makefile.am @@ -103,10 +103,9 @@ gnunet_service_dht_xvine_LDADD = \ gnunet_service_dht_whanau_SOURCES = \ gnunet-service-wdht.c gnunet-service-wdht.h \ - gnunet-service-wdht_clients.c gnunet-service-wdht_clients.h \ gnunet-service-dht_datacache.c gnunet-service-dht_datacache.h \ gnunet-service-dht_nse.c gnunet-service-dht_nse.h \ - gnunet-service-wdht_neighbours.c gnunet-service-wdht_neighbours.h + gnunet-service-wdht_neighbours.c gnunet-service-dht_neighbours.h gnunet_service_dht_whanau_LDADD = \ $(top_builddir)/src/statistics/libgnunetstatistics.la \ $(top_builddir)/src/core/libgnunetcore.la \ diff --git a/src/dht/gnunet-service-dht.h b/src/dht/gnunet-service-dht.h index 493c3b961..8b0602104 100644 --- a/src/dht/gnunet-service-dht.h +++ b/src/dht/gnunet-service-dht.h @@ -158,7 +158,7 @@ GDS_CLIENTS_process_put (uint32_t options, unsigned int path_length, const struct GNUNET_PeerIdentity *path, struct GNUNET_TIME_Absolute exp, - const struct GNUNET_HashCode * key, + const struct GNUNET_HashCode *key, const void *data, size_t size); diff --git a/src/dht/gnunet-service-wdht.c b/src/dht/gnunet-service-wdht.c index 8be25ad5e..e1ca1c968 100644 --- a/src/dht/gnunet-service-wdht.c +++ b/src/dht/gnunet-service-wdht.c @@ -24,7 +24,6 @@ * @author Christian Grothoff * @author Nathan Evans */ - #include "platform.h" #include "gnunet_block_lib.h" #include "gnunet_util_lib.h" @@ -33,27 +32,13 @@ #include "gnunet_dht_service.h" #include "gnunet_statistics_service.h" #include "gnunet-service-wdht.h" -#include "gnunet-service-wdht_clients.h" #include "gnunet-service-dht_datacache.h" -#include "gnunet-service-wdht_neighbours.h" +#include "gnunet-service-dht_neighbours.h" #include "gnunet-service-dht_nse.h" - -/** - * Handle for the statistics service. - */ -struct GNUNET_STATISTICS_Handle *GDS_stats; - -/** - * Our handle to the BLOCK library. - */ -struct GNUNET_BLOCK_Context *GDS_block_context; - -/** - * The configuration the DHT service is running with - */ -const struct GNUNET_CONFIGURATION_Handle *GDS_cfg; +/* Code shared between different DHT implementations */ +#include "gnunet-service-dht_clients.c" /** @@ -67,16 +52,17 @@ shutdown_task (void *cls) GDS_NEIGHBOURS_done (); GDS_DATACACHE_done (); GDS_NSE_done (); - if (GDS_block_context != NULL) + if (NULL != GDS_block_context) { GNUNET_BLOCK_context_destroy (GDS_block_context); GDS_block_context = NULL; } - if (GDS_stats != NULL) + if (NULL != GDS_stats) { GNUNET_STATISTICS_destroy (GDS_stats, GNUNET_YES); GDS_stats = NULL; } + GDS_CLIENTS_stop (); } @@ -84,48 +70,34 @@ shutdown_task (void *cls) * Process dht requests. * * @param cls closure - * @param server the initialized server * @param c configuration to use + * @param service the initialized service */ static void -run (void *cls, struct GNUNET_SERVER_Handle *server, - const struct GNUNET_CONFIGURATION_Handle *c) +run (void *cls, + const struct GNUNET_CONFIGURATION_Handle *c, + struct GNUNET_SERVICE_Handle *service) { GDS_cfg = c; + GDS_service = service; GDS_block_context = GNUNET_BLOCK_context_create (GDS_cfg); - GDS_stats = GNUNET_STATISTICS_create ("dht", GDS_cfg); + GDS_stats = GNUNET_STATISTICS_create ("dht", + GDS_cfg); GDS_NSE_init (); GDS_DATACACHE_init (); - GDS_CLIENTS_init (server); + GDS_CLIENTS_init (); + GNUNET_SCHEDULER_add_shutdown (&shutdown_task, + NULL); if (GNUNET_OK != GDS_NEIGHBOURS_init ()) { - shutdown_task (NULL); + GNUNET_SCHEDULER_shutdown (); return; } - GNUNET_SCHEDULER_add_shutdown (&shutdown_task, - NULL); } -/** - * The main function for the dht service. - * - * @param argc number of arguments from the command line - * @param argv command line arguments - * @return 0 ok, 1 on error - */ -int -main (int argc, char *const *argv) -{ - int ret; +/* Finally, define the main method */ +GDS_DHT_SERVICE_INIT("wdht", &run); - ret = - (GNUNET_OK == - GNUNET_SERVICE_run (argc, argv, "wdht", - GNUNET_SERVICE_OPTION_NONE, &run, - NULL)) ? 0 : 1; - GDS_CLIENTS_done (); - return ret; -} /* end of gnunet-service-wdht.c */ diff --git a/src/dht/gnunet-service-wdht_clients.h b/src/dht/gnunet-service-wdht_clients.h deleted file mode 100644 index f51564136..000000000 --- a/src/dht/gnunet-service-wdht_clients.h +++ /dev/null @@ -1,149 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2009, 2010, 2011 GNUnet e.V. - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -/** - * @file dht/gnunet-service-xdht_clients.h - * @brief GNUnet DHT service's client management code - * @author Christian Grothoff - * @author Nathan Evans - */ -#ifndef GNUNET_SERVICE_DHT_CLIENT_H -#define GNUNET_SERVICE_DHT_CLIENT_H - -#include "gnunet_util_lib.h" -#include "gnunet_block_lib.h" - -/** - * Handle a reply we've received from another peer. If the reply - * matches any of our pending queries, forward it to the respective - * client(s). - * - * @param expiration when will the reply expire - * @param key the query this reply is for - * @param get_path_length number of peers in @a get_path - * @param get_path path the reply took on get - * @param put_path_length number of peers in @a put_path - * @param put_path path the reply took on put - * @param type type of the reply - * @param data_size number of bytes in @a data - * @param data application payload data - */ -void -GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration, - const struct GNUNET_HashCode *key, - unsigned int get_path_length, - const struct GNUNET_PeerIdentity *get_path, - unsigned int put_path_length, - const struct GNUNET_PeerIdentity *put_path, - enum GNUNET_BLOCK_Type type, size_t data_size, - const void *data); - - -/** - * Check if some client is monitoring GET messages and notify - * them in that case. - * - * @param options Options, for instance RecordRoute, DemultiplexEverywhere. - * @param type The type of data in the request. - * @param hop_count Hop count so far. - * @param path_length number of entries in path (or 0 if not recorded). - * @param path peers on the GET path (or NULL if not recorded). - * @param desired_replication_level Desired replication level. - * @param key Key of the requested data. - */ -void -GDS_CLIENTS_process_get (uint32_t options, - enum GNUNET_BLOCK_Type type, - uint32_t hop_count, - uint32_t desired_replication_level, - unsigned int path_length, - const struct GNUNET_PeerIdentity *path, - const struct GNUNET_HashCode *key); - - -/** - * Check if some client is monitoring GET RESP messages and notify - * them in that case. - * - * @param type The type of data in the result. - * @param get_path Peers on GET path (or NULL if not recorded). - * @param get_path_length number of entries in @a get_path. - * @param put_path peers on the PUT path (or NULL if not recorded). - * @param put_path_length number of entries in @a get_path. - * @param exp Expiration time of the data. - * @param key Key of the @a data. - * @param data Pointer to the result data. - * @param size Number of bytes in @a data. - */ -void -GDS_CLIENTS_process_get_resp (enum GNUNET_BLOCK_Type type, - const struct GNUNET_PeerIdentity *get_path, - unsigned int get_path_length, - const struct GNUNET_PeerIdentity *put_path, - unsigned int put_path_length, - struct GNUNET_TIME_Absolute exp, - const struct GNUNET_HashCode * key, - const void *data, - size_t size); - - -/** - * Check if some client is monitoring PUT messages and notify - * them in that case. - * - * @param options Options, for instance RecordRoute, DemultiplexEverywhere. - * @param type The type of data in the request. - * @param hop_count Hop count so far. - * @param path_length number of entries in path (or 0 if not recorded). - * @param path peers on the PUT path (or NULL if not recorded). - * @param desired_replication_level Desired replication level. - * @param exp Expiration time of the data. - * @param key Key under which data is to be stored. - * @param data Pointer to the data carried. - * @param size Number of bytes in data. - */ -void -GDS_CLIENTS_process_put (uint32_t options, - enum GNUNET_BLOCK_Type type, - uint32_t hop_count, - uint32_t desired_replication_level, - unsigned int path_length, - const struct GNUNET_PeerIdentity *path, - struct GNUNET_TIME_Absolute exp, - const struct GNUNET_HashCode * key, - const void *data, - size_t size); - -/** - * Initialize client subsystem. - * - * @param server the initialized server - */ -void -GDS_CLIENTS_init (struct GNUNET_SERVER_Handle *server); - - -/** - * Shutdown client subsystem. - */ -void -GDS_CLIENTS_done (void); - -#endif diff --git a/src/dht/gnunet-service-wdht_neighbours.c b/src/dht/gnunet-service-wdht_neighbours.c index 2a88ffa09..d3b92585b 100644 --- a/src/dht/gnunet-service-wdht_neighbours.c +++ b/src/dht/gnunet-service-wdht_neighbours.c @@ -39,10 +39,9 @@ #include "gnunet_transport_service.h" #include "gnunet_dht_service.h" #include "gnunet_statistics_service.h" -#include "gnunet-service-wdht.h" -#include "gnunet-service-wdht_clients.h" +#include "gnunet-service-dht.h" #include "gnunet-service-dht_datacache.h" -#include "gnunet-service-wdht_neighbours.h" +#include "gnunet-service-dht_neighbours.h" #include "gnunet-service-dht_nse.h" #include "dht.h" @@ -585,20 +584,29 @@ static struct GNUNET_CORE_Handle *core_api; /** * Handle the put request from the client. * - * @param key Key for the content * @param block_type Type of the block - * @param options Routing options - * @param desired_replication_level Desired replication count - * @param expiration_time When does the content expire - * @param data Content to store - * @param data_size Size of content @a data in bytes + * @param options routing options + * @param desired_replication_level desired replication level + * @param expiration_time when does the content expire + * @param hop_count how many hops has this message traversed so far + * @param bf Bloom filter of peers this PUT has already traversed + * @param key key for the content + * @param put_path_length number of entries in put_path + * @param put_path peers this request has traversed so far (if tracked) + * @param data payload to store + * @param data_size number of bytes in data + * @return #GNUNET_OK if the request was forwarded, #GNUNET_NO if not */ -void -GDS_NEIGHBOURS_handle_put (const struct GNUNET_HashCode *key, - enum GNUNET_BLOCK_Type block_type, +int +GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type block_type, enum GNUNET_DHT_RouteOption options, uint32_t desired_replication_level, struct GNUNET_TIME_Absolute expiration_time, + uint32_t hop_count, + struct GNUNET_CONTAINER_BloomFilter *bf, + const struct GNUNET_HashCode *key, + unsigned int put_path_length, + struct GNUNET_PeerIdentity *put_path, const void *data, size_t data_size) { @@ -610,34 +618,51 @@ GDS_NEIGHBOURS_handle_put (const struct GNUNET_HashCode *key, data); GDS_CLIENTS_process_put (options, block_type, - 0, 0, - 0, NULL, + hop_count, + desired_replication_level, + put_path_length, put_path, expiration_time, key, data, data_size); + return GNUNET_OK; /* FIXME... */ } /** - * Handle the get request from the client file. If I am destination do - * datacache put and return. Else find the target friend and forward message - * to it. + * Perform a GET operation. Forwards the given request to other + * peers. Does not lookup the key locally. May do nothing if this is + * the only peer in the network (or if we are the closest peer in the + * network). * - * @param key Key for the content - * @param block_type Type of the block - * @param options Routing options - * @param desired_replication_level Desired replication count + * @param type type of the block + * @param options routing options + * @param desired_replication_level desired replication count + * @param hop_count how many hops did this request traverse so far? + * @param key key for the content + * @param xquery extended query + * @param xquery_size number of bytes in @a xquery + * @param reply_bf bloomfilter to filter duplicates + * @param reply_bf_mutator mutator for @a reply_bf + * @param peer_bf filter for peers not to select (again, updated) + * @return #GNUNET_OK if the request was forwarded, #GNUNET_NO if not */ -void -GDS_NEIGHBOURS_handle_get (const struct GNUNET_HashCode *key, - enum GNUNET_BLOCK_Type block_type, +int +GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, enum GNUNET_DHT_RouteOption options, - uint32_t desired_replication_level) + uint32_t desired_replication_level, + uint32_t hop_count, + const struct GNUNET_HashCode *key, + const void *xquery, size_t xquery_size, + const struct GNUNET_CONTAINER_BloomFilter *reply_bf, + uint32_t reply_bf_mutator, + struct GNUNET_CONTAINER_BloomFilter *peer_bf) { // find closest finger(s) on all layers // use TrailRoute with PeerGetMessage embedded to contact peer // NOTE: actually more complicated, see paper! + GNUNET_break (0); // not implemented! + return GNUNET_SYSERR; } @@ -1734,10 +1759,10 @@ GDS_NEIGHBOURS_done (void) * * @return my identity */ -struct GNUNET_PeerIdentity -GDS_NEIGHBOURS_get_my_id (void) +struct GNUNET_PeerIdentity * +GDS_NEIGHBOURS_get_id (void) { - return my_identity; + return &my_identity; } /* end of gnunet-service-wdht_neighbours.c */ diff --git a/src/dht/gnunet-service-wdht_neighbours.h b/src/dht/gnunet-service-wdht_neighbours.h deleted file mode 100644 index 8461d16e8..000000000 --- a/src/dht/gnunet-service-wdht_neighbours.h +++ /dev/null @@ -1,121 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2009, 2010, 2011, 2015 GNUnet e.V. - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -/** - * @file dht/gnunet-service-wdht_neighbours.h - * @brief GNUnet DHT routing code - * @author Supriti Singh - */ - -#ifndef GNUNET_SERVICE_WDHT_NEIGHBOURS_H -#define GNUNET_SERVICE_WDHT_NEIGHBOURS_H - -#include "gnunet_util_lib.h" -#include "gnunet_block_lib.h" -#include "gnunet_dht_service.h" - - -/** - * Handle the put request from the client. - * - * @param key Key for the content - * @param block_type Type of the block - * @param options Routing options - * @param desired_replication_level Desired replication count - * @param expiration_time When does the content expire - * @param data Content to store - * @param data_size Size of content @a data in bytes - */ -void -GDS_NEIGHBOURS_handle_put (const struct GNUNET_HashCode *key, - enum GNUNET_BLOCK_Type block_type, - enum GNUNET_DHT_RouteOption options, - uint32_t desired_replication_level, - struct GNUNET_TIME_Absolute expiration_time, - const void *data, size_t data_size); - -/** - * Handle the get request from the client file. If I am destination do - * datacache put and return. Else find the target friend and forward message - * to it. - * - * @param key Key for the content - * @param block_type Type of the block - * @param options Routing options - * @param desired_replication_level Desired replication count - */ -void -GDS_NEIGHBOURS_handle_get (const struct GNUNET_HashCode *key, - enum GNUNET_BLOCK_Type block_type, - enum GNUNET_DHT_RouteOption options, - uint32_t desired_replication_level); - - -/** - * Send the get result to requesting client. - * - * @param cls a `const struct GNUNET_HashCode *` trail identifying where to send the result to, NULL for us - * @param options routing options (from GET request) - * @param key key of the requested data. - * @param type block type - * @param put_path_length number of peers in @a put_path - * @param put_path path taken to put the data at its stored location. - * @param expiration when will this result expire? - * @param data payload to store - * @param data_size size of the @a data - */ -void -GDS_NEIGHBOURS_send_get_result (void *cls, - enum GNUNET_DHT_RouteOption options, - const struct GNUNET_HashCode *key, - enum GNUNET_BLOCK_Type type, - unsigned int put_path_length, - const struct GNUNET_PeerIdentity *put_path, - struct GNUNET_TIME_Absolute expiration, - const void *data, - size_t data_size); - - -/** - * Initialize neighbours subsystem. - * - * @return #GNUNET_OK on success, - * #GNUNET_SYSERR on error - */ -int -GDS_NEIGHBOURS_init (void); - - -/** - * Shutdown neighbours subsystem. - */ -void -GDS_NEIGHBOURS_done (void); - - -/** - * Get my identity - * - * @return my identity - */ -struct GNUNET_PeerIdentity -GDS_NEIGHBOURS_get_my_id (void); - -#endif diff --git a/src/dht/gnunet-service-xdht.c b/src/dht/gnunet-service-xdht.c index 382a3b7c3..7d0cb8a3a 100644 --- a/src/dht/gnunet-service-xdht.c +++ b/src/dht/gnunet-service-xdht.c @@ -104,13 +104,13 @@ run (void *cls, { track_topology = (unsigned int) _track_topology; } + GNUNET_SCHEDULER_add_shutdown (&shutdown_task, + NULL); if (GNUNET_OK != GDS_NEIGHBOURS_init ()) { - shutdown_task (NULL); + GNUNET_SCHEDULER_shutdown (); return; } - GNUNET_SCHEDULER_add_shutdown (&shutdown_task, - NULL); } -- 2.25.1