[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r10844 - gnunet/src/hostlist
From: |
gnunet |
Subject: |
[GNUnet-SVN] r10844 - gnunet/src/hostlist |
Date: |
Thu, 8 Apr 2010 15:06:54 +0200 |
Author: wachs
Date: 2010-04-08 15:06:54 +0200 (Thu, 08 Apr 2010)
New Revision: 10844
Modified:
gnunet/src/hostlist/gnunet-daemon-hostlist.c
gnunet/src/hostlist/hostlist-client.c
gnunet/src/hostlist/hostlist-client.h
Log:
hostlist client gets notified when hostlist advertisments arrive
Modified: gnunet/src/hostlist/gnunet-daemon-hostlist.c
===================================================================
--- gnunet/src/hostlist/gnunet-daemon-hostlist.c 2010-04-08 12:49:21 UTC
(rev 10843)
+++ gnunet/src/hostlist/gnunet-daemon-hostlist.c 2010-04-08 13:06:54 UTC
(rev 10844)
@@ -75,6 +75,12 @@
struct GNUNET_CORE_Handle *core;
/**
+ * Handle to the hostlist client's advertisement handler
+ */
+GNUNET_CORE_MessageCallback client_adv_handler = NULL;
+
+
+/**
* gnunet-daemon-hostlist command line options.
*/
static struct GNUNET_GETOPT_CommandLineOption options[] = {
@@ -112,20 +118,41 @@
/**
* Core handler for p2p hostlist advertisements
*/
-static int handle_hostlist_advertisement (void *cls,
+static int advertisement_handler (void *cls,
const struct GNUNET_PeerIdentity * peer,
const struct GNUNET_MessageHeader * message,
struct GNUNET_TIME_Relative latency,
uint32_t distance)
{
-#if DEBUG_HOSTLIST_LEARNING
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Recieved hostlist advertisement\n"));
-#endif
+ if (advertising && (NULL != client_adv_handler))
+ {
+ (*client_adv_handler) (cls, peer, message, latency, distance);
+ return GNUNET_YES;
+ }
+ return GNUNET_NO;
+}
- return GNUNET_OK;
+/**
+ * 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)
+{
+ /* call hostlist client connection handler*/
+
+ /* do my own stuff */
}
+
/**
* Last task run during shutdown. Disconnects us from
* the other services.
@@ -161,7 +188,7 @@
* service.
*/
static struct GNUNET_CORE_MessageHandler handlers[] = {
- { &handle_hostlist_advertisement,
GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT, 0},
+ { &advertisement_handler, GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT, 0},
{ NULL, 0, 0 }
};
@@ -184,14 +211,6 @@
GNUNET_CORE_ConnectEventHandler ch = NULL;
GNUNET_CORE_DisconnectEventHandler dh = NULL;
-
-
- struct GNUNET_CORE_MessageHandler null_handler[] = {
- { NULL, 0, 0 }
- };
-
- struct GNUNET_CORE_MessageHandler *used_handler = null_handler;
-
if ( (! bootstrapping) &&
(! learning) &&
(! provide_hostlist) )
@@ -204,7 +223,7 @@
if (bootstrapping)
{
GNUNET_HOSTLIST_client_start (cfg, sched, stats,
- &ch, &dh);
+ &ch, &dh, &client_adv_handler);
}
if (provide_hostlist)
{
@@ -212,9 +231,14 @@
}
if (learning)
{
- used_handler = handlers;
+
}
+
+ struct GNUNET_TIME_Relative a;
+ advertisement_handler(NULL,NULL,NULL,a,6);
+
+
core = GNUNET_CORE_connect (sched, cfg,
GNUNET_TIME_UNIT_FOREVER_REL,
NULL,
@@ -222,7 +246,7 @@
NULL, ch, dh,
NULL, GNUNET_NO,
NULL, GNUNET_NO,
- used_handler);
+ handlers);
GNUNET_SCHEDULER_add_delayed (sched,
GNUNET_TIME_UNIT_FOREVER_REL,
Modified: gnunet/src/hostlist/hostlist-client.c
===================================================================
--- gnunet/src/hostlist/hostlist-client.c 2010-04-08 12:49:21 UTC (rev
10843)
+++ gnunet/src/hostlist/hostlist-client.c 2010-04-08 13:06:54 UTC (rev
10844)
@@ -32,7 +32,7 @@
#include "gnunet_transport_service.h"
#include <curl/curl.h>
-#define DEBUG_HOSTLIST_CLIENT GNUNET_NO
+#define DEBUG_HOSTLIST_CLIENT GNUNET_YES
/**
* Number of connections that we must have to NOT download
@@ -695,7 +695,7 @@
/**
- * Method called whenever a given peer connects.
+ * Method called whenever a given peer disconnects.
*
* @param cls closure
* @param peer peer identity this notification is about
@@ -712,7 +712,32 @@
GNUNET_NO);
}
+/**
+ * Method called whenever an advertisement message arrives.
+ *
+ * @param cls closure (always NULL)
+ * @param client identification of the client
+ * @param message the actual message
+ * @return GNUNET_OK to keep the connection open,
+ * GNUNET_SYSERR to close it (signal serious error)
+ */
+static int
+advertisement_handler (void *cls,
+ const struct GNUNET_PeerIdentity * peer,
+ const struct GNUNET_MessageHeader * message,
+ struct GNUNET_TIME_Relative latency,
+ uint32_t distance)
+{
+#if DEBUG_HOSTLIST_CLIENT
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Hostlist client recieved advertisement message\n");
+#endif
+ /* put code to use message here */
+
+ return GNUNET_YES;
+}
+
/**
* Continuation called by the statistics code once
* we go the stat. Initiates hostlist download scheduling.
@@ -757,7 +782,8 @@
struct GNUNET_SCHEDULER_Handle *s,
struct GNUNET_STATISTICS_Handle *st,
GNUNET_CORE_ConnectEventHandler *ch,
- GNUNET_CORE_DisconnectEventHandler *dh)
+ GNUNET_CORE_DisconnectEventHandler *dh,
+ GNUNET_CORE_MessageCallback *msgh)
{
if (0 != curl_global_init (CURL_GLOBAL_WIN32))
{
@@ -781,6 +807,7 @@
proxy = NULL;
*ch = &connect_handler;
*dh = &disconnect_handler;
+ *msgh = &advertisement_handler;
GNUNET_STATISTICS_get (stats,
"hostlist",
gettext_noop("Minimum time between hostlist
downloads"),
Modified: gnunet/src/hostlist/hostlist-client.h
===================================================================
--- gnunet/src/hostlist/hostlist-client.h 2010-04-08 12:49:21 UTC (rev
10843)
+++ gnunet/src/hostlist/hostlist-client.h 2010-04-08 13:06:54 UTC (rev
10844)
@@ -40,6 +40,7 @@
* @param st hande for publishing statistics
* @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
* @return GNUNET_OK on success
*/
int
@@ -47,7 +48,8 @@
struct GNUNET_SCHEDULER_Handle *s,
struct GNUNET_STATISTICS_Handle *st,
GNUNET_CORE_ConnectEventHandler *ch,
- GNUNET_CORE_DisconnectEventHandler *dh);
+ GNUNET_CORE_DisconnectEventHandler *dh,
+ GNUNET_CORE_MessageCallback *msgh);
/**
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r10844 - gnunet/src/hostlist,
gnunet <=