[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r24946 - gnunet/src/testbed
From: |
gnunet |
Subject: |
[GNUnet-SVN] r24946 - gnunet/src/testbed |
Date: |
Wed, 14 Nov 2012 13:18:55 +0100 |
Author: harsha
Date: 2012-11-14 13:18:55 +0100 (Wed, 14 Nov 2012)
New Revision: 24946
Modified:
gnunet/src/testbed/gnunet-service-testbed.c
Log:
- try connect as task
Modified: gnunet/src/testbed/gnunet-service-testbed.c
===================================================================
--- gnunet/src/testbed/gnunet-service-testbed.c 2012-11-14 10:50:52 UTC (rev
24945)
+++ gnunet/src/testbed/gnunet-service-testbed.c 2012-11-14 12:18:55 UTC (rev
24946)
@@ -495,6 +495,39 @@
/**
+ * Context information for transport try connect
+ */
+struct TryConnectContext
+{
+ /**
+ * The identity of the peer to which the transport has to attempt a
connection
+ */
+ struct GNUNET_PeerIdentity *pid;
+
+ /**
+ * The transport handle
+ */
+ struct GNUNET_TRANSPORT_Handle *th;
+
+ /**
+ * the try connect handle
+ */
+ struct GNUNET_TRANSPORT_TryConnectHandle *tch;
+
+ /**
+ * The task handle
+ */
+ GNUNET_SCHEDULER_TaskIdentifier task;
+
+ /**
+ * The number of times we attempted to connect
+ */
+ unsigned int retries;
+
+};
+
+
+/**
* Context information for connecting 2 peers in overlay
*/
struct OverlayConnectContext
@@ -550,11 +583,6 @@
struct GNUNET_TRANSPORT_OfferHelloHandle *ohh;
/**
- * The handle for transport try connect
- */
- struct GNUNET_TRANSPORT_TryConnectHandle *tch;
-
- /**
* The error message we send if this overlay connect operation has timed out
*/
char *emsg;
@@ -570,6 +598,11 @@
struct GNUNET_TESTBED_Controller *peer2_controller;
/**
+ * The transport try connect context
+ */
+ struct TryConnectContext tcc;
+
+ /**
* The peer identity of the first peer
*/
struct GNUNET_PeerIdentity peer_identity;
@@ -2752,8 +2785,10 @@
GNUNET_TRANSPORT_get_hello_cancel (occ->ghh);
if (NULL != occ->ohh)
GNUNET_TRANSPORT_offer_hello_cancel (occ->ohh);
- if (NULL != occ->tch)
- GNUNET_TRANSPORT_try_connect_cancel (occ->tch);
+ if (GNUNET_SCHEDULER_NO_TASK != occ->tcc.task)
+ GNUNET_SCHEDULER_cancel (occ->tcc.task);
+ if (NULL != occ->tcc.tch)
+ GNUNET_TRANSPORT_try_connect_cancel (occ->tcc.tch);
if (NULL != occ->p1th)
{
GNUNET_TRANSPORT_disconnect (occ->p1th);
@@ -2886,6 +2921,16 @@
/**
+ * Task to ask transport of a peer to connect to another peer
+ *
+ * @param cls the TryConnectContext
+ * @param tc the scheduler task context
+ */
+static void
+try_connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
+
+
+/**
* Callback to be called with result of the try connect request.
*
* @param cls the overlay connect context
@@ -2895,22 +2940,39 @@
static void
try_connect_cb (void *cls, const int result)
{
- struct OverlayConnectContext *occ = cls;
-
- occ->tch = NULL;
- if (GNUNET_OK == result)
- {
- GNUNET_free_non_null (occ->emsg);
- occ->emsg = GNUNET_strdup ("Waiting for transport to connect");
- //return; FIXME: should return here
- }
- // GNUNET_break (0);
- occ->tch = GNUNET_TRANSPORT_try_connect (occ->p2th, &occ->peer_identity,
- &try_connect_cb, occ);
+ struct TryConnectContext *tcc = cls;
+
+ tcc->tch = NULL;
+ GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == tcc->task);
+ tcc->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS,
+ pow (10, ++tcc->retries)),
+ &try_connect_task, tcc);
}
/**
+ * Task to ask transport of a peer to connect to another peer
+ *
+ * @param cls the TryConnectContext
+ * @param tc the scheduler task context
+ */
+static void
+try_connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct TryConnectContext *tcc = cls;
+
+ tcc->task = GNUNET_SCHEDULER_NO_TASK;
+ if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
+ return;
+ GNUNET_assert (NULL == tcc->tch);
+ GNUNET_assert (NULL != tcc->pid);
+ GNUNET_assert (NULL != tcc->th);
+ tcc->tch = GNUNET_TRANSPORT_try_connect (tcc->th, tcc->pid, &try_connect_cb,
tcc);
+}
+
+
+/**
* Task to offer HELLO of peer 1 to peer 2 and try to make peer 2 to connect to
* peer 1.
*
@@ -2938,23 +3000,18 @@
GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == occ->send_hello_task);
if (GNUNET_SCHEDULER_REASON_TIMEOUT == tc->reason)
{
- //GNUNET_break (0);
- goto schedule_send_hello;
+ GNUNET_free_non_null (occ->emsg);
+ occ->emsg = GNUNET_strdup ("Timeout while offering HELLO to other peer");
+ occ->send_hello_task = GNUNET_SCHEDULER_add_now (&send_hello, occ);
+ return;
}
if (GNUNET_SCHEDULER_REASON_READ_READY != tc->reason)
return;
GNUNET_free_non_null (occ->emsg);
occ->emsg = GNUNET_strdup ("Timeout while try connect\n");
- occ->tch = GNUNET_TRANSPORT_try_connect (occ->p2th, &occ->peer_identity,
- &try_connect_cb, occ);
- if (NULL != occ->tch)
- return;
- GNUNET_break (0);
-
- schedule_send_hello:
- GNUNET_free_non_null (occ->emsg);
- occ->emsg = GNUNET_strdup ("Timeout while offering HELLO to other peer");
- occ->send_hello_task = GNUNET_SCHEDULER_add_now (&send_hello, occ);
+ occ->tcc.pid = &occ->peer_identity;
+ occ->tcc.th = occ->p2th;
+ occ->tcc.task = GNUNET_SCHEDULER_add_now (&try_connect_task, &occ->tcc);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r24946 - gnunet/src/testbed,
gnunet <=