do latency computation - #1768
authorChristian Grothoff <christian@grothoff.org>
Mon, 19 Sep 2011 09:39:28 +0000 (09:39 +0000)
committerChristian Grothoff <christian@grothoff.org>
Mon, 19 Sep 2011 09:39:28 +0000 (09:39 +0000)
src/transport/gnunet-service-transport.c
src/transport/gnunet-service-transport_validation.c

index 4687a090716c8e06ac8670b4ae46beb7bdd92584..07861eaff22604b63c6f128ca2a67ad89e30bb53 100644 (file)
@@ -241,13 +241,17 @@ plugin_env_receive_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
       break;
     }
   }
-
   GNUNET_assert ((ats_count > 0) && (ats != NULL));
-
+  /*
+     FIXME: this gives an address that might not have been validated to
+     ATS for 'selection', which is probably not what we want; this 
+     might be particularly wrong (as in, possibly hiding bugs with address
+     validation) as 'GNUNET_ATS_address_update' currently ignores
+     the expiration given.
+  */
   GNUNET_ATS_address_update (GST_ats, peer, GNUNET_TIME_absolute_get (),        /* valid at least until right now... */
                              plugin_name, session, sender_address,
                              sender_address_len, ats, ats_count);
-
   return ret;
 }
 
index 57fa86260c257b64026766fe5a1b7da651d70214..7fcb76396dfe3574a995752e95235c1059dfbb0e 100644 (file)
@@ -394,6 +394,7 @@ add_valid_address (void *cls, const char *tname,
   struct ValidationEntry *ve;
   struct GNUNET_PeerIdentity pid;
   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key;
+  struct GNUNET_TRANSPORT_ATS_Information ats;
 
   if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value == 0)
     return GNUNET_OK;           /* expired */
@@ -405,11 +406,8 @@ add_valid_address (void *cls, const char *tname,
   }
   ve = find_validation_entry (&public_key, &pid, tname, addr, addrlen);
   ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until, expiration);
-  struct GNUNET_TRANSPORT_ATS_Information ats;
-
   ats.type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
   ats.value = htonl (0);
-
   GNUNET_ATS_address_update (GST_ats, &pid, ve->valid_until, tname, NULL, addr,
                              addrlen, &ats, 1);
   return GNUNET_OK;
@@ -979,12 +977,18 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
 
   /* validity achieved, remember it! */
   ve->valid_until = GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION);
-  struct GNUNET_TRANSPORT_ATS_Information ats;
-
-  ats.type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
-  ats.value = htonl (0);
-  GNUNET_ATS_address_update (GST_ats, &ve->pid, ve->valid_until, ve->transport_name, NULL, ve->addr, ve->addrlen, &ats, 1);     /* FIXME: compute and add latency here... */
-
+  {
+    struct GNUNET_TRANSPORT_ATS_Information ats[2];
+
+    ats[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY);
+    ats[0].value = htonl ((uint32_t) GNUNET_TIME_absolute_get_duration (ve->send_time).rel_value);
+    ats[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
+    ats[1].value = htonl (0);
+    GNUNET_ATS_address_update (GST_ats, &ve->pid, ve->valid_until, 
+                              ve->transport_name, NULL, ve->addr, ve->addrlen, 
+                              ats, 2);
+  }
+  
   /* build HELLO to store in PEERINFO */
   ve->copied = GNUNET_NO;
   hello = GNUNET_HELLO_create (&ve->public_key, &add_valid_peer_address, ve);