From: Matthias Wachs Date: Tue, 13 Apr 2010 15:25:50 +0000 (+0000) Subject: added some code for hostlist management X-Git-Tag: initial-import-from-subversion-38251~22172 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=9c8285667baa991e8fc4c411c94be8816512647f;p=oweals%2Fgnunet.git added some code for hostlist management --- diff --git a/src/hostlist/gnunet-daemon-hostlist.c b/src/hostlist/gnunet-daemon-hostlist.c index 9a12c98f1..3622e0e8f 100644 --- a/src/hostlist/gnunet-daemon-hostlist.c +++ b/src/hostlist/gnunet-daemon-hostlist.c @@ -306,7 +306,7 @@ run (void *cls, if (bootstrapping) { GNUNET_HOSTLIST_client_start (cfg, sched, stats, - &client_ch, &client_dh, &client_adv_handler); + &client_ch, &client_dh, &client_adv_handler, learning); } if (provide_hostlist) { diff --git a/src/hostlist/hostlist-client.c b/src/hostlist/hostlist-client.c index 78eb8acaa..a5cc03912 100644 --- a/src/hostlist/hostlist-client.c +++ b/src/hostlist/hostlist-client.c @@ -111,11 +111,23 @@ static int bogus_url; */ static unsigned int connection_count; +/** + * Set if the user allows us to learn about new hostlists + * from the network. + */ +static int learning; + /** * At what time MUST the current hostlist request be done? */ static struct GNUNET_TIME_Absolute end_time; +/** + * Hashmap of PeerIdentities to "struct GNUNET_Hostlist" + * (for fast lookup). NULL until the library + * is actually being used. + */ +static struct GNUNET_CONTAINER_MultiHashMap *hostlist_hashmap; /** * Process downloaded bits by calling callback on each HELLO. @@ -728,28 +740,37 @@ advertisement_handler (void *cls, struct GNUNET_TIME_Relative latency, uint32_t distance) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Hostlist client recieved advertisement, checking message: %s\n"); + if ( !learning ) + return GNUNET_NO; + int size = ntohs (message->size); int uri_size = size - sizeof ( struct GNUNET_HOSTLIST_ADV_Message ); - int type = ntohs (message->type); char * uri = GNUNET_malloc ( uri_size ); + struct GNUNET_Hostlist * hostlist; - if ( type != GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT) + if ( ntohs (message->type) != GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT) return GNUNET_NO; const struct GNUNET_HOSTLIST_ADV_Message * incoming = (const struct GNUNET_HOSTLIST_ADV_Message *) message; - //struct GNUNET_HOSTLIST_ADV_Message * msg = message; memcpy ( uri, &incoming[1], uri_size ); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Hostlist client recieved advertisement uri: %s\n", uri); - #if DEBUG_HOSTLIST_CLIENT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Hostlist client recieved advertisement message, type %u, message size %u, headersize %u, uri length %u, uri: %s\n",type,size,sizeof( struct GNUNET_HOSTLIST_ADV_Message ),uri_size,uri); -#endif + "Hostlist client recieved advertisement from peer '%4s' containing URI %s\n", GNUNET_i2s (peer), uri ); + + hostlist = GNUNET_malloc ( sizeof (struct GNUNET_Hostlist) ); + + /* search in map for peer identity */ + if ( NULL != hostlist_hashmap) + /* GNUNET_CONTAINER_multihashmap_contains( hostlist_hashmap, )*/ + /* if it is not existing in map, create new a hostlist */ + hostlist->peer = (*peer); + hostlist->hello_count = 0; + hostlist->hostlist_uri = GNUNET_malloc ( uri_size); + memcpy ( hostlist->hostlist_uri, &incoming[1], uri_size ); + hostlist->time_creation = GNUNET_TIME_absolute_get(); + hostlist->time_last_usage = GNUNET_TIME_absolute_get_zero(); - return GNUNET_YES; + return GNUNET_YES; } /** @@ -806,6 +827,9 @@ static int load_hostlist_file () "HOSTLISTFILE", "HOSTLIST"); return GNUNET_SYSERR; } + + /* add code to write hostlists to file using bio */ + return GNUNET_OK; } @@ -824,11 +848,12 @@ static int save_hostlist_file () &servers)) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("No `%s' specified in `%s' configuration, cannot save hostlist to file.\n"), + _("No `%s' specified in `%s' configuration, cannot save hostlists to file.\n"), "HOSTLISTFILE", "HOSTLIST"); return GNUNET_SYSERR; } + /* add code to write hostlists to file using bio */ return GNUNET_OK; } @@ -842,7 +867,8 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_STATISTICS_Handle *st, GNUNET_CORE_ConnectEventHandler *ch, GNUNET_CORE_DisconnectEventHandler *dh, - GNUNET_CORE_MessageCallback *msgh) + GNUNET_CORE_MessageCallback *msgh, + int learn) { if (0 != curl_global_init (CURL_GLOBAL_WIN32)) { @@ -868,6 +894,11 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, *dh = &disconnect_handler; *msgh = &advertisement_handler; + learning = learn; + if ( learning ) + { + hostlist_hashmap = GNUNET_CONTAINER_multihashmap_create (16); + } load_hostlist_file (); GNUNET_STATISTICS_get (stats, @@ -893,6 +924,11 @@ GNUNET_HOSTLIST_client_stop () #endif save_hostlist_file (); + if ( learning ) + { + GNUNET_CONTAINER_multihashmap_destroy ( hostlist_hashmap ); + } + if (current_task != GNUNET_SCHEDULER_NO_TASK) { GNUNET_SCHEDULER_cancel (sched, diff --git a/src/hostlist/hostlist-client.h b/src/hostlist/hostlist-client.h index 378a91996..26cd73b52 100644 --- a/src/hostlist/hostlist-client.h +++ b/src/hostlist/hostlist-client.h @@ -30,6 +30,22 @@ #include "gnunet_core_service.h" #include "gnunet_statistics_service.h" #include "gnunet_util_lib.h" +#include "gnunet_time_lib.h" + +/* + * a single hostlist obtained by hostlist advertisements + */ +struct GNUNET_Hostlist +{ + + struct GNUNET_PeerIdentity peer; + char * hostlist_uri; + unsigned long hello_count; + unsigned long times_used; + struct GNUNET_TIME_Absolute time_creation; + struct GNUNET_TIME_Absolute time_last_usage; + uint64_t quality; +}; /** @@ -41,6 +57,7 @@ * @param ch set to handler for connect notifications * @param dh set to handler for disconnect notifications * @param msgh set to handler for message handler notifications + * @param learn set if client is learning new hostlists * @return GNUNET_OK on success */ int @@ -49,7 +66,8 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_STATISTICS_Handle *st, GNUNET_CORE_ConnectEventHandler *ch, GNUNET_CORE_DisconnectEventHandler *dh, - GNUNET_CORE_MessageCallback *msgh); + GNUNET_CORE_MessageCallback *msgh, + int learn); /** diff --git a/src/hostlist/hostlist-server.c b/src/hostlist/hostlist-server.c index bfd9ae729..92e5756ad 100644 --- a/src/hostlist/hostlist-server.c +++ b/src/hostlist/hostlist-server.c @@ -109,6 +109,17 @@ struct HostSet */ static int advertising; +/* + * How many times was the hostlist advertised? + */ +static uint64_t hostlist_adv_count = 0; + +/* + * Buffer for the hostlist address + */ +char hostlist_uri[255]; + + /** * Task that will produce a new response object. */ @@ -116,6 +127,7 @@ static void update_response (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); + /** * Function that assembles our response. */ @@ -361,11 +373,6 @@ access_handler_callback (void *cls, return MHD_queue_response (connection, MHD_HTTP_OK, response); } -/* - * Buffer for the hostlist address - */ -char hostlist_uri[255]; - /** * Handler called by core when core is ready to transmit message * @param cls closure @@ -407,6 +414,12 @@ adv_transmit_ready ( void *cls, size_t size, void *buf) return transmission_size; } + hostlist_adv_count++; + GNUNET_STATISTICS_set (stats, + gettext_noop("# hostlist advertisements send"), + hostlist_adv_count, + GNUNET_YES); + GNUNET_free (adv_message ); return size; } diff --git a/src/hostlist/learning_data.conf b/src/hostlist/learning_data.conf index 3cfc9c27d..2b9f63a6e 100644 --- a/src/hostlist/learning_data.conf +++ b/src/hostlist/learning_data.conf @@ -13,4 +13,4 @@ BINARY = gnunet-daemon-hostlist OPTIONS = -b -e SERVERS = http://gnunet.org:8080/ # proxy for downloading hostlists -HTTP-PROXY = +HTTP-PROXY = \ No newline at end of file diff --git a/src/hostlist/learning_peer1.conf b/src/hostlist/learning_peer1.conf index 95b0d1850..51ac2caae 100644 --- a/src/hostlist/learning_peer1.conf +++ b/src/hostlist/learning_peer1.conf @@ -38,8 +38,10 @@ HTTPPORT = 12980 SERVERS = http://localhost:12981/ OPTIONS = -b -p -e -a DEBUG = YES +HOSTLISTFILE = hostlists.file #BINARY = /home/grothoff/bin/gnunet-daemon-hostlist + [topology] #DEBUG = YES #PREFIX = valgrind --tool=memcheck diff --git a/src/hostlist/test_gnunet_daemon_hostlist_peer1.conf b/src/hostlist/test_gnunet_daemon_hostlist_peer1.conf index 8f3e8c91f..4ffd7f655 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist_peer1.conf +++ b/src/hostlist/test_gnunet_daemon_hostlist_peer1.conf @@ -9,6 +9,7 @@ PORT = 12964 PORT = 12965 PLUGINS = tcp #DEBUG = YES +DEBUG = NO [arm] PORT = 12966 @@ -20,6 +21,7 @@ PORT = 12967 [transport-tcp] PORT = 12968 +DEBUG = NO [peerinfo] PORT = 12969 @@ -27,7 +29,8 @@ PORT = 12969 [core] PORT = 12970 #DEBUG = YES -#PREFIX = valgrind --tool=memcheck +#PREFIX = valgrind --tool=memcheck\ +DEBUG = NO [testing] WEAKRANDOM = YES @@ -38,7 +41,9 @@ SERVERS = http://localhost:12981/ OPTIONS = -b -p #DEBUG = YES #BINARY = /home/grothoff/bin/gnunet-daemon-hostlist +DEBUG = NO [topology] #DEBUG = YES #PREFIX = valgrind --tool=memcheck +DEBUG = NO \ No newline at end of file diff --git a/src/hostlist/test_gnunet_daemon_hostlist_peer2.conf b/src/hostlist/test_gnunet_daemon_hostlist_peer2.conf index 9f66cf4d0..b689154de 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist_peer2.conf +++ b/src/hostlist/test_gnunet_daemon_hostlist_peer2.conf @@ -4,29 +4,32 @@ DEFAULTCONFIG = test_gnunet_daemon_hostlist_peer2.conf [resolver] PORT = 22964 +DEBUG = NO [transport] PORT = 22965 PLUGINS = tcp -#DEBUG = YES +DEBUG = NO [arm] PORT = 22966 DEFAULTSERVICES = resolver transport core statistics topology #GLOBAL_PREFIX = xterm -e gdb -x cmd --args +DEBUG = NO [statistics] PORT = 22967 [transport-tcp] PORT = 22968 +DEBUG = NO [peerinfo] PORT = 22969 [core] PORT = 22970 -#DEBUG = YES +DEBUG = NO #PREFIX = valgrind --tool=memcheck [testing] @@ -36,9 +39,10 @@ WEAKRANDOM = YES HTTPPORT = 12981 SERVERS = http://localhost:12980/ OPTIONS = -b -p -#DEBUG = YES +DEBUG = NO #BINARY = /home/grothoff/bin/gnunet-daemon-hostlist [topology] #DEBUG = YES #PREFIX = valgrind --tool=memcheck +DEBUG = NO