From: Matthias Wachs Date: Tue, 13 Apr 2010 12:14:08 +0000 (+0000) Subject: Correct handling of daemon options to en/disable learning and advertising X-Git-Tag: initial-import-from-subversion-38251~22177 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=d6af5432c3f6a61cd9c1aea68e89e8da39c6219b;p=oweals%2Fgnunet.git Correct handling of daemon options to en/disable learning and advertising --- diff --git a/src/hostlist/gnunet-daemon-hostlist.c b/src/hostlist/gnunet-daemon-hostlist.c index 919c80a99..9a12c98f1 100644 --- a/src/hostlist/gnunet-daemon-hostlist.c +++ b/src/hostlist/gnunet-daemon-hostlist.c @@ -168,7 +168,14 @@ static int advertisement_handler (void *cls, struct GNUNET_TIME_Relative latency, uint32_t distance) { - if (advertising && (NULL != client_adv_handler)) + if ( !learning ) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Recieved hostlist advertisement, but I am not learning!\n"); + return GNUNET_NO; + } + + if (learning && (NULL != client_adv_handler)) { (*client_adv_handler) (cls, peer, message, latency, distance); return GNUNET_YES; @@ -303,7 +310,7 @@ run (void *cls, } if (provide_hostlist) { - GNUNET_HOSTLIST_server_start (cfg, sched, stats, core, &server_ch, &server_dh); + GNUNET_HOSTLIST_server_start (cfg, sched, stats, core, &server_ch, &server_dh, advertising ); } if (learning) { diff --git a/src/hostlist/hostlist-client.c b/src/hostlist/hostlist-client.c index 9af75fec2..9e86053fc 100644 --- a/src/hostlist/hostlist-client.c +++ b/src/hostlist/hostlist-client.c @@ -30,6 +30,7 @@ #include "gnunet_hello_lib.h" #include "gnunet_statistics_service.h" #include "gnunet_transport_service.h" +#include "gnunet-daemon-hostlist.h" #include #define DEBUG_HOSTLIST_CLIENT GNUNET_YES @@ -727,15 +728,27 @@ 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"); 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 ); + if ( type != GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT) return GNUNET_NO; -#if DEBUG_HOSTLIST_CLIENT + + 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, size %u, type %u\n",size,type); + "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 + return GNUNET_YES; } diff --git a/src/hostlist/hostlist-server.c b/src/hostlist/hostlist-server.c index 69db67d2d..bfd9ae729 100644 --- a/src/hostlist/hostlist-server.c +++ b/src/hostlist/hostlist-server.c @@ -104,6 +104,11 @@ struct HostSet char *data; }; +/** + * Set if we are allowed to advertise our hostlist to others. + */ +static int advertising; + /** * Task that will produce a new response object. */ @@ -478,7 +483,9 @@ adv_create_message ( const struct GNUNET_PeerIdentity * peer ) uri = strcat(uri, ":"); uri = strcat(uri, port_s); uri = strcat(uri, "/"); - strcpy(hostlist_uri,uri); + if ( length < 255); + strcpy(hostlist_uri,uri); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Address to obtain hostlist: %s\n", hostlist_uri); if ( ( size + sizeof( struct GNUNET_HOSTLIST_ADV_Message )) > GNUNET_SERVER_MAX_MESSAGE_SIZE) @@ -513,6 +520,9 @@ connect_handler (void *cls, struct GNUNET_TIME_Relative latency, uint32_t distance) { + if ( !advertising ) + return; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "A new peer connected to the server, preparing to send hostlist advertisement\n"); /* create a new advertisement message */ @@ -639,10 +649,18 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_STATISTICS_Handle *st, struct GNUNET_CORE_Handle *co, GNUNET_CORE_ConnectEventHandler *server_ch, - GNUNET_CORE_DisconnectEventHandler *server_dh) + GNUNET_CORE_DisconnectEventHandler *server_dh, + int advertise) { unsigned long long port; + advertising = advertise; + if ( !advertising ) + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Advertising not enabled on this hostlist server\n"); + else + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Advertising enabled on this hostlist server\n"); sched = s; cfg = c; stats = st; diff --git a/src/hostlist/hostlist-server.h b/src/hostlist/hostlist-server.h index bdd7084e4..cffcac05f 100644 --- a/src/hostlist/hostlist-server.h +++ b/src/hostlist/hostlist-server.h @@ -44,7 +44,8 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_STATISTICS_Handle *st, struct GNUNET_CORE_Handle *core, GNUNET_CORE_ConnectEventHandler *server_ch, - GNUNET_CORE_DisconnectEventHandler *server_dh); + GNUNET_CORE_DisconnectEventHandler *server_dh, + int advertise); /** diff --git a/src/hostlist/test_gnunet_daemon_hostlist_learning.c b/src/hostlist/test_gnunet_daemon_hostlist_learning.c index 3da4f87e8..e903574b2 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist_learning.c +++ b/src/hostlist/test_gnunet_daemon_hostlist_learning.c @@ -30,9 +30,6 @@ #define START_ARM GNUNET_YES -#define VERBOSE GNUNET_YES -#define DEBUG GNUNET_YES - /** * How long until we give up on transmitting the message? */