added some code for hostlist management
authorMatthias Wachs <wachs@net.in.tum.de>
Tue, 13 Apr 2010 15:25:50 +0000 (15:25 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Tue, 13 Apr 2010 15:25:50 +0000 (15:25 +0000)
src/hostlist/gnunet-daemon-hostlist.c
src/hostlist/hostlist-client.c
src/hostlist/hostlist-client.h
src/hostlist/hostlist-server.c
src/hostlist/learning_data.conf
src/hostlist/learning_peer1.conf
src/hostlist/test_gnunet_daemon_hostlist_peer1.conf
src/hostlist/test_gnunet_daemon_hostlist_peer2.conf

index 9a12c98f1129b0da250a4c7f5d0e93aedf15d307..3622e0e8faa3b80ebf1c71faf3c298202799710e 100644 (file)
@@ -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)
     {      
index 78eb8acaa97c1043a1051e3b142b9dec9fad60f2..a5cc0391279e8d64cdcb01d967a808ddf80f2025 100644 (file)
@@ -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,
index 378a919967293bb32ec399b82f43815038066705..26cd73b528b1a14d2ed795ec4c723d25facf6672 100644 (file)
 #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);
 
 
 /**
index bfd9ae7294a5c9c9b16bcf1a1296916769fc58ed..92e5756ad30d8e8fdb2c221d99b49208137152e6 100644 (file)
@@ -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;
 }
index 3cfc9c27def9b0fc332b41e637e315c9e1131a8e..2b9f63a6e02b6c76d737b4dbdc543e7fefa40064 100644 (file)
@@ -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
index 95b0d185030e700d1794cc2e7ef4cd13d9e60cf9..51ac2caae2b2dc75242d799aacb4b5c28b94b87e 100644 (file)
@@ -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
index 8f3e8c91fbfd1a36a0d3b924109007b92fa42155..4ffd7f65587729ed5fb14198711bd6f6aa0659b5 100644 (file)
@@ -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
index 9f66cf4d0c0dfa1d74dfa44ff1423251d721cbe1..b689154deb83a657ee62d382ce232bc9da293865 100644 (file)
@@ -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