reduce config variables
[oweals/gnunet.git] / src / testing / testing.c
index 93da8c951936d823a8a11f05032d9a519d6b3c9a..0204f311b47f24b563599a17a2e880ba761f1eaa 100644 (file)
@@ -1266,6 +1266,11 @@ struct ConnectContext
    */
   struct GNUNET_CORE_Handle *d1core;
 
+  /**
+   * Have we actually connected to the core of the first daemon yet?
+   */
+  int d1core_ready;
+
   /**
    * Testing handle to the second daemon.
    */
@@ -1407,6 +1412,7 @@ notify_connect_result (void *cls,
           GNUNET_CORE_disconnect (ctx->d1core);
           ctx->d1core = NULL;
         }
+      ctx->d1core_ready = GNUNET_NO;
 #if CONNECT_CORE2
       if (ctx->d2core != NULL)
         {
@@ -1519,7 +1525,7 @@ send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   ctx->hello_send_task = GNUNET_SCHEDULER_NO_TASK;
   if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
     return;
-  if ((ctx->d2->hello != NULL)
+  if ((ctx->d1core_ready == GNUNET_YES) && (ctx->d2->hello != NULL)
       && (NULL != GNUNET_HELLO_get_header (ctx->d2->hello)))
     {
       hello = GNUNET_HELLO_get_header (ctx->d2->hello);
@@ -1548,6 +1554,20 @@ send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
                                                        &send_hello, ctx);
 }
 
+void
+core_init_notify (void *cls,
+                  struct GNUNET_CORE_Handle * server,
+                  const struct GNUNET_PeerIdentity *
+                  my_identity,
+                  const struct
+                  GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *
+                  publicKey)
+{
+  struct ConnectContext *connect_ctx = cls;
+
+  connect_ctx->d1core_ready = GNUNET_YES;
+}
+
 /**
  * Establish a connection between two GNUnet daemons.
  *
@@ -1594,9 +1614,10 @@ GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
               d1->shortname, d2->shortname);
 #endif
 
+  /* FIXME: possible bug, core gets connected after peers are connected, thus the connect_notify function is never called (?) */
   ctx->d1core = GNUNET_CORE_connect (d1->cfg, 1,
                                      ctx,
-                                     NULL,
+                                     &core_init_notify,
                                      &connect_notify, NULL, NULL,
                                      NULL, GNUNET_NO,
                                      NULL, GNUNET_NO, no_handlers);
@@ -1676,14 +1697,10 @@ reattempt_daemons_connect (void *cls,
 #endif
 
   GNUNET_assert (ctx->d1core == NULL);
-
+  ctx->d1core_ready = GNUNET_NO;
   ctx->d1core = GNUNET_CORE_connect (ctx->d1->cfg, 1,
-#if NO_MORE_TIMEOUT_FIXME
-                                     GNUNET_TIME_absolute_get_remaining
-                                     (ctx->timeout),
-#endif
                                      ctx,
-                                     NULL,
+                                     &core_init_notify,
                                      &connect_notify, NULL, NULL,
                                      NULL, GNUNET_NO,
                                      NULL, GNUNET_NO, no_handlers);