gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r11081 - gnunet/src/testing


From: gnunet
Subject: [GNUnet-SVN] r11081 - gnunet/src/testing
Date: Tue, 27 Apr 2010 17:32:55 +0200

Author: nevans
Date: 2010-04-27 17:32:55 +0200 (Tue, 27 Apr 2010)
New Revision: 11081

Modified:
   gnunet/src/testing/test_testing_connect.c
   gnunet/src/testing/test_testing_topology.c
   gnunet/src/testing/testing.c
   gnunet/src/testing/testing_group.c
Log:
testing bug fixes (hopefully)

Modified: gnunet/src/testing/test_testing_connect.c
===================================================================
--- gnunet/src/testing/test_testing_connect.c   2010-04-27 15:06:15 UTC (rev 
11080)
+++ gnunet/src/testing/test_testing_connect.c   2010-04-27 15:32:55 UTC (rev 
11081)
@@ -24,7 +24,7 @@
 #include "platform.h"
 #include "gnunet_testing_lib.h"
 
-#define VERBOSE GNUNET_YES
+#define VERBOSE GNUNET_NO
 
 
 /**

Modified: gnunet/src/testing/test_testing_topology.c
===================================================================
--- gnunet/src/testing/test_testing_topology.c  2010-04-27 15:06:15 UTC (rev 
11080)
+++ gnunet/src/testing/test_testing_topology.c  2010-04-27 15:32:55 UTC (rev 
11081)
@@ -25,7 +25,7 @@
 #include "gnunet_testing_lib.h"
 #include "gnunet_core_service.h"
 
-#define VERBOSE GNUNET_NO
+#define VERBOSE GNUNET_YES
 
 /**
  * How long until we fail the whole testcase?
@@ -37,8 +37,10 @@
  */
 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
 
-#define DEFAULT_NUM_PEERS 4;
+#define DEFAULT_NUM_PEERS 4
 
+#define MAX_OUTSTANDING_CONNECTIONS 300
+
 static float fail_percentage = 0.05;
 
 static int ok;
@@ -75,12 +77,25 @@
 
 static int transmit_ready_scheduled;
 
+static int transmit_ready_failed;
+
 static int transmit_ready_called;
 
-struct TestMessageContext *global_pos;
-
 #define MTYPE 12345
 
+struct GNUNET_TestMessage
+{
+  /**
+   * Header of the message
+   */
+  struct GNUNET_MessageHeader header;
+
+  /**
+   * Unique identifier for this message.
+   */
+  uint32_t uid;
+};
+
 struct TestMessageContext
 {
   /* This is a linked list */
@@ -98,46 +113,45 @@
   /* Handle to the receiving peer daemon */
   struct GNUNET_TESTING_Daemon *peer2;
 
-  /* Maintain some state */
-  int first_step_done;
+  /* Identifier for this message, so we don't disconnect other peers! */
+  uint32_t uid;
 
 };
 
-struct Connection
-{
-  struct Connection *next;
-  struct GNUNET_TESTING_Daemon *peer;
-  struct GNUNET_CORE_Handle *server;
-};
-
-static struct Connection *global_connections;
-
 static struct TestMessageContext *test_messages;
 
 static void
 finish_testing ()
 {
   GNUNET_assert (pg != NULL);
-  struct Connection *pos;
+  struct TestMessageContext *pos;
+  struct TestMessageContext *free_pos;
 #if VERBOSE
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Called finish testing, stopping daemons.\n");
 #endif
   int count;
   count = 0;
-  pos = global_connections;
+  pos = test_messages;
   while (pos != NULL)
     {
-      if (pos->server != NULL)
+      if (pos->peer1handle != NULL)
         {
-          GNUNET_CORE_disconnect(pos->server);
-          pos->server = NULL;
+          GNUNET_CORE_disconnect(pos->peer1handle);
+          pos->peer1handle = NULL;
         }
+      if (pos->peer2handle != NULL)
+        {
+          GNUNET_CORE_disconnect(pos->peer2handle);
+          pos->peer2handle = NULL;
+        }
+      free_pos = pos;
       pos = pos->next;
+      GNUNET_free(free_pos);
     }
 #if VERBOSE
           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                      "transmit_ready's scheduled %d, transmit_ready's called 
%d\n", transmit_ready_scheduled, transmit_ready_called);
+                      "transmit_ready's scheduled %d, failed %d, 
transmit_ready's called %d\n", transmit_ready_scheduled, transmit_ready_failed, 
transmit_ready_called);
 #endif
   sleep(1);
 #if VERBOSE
