*/
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.
*/
/**
* 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.
* 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 }
};
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) )
if (bootstrapping)
{
GNUNET_HOSTLIST_client_start (cfg, sched, stats,
- &ch, &dh);
+ &ch, &dh, &client_adv_handler);
}
if (provide_hostlist)
{
}
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,
NULL, ch, dh,
NULL, GNUNET_NO,
NULL, GNUNET_NO,
- used_handler);
+ handlers);
GNUNET_SCHEDULER_add_delayed (sched,
GNUNET_TIME_UNIT_FOREVER_REL,
#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
/**
- * 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
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
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))
{
proxy = NULL;
*ch = &connect_handler;
*dh = &disconnect_handler;
+ *msgh = &advertisement_handler;
GNUNET_STATISTICS_get (stats,
"hostlist",
gettext_noop("Minimum time between hostlist downloads"),
* @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
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);
/**