initial dv changes for atsi information handling, test case BROKEN
authorNathan S. Evans <evans@in.tum.de>
Tue, 7 Dec 2010 15:09:29 +0000 (15:09 +0000)
committerNathan S. Evans <evans@in.tum.de>
Tue, 7 Dec 2010 15:09:29 +0000 (15:09 +0000)
src/dv/gnunet-service-dv.c
src/dv/test_transport_api_dv.c
src/dv/test_transport_dv_data.conf

index d3897f23dc863004b1d59e463d6db3c566c4a6d8..78e63facc7b6558f947abc8ef3e3bba28ed7071e 100644 (file)
@@ -27,9 +27,6 @@
  * @author Christian Grothoff
  * @author Nathan Evans
  *
- * TODO: The gossip rates need to be worked out.  Probably many other things
- * as well.
- *
  */
 #include "platform.h"
 #include "gnunet_client_lib.h"
@@ -1298,6 +1295,48 @@ void send_message_delayed (void *cls,
 }
 #endif
 
+/**
+ * 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 DIRECT_NEIGHBOR_COST;
+    }
+  return ntohl (atsi->value);
+}
+
+/**
+ * Find latency information in 'atsi'.
+ *
+ * @param atsi performance data
+ * @return connection latency
+ */
+static struct GNUNET_TIME_Relative
+get_atsi_latency (const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+{
+  while ( (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) &&
+          (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY) )
+    atsi++;
+  if (ntohl (atsi->type) == GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR)
+    {
+      GNUNET_break (0);
+      /* how can we not have latency data? */
+      return GNUNET_TIME_UNIT_SECONDS;
+    }
+  /* FIXME: Multiply by GNUNET_TIME_UNIT_MILLISECONDS (1) to get as a GNUNET_TIME_Relative */
+  return GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, ntohl (atsi->value));
+}
 
 /**
  * Core handler for dv data messages.  Whatever this message
@@ -1341,6 +1380,8 @@ handle_dv_data_message (void *cls,
   int ret;
   size_t packed_message_size;
   char *cbuf;
+  uint32_t distance; /* Distance information */
+  struct GNUNET_TIME_Relative latency; /* Latency information */
 
   packed_message_size = ntohs(incoming->header.size) - sizeof(p2p_dv_MESSAGE_Data);
 #if DEBUG_DV
@@ -1350,7 +1391,6 @@ handle_dv_data_message (void *cls,
 
   if (ntohs (incoming->header.size) <  sizeof (p2p_dv_MESSAGE_Data) + sizeof (struct GNUNET_MessageHeader))
     {
-
 #if DEBUG_DV
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "`%s': Message sizes don't add up, total size %u, expected at least %u!\n", "dv service", ntohs(incoming->header.size), sizeof (p2p_dv_MESSAGE_Data) + sizeof (struct GNUNET_MessageHeader));
@@ -1358,6 +1398,9 @@ handle_dv_data_message (void *cls,
       return GNUNET_SYSERR;
     }
 
+  /* Iterate over ATS_Information to get distance and latency */
+  latency = get_atsi_latency(atsi);
+  distance = get_atsi_distance(atsi);
   dn = GNUNET_CONTAINER_multihashmap_get (direct_neighbors,
                                           &peer->hashPubKey);
   if (dn == NULL)
@@ -1481,9 +1524,6 @@ handle_dv_data_message (void *cls,
   if (0 == memcmp (destination, peer, sizeof (struct GNUNET_PeerIdentity)))
     {
       /* FIXME: create stat: routing loop-discard! */
-#if DEBUG_DV_PEER_NUMBERS
-      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "\n\n\nLoopy loo message\n\n\n");
-#endif
 
 #if DEBUG_DV_MESSAGES
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1588,14 +1628,14 @@ neighbor_send_task (void *cls,
   struct PendingMessage *pending_message;
 
   if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
-  {
+    {
 #if DEBUG_DV_GOSSIP
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "%s: Called with reason shutdown, shutting down!\n",
               GNUNET_i2s(&my_identity));
 #endif
-    return;
-  }
+      return;
+    }
 
   if (send_context->fast_gossip_list_head != NULL)
     {
@@ -2465,10 +2505,17 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity * peer,
 #if DEBUG_DV_MESSAGES
                   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: learned about peer %llu from which we have a previous unknown message, processing!\n", my_short_id, referrer_peer_id);
 #endif
-                  handle_dv_data_message(NULL, &referrer->pending_messages[i].sender, 
+                  struct GNUNET_TRANSPORT_ATS_Information atsi[3];
+                  atsi[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
+                  atsi[0].value = htonl (referrer->pending_messages[i].distance);
+                  atsi[1].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY);
+                  atsi[1].value = htonl ((uint32_t)referrer->pending_messages[i].latency.rel_value);
+                  atsi[2].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
+                  atsi[2].value = htonl (0);
+                  handle_dv_data_message(NULL,
+                                         &referrer->pending_messages[i].sender,
                                         referrer->pending_messages[i].message, 
-                                        referrer->pending_messages[i].latency, 
-                                        referrer->pending_messages[i].distance);
+                                        (const struct GNUNET_TRANSPORT_ATS_Information *)&atsi);
                   GNUNET_free(referrer->pending_messages[i].message);
                   referrer->pending_messages[i].sender_id = 0;
                 }
@@ -2849,8 +2896,11 @@ handle_core_connect (void *cls,
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "%s: Receives core connect message for peer %s distance %d!\n", "dv", GNUNET_i2s(peer), distance);
 #endif
+  uint32_t distance;
 
-  if ((distance == DIRECT_NEIGHBOR_COST) && (GNUNET_CONTAINER_multihashmap_get(direct_neighbors, &peer->hashPubKey) == NULL))
+  distance = get_atsi_distance (atsi);
+  if ((distance == DIRECT_NEIGHBOR_COST) &&
+      (GNUNET_CONTAINER_multihashmap_get(direct_neighbors, &peer->hashPubKey) == NULL))
   {
     peerinfo_iterator = GNUNET_malloc(sizeof(struct PeerIteratorContext));
     neighbor = GNUNET_malloc (sizeof (struct DirectNeighbor));
index d4c7eef2caa41bcf0dd540f0e7495cd843ff4bc7..47b35a3589b82a5de75571ecdb4b86f6d89e3767 100644 (file)
@@ -25,7 +25,7 @@
 #include "gnunet_testing_lib.h"
 #include "gnunet_core_service.h"
 
-#define VERBOSE GNUNET_NO
+#define VERBOSE GNUNET_YES
 
 #define TEST_ALL GNUNET_NO
 
@@ -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)
     {
@@ -530,14 +556,12 @@ init_notify_peer1 (void *cls,
    */
   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,7 +593,6 @@ 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,
@@ -801,8 +824,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 +832,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,
@@ -884,7 +909,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, 
index 34930332fe756be96019653ebfe76b175b477b4f..63ca7b3c2498608df3791ee02ef8c58bc0e11508 100644 (file)
@@ -20,6 +20,9 @@ DEFAULTSERVICES =
 PORT = 2567
 
 [transport-tcp]
+ENABLE_NAT_CLIENT = NO
+ENABLE_NAT_SERVER = NO
+ENABLE_UPNP = NO
 PORT = 2568
 
 [transport-udp]