@@ -158,6 +172,32 @@
   ok = 0;
 }
 
+
+static void
+disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
+{
+  struct TestMessageContext *pos = cls;
+
+  /* Disconnect from the respective cores */
+#if VERBOSE
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Disconnecting from peer 1 `%4s'\n", GNUNET_i2s 
(&pos->peer1->id));
+#endif
+  if (pos->peer1handle != NULL)
+    GNUNET_CORE_disconnect(pos->peer1handle);
+#if VERBOSE
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Disconnecting from peer 2 `%4s'\n", GNUNET_i2s 
(&pos->peer2->id));
+#endif
+  if (pos->peer2handle != NULL)
+    GNUNET_CORE_disconnect(pos->peer2handle);
+  /* Set handles to NULL so test case can be ended properly */
+  pos->peer1handle = NULL;
+  pos->peer2handle = NULL;
+  /* Decrement total connections so new can be established */
+  total_server_connections -= 2;
+}
+
 static int
 process_mtype (void *cls,
                const struct GNUNET_PeerIdentity *peer,
@@ -165,6 +205,11 @@
                struct GNUNET_TIME_Relative latency,
                uint32_t distance)
 {
+  struct TestMessageContext *pos = cls;
+  struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *)message;
+  if (pos->uid != ntohl(msg->uid))
+    return GNUNET_OK;
+
   total_messages_received++;
 #if VERBOSE
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -178,6 +223,11 @@
       GNUNET_SCHEDULER_cancel (sched, die_task);
       GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL);
     }
+  else
+    {
+      GNUNET_SCHEDULER_add_now(sched, &disconnect_cores, pos);
+    }
+
   return GNUNET_OK;
 }
 
@@ -187,17 +237,25 @@
   char *msg = cls;
   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
               "End badly was called (%s)... stopping daemons.\n", msg);
-  struct Connection *pos;
+  struct TestMessageContext *pos;
+  struct TestMessageContext *free_pos;
 
-  pos = global_connections;
+  pos = test_messages;
   while (pos != NULL)
     {
-      if (pos->server != NULL)
+      if (pos->peer1handle != NULL)
         {
-          GNUNET_CORE_disconnect(pos->server);
-          pos->server = NULL;
+          GNUNET_CORE_disconnect(pos->peer1handle);
+          pos->peer1handle = NULL;
         }
+      if (pos->peer2handle != NULL)
+        {
+          GNUNET_CORE_disconnect(pos->peer2handle);
+          pos->peer2handle = NULL;
+        }
+      free_pos = pos;
       pos = pos->next;
+      GNUNET_free(free_pos);
     }
 
   if (pg != NULL)
@@ -216,195 +274,151 @@
 }
 
 
-/**
- * Forward declaration.
- */
-static size_t
-transmit_ready (void *cls, size_t size, void *buf);
 
