Modifications so hostlist client and server will notified when new peers connect
authorMatthias Wachs <wachs@net.in.tum.de>
Thu, 8 Apr 2010 14:29:44 +0000 (14:29 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Thu, 8 Apr 2010 14:29:44 +0000 (14:29 +0000)
src/hostlist/gnunet-daemon-hostlist.c
src/hostlist/hostlist-server.c
src/hostlist/hostlist-server.h
src/hostlist/learning_peer1.conf
src/hostlist/learning_peer2.conf
src/hostlist/test_gnunet_daemon_hostlist_learning.c

index 2197a50b18a45081a657e9eb23f93e0c5757a904..cf4be4798f606ef6b1ef63081f1c906d0cee540b 100644 (file)
@@ -42,6 +42,8 @@
 #include "gnunet_time_lib.h"
 #include "gnunet_util_lib.h"
 
+#define DEBUG_HOSTLIST GNUNET_YES
+
 /**
  * Set if we are allowed to advertise our hostlist to others.
  */
@@ -79,6 +81,25 @@ struct GNUNET_CORE_Handle *core;
  */
 GNUNET_CORE_MessageCallback client_adv_handler = NULL;
 
+/**
+ * Handle to hostlist client's connect handler
+ */
+GNUNET_CORE_ConnectEventHandler client_ch = NULL;
+
+/**
+ * Handle to hostlist client's disconnect handler
+ */
+GNUNET_CORE_DisconnectEventHandler client_dh = NULL;
+
+/**
+ * Handle to hostlist server's connect handler
+ */
+GNUNET_CORE_ConnectEventHandler server_ch = NULL;
+
+/**
+ * Handle to hostlist server's disconnect handler
+ */
+GNUNET_CORE_DisconnectEventHandler server_dh = NULL;
 
 /**
  * gnunet-daemon-hostlist command line options.
@@ -133,7 +154,7 @@ static int advertisement_handler (void *cls,
 }
 
 /**
- * Method called whenever a given peer connects.
+ * Method called whenever a given peer connects.  Wrapper to call both client's and server's functions
  *
  * @param cls closure
  * @param peer peer identity this notification is about
@@ -147,11 +168,36 @@ connect_handler (void *cls,
                  struct GNUNET_TIME_Relative latency,
                  uint32_t distance)
 {
-  /* call hostlist client connection handler*/
-
-  /* do my own stuff */
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "A new peer connected, notifying client and server\n");
+  if ( NULL != client_ch)
+    (*client_ch) (cls, peer, latency, distance);
+  if ( NULL != server_ch)
+    (*server_ch) (cls, peer, latency, distance);
 }
 
