[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r10851 - gnunet/src/hostlist
From: |
gnunet |
Subject: |
[GNUnet-SVN] r10851 - gnunet/src/hostlist |
Date: |
Thu, 8 Apr 2010 16:29:44 +0200 |
Author: wachs
Date: 2010-04-08 16:29:44 +0200 (Thu, 08 Apr 2010)
New Revision: 10851
Modified:
gnunet/src/hostlist/gnunet-daemon-hostlist.c
gnunet/src/hostlist/hostlist-server.c
gnunet/src/hostlist/hostlist-server.h
gnunet/src/hostlist/learning_peer1.conf
gnunet/src/hostlist/learning_peer2.conf
gnunet/src/hostlist/test_gnunet_daemon_hostlist_learning.c
Log:
Modifications so hostlist client and server will notified when new peers connect
Modified: gnunet/src/hostlist/gnunet-daemon-hostlist.c
===================================================================
--- gnunet/src/hostlist/gnunet-daemon-hostlist.c 2010-04-08 14:01:38 UTC
(rev 10850)
+++ gnunet/src/hostlist/gnunet-daemon-hostlist.c 2010-04-08 14:29:44 UTC
(rev 10851)
@@ -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,8 +81,27 @@
*/
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.
*/
static struct GNUNET_GETOPT_CommandLineOption options[] = {
@@ -133,7 +154,7 @@
}
/**
- * 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,12 +168,37 @@
struct GNUNET_TIME_Relative latency,
uint32_t distance)
{
- /* call hostlist client connection handler*/
+ 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);
+}
- /* do my own stuff */
+/**
+ * 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
* the other services.
@@ -208,9 +254,6 @@
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 @@
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);
Modified: gnunet/src/hostlist/hostlist-server.c
===================================================================
--- gnunet/src/hostlist/hostlist-server.c 2010-04-08 14:01:38 UTC (rev
10850)
+++ gnunet/src/hostlist/hostlist-server.c 2010-04-08 14:29:44 UTC (rev
10851)
@@ -349,8 +349,42 @@
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
* starts the task waiting for them.
*/
@@ -446,7 +480,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)
{
unsigned long long port;
@@ -500,6 +536,10 @@
(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)
Modified: gnunet/src/hostlist/hostlist-server.h
===================================================================
--- gnunet/src/hostlist/hostlist-server.h 2010-04-08 14:01:38 UTC (rev
10850)
+++ gnunet/src/hostlist/hostlist-server.h 2010-04-08 14:29:44 UTC (rev
10851)
@@ -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);
/**
Modified: gnunet/src/hostlist/learning_peer1.conf
===================================================================
--- gnunet/src/hostlist/learning_peer1.conf 2010-04-08 14:01:38 UTC (rev
10850)
+++ gnunet/src/hostlist/learning_peer1.conf 2010-04-08 14:29:44 UTC (rev
10851)
@@ -8,13 +8,13 @@
[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 @@
HTTPPORT = 12980
SERVERS = http://localhost:12981/
OPTIONS = -b -p -e -a
-DEBUG = NO
+DEBUG = YES
#BINARY = /home/grothoff/bin/gnunet-daemon-hostlist
[topology]
Modified: gnunet/src/hostlist/learning_peer2.conf
===================================================================
--- gnunet/src/hostlist/learning_peer2.conf 2010-04-08 14:01:38 UTC (rev
10850)
+++ gnunet/src/hostlist/learning_peer2.conf 2010-04-08 14:29:44 UTC (rev
10851)
@@ -8,13 +8,13 @@
[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 @@
[core]
PORT = 22970
-#DEBUG = YES
+DEBUG = YES
#PREFIX = valgrind --tool=memcheck
[testing]
@@ -37,7 +37,7 @@
HTTPPORT = 12981
SERVERS = http://localhost:12980/
OPTIONS = -b -p -e -a
-#DEBUG = YES
+DEBUG = YES
#BINARY = /home/grothoff/bin/gnunet-daemon-hostlist
[topology]
Modified: gnunet/src/hostlist/test_gnunet_daemon_hostlist_learning.c
===================================================================
--- gnunet/src/hostlist/test_gnunet_daemon_hostlist_learning.c 2010-04-08
14:01:38 UTC (rev 10850)
+++ gnunet/src/hostlist/test_gnunet_daemon_hostlist_learning.c 2010-04-08
14:29:44 UTC (rev 10851)
@@ -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?
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r10851 - gnunet/src/hostlist,
gnunet <=