-static void
-schedule_transmission (void *cls, const struct GNUNET_SCHEDULER_TaskContext * 
tc)
-{
-
-  if (global_pos != NULL)
-  {
-    if (NULL == GNUNET_CORE_notify_transmit_ready (global_pos->peer1handle,
-                                                 0,
-                                                 TIMEOUT,
-                                                 &global_pos->peer2->id,
-                                                 sizeof (struct 
GNUNET_MessageHeader),
-                                                 &transmit_ready, 
&global_pos->peer1->id))
-      {
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                    "RECEIVED NULL when asking core (1) for transmission to 
peer `%4s'\n",
-                    GNUNET_i2s (&global_pos->peer2->id));
-      }
-    else
-      {
-        transmit_ready_scheduled++;
-      }
-    global_pos = global_pos->next;
-  }
-  else
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Transmit ready scheduled on %d messages\n",
-                transmit_ready_scheduled);
-  }
-
-}
-
 static size_t
 transmit_ready (void *cls, size_t size, void *buf)
 {
-  struct GNUNET_MessageHeader *m;
-#if VERBOSE
-  struct GNUNET_PeerIdentity *peer = cls;
-#endif
+  struct GNUNET_TestMessage *m;
+  struct TestMessageContext *pos = cls;
+
   GNUNET_assert (buf != NULL);
-  m = (struct GNUNET_MessageHeader *) buf;
-  m->type = htons (MTYPE);
-  m->size = htons (sizeof (struct GNUNET_MessageHeader));
-
+  m = (struct GNUNET_TestMessage *) buf;
+  m->header.type = htons (MTYPE);
+  m->header.size = htons (sizeof (struct GNUNET_TestMessage));
+  m->uid = htonl(pos->uid);
   transmit_ready_called++;
 #if VERBOSE
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "transmit ready for peer %s\ntransmit_ready's scheduled %d, 
transmit_ready's called %d\n", GNUNET_i2s(peer), transmit_ready_scheduled, 
transmit_ready_called);
+              "transmit ready for peer %s\ntransmit_ready's scheduled %d, 
transmit_ready's called %d\n", GNUNET_i2s(&pos->peer1->id), 
transmit_ready_scheduled, transmit_ready_called);
 #endif
-  GNUNET_SCHEDULER_add_delayed(sched, 
GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 50), 
&schedule_transmission, NULL);
-  return sizeof (struct GNUNET_MessageHeader);
+  return sizeof (struct GNUNET_TestMessage);
 }
 
 
+static struct GNUNET_CORE_MessageHandler no_handlers[] = {
+  {NULL, 0, 0}
+};
+
 static struct GNUNET_CORE_MessageHandler handlers[] = {
-  {&process_mtype, MTYPE, sizeof (struct GNUNET_MessageHeader)},
+  {&process_mtype, MTYPE, sizeof (struct GNUNET_TestMessage)},
   {NULL, 0, 0}
 };
 
-
-
 static void
-send_test_messages ()
+init_notify_peer2 (void *cls,
+             struct GNUNET_CORE_Handle *server,
+             const struct GNUNET_PeerIdentity *my_identity,
+             const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
 {
-  struct TestMessageContext *pos;
-  struct Connection *conn_pos;
-  die_task = GNUNET_SCHEDULER_add_delayed (sched,
-                                           TEST_TIMEOUT,
-                                           &end_badly, "from send test 
messages");
+  struct TestMessageContext *pos = cls;
 
-  int count = 0;
-  int conn_count = 0;
-  pos = test_messages;
-  while (pos != NULL)
+#if VERBOSE
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Core connection to `%4s' established, scheduling message 
send\n",
+              GNUNET_i2s (my_identity));
+#endif
+  total_server_connections++;
+
+  if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
+                                                 0,
+                                                 TIMEOUT,
+                                                 &pos->peer2->id,
+                                                 sizeof (struct 
GNUNET_TestMessage),
+                                                 &transmit_ready, pos))
     {
-      conn_pos = global_connections;
-      conn_count = 0;
-      while (conn_pos != NULL)
-        {
-          if (conn_pos->peer == pos->peer1)
-            {
-              pos->peer1handle = conn_pos->server;
-              break;
-            }
-          conn_count++;
-          conn_pos = conn_pos->next;
-        }
-      GNUNET_assert(pos->peer1handle != NULL);
-
-      /*
-      if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
-                                                   0,
-                                                   TIMEOUT,
-                                                   &pos->peer2->id,
-                                                   sizeof (struct 
GNUNET_MessageHeader),
-                                                   &transmit_ready, 
&pos->peer1->id))
-        {
-          GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                      "RECEIVED NULL when asking core (1) for transmission to 
peer `%4s'\n",
-                      GNUNET_i2s (&pos->peer2->id));
-        }
-      else
-        {
-          transmit_ready_scheduled++;
-        }
-      */
-      pos = pos->next;
-      count++;
-
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "RECEIVED NULL when asking core (1) for transmission to peer 
`%4s'\n",
+                  GNUNET_i2s (&pos->peer2->id));
+      transmit_ready_failed++;
     }
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Prepared %d messages\n",
-              count);
-  global_pos = test_messages;
-
-  GNUNET_SCHEDULER_add_now(sched, &schedule_transmission, NULL);
+  else
+    {
+      transmit_ready_scheduled++;
+    }
 }
 
 
-
 static void
-init_notify (void *cls,
+init_notify_peer1 (void *cls,
              struct GNUNET_CORE_Handle *server,
              const struct GNUNET_PeerIdentity *my_identity,
              const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
 {
-  struct Connection *connection = cls;
+  struct TestMessageContext *pos = cls;
+  total_server_connections++;
 
 #if VERBOSE
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Core connection to `%4s' established, setting up handles\n",
               GNUNET_i2s (my_identity));
 #endif
