gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r24874 - gnunet/src/testbed


From: gnunet
Subject: [GNUnet-SVN] r24874 - gnunet/src/testbed
Date: Fri, 9 Nov 2012 17:14:21 +0100

Author: harsha
Date: 2012-11-09 17:14:20 +0100 (Fri, 09 Nov 2012)
New Revision: 24874

Modified:
   gnunet/src/testbed/gnunet-service-testbed.c
   gnunet/src/testbed/test_testbed_api_test.c
Log:
-fixes 

Modified: gnunet/src/testbed/gnunet-service-testbed.c
===================================================================
--- gnunet/src/testbed/gnunet-service-testbed.c 2012-11-09 15:56:38 UTC (rev 
24873)
+++ gnunet/src/testbed/gnunet-service-testbed.c 2012-11-09 16:14:20 UTC (rev 
24874)
@@ -545,6 +545,16 @@
   struct GNUNET_TRANSPORT_GetHelloHandle *ghh;
 
   /**
+   * The handle for offering HELLO
+   */
+  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;
@@ -2730,6 +2740,10 @@
   }
   if (NULL != occ->ghh)
     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 (NULL != occ->p1th)
   {
     GNUNET_TRANSPORT_disconnect (occ->p1th);
@@ -2862,6 +2876,31 @@
 
 
 /**
+ * Callback to be called with result of the try connect request.
+ *
+ * @param cls the overlay connect context
+ * @param result GNUNET_OK if message was transmitted to transport service
+ *               GNUNET_SYSERR if message was not transmitted to transport 
service
+ */
+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);
+}
+
+
+/**
  * Task to offer HELLO of peer 1 to peer 2 and try to make peer 2 to connect to
  * peer 1.
  *
@@ -2880,31 +2919,34 @@
  *          GNUNET_SCHEDULER_REASON_TIMEOUT then sending HELLO failed; if
  *          GNUNET_SCHEDULER_REASON_READ_READY is succeeded
  */
-//static FIXME: uncomment when using
-void
+static void
 occ_hello_sent_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct OverlayConnectContext *occ = cls;
-  int ret;
 
+  occ->ohh = NULL;
   GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == occ->send_hello_task);
   if (GNUNET_SCHEDULER_REASON_TIMEOUT == tc->reason)
   {
-    occ->send_hello_task =
-        GNUNET_SCHEDULER_add_delayed
-        (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
-                                        100 + GNUNET_CRYPTO_random_u32
-                                        (GNUNET_CRYPTO_QUALITY_WEAK, 500)),
-         &send_hello, occ);
-    return;
+    GNUNET_break (0);
+    goto schedule_send_hello;
   }
   if (GNUNET_SCHEDULER_REASON_READ_READY != tc->reason)
+  {
+    GNUNET_break (0);
     return;
-  ret = GNUNET_TRANSPORT_try_connect (occ->p2th, &occ->peer_identity, NULL, 
NULL); /*FIXME TRY_CONNECT change */
-  if (GNUNET_OK == ret)
+  }
+  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;
-  if (GNUNET_SYSERR == ret)
-    GNUNET_break (0);
+  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_delayed
       (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
@@ -2956,21 +2998,20 @@
   {
     LOG_DEBUG ("Offering HELLO of %s to %s\n", 
               GNUNET_i2s (&occ->peer_identity), other_peer_str);
-    /* FIXME: To be replaced by */
-    /* occ->offer_hello_handle = GNUNET_TRANSPORT_offer_hello (occ->p2th, */
-    /*                                                         occ->hello, */
-    /*                                                         
occ_hello_sent_cb,   */
-    /*                                                         occ); */
-
-    /* FIXME: once offer_hello offers a handle to cancel remove the following 
lines */
-    GNUNET_TRANSPORT_offer_hello (occ->p2th, occ->hello, NULL, NULL);
-    GNUNET_TRANSPORT_try_connect (occ->p2th, &occ->peer_identity, NULL, NULL); 
/*FIXME TRY_CONNECT change */
-    occ->send_hello_task =
-        GNUNET_SCHEDULER_add_delayed
-        (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
-                                        100 + GNUNET_CRYPTO_random_u32
-                                        (GNUNET_CRYPTO_QUALITY_WEAK, 500)),
-         &send_hello, occ);
+    occ->ohh = GNUNET_TRANSPORT_offer_hello (occ->p2th,
+                                             occ->hello,
+                                             occ_hello_sent_cb,
+                                             occ);
+    if (NULL == occ->ohh)
+    {
+      GNUNET_break (0);
+      occ->send_hello_task =
+          GNUNET_SCHEDULER_add_delayed
+          (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
+                                          100 + GNUNET_CRYPTO_random_u32
+                                          (GNUNET_CRYPTO_QUALITY_WEAK, 500)),
+           &send_hello, occ);
+    }
   }
   GNUNET_free (other_peer_str);  
 }

Modified: gnunet/src/testbed/test_testbed_api_test.c
===================================================================
--- gnunet/src/testbed/test_testbed_api_test.c  2012-11-09 15:56:38 UTC (rev 
24873)
+++ gnunet/src/testbed/test_testbed_api_test.c  2012-11-09 16:14:20 UTC (rev 
24874)
@@ -28,7 +28,14 @@
 #include "gnunet_common.h"
 #include "gnunet_testbed_service.h"
 
