reduce config variables
[oweals/gnunet.git] / src / testing / testing.c
index 84493410af0010c6d786a338b0df14818b70a375..0204f311b47f24b563599a17a2e880ba761f1eaa 100644 (file)
@@ -37,8 +37,8 @@
 #include "gnunet_transport_service.h"
 #include "gnunet_hello_lib.h"
 
-#define DEBUG_TESTING GNUNET_YES
-#define DEBUG_TESTING_RECONNECT GNUNET_YES
+#define DEBUG_TESTING GNUNET_NO
+#define DEBUG_TESTING_RECONNECT GNUNET_NO
 
 /**
  * How long do we wait after starting gnunet-service-arm
@@ -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);
@@ -1533,10 +1539,12 @@ send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
                                            ctx->max_connect_attempts + 1),
                                           &ctx->d2->id,
                                           &core_connect_request_cont, ctx);
-      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+#if DEBUG_TESTING
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   "Sending connect request to CORE of %s for peer %s\n",
                   GNUNET_i2s (&ctx->d1->id),
                   GNUNET_h2s (&ctx->d2->id.hashPubKey));
+#endif
       ctx->timeout_hello =
         GNUNET_TIME_relative_add (ctx->timeout_hello,
                                   GNUNET_TIME_relative_multiply
@@ -1546,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.
  *
@@ -1592,12 +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,
-#if NO_MORE_TIMEOUT_FIXME
-                                     timeout,
-#endif
                                      ctx,
-                                     NULL,
+                                     &core_init_notify,
                                      &connect_notify, NULL, NULL,
                                      NULL, GNUNET_NO,
                                      NULL, GNUNET_NO, no_handlers);
@@ -1655,7 +1675,7 @@ GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
     GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide
                                   (ctx->relative_timeout,
                                    ctx->max_connect_attempts),
-                                  &notify_connect_result, ctx);
+                                   &notify_connect_result, ctx);
 
   ctx->hello_send_task = GNUNET_SCHEDULER_add_now (&send_hello, ctx);
 }
@@ -1677,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);