-  connection->server = server;
-  total_server_connections++;
 
-  if (total_server_connections == num_peers)
-    {
-      GNUNET_SCHEDULER_cancel(sched, die_task);
-      GNUNET_SCHEDULER_add_now(sched, &send_test_messages, NULL);
-    }
+  /*
+   * Connect to the receiving peer
+   */
+  pos->peer2handle = GNUNET_CORE_connect (sched,
+                       pos->peer2->cfg,
+                       TIMEOUT,
+                       pos,
+                       &init_notify_peer2,
+                       NULL,
+                       NULL,
+                       NULL,
+                       GNUNET_YES, NULL, GNUNET_YES, handlers);
+
 }
 
 
 static void
-setup_handlers ()
+send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
 {
-  int i;
-  struct Connection *new_connection;
+  struct TestMessageContext *pos = cls;
 
-  struct GNUNET_TESTING_Daemon *temp_daemon;
-  die_task = GNUNET_SCHEDULER_add_delayed (sched,
-                                           TEST_TIMEOUT,
-                                           &end_badly, "from setup_handlers");
+  if ((tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) || (cls == NULL))
+    return;
 
+  if (die_task == GNUNET_SCHEDULER_NO_TASK)
+    {
+      die_task = GNUNET_SCHEDULER_add_delayed (sched,
+                                               TEST_TIMEOUT,
+                                               &end_badly, "from create 
topology (timeout)");
+    }
 
-  /**
-   * Set up a single handler for each peer
+  if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS)
+    {
+      GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply 
(GNUNET_TIME_UNIT_SECONDS, 1),
+                                    &send_test_messages, pos);
+      return; /* Otherwise we'll double schedule messages here! */
+    }
+
+  /*
+   * Connect to the sending peer
    */
-  for (i = 0; i < num_peers; i++)
+  pos->peer1handle = GNUNET_CORE_connect (sched,
+                                          pos->peer1->cfg,
+                                          TIMEOUT,
+                                          pos,
+                                          &init_notify_peer1,
+                                          NULL,
+                                          NULL,
+                                          NULL,
+                                          GNUNET_NO, NULL, GNUNET_NO, 
no_handlers);
+
+  GNUNET_assert(pos->peer1handle != NULL);
+
+  if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS)
     {
-      new_connection = GNUNET_malloc(sizeof(struct Connection));
-      temp_daemon = GNUNET_TESTING_daemon_get(pg, i);
-      new_connection->peer = temp_daemon;
-      new_connection->server = NULL;
-      new_connection->next = global_connections;
-      global_connections = new_connection;
-
-      GNUNET_CORE_connect (sched,
-                           temp_daemon->cfg,
-                           TIMEOUT,
-                           new_connection,
-                           &init_notify,                         
-                           NULL,
-                           NULL,
-                           NULL,
-                           GNUNET_YES, NULL, GNUNET_YES, handlers);
+      GNUNET_SCHEDULER_add_now (sched,
+                                &send_test_messages, pos->next);
     }