+/**
+ * Method called whenever a given peer disconnects. Wrapper to call both client's and server's functions
+ *
+ * @param cls closure
+ * @param peer peer identity this notification is about
+ * @param latency reported latency of the connection with 'other'
+ * @param distance reported distance (DV) to 'other'
+ */
+static void
+disconnect_handler (void *cls,
+                    const struct
+                    GNUNET_PeerIdentity * peer)
+{
+
+  /* call hostlist client disconnect handler*/
+  if ( NULL != client_dh)
+    (*client_dh) (cls, peer);
+
+  /* call hostlist server disconnect handler*/
+  if ( NULL != server_dh)
+    (*server_dh) (cls, peer);
+}
 
 /**
  * Last task run during shutdown.  Disconnects us from
@@ -208,9 +254,6 @@ run (void *cls,
      const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle * cfg)
 {
-  GNUNET_CORE_ConnectEventHandler ch = NULL;
-  GNUNET_CORE_DisconnectEventHandler dh = NULL;
-
   if ( (! bootstrapping) &&
        (! learning) &&
        (! provide_hostlist) )
@@ -223,27 +266,22 @@ run (void *cls,
   if (bootstrapping)
     {
       GNUNET_HOSTLIST_client_start (cfg, sched, stats,
-                                   &ch, &dh, &client_adv_handler);
+                                   &client_ch, &client_dh, &client_adv_handler);
     }
   if (provide_hostlist)
     {      
-      GNUNET_HOSTLIST_server_start (cfg, sched, stats);
+      GNUNET_HOSTLIST_server_start (cfg, sched, stats, &server_ch, &server_dh);
     }
   if (learning)
     {
 
     }
 
-
-  struct GNUNET_TIME_Relative a;
-  advertisement_handler(NULL,NULL,NULL,a,6);
-
-
   core = GNUNET_CORE_connect (sched, cfg,
                             GNUNET_TIME_UNIT_FOREVER_REL,
                             NULL,
                             &core_init,
-                            NULL, ch, dh,
+                            NULL, &connect_handler, &disconnect_handler,
                             NULL, GNUNET_NO,
                             NULL, GNUNET_NO,
                             handlers);
index bd4203475e37280b867d38088bc8427254a9cf57..6c7c5a8f148c89c14717f7d41146f9807a62abc4 100644 (file)
@@ -349,6 +349,40 @@ access_handler_callback (void *cls,
   return MHD_queue_response (connection, MHD_HTTP_OK, response);
 }
 
+/**
+ * Method called whenever a given peer connects.
+ *
+ * @param cls closure
+ * @param peer peer identity this notification is about
+ * @param latency reported latency of the connection with 'other'
+ * @param distance reported distance (DV) to 'other'
+ */
+static void
+connect_handler (void *cls,
+                 const struct
+                 GNUNET_PeerIdentity * peer,
+                 struct GNUNET_TIME_Relative latency,
+                 uint32_t distance)
+{
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "A new peer connected to the server, preparing to send hostlist advertisement\n");
+}
+
+
+/**
+ * Method called whenever a given peer disconnects.
+ *
+ * @param cls closure
+ * @param peer peer identity this notification is about
+ */
+static void
+disconnect_handler (void *cls,
+                    const struct
+                    GNUNET_PeerIdentity * peer)
+{
+
+}
+
 
 /**
  * Function that queries MHD's select sets and
@@ -446,7 +480,9 @@ prepare_daemon (struct MHD_Daemon *daemon_handle)
 int
 GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
                              struct GNUNET_SCHEDULER_Handle *s,
-                             struct GNUNET_STATISTICS_Handle *st)
+                             struct GNUNET_STATISTICS_Handle *st,
+                             GNUNET_CORE_ConnectEventHandler *server_ch,
+                              GNUNET_CORE_DisconnectEventHandler *server_dh)
 {
   unsigned long long port;
 
@@ -500,6 +536,10 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
                  (unsigned short) port);
       return GNUNET_SYSERR;    
     }
+
+  *server_ch = &connect_handler;
+  *server_dh = &disconnect_handler;
+
   if (daemon_handle_v4 != NULL)
     hostlist_task_v4 = prepare_daemon (daemon_handle_v4);
   if (daemon_handle_v6 != NULL)
index c6c6337e7dbc613b73fff3ca7be4908d2ce4ab0f..7251ce11c63913aec4ba5ab8660cf73a2d35efec 100644 (file)
@@ -40,7 +40,9 @@
 int
 GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
                              struct GNUNET_SCHEDULER_Handle *s,
-                             struct GNUNET_STATISTICS_Handle *st);
+                             struct GNUNET_STATISTICS_Handle *st,
+                              GNUNET_CORE_ConnectEventHandler *server_ch,
+                             GNUNET_CORE_DisconnectEventHandler *server_dh);
 
 
 /**
index b9680e5a1862c344946aef55ae1474f38ae3a085..95b0d185030e700d1794cc2e7ef4cd13d9e60cf9 100644 (file)
@@ -8,13 +8,13 @@ PORT = 12964
 [transport]
 PORT = 12965
 PLUGINS = tcp
-#DEBUG = NO
+DEBUG = YES
 
 [arm]
 PORT = 12966
 DEFAULTSERVICES = resolver transport core statistics topology
 #GLOBAL_PREFIX = xterm -e gdb -x cmd --args 
-DEBUG=NO
+#DEBUG=NO
 
 [statistics]
 PORT = 12967
@@ -37,7 +37,7 @@ WEAKRANDOM = YES
 HTTPPORT = 12980
 SERVERS = http://localhost:12981/
 OPTIONS = -b -p -e -a
-DEBUG = NO
+DEBUG = YES
 #BINARY = /home/grothoff/bin/gnunet-daemon-hostlist
 
 [topology]
index a026a7fc15b3dd3cf87069f1167d18e5e5a12143..dc1216a86d3a2b741fe5331c9a83e7e2d2426b27 100644 (file)
@@ -8,13 +8,13 @@ PORT = 22964
 [transport]
 PORT = 22965
 PLUGINS = tcp
-#DEBUG = YES
+DEBUG = YES
 
 [arm]
 PORT = 22966
 DEFAULTSERVICES = resolver transport core statistics topology
 #GLOBAL_PREFIX = xterm -e gdb -x cmd --args
-DEBUG=NO
+#DEBUG=NO
 
 [statistics]
 PORT = 22967
@@ -27,7 +27,7 @@ PORT = 22969
 
 [core]
 PORT = 22970
-#DEBUG = YES
+DEBUG = YES
 #PREFIX = valgrind --tool=memcheck
 
 [testing]
@@ -37,7 +37,7 @@ WEAKRANDOM = YES
 HTTPPORT = 12981
 SERVERS = http://localhost:12980/
 OPTIONS = -b -p -e -a
-#DEBUG = YES
+DEBUG = YES
 #BINARY = /home/grothoff/bin/gnunet-daemon-hostlist
 
 [topology]
index c468623e81aa349ead9c32310a5a6e5dc63b1ee4..9ed891969eb7961a4946f40b7747dfb1600809fe 100644 (file)
@@ -30,7 +30,8 @@
 
 #define START_ARM GNUNET_YES
 
-#define VERBOSE GNUNET_NO
+#define VERBOSE GNUNET_YES
+#define DEBUG GNUNET_YES
 
 /**
  * How long until we give up on transmitting the message?