+
 /**
+ * Generic logging shortcut
+ */
+#define LOG(kind,...)                          \
+  GNUNET_log (kind, __VA_ARGS__)
+
+/**
  * Number of peers we want to start
  */
 #define NUM_PEERS 25
@@ -44,6 +51,16 @@
 static struct GNUNET_TESTBED_Operation *op;
 
 /**
+ * Abort task identifier
+ */
+static GNUNET_SCHEDULER_TaskIdentifier abort_task;
+
+/**
+ * shutdown task identifier
+ */
+static GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
+
+/**
  * Testing result
  */
 static int result;
@@ -57,12 +74,49 @@
  */
 static void
 do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
+{  
+  shutdown_task = GNUNET_SCHEDULER_NO_TASK;
+  if (GNUNET_SCHEDULER_NO_TASK != abort_task)
+    GNUNET_SCHEDULER_cancel (abort_task);
+  if (NULL != op)
+    GNUNET_TESTBED_operation_done (op);
   GNUNET_SCHEDULER_shutdown ();
 }
 
+/**
+ * shortcut to exit during failure
+ */
+#define FAIL_TEST(cond) do {                                            \
+    if (!(cond)) {                                                      \
+      GNUNET_break(0);                                                  \
+      if (GNUNET_SCHEDULER_NO_TASK != abort_task)                       \
+        GNUNET_SCHEDULER_cancel (abort_task);                           \
+      abort_task = GNUNET_SCHEDULER_NO_TASK;                            \
+      if (GNUNET_SCHEDULER_NO_TASK == shutdown_task)                    \
+        shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL);   \
+      return;                                                           \
+    }                                                                   \
+  } while (0)
 
+
 /**
+ * abort task to run on test timed out
+ *
+ * @param cls NULL
+ * @param tc the task context
+ */
+static void
+do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
+  abort_task = GNUNET_SCHEDULER_NO_TASK;
+  if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
+     GNUNET_SCHEDULER_cancel (shutdown_task);
+  shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL);
+}
+
+
+/**
  * Callback to be called when the requested peer information is available
  *
  * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information()
@@ -76,14 +130,15 @@
             const struct GNUNET_TESTBED_PeerInformation *pinfo,
             const char *emsg)
 {
-  GNUNET_assert (op == op_);
-  GNUNET_assert (NULL == cb_cls);
-  GNUNET_assert (NULL == emsg);
-  GNUNET_assert (GNUNET_TESTBED_PIT_IDENTITY == pinfo->pit);
-  GNUNET_assert (NULL != pinfo->result.id);
+  FAIL_TEST (op == op_);
+  FAIL_TEST (NULL == cb_cls);
+  FAIL_TEST (NULL == emsg);
+  FAIL_TEST (GNUNET_TESTBED_PIT_IDENTITY == pinfo->pit);
+  FAIL_TEST (NULL != pinfo->result.id);
   GNUNET_TESTBED_operation_done (op);
+  op = NULL;
   result = GNUNET_OK;
-  GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+  shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
 }
 
 
@@ -98,9 +153,13 @@
 static void 
 op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op_, const char *emsg)
 {
-  GNUNET_assert (NULL == cls);
-  GNUNET_assert (op == op_);
-  GNUNET_assert (NULL == emsg);
+  FAIL_TEST (NULL == cls);
+  FAIL_TEST (op == op_);
+  if (NULL != emsg)
+  {
+    LOG (GNUNET_ERROR_TYPE_WARNING, "%s\n", emsg);
+    FAIL_TEST (0);
+  }
   GNUNET_TESTBED_operation_done (op);
   op = GNUNET_TESTBED_peer_get_information (peers[0],
                                            GNUNET_TESTBED_PIT_IDENTITY,
@@ -121,11 +180,11 @@
   switch (event->type)
   {
   case GNUNET_TESTBED_ET_CONNECT:
-    GNUNET_assert (event->details.peer_connect.peer1 == peers[0]);
-    GNUNET_assert (event->details.peer_connect.peer2 == peers[1]);    
+    FAIL_TEST (event->details.peer_connect.peer1 == peers[0]);
+    FAIL_TEST (event->details.peer_connect.peer2 == peers[1]);    
     break;
   default:
-    GNUNET_assert (0);
+    FAIL_TEST (0);
   }  
 }
 
@@ -143,13 +202,17 @@
 {
   unsigned int peer;
 
-  GNUNET_assert (NULL == cls);
-  GNUNET_assert (NUM_PEERS == num_peers);
-  GNUNET_assert (NULL != peers_);
+  FAIL_TEST (NULL == cls);
+  FAIL_TEST (NUM_PEERS == num_peers);
+  FAIL_TEST (NULL != peers_);
   for (peer = 0; peer < num_peers; peer++)
-    GNUNET_assert (NULL != peers_[peer]);
+    FAIL_TEST (NULL != peers_[peer]);
   peers = peers_;
   op = GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peers[0], 
peers[1]);
+  abort_task =
+      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+                                    (GNUNET_TIME_UNIT_MINUTES, 3), &do_abort,
+                                    NULL);
 }
 
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]