+  else
+    {
+      GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply 
(GNUNET_TIME_UNIT_SECONDS, 1),
+                                    &send_test_messages, pos->next);
+    }
 }
 
 
-
 void
 topology_callback (void *cls,
                    const struct GNUNET_PeerIdentity *first,
@@ -425,12 +439,10 @@
                second_daemon->shortname);
 #endif
       temp_context = GNUNET_malloc(sizeof(struct TestMessageContext));
-      temp_context->first_step_done = 0;
-      temp_context->peer1handle = NULL;
       temp_context->peer1 = first_daemon;
       temp_context->peer2 = second_daemon;
-      temp_context->peer2handle = NULL;
       temp_context->next = test_messages;
+      temp_context->uid = total_connections;
       test_messages = temp_context;
 
       expected_messages++;
@@ -456,16 +468,16 @@
 #endif
 
       GNUNET_SCHEDULER_cancel (sched, die_task);
-      /* die_task = GNUNET_SCHEDULER_add_now (sched, &setup_handlers, NULL); */
-      die_task = GNUNET_SCHEDULER_add_delayed (sched, 
GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &setup_handlers, 
NULL);
+      die_task = GNUNET_SCHEDULER_NO_TASK;
+      GNUNET_SCHEDULER_add_delayed (sched, 
GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), 
&send_test_messages, test_messages);
     }
   else if (total_connections + failed_connections == expected_connections)
     {
       if (failed_connections < (unsigned int)(fail_percentage * 
total_connections))
         {
           GNUNET_SCHEDULER_cancel (sched, die_task);
-          /* die_task = GNUNET_SCHEDULER_add_now (sched, &setup_handlers, 
NULL); */
-          die_task = GNUNET_SCHEDULER_add_delayed (sched, 
GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &setup_handlers, 
NULL);
+          die_task = GNUNET_SCHEDULER_NO_TASK;
+          GNUNET_SCHEDULER_add_delayed (sched, 
GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), 
&send_test_messages, test_messages);
         }
       else
         {
@@ -541,7 +553,7 @@
       die_task = GNUNET_SCHEDULER_add_delayed (sched,
                                                GNUNET_TIME_relative_multiply
                                                (GNUNET_TIME_UNIT_MINUTES, 5),
-                                               &end_badly, NULL);
+                                               &end_badly, "from my_cb");
       create_topology ();
       ok = 0;
     }
