allow dv to be built and installed
[oweals/gnunet.git] / src / dv / test_transport_api_dv.c
index d4c7eef2caa41bcf0dd540f0e7495cd843ff4bc7..c37448342cb563b8b14db99df41f57d8e3ba7e0b 100644 (file)
@@ -385,18 +385,44 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
 static void
 send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc);
 
+/**
+ * Get distance information from 'atsi'.
+ *
+ * @param atsi performance data
+ * @return connected transport distance
+ */
+static uint32_t
+get_atsi_distance (const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+{
+  while ( (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) &&
+          (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE) )
+    atsi++;
+  if (ntohl (atsi->type) == GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR)
+    {
+      GNUNET_break (0);
+      /* FIXME: we do not have distance data? Assume direct neighbor. */
+      return 1;
+    }
+  return ntohl (atsi->value);
+}
+
 static int
 process_mtype (void *cls,
                const struct GNUNET_PeerIdentity *peer,
                const struct GNUNET_MessageHeader *message,
-               struct GNUNET_TIME_Relative latency,
-               uint32_t distance)
+               const struct GNUNET_TRANSPORT_ATS_Information *atsi)
 {
   struct TestMessageContext *pos = cls;
   struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *)message;
+#if VERBOSE
+  uint32_t distance;
+#endif
   if (pos->uid != ntohl(msg->uid))
     return GNUNET_OK;
 
+#if VERBOSE
+  distance = get_atsi_distance(atsi);
+#endif
   GNUNET_assert(0 == memcmp(peer, &pos->peer1->id, sizeof(struct GNUNET_PeerIdentity)));
   if (total_other_expected_messages == 0)
     {
@@ -476,68 +502,111 @@ static struct GNUNET_CORE_MessageHandler handlers[] = {
   {NULL, 0, 0}
 };
 
+/**
+ * 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,
+                                                     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)
 {
-  struct TestMessageContext *pos = cls;
-
 #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++;
+}
 
-  if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
-                                                 0,
-                                                 TIMEOUT,
-                                                 &pos->peer2->id,
-                                                 sizeof (struct GNUNET_TestMessage),
-                                                 &transmit_ready, pos))
+/**
+ * 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 (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 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, 
-                                         TIMEOUT,
-                                         pos,
-                                         &init_notify_peer2,
-                                         NULL,
-                                         NULL,
-                                         NULL, NULL,
-                                         GNUNET_YES, NULL, GNUNET_YES, handlers);
-
 }
 
 
@@ -569,10 +638,10 @@ send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
    */
   pos->peer1handle = GNUNET_CORE_connect (pos->peer1->cfg,
                                          1,
-                                          TIMEOUT,
                                           pos,
                                           &init_notify_peer1,
-                                          NULL, NULL,
+                                          &connect_notify_peer1,
+                                          NULL,
                                           NULL,
                                           NULL,
                                           GNUNET_NO, NULL, GNUNET_NO, no_handlers);
@@ -695,9 +764,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
@@ -801,8 +868,7 @@ create_topology ()
 static void all_connect_handler (void *cls,
                                  const struct
                                  GNUNET_PeerIdentity * peer,
-                                 struct GNUNET_TIME_Relative latency,
-                                 uint32_t distance)
+                                 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
 {
   struct GNUNET_TESTING_Daemon *d = cls;
   struct GNUNET_TESTING_Daemon *second_daemon;
@@ -810,6 +876,9 @@ static void all_connect_handler (void *cls,
 #if !TEST_ALL
   struct TestMessageContext *temp_context;
 #endif
+  uint32_t distance;
+  distance = get_atsi_distance(atsi);
+
 #if VERBOSE
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s, distance %u\n",
            d->shortname,
@@ -839,7 +908,6 @@ static void all_connect_handler (void *cls,
     }
 #endif
 
-
   if (dotOutFile != NULL)
     {
       if (distance == 1)
@@ -884,7 +952,6 @@ peers_started_callback (void *cls,
   new_peer = GNUNET_malloc(sizeof(struct PeerContext));
   new_peer->peer_handle = GNUNET_CORE_connect(cfg, 
                                              1,
-                                             GNUNET_TIME_UNIT_FOREVER_REL,
                                              d, NULL,
                                              &all_connect_handler, 
                                              NULL, NULL, NULL,