fixes
[oweals/gnunet.git] / src / dv / test_transport_api_dv.c
index 47b35a3589b82a5de75571ecdb4b86f6d89e3767..39dd08877db643700a50cc0bc104b3ef68985ad2 100644 (file)
@@ -25,7 +25,7 @@
 #include "gnunet_testing_lib.h"
 #include "gnunet_core_service.h"
 
-#define VERBOSE GNUNET_YES
+#define VERBOSE GNUNET_NO
 
 #define TEST_ALL GNUNET_NO
 
@@ -502,66 +502,112 @@ static struct GNUNET_CORE_MessageHandler handlers[] = {
   {NULL, 0, 0}
 };
 
-static void
-init_notify_peer2 (void *cls,
-             struct GNUNET_CORE_Handle *server,
-             const struct GNUNET_PeerIdentity *my_identity,
-             const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
+/**
+ * Notify of all peer1's peers, once peer 2 is found, schedule connect
+ * to peer two for message send.
+ *
+ * @param cls closure
+ * @param peer peer identity this notification is about
+ * @param atsi performance data for the connection
+ */
+static void connect_notify_peer2 (void *cls,
+                                  const struct
+                                  GNUNET_PeerIdentity *peer,
+                                  const struct GNUNET_TRANSPORT_ATS_Information *atsi)
 {
   struct TestMessageContext *pos = cls;
 
+  if (0 == memcmp(&pos->peer1->id, peer, sizeof(struct GNUNET_PeerIdentity)))
+    {
+#if VERBOSE
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "Core connection from `%s' to `%4s' verfied, sending message!\n",
+                  GNUNET_i2s(&pos->peer2->id), GNUNET_h2s (&peer->hashPubKey));
+#endif
+      if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
+                                                     GNUNET_YES,
+                                                     0,
+                                                     TIMEOUT,
+                                                     &pos->peer2->id,
+                                                     sizeof (struct GNUNET_TestMessage),
+                                                     &transmit_ready, pos))
+        {
+          /* This probably shouldn't happen, but it does (timing issue?) */
+          GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                      "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
+                      GNUNET_i2s (&pos->peer2->id));
+          transmit_ready_failed++;
+          total_other_expected_messages--;
+        }
+      else
+        {
+          transmit_ready_scheduled++;
+        }
+    }
+}
+
+static void
+init_notify_peer2 (void *cls,
+                   struct GNUNET_CORE_Handle *server,
+                   const struct GNUNET_PeerIdentity *my_identity,
+                   const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
+{
 #if VERBOSE
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Core connection to `%4s' established, scheduling message send\n",
+              "Core connection to `%4s' established, awaiting connections.\n",
               GNUNET_i2s (my_identity));
 #endif
   total_server_connections++;
+}
+
+/**
+ * Notify of all peer1's peers, once peer 2 is found, schedule connect
+ * to peer two for message send.
+ *
+ * @param cls closure
+ * @param peer peer identity this notification is about
+ * @param atsi performance data for the connection
+ */
+static void connect_notify_peer1 (void *cls,
+                                  const struct
+                                  GNUNET_PeerIdentity *peer,
+                                  const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+{
+  struct TestMessageContext *pos = cls;
 
-  if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
-                                                 0,
-                                                 TIMEOUT,
-                                                 &pos->peer2->id,
-                                                 sizeof (struct GNUNET_TestMessage),
-                                                 &transmit_ready, pos))
+  if (0 == memcmp(&pos->peer2->id, peer, sizeof(struct GNUNET_PeerIdentity)))
     {
+#if VERBOSE
       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++;
-    }
-  else
-    {
-      transmit_ready_scheduled++;
+                  "Core connection from `%s' to `%4s' verified.\n",
+                  GNUNET_i2s(&pos->peer1->id), GNUNET_h2s (&peer->hashPubKey));
+#endif
+      /*
+       * Connect to the receiving peer
+       */
+      pos->peer2handle = GNUNET_CORE_connect (pos->peer2->cfg,
+                                              1,
+                                              pos,
+                                              &init_notify_peer2,
+                                              &connect_notify_peer2,
+                                              NULL,
+                                              NULL, NULL,
+                                              GNUNET_YES, NULL, GNUNET_YES, handlers);
     }
 }
 