@@ -580,7 +592,7 @@
   die_task = GNUNET_SCHEDULER_add_delayed (sched,
                                            GNUNET_TIME_relative_multiply
                                            (GNUNET_TIME_UNIT_MINUTES, 5),
-                                           &end_badly, NULL);
+                                           &end_badly, "didn't start all 
daemons in reasonable amount of time!!!");
 
   pg = GNUNET_TESTING_daemons_start (sched, cfg,
                                      peers_left, &my_cb, NULL,

Modified: gnunet/src/testing/testing.c
===================================================================
--- gnunet/src/testing/testing.c        2010-04-27 15:06:15 UTC (rev 11080)
+++ gnunet/src/testing/testing.c        2010-04-27 15:32:55 UTC (rev 11081)
@@ -38,6 +38,7 @@
 #include "gnunet_hello_lib.h"
 
 #define DEBUG_TESTING GNUNET_NO
+#define DEBUG_TESTING_RECONNECT GNUNET_YES
 
 /**
  * How long do we wait after starting gnunet-service-arm
@@ -64,14 +65,26 @@
 process_hello (void *cls, const struct GNUNET_MessageHeader *message)
 {
   struct GNUNET_TESTING_Daemon *daemon = cls;
-  GNUNET_TRANSPORT_get_hello_cancel(daemon->th, &process_hello, daemon);
+  if (daemon == NULL)
+    return;
+
+  if (daemon->server != NULL)
+    {
+      GNUNET_CORE_disconnect(daemon->server);
+      daemon->server = NULL;
+    }
+
+  GNUNET_assert (message != NULL);
+  if (daemon->th != NULL)
+    {
+      GNUNET_TRANSPORT_get_hello_cancel(daemon->th, &process_hello, daemon);
+    }
 #if DEBUG_TESTING
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Received `%s' from transport service of `%4s'\n",
               "HELLO", GNUNET_i2s (&daemon->id));
 #endif
 
-  GNUNET_assert (message != NULL);
   GNUNET_free_non_null(daemon->hello);
   daemon->hello = GNUNET_malloc(ntohs(message->size));
   memcpy(daemon->hello, message, ntohs(message->size));
@@ -126,6 +139,7 @@
   d->id = *my_identity;
   d->shortname = strdup (GNUNET_i2s (my_identity));
   d->server = server;
+  d->running = GNUNET_YES;
   if (GNUNET_YES == d->dead)
     GNUNET_TESTING_daemon_stop (d, d->dead_cb, d->dead_cb_cls);
   else if (NULL != cb)
@@ -344,6 +358,7 @@
                 }
               GNUNET_CONFIGURATION_destroy (d->cfg);
               GNUNET_free (d->cfgfile);
+              GNUNET_free_non_null(d->hello);
               GNUNET_free_non_null (d->hostname);
               GNUNET_free_non_null (d->username);
               GNUNET_free_non_null (d->shortname);
@@ -370,6 +385,7 @@
             }
           GNUNET_CONFIGURATION_destroy (d->cfg);
           GNUNET_free (d->cfgfile);
+          GNUNET_free_non_null(d->hello);
           GNUNET_free_non_null (d->hostname);
           GNUNET_free_non_null (d->username);
           GNUNET_free_non_null (d->shortname);
@@ -388,6 +404,7 @@
       /* state clean up and notifications */
       GNUNET_CONFIGURATION_destroy (d->cfg);
       GNUNET_free (d->cfgfile);
+      GNUNET_free_non_null(d->hello);
       GNUNET_free_non_null (d->hostname);
       GNUNET_free_non_null (d->username);
       GNUNET_free_non_null (d->shortname);
@@ -633,14 +650,11 @@
                                             "-c", d->cfgfile, "-e", "-d", 
"-q", NULL);
   }
 
-  GNUNET_free_non_null(d->hello);
-
   d->wait_runs = 0;
   d->task
     = GNUNET_SCHEDULER_add_delayed (d->sched,
                                     GNUNET_CONSTANTS_EXEC_WAIT,
                                     &start_fsm, d);
-  return;
 }
 
 
@@ -820,6 +834,12 @@
       ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK;
     }
 
+  if ((ctx->timeout_task != GNUNET_SCHEDULER_NO_TASK) && (tc->reason != 
GNUNET_SCHEDULER_REASON_TIMEOUT))
+    {
+      GNUNET_SCHEDULER_cancel(ctx->d1->sched, ctx->timeout_task);
+      ctx->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+    }
+
   if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
     {
       if (ctx->d2th != NULL)
@@ -842,10 +862,20 @@
           ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, ctx->d1->cfg,
                    ctx->d2->cfg, ctx->d1, ctx->d2, NULL);
         }
-      GNUNET_SCHEDULER_cancel(ctx->d1->sched, ctx->timeout_task);
     }
   else if (remaining.value > 0)
     {
+      if (ctx->d1core != NULL)
+        {
+          GNUNET_CORE_disconnect(ctx->d1core);
+          ctx->d1core = NULL;
+        }
+
+      if (ctx->d2th != NULL)
+        {
+          GNUNET_TRANSPORT_disconnect(ctx->d2th);
+          ctx->d2th = NULL;
+        }
       GNUNET_SCHEDULER_add_now(ctx->d1->sched, &reattempt_daemons_connect, 
ctx);
       return;
     }
@@ -859,7 +889,6 @@
         }
     }
 
-
   GNUNET_TRANSPORT_disconnect (ctx->d2th);
   ctx->d2th = NULL;
   GNUNET_CORE_disconnect (ctx->d1core);
