[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r10994 - gnunet/src/hostlist
From: |
gnunet |
Subject: |
[GNUnet-SVN] r10994 - gnunet/src/hostlist |
Date: |
Tue, 20 Apr 2010 15:10:56 +0200 |
Author: wachs
Date: 2010-04-20 15:10:56 +0200 (Tue, 20 Apr 2010)
New Revision: 10994
Modified:
gnunet/src/hostlist/test_gnunet_daemon_hostlist_learning.c
Log:
Modified: gnunet/src/hostlist/test_gnunet_daemon_hostlist_learning.c
===================================================================
--- gnunet/src/hostlist/test_gnunet_daemon_hostlist_learning.c 2010-04-20
12:41:58 UTC (rev 10993)
+++ gnunet/src/hostlist/test_gnunet_daemon_hostlist_learning.c 2010-04-20
13:10:56 UTC (rev 10994)
@@ -27,12 +27,13 @@
#include "gnunet_arm_service.h"
#include "gnunet_core_service.h"
#include "gnunet_transport_service.h"
+#include "gnunet_resolver_service.h"
#define VERBOSE GNUNET_NO
#define START_ARM GNUNET_YES
+#define MAX_URL_LEN 1000
-
/**
* How long until we give up on transmitting the message?
*/
@@ -65,28 +66,40 @@
clean_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (adv_peer.th != NULL)
- {
- GNUNET_TRANSPORT_disconnect (adv_peer.th);
- adv_peer.th = NULL;
- }
+ {
+ GNUNET_TRANSPORT_disconnect (adv_peer.th);
+ adv_peer.th = NULL;
+ }
if (learn_peer.th != NULL)
- {
- GNUNET_TRANSPORT_disconnect (learn_peer.th);
- learn_peer.th = NULL;
- }
+ {
+ GNUNET_TRANSPORT_disconnect (learn_peer.th);
+ learn_peer.th = NULL;
+ }
if (adv_peer.core != NULL)
- {
- GNUNET_CORE_disconnect (adv_peer.core);
- adv_peer.core = NULL;
- }
+ {
+ GNUNET_CORE_disconnect (adv_peer.core);
+ adv_peer.core = NULL;
+ }
if (learn_peer.core != NULL)
- {
- GNUNET_CORE_disconnect (learn_peer.core);
- learn_peer.core = NULL;
- }
+ {
+ GNUNET_CORE_disconnect (learn_peer.core);
+ learn_peer.core = NULL;
+ }
GNUNET_SCHEDULER_shutdown (sched);
}
+static void shutdown_testcase()
+{
+ if (timeout_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (sched,
+ timeout_task);
+ timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ GNUNET_SCHEDULER_add_now (sched,
+ &clean_up, NULL);
+}
+
/**
* Timeout, give up.
*/
@@ -103,34 +116,61 @@
/**
* Core handler for p2p hostlist advertisements
*/
-static void ad_arrive_handler (void *cls,
+static int ad_arrive_handler (void *cls,
const struct GNUNET_PeerIdentity * peer,
const struct GNUNET_MessageHeader * message,
struct GNUNET_TIME_Relative latency,
uint32_t distance)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "A ADV message, notifying client and server\n");
- if (timeout_task != GNUNET_SCHEDULER_NO_TASK)
+ char *hostname;
+ char *expected_uri = GNUNET_malloc (MAX_URL_LEN);
+ char *recv_uri;
+
+ unsigned long long port;
+ size_t size;
+ const struct GNUNET_MessageHeader * incoming;
+
+ if (-1 == GNUNET_CONFIGURATION_get_value_number (adv_peer.cfg,
+ "HOSTLIST",
+ "HTTPPORT",
+ &port))
{
- GNUNET_SCHEDULER_cancel (sched,
- timeout_task);
- timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Could not read advertising server's configuration\n" );
+ return GNUNET_SYSERR;
}
- adv_arrived = GNUNET_YES;
- GNUNET_SCHEDULER_add_now (sched,
- &clean_up, NULL);
-}
+ hostname = GNUNET_RESOLVER_local_hostname_get ();
+ if (NULL != hostname)
+ {
+ size = strlen (hostname);
+ if (size + 15 > MAX_URL_LEN)
+ {
+ GNUNET_break (0);
+ }
+ else
+ {
+ GNUNET_asprintf (&expected_uri,
+ "http://%s:%u/",
+ hostname,
+ (unsigned int) port);
+ }
+ }
-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, notifying client and server\n");
+ incoming = (const struct GNUNET_MessageHeader *) message;
+ recv_uri = (char*) &incoming[1];
+ if ( 0 == strcmp( expected_uri, recv_uri ) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Recieved hostlist advertisement with URI `%s'as expected\n",
recv_uri);
+ adv_arrived = GNUNET_YES;
+ }
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Expected URI `%s' and recieved URI `%s' differ\n",
expected_uri, recv_uri);
+ GNUNET_free ( expected_uri );
+ GNUNET_free ( hostname );
+ shutdown_testcase();
+ return GNUNET_OK;
}
/**
@@ -160,13 +200,11 @@
GNUNET_TIME_UNIT_FOREVER_REL,
NULL,
NULL,
- &connect_handler, NULL,
+ NULL, NULL,
NULL, GNUNET_NO,
NULL, GNUNET_NO,
learn_handlers );
GNUNET_assert ( NULL != p->core );
-
-
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r10994 - gnunet/src/hostlist,
gnunet <=