-
 static void
 init_notify_peer1 (void *cls,
-             struct GNUNET_CORE_Handle *server,
-             const struct GNUNET_PeerIdentity *my_identity,
-             const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
+                   struct GNUNET_CORE_Handle *server,
+                   const struct GNUNET_PeerIdentity *my_identity,
+                   const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
 {
-  struct TestMessageContext *pos = cls;
   total_server_connections++;
-
 #if VERBOSE
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Core connection to `%4s' established, setting up handles\n",
+              "Core connection to `%4s' established, awaiting connections...\n",
               GNUNET_i2s (my_identity));
 #endif
-
-  /*
-   * Connect to the receiving peer
-   */
-  pos->peer2handle = GNUNET_CORE_connect (pos->peer2->cfg,
-                                         1, 
-                                         pos,
-                                         &init_notify_peer2,
-                                         NULL,
-                                         NULL,
-                                         NULL, NULL,
-                                         GNUNET_YES, NULL, GNUNET_YES, handlers);
 }
 
 
@@ -570,7 +616,7 @@ send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
 {
   struct TestMessageContext *pos = cls;
 
-  if ((tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) || (cls == NULL))
+  if (( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) || (cls == NULL))
     return;
 
   if (die_task == GNUNET_SCHEDULER_NO_TASK)
@@ -595,7 +641,8 @@ send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
                                          1,
                                           pos,
                                           &init_notify_peer1,
-                                          NULL, NULL,
+                                          &connect_notify_peer1,
+                                          NULL,
                                           NULL,
                                           NULL,
                                           GNUNET_NO, NULL, GNUNET_NO, no_handlers);
@@ -718,9 +765,7 @@ topology_callback (void *cls,
       temp_context->uid = total_connections;
       temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
       test_messages = temp_context;
-
       expected_messages++;
-
     }
 #if VERBOSE
   else
@@ -774,7 +819,13 @@ connect_topology ()
   expected_connections = -1;
   if ((pg != NULL) && (peers_left == 0))
     {
-      expected_connections = GNUNET_TESTING_connect_topology (pg, connection_topology, connect_topology_option, connect_topology_option_modifier, NULL, NULL);
+      expected_connections = GNUNET_TESTING_connect_topology (pg,
+                                                              connection_topology,
+                                                              connect_topology_option,
+                                                              connect_topology_option_modifier,
+                                                              TIMEOUT,
+                                                              12,
+                                                              NULL, NULL);
 #if VERBOSE
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   "Have %d expected connections\n", expected_connections);
@@ -833,6 +884,10 @@ static void all_connect_handler (void *cls,
   struct TestMessageContext *temp_context;
 #endif
   uint32_t distance;
+
+  if (0 == memcmp(&d->id, peer, sizeof(struct GNUNET_PeerIdentity)))
+    return;
+
   distance = get_atsi_distance(atsi);
 
 #if VERBOSE
@@ -864,7 +919,6 @@ static void all_connect_handler (void *cls,
     }
 #endif
 
-
   if (dotOutFile != NULL)
     {
       if (distance == 1)
@@ -1085,8 +1139,17 @@ run (void *cls,
 
   peer_daemon_hash = GNUNET_CONTAINER_multihashmap_create(peers_left);
   pg = GNUNET_TESTING_daemons_start (cfg,
-                                     peers_left, TIMEOUT, &hostkey_callback, NULL, &peers_started_callback, NULL,
-                                     &topology_callback, NULL, NULL);
+                                     peers_left, /* Total number of peers */
+                                     peers_left, /* Number of outstanding connections */
+                                     peers_left, /* Number of parallel ssh connections, or peers being started at once */
+                                     TIMEOUT,
+                                     &hostkey_callback,
+                                     NULL,
+                                     &peers_started_callback,
+                                     NULL,
+                                     &topology_callback,
+                                     NULL,
+                                     NULL);
 
 }