@@ -886,6 +915,8 @@
   if (memcmp(&ctx->d2->id, peer, sizeof(struct GNUNET_PeerIdentity)) == 0)
     {
       ctx->connected = GNUNET_YES;
+      GNUNET_SCHEDULER_cancel(ctx->d1->sched, ctx->timeout_task);
+      ctx->timeout_task = GNUNET_SCHEDULER_NO_TASK;
       GNUNET_SCHEDULER_add_now (ctx->d1->sched,
                                 &notify_connect_result,
                                 ctx);
@@ -935,7 +966,7 @@
 {
   struct ConnectContext *ctx;
 
-  if ((d1->server == NULL) || (d2->server == NULL))
+  if ((d1->running == GNUNET_NO) || (d2->running == GNUNET_NO))
     {
       if (NULL != cb)
         cb (cb_cls, &d1->id, &d2->id, d1->cfg, d2->cfg, d1, d2,
@@ -988,6 +1019,7 @@
                                         d2->cfg, d2, NULL, NULL, NULL);
   if (ctx->d2th == NULL)
     {
+      GNUNET_CORE_disconnect(ctx->d1core);
       GNUNET_free (ctx);
       if (NULL != cb)
         cb (cb_cls, &d1->id, &d2->id, d1->cfg, d2->cfg, d1, d2,
@@ -1011,23 +1043,13 @@
     {
       return;
     }
-#if DEBUG_TESTING
+#if DEBUG_TESTING_RECONNECT
   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "re-attempting connect of peer %s to 
peer %s\n",
               ctx->d1->shortname, ctx->d2->shortname);
 #endif
 
-  if (ctx->d1core != NULL)
-    {
-      GNUNET_CORE_disconnect(ctx->d1core);
-      ctx->d1core = NULL;
-    }
+  GNUNET_assert(ctx->d1core == NULL);
 
-  if (ctx->d2th != NULL)
-    {
-      GNUNET_TRANSPORT_disconnect(ctx->d2th);
-      ctx->d2th = NULL;
-    }
-
   ctx->d1core = GNUNET_CORE_connect (ctx->d1->sched,
                                      ctx->d1->cfg,
                                      
GNUNET_TIME_absolute_get_remaining(ctx->timeout),
@@ -1049,6 +1071,7 @@
                                         ctx->d2->cfg, ctx->d2, NULL, NULL, 
NULL);
   if (ctx->d2th == NULL)
     {
+      GNUNET_CORE_disconnect(ctx->d1core);
       GNUNET_free (ctx);
       if (NULL != ctx->cb)
         ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, ctx->d1->cfg, 
ctx->d2->cfg, ctx->d1, ctx->d2,

Modified: gnunet/src/testing/testing_group.c
===================================================================
--- gnunet/src/testing/testing_group.c  2010-04-27 15:06:15 UTC (rev 11080)
+++ gnunet/src/testing/testing_group.c  2010-04-27 15:32:55 UTC (rev 11081)
@@ -84,7 +84,6 @@
 
   /*
    * Linked list of peer connections (simply indexes of PeerGroup)
-   * FIXME: Question, store pointer or integer?  Pointer for now...
    */
   struct PeerConnection *connected_peers;
 };
@@ -255,7 +254,7 @@
 
   if (GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "control_host", 
&control_host) == GNUNET_OK)
     {
-      GNUNET_asprintf(&allowed_hosts, "%s 127.0.0.1;", control_host);
+      GNUNET_asprintf(&allowed_hosts, "%s; 127.0.0.1;", control_host);
       GNUNET_CONFIGURATION_set_value_string(uc.ret, "core", "ACCEPT_FROM", 
allowed_hosts);
       GNUNET_free_non_null(control_host);
       GNUNET_free(allowed_hosts);
@@ -957,6 +956,10 @@
         }
     }
 
+#if VERBOSE_TESTING
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                _("Finished copying all friend files!\n"));
+#endif
   GNUNET_free(pidarr);
   return ret;
 }





reply via email to

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