Correct handling of daemon options to en/disable learning and advertising
authorMatthias Wachs <wachs@net.in.tum.de>
Tue, 13 Apr 2010 12:14:08 +0000 (12:14 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Tue, 13 Apr 2010 12:14:08 +0000 (12:14 +0000)
src/hostlist/gnunet-daemon-hostlist.c
src/hostlist/hostlist-client.c
src/hostlist/hostlist-server.c
src/hostlist/hostlist-server.h
src/hostlist/test_gnunet_daemon_hostlist_learning.c

index 919c80a995a14521610e043086c1b06ac1172f15..9a12c98f1129b0da250a4c7f5d0e93aedf15d307 100644 (file)
@@ -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)
     {
index 9af75fec2b3b118dee7b599a85a50871c1bfa364..9e86053fc3afbe7ecfd2779c774166edfbf69e09 100644 (file)
@@ -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 <curl/curl.h>
 
 #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;
 }
 
index 69db67d2dd3f1e2c363d89c2144f4c026ea1d38e..bfd9ae7294a5c9c9b16bcf1a1296916769fc58ed 100644 (file)
@@ -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;
index bdd7084e4a05eda485f1fc5e1830db2b13718ce5..cffcac05fd22905d9305ca1d0fdaf8383b99cba2 100644 (file)
@@ -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);
 
 
 /**
index 3da4f87e82da224506b2ea34ce4a0ecb9eba1d08..e903574b2c6be72c2ce18ee828350a94bdde1f9f 100644 (file)
@@ -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?
  */