modified validation to use new api call to set networktype
authorMatthias Wachs <wachs@net.in.tum.de>
Wed, 10 Jul 2013 12:01:41 +0000 (12:01 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Wed, 10 Jul 2013 12:01:41 +0000 (12:01 +0000)
src/transport/gnunet-service-transport.c
src/transport/gnunet-service-transport_validation.c

index 99f72e72957e3f7afbefc72bc7031a3e7d1ae8f5..d17b96313c73b449a779f5bce00c46e9da9cc6d2 100644 (file)
@@ -422,10 +422,20 @@ GST_ats_add_address (struct GNUNET_HELLO_Address *address,
   }
 
        net = papi->get_network (NULL, session);
+  if (GNUNET_ATS_NET_UNSPECIFIED == net)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                                               _("Could not obtain a valid network for `%s' %s\n"),
+                GNUNET_i2s (&address->peer), GST_plugins_a2s (address));
+       GNUNET_break (0);
+  }
        ats.type = htonl (GNUNET_ATS_NETWORK_TYPE);
        ats.value = htonl(net);
-       GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Notifying ATS about new address `%s' in network %s\n",
+       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                       "Notifying ATS about peer `%s''s new address `%s' session %p in network %s\n",
+                       GNUNET_i2s (&address->peer),
                        (0 == address->address_length) ? "<inbound>" : GST_plugins_a2s (address),
+                       session,
                        GNUNET_ATS_print_network_type(net));
        GNUNET_ATS_address_add (GST_ats,
                        address, session, &ats, 1);
index d80818369e621f195ce4a9386494d57e6d8719ef..d467c71a7ff72ccb315975525e79ee8ecfaef5b9 100644 (file)
@@ -266,6 +266,8 @@ struct ValidationEntry
   /* FIXME: DEBUGGING */
   int last_line_set_to_no;
   int last_line_set_to_yes;
+
+  enum GNUNET_ATS_Network_Type network;
 };
 
 
@@ -473,6 +475,7 @@ transmit_ping_if_allowed (void *cls, const struct GNUNET_PeerIdentity *pid,
   struct GNUNET_TRANSPORT_PluginFunctions *papi;
   struct GNUNET_TIME_Absolute next;
   const struct GNUNET_MessageHeader *hello;
+  enum GNUNET_ATS_Network_Type network;
   ssize_t ret;
   size_t tsize;
   size_t slen;
@@ -546,6 +549,14 @@ transmit_ping_if_allowed (void *cls, const struct GNUNET_PeerIdentity *pid,
                           message_buf, tsize,
                           PING_PRIORITY, ACCEPTABLE_PING_DELAY,
                           NULL, NULL);
+        network = papi->get_network (ve->address, session);
+        if (GNUNET_ATS_NET_UNSPECIFIED == network)
+        {
+          GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                                                       "Could not obtain a valid network for `%s' %s\n",
+                      GNUNET_i2s (pid), GST_plugins_a2s (ve->address));
+               GNUNET_break (0);
+        }
       }
       else
       {
@@ -563,6 +574,8 @@ transmit_ping_if_allowed (void *cls, const struct GNUNET_PeerIdentity *pid,
                               gettext_noop
                               ("# PING without HELLO messages sent"), 1,
                               GNUNET_NO);
+
+    ve->network = network;
     ve->expecting_pong = GNUNET_YES;
     validations_running ++;
          GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -723,6 +736,7 @@ add_valid_address (void *cls, const struct GNUNET_HELLO_Address *address,
   const struct GNUNET_HELLO_Message *hello = cls;
   struct ValidationEntry *ve;
   struct GNUNET_PeerIdentity pid;
+  struct GNUNET_ATS_Information ats;
   struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded public_key;
 
   if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value == 0)
@@ -744,7 +758,11 @@ add_valid_address (void *cls, const struct GNUNET_HELLO_Address *address,
 
   if (GNUNET_SCHEDULER_NO_TASK == ve->revalidation_task)
     ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve);
-  GNUNET_ATS_address_add (GST_ats, address, NULL, NULL, 0);
+
+  ats.type = htonl (GNUNET_ATS_NETWORK_TYPE);
+  ats.value = htonl (ve->network);
+  GNUNET_ATS_address_add (GST_ats, address, NULL, &ats, 1);
+
   return GNUNET_OK;
 }
 
@@ -1248,10 +1266,12 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
        ve->pong_sig_valid_until = GNUNET_TIME_absolute_ntoh (pong->expiration);
   ve->latency = GNUNET_TIME_absolute_get_duration (ve->send_time);
   {
-    struct GNUNET_ATS_Information ats;
-    ats.type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
-    ats.value = htonl ((uint32_t) ve->latency.rel_value);
-    GNUNET_ATS_address_add (GST_ats, ve->address, NULL, &ats, 1);
+    struct GNUNET_ATS_Information ats[2];
+    ats[0].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
+    ats[0].value = htonl ((uint32_t) ve->latency.rel_value);
+    ats[1].type = htonl (GNUNET_ATS_NETWORK_TYPE);
+    ats[1].value = htonl ((uint32_t) ve->network);
+    GNUNET_ATS_address_add (GST_ats, ve->address, NULL, ats, 2);
   }
   if (validations_running > 0)
   {