gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r10900 - gnunet/src/hostlist


From: gnunet
Subject: [GNUnet-SVN] r10900 - gnunet/src/hostlist
Date: Tue, 13 Apr 2010 17:25:50 +0200

Author: wachs
Date: 2010-04-13 17:25:50 +0200 (Tue, 13 Apr 2010)
New Revision: 10900

Modified:
   gnunet/src/hostlist/gnunet-daemon-hostlist.c
   gnunet/src/hostlist/hostlist-client.c
   gnunet/src/hostlist/hostlist-client.h
   gnunet/src/hostlist/hostlist-server.c
   gnunet/src/hostlist/learning_data.conf
   gnunet/src/hostlist/learning_peer1.conf
   gnunet/src/hostlist/test_gnunet_daemon_hostlist_peer1.conf
   gnunet/src/hostlist/test_gnunet_daemon_hostlist_peer2.conf
Log:
added some code for hostlist management

Modified: gnunet/src/hostlist/gnunet-daemon-hostlist.c
===================================================================
--- gnunet/src/hostlist/gnunet-daemon-hostlist.c        2010-04-13 14:14:29 UTC 
(rev 10899)
+++ gnunet/src/hostlist/gnunet-daemon-hostlist.c        2010-04-13 15:25:50 UTC 
(rev 10900)
@@ -306,7 +306,7 @@
   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)
     {      

Modified: gnunet/src/hostlist/hostlist-client.c
===================================================================
--- gnunet/src/hostlist/hostlist-client.c       2010-04-13 14:14:29 UTC (rev 
10899)
+++ gnunet/src/hostlist/hostlist-client.c       2010-04-13 15:25:50 UTC (rev 
10900)
@@ -112,10 +112,22 @@
 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 @@
     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) );
 
-     return GNUNET_YES;
+
+  /* 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;
 }
 
 /**
@@ -806,6 +827,9 @@
                   "HOSTLISTFILE", "HOSTLIST");
       return GNUNET_SYSERR;
     }
+
+  /* add code to write hostlists to file using bio */
+
   return GNUNET_OK;
 }
 
@@ -824,11 +848,12 @@
                                              &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 @@
                              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 @@
   *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 @@
 #endif
   save_hostlist_file ();
 
+  if ( learning )
+  {
+    GNUNET_CONTAINER_multihashmap_destroy ( hostlist_hashmap );
+  }
+
   if (current_task != GNUNET_SCHEDULER_NO_TASK)
     {
       GNUNET_SCHEDULER_cancel (sched,

Modified: gnunet/src/hostlist/hostlist-client.h
===================================================================
--- gnunet/src/hostlist/hostlist-client.h       2010-04-13 14:14:29 UTC (rev 
10899)
+++ gnunet/src/hostlist/hostlist-client.h       2010-04-13 15:25:50 UTC (rev 
10900)
@@ -30,8 +30,24 @@
 #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;
+};
+
+
 /**
  * Start downloading hostlists from hostlist servers as necessary.
  *
@@ -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 @@
                              struct GNUNET_STATISTICS_Handle *st,
                              GNUNET_CORE_ConnectEventHandler *ch,
                              GNUNET_CORE_DisconnectEventHandler *dh,
-                             GNUNET_CORE_MessageCallback *msgh);
+                             GNUNET_CORE_MessageCallback *msgh,
+                             int learn);
 
 
 /**

Modified: gnunet/src/hostlist/hostlist-server.c
===================================================================
--- gnunet/src/hostlist/hostlist-server.c       2010-04-13 14:14:29 UTC (rev 
10899)
+++ gnunet/src/hostlist/hostlist-server.c       2010-04-13 15:25:50 UTC (rev 
10900)
@@ -109,6 +109,17 @@
  */
 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 @@
 update_response (void *cls,
                 const struct GNUNET_SCHEDULER_TaskContext *tc);
 
+
 /**
  * Function that assembles our response.
  */
@@ -361,11 +373,6 @@
   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 @@
       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;
 }

Modified: gnunet/src/hostlist/learning_data.conf
===================================================================
--- gnunet/src/hostlist/learning_data.conf      2010-04-13 14:14:29 UTC (rev 
10899)
+++ gnunet/src/hostlist/learning_data.conf      2010-04-13 15:25:50 UTC (rev 
10900)
@@ -13,4 +13,4 @@
 OPTIONS = -b -e
 SERVERS = http://gnunet.org:8080/
 # proxy for downloading hostlists
-HTTP-PROXY = 
+HTTP-PROXY = 
\ No newline at end of file

Modified: gnunet/src/hostlist/learning_peer1.conf
===================================================================
--- gnunet/src/hostlist/learning_peer1.conf     2010-04-13 14:14:29 UTC (rev 
10899)
+++ gnunet/src/hostlist/learning_peer1.conf     2010-04-13 15:25:50 UTC (rev 
10900)
@@ -38,8 +38,10 @@
 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

Modified: gnunet/src/hostlist/test_gnunet_daemon_hostlist_peer1.conf
===================================================================
--- gnunet/src/hostlist/test_gnunet_daemon_hostlist_peer1.conf  2010-04-13 
14:14:29 UTC (rev 10899)
+++ gnunet/src/hostlist/test_gnunet_daemon_hostlist_peer1.conf  2010-04-13 
15:25:50 UTC (rev 10900)
@@ -9,6 +9,7 @@
 PORT = 12965
 PLUGINS = tcp
 #DEBUG = YES
+DEBUG = NO
 
 [arm]
 PORT = 12966
@@ -20,6 +21,7 @@
 
 [transport-tcp]
 PORT = 12968
+DEBUG = NO
 
 [peerinfo]
 PORT = 12969
@@ -27,7 +29,8 @@
 [core]
 PORT = 12970
 #DEBUG = YES
-#PREFIX = valgrind --tool=memcheck
+#PREFIX = valgrind --tool=memcheck\
+DEBUG = NO
 
 [testing]
 WEAKRANDOM = YES
@@ -38,7 +41,9 @@
 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

Modified: gnunet/src/hostlist/test_gnunet_daemon_hostlist_peer2.conf
===================================================================
--- gnunet/src/hostlist/test_gnunet_daemon_hostlist_peer2.conf  2010-04-13 
14:14:29 UTC (rev 10899)
+++ gnunet/src/hostlist/test_gnunet_daemon_hostlist_peer2.conf  2010-04-13 
15:25:50 UTC (rev 10900)
@@ -4,29 +4,32 @@
 
 [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 @@
 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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]