-towards using ATS for latency info
authorChristian Grothoff <christian@grothoff.org>
Mon, 25 Mar 2013 12:16:24 +0000 (12:16 +0000)
committerChristian Grothoff <christian@grothoff.org>
Mon, 25 Mar 2013 12:16:24 +0000 (12:16 +0000)
src/fs/gnunet-service-fs.c
src/fs/gnunet-service-fs.h
src/fs/gnunet-service-fs_cp.c
src/fs/gnunet-service-fs_cp.h

index 4a0a14f58e9d5164637fedda15abbe0493fe5975..0f1f0ddbc3a7bff98b0834da52662f947a2ef1b0 100644 (file)
@@ -100,6 +100,12 @@ struct GNUNET_LOAD_Value *GSF_rt_entry_lifetime;
  */
 struct GNUNET_TIME_Relative GSF_avg_latency = { 500 };
 
+/**
+ * Handle to ATS service.
+ */
+struct GNUNET_ATS_PerformanceHandle *GSF_ats;
+
+
 /**
  * Typical priorities we're seeing from other peers right now.  Since
  * most priorities will be zero, this value is the weighted average of
@@ -226,29 +232,41 @@ GSF_test_get_load_too_high_ (uint32_t priority)
 /**
  * We've received peer performance information. Update
  * our running average for the P2P latency.
- *
- * @param atsi performance information
- * @param atsi_count number of 'atsi' records
+*
+ * @param cls closure
+ * @param address the address
+ * @param bandwidth_out assigned outbound bandwidth for the connection
+ * @param bandwidth_in assigned inbound bandwidth for the connection
+ * @param ats performance data for the address (as far as known)
+ * @param ats_count number of performance records in 'ats'
  */
 static void
-update_latencies (const struct GNUNET_ATS_Information *atsi,
-                  unsigned int atsi_count)
+update_latencies (void *cls,
+                 const struct GNUNET_HELLO_Address *address,
+                 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
+                 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
+                 const struct GNUNET_ATS_Information *ats, 
+                 uint32_t ats_count)
 {
   unsigned int i;
+  struct GNUNET_TIME_Relative latency;
 
-  for (i = 0; i < atsi_count; i++)
+  // FIXME: if (GNUNET_YES != current_address) return;
+  for (i = 0; i < ats_count; i++)
   {
-    if (ntohl (atsi[i].type) == GNUNET_ATS_QUALITY_NET_DELAY)
-    {
-      GSF_avg_latency.rel_value =
-          (GSF_avg_latency.rel_value * 31 +
-           GNUNET_MIN (5000, ntohl (atsi[i].value))) / 32;
-      GNUNET_STATISTICS_set (GSF_stats,
-                             gettext_noop
-                             ("# running average P2P latency (ms)"),
-                             GSF_avg_latency.rel_value, GNUNET_NO);
-      break;
-    }
+    if (GNUNET_ATS_QUALITY_NET_DELAY != ntohl (ats[i].type))
+      continue;
+    latency.rel_value = ntohl (ats[i].value);
+    GSF_update_peer_latency_ (&address->peer,
+                             latency);
+    GSF_avg_latency.rel_value =
+      (GSF_avg_latency.rel_value * 31 +
+       GNUNET_MIN (5000, ntohl (ats[i].value))) / 32;
+    GNUNET_STATISTICS_set (GSF_stats,
+                          gettext_noop
+                          ("# running average P2P latency (ms)"),
+                          GSF_avg_latency.rel_value, GNUNET_NO);
+    break;    
   }
 }
 
@@ -276,8 +294,6 @@ handle_p2p_put (void *cls, const struct GNUNET_PeerIdentity *other,
     return GNUNET_OK;
   }
   GSF_cover_content_count++;
-  fprintf (stderr, "FIX ATS DATA: %s:%u!\n", __FILE__, __LINE__);
-  update_latencies (NULL, 0);
   return GSF_handle_p2p_content_ (cp, message);
 }
 
@@ -353,8 +369,6 @@ handle_p2p_get (void *cls, const struct GNUNET_PeerIdentity *other,
     return GNUNET_SYSERR;
   GSF_pending_request_get_data_ (pr)->has_started = GNUNET_YES;
   GSF_local_lookup_ (pr, &consider_forwarding, NULL);
-  fprintf (stderr, "FIX ATS DATA: %s:%u!\n", __FILE__, __LINE__);
-  update_latencies (NULL, 0);
   return GNUNET_OK;
 }
 
@@ -463,6 +477,11 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
     GNUNET_CORE_disconnect (GSF_core);
     GSF_core = NULL;
   }
+  if (NULL != GSF_ats)
+  {
+    GNUNET_ATS_performance_done (GSF_ats);
+    GSF_ats = NULL;
+  }
   GSF_put_done_ ();
   GSF_push_done_ ();
   GSF_pending_request_done_ ();
@@ -534,8 +553,7 @@ peer_connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer)
 
   if (0 == memcmp (&my_id, peer, sizeof (struct GNUNET_PeerIdentity)))
     return;
-  fprintf (stderr, "FIX ATS DATA: %s:%u!\n", __FILE__, __LINE__);
-  cp = GSF_peer_connect_handler_ (peer, NULL, 0);
+  cp = GSF_peer_connect_handler_ (peer);
   if (NULL == cp)
     return;
   GSF_iterate_pending_requests_ (&consider_peer_for_forwarding, cp);
@@ -672,6 +690,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
   GSF_plan_init ();
   GSF_pending_request_init_ ();
   GSF_connected_peer_init_ ();
+  GSF_ats = GNUNET_ATS_performance_init (GSF_cfg, &update_latencies, NULL);
   GSF_push_init_ ();
   GSF_put_init_ ();
   if ((GNUNET_OK != GNUNET_FS_indexing_init (cfg, GSF_dsh)) ||
index 60075e097d0c19c669338dda5e758ac1760dc2a8..8830058e99a4ca9712c34871e027267590c1f0f7 100644 (file)
@@ -31,6 +31,7 @@
 #include "gnunet_transport_service.h"
 #include "gnunet_core_service.h"
 #include "gnunet_block_lib.h"
+#include "gnunet_ats_service.h"
 #include "fs.h"
 
 
@@ -217,6 +218,12 @@ extern struct GNUNET_LOAD_Value *GSF_rt_entry_lifetime;
  */
 extern struct GNUNET_TIME_Relative GSF_avg_latency;
 
+/**
+ * Handle to ATS service.
+ */
+extern struct GNUNET_ATS_PerformanceHandle *GSF_ats;
+
+
 /**
  * Typical priorities we're seeing from other peers right now.  Since
  * most priorities will be zero, this value is the weighted average of
index f33b97d81a7faf98d9d7dea10c5ce05e2352d61a..c9e61d5d4c830a83999ef73a0e6929a66bda3f39 100644 (file)
@@ -25,7 +25,6 @@
  */
 #include "platform.h"
 #include "gnunet_load_lib.h"
-#include "gnunet_ats_service.h"
 #include "gnunet-service-fs.h"
 #include "gnunet-service-fs_cp.h"
 #include "gnunet-service-fs_pe.h"
@@ -315,11 +314,6 @@ static struct GNUNET_CONTAINER_MultiHashMap *cp_map;
  */
 static char *respectDirectory;
 
-/**
- * Handle to ATS service.
- */
-static struct GNUNET_ATS_PerformanceHandle *ats;
-
 
 /**
  * Get the filename under which we would store respect
@@ -341,39 +335,18 @@ get_respect_filename (const struct GNUNET_PeerIdentity *id)
 
 
 /**
- * Find latency information in 'atsi'.
+ * Update the latency information kept for the given peer.
  *
- * @param atsi performance data
- * @param atsi_count number of records in 'atsi'
- * @return connection latency
+ * @param id peer record to update
+ * @param latency current latency value
  */
-static struct GNUNET_TIME_Relative
-get_latency (const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count)
-{
-  unsigned int i;
-
-  for (i = 0; i < atsi_count; i++)
-    if (ntohl (atsi->type) == GNUNET_ATS_QUALITY_NET_DELAY)
-      return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
-                                            ntohl (atsi->value));
-  return GNUNET_TIME_UNIT_SECONDS;
-}
-
-
-/**
- * Update the performance information kept for the given peer.
- *
- * @param cp peer record to update
- * @param atsi transport performance data
- * @param atsi_count number of records in 'atsi'
- */
-static void
-update_atsi (struct GSF_ConnectedPeer *cp,
-             const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count)
+void
+GSF_update_peer_latency_ (const struct GNUNET_PeerIdentity *id,
+                         struct GNUNET_TIME_Relative latency)
 {
-  struct GNUNET_TIME_Relative latency;
+  struct GSF_ConnectedPeer *cp;
 
-  latency = get_latency (atsi, atsi_count);
+  cp = GSF_peer_get_ (id);
   GNUNET_LOAD_value_set_decline (cp->ppd.transmission_delay, latency);
   /* LATER: merge atsi into cp's performance data (if we ever care...) */
 }
@@ -439,7 +412,7 @@ schedule_transmission (struct GSF_PeerTransmitHandle *pth)
 
   if (0 != cp->inc_preference)
   {
-    GNUNET_ATS_change_preference (ats, &target, GNUNET_ATS_PREFERENCE_BANDWIDTH,
+    GNUNET_ATS_change_preference (GSF_ats, &target, GNUNET_ATS_PREFERENCE_BANDWIDTH,
                                   (double) cp->inc_preference,
                                   GNUNET_ATS_PREFERENCE_END);
     cp->inc_preference = 0;
@@ -454,7 +427,7 @@ schedule_transmission (struct GSF_PeerTransmitHandle *pth)
     /* reservation already done! */
     pth->was_reserved = GNUNET_YES;
     cp->rc =
-        GNUNET_ATS_reserve_bandwidth (ats, &target, DBLOCK_SIZE,
+        GNUNET_ATS_reserve_bandwidth (GSF_ats, &target, DBLOCK_SIZE,
                                       &ats_reserve_callback, cp);
     return;
   }
@@ -540,8 +513,8 @@ retry_reservation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   GNUNET_PEER_resolve (cp->ppd.pid, &target);
   cp->rc_delay_task = GNUNET_SCHEDULER_NO_TASK;
   cp->rc =
-      GNUNET_ATS_reserve_bandwidth (ats, &target, DBLOCK_SIZE,
-                                    &ats_reserve_callback, cp);
+    GNUNET_ATS_reserve_bandwidth (GSF_ats, &target, DBLOCK_SIZE,
+                                 &ats_reserve_callback, cp);
 }
 
 
@@ -595,14 +568,10 @@ ats_reserve_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
  * records.
  *
  * @param peer identity of peer that connected
- * @param atsi performance data for the connection
- * @param atsi_count number of records in 'atsi'
  * @return handle to connected peer entry
  */
 struct GSF_ConnectedPeer *
-GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer,
-                           const struct GNUNET_ATS_Information *atsi,
-                           unsigned int atsi_count)
+GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer)
 {
   struct GSF_ConnectedPeer *cp;
   char *fn;
@@ -614,7 +583,7 @@ GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer,
   cp->ppd.pid = GNUNET_PEER_intern (peer);
   cp->ppd.transmission_delay = GNUNET_LOAD_value_init (GNUNET_TIME_UNIT_ZERO);
   cp->rc =
-      GNUNET_ATS_reserve_bandwidth (ats, peer, DBLOCK_SIZE,
+      GNUNET_ATS_reserve_bandwidth (GSF_ats, peer, DBLOCK_SIZE,
                                     &ats_reserve_callback, cp);
   fn = get_respect_filename (peer);
   if ((GNUNET_YES == GNUNET_DISK_file_test (fn)) &&
@@ -630,7 +599,6 @@ GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer,
   GNUNET_STATISTICS_set (GSF_stats, gettext_noop ("# peers connected"),
                          GNUNET_CONTAINER_multihashmap_size (cp_map),
                          GNUNET_NO);
-  update_atsi (cp, atsi, atsi_count);
   GSF_push_start_ (cp);
   return cp;
 }
@@ -718,8 +686,6 @@ GSF_handle_p2p_migration_stop_ (void *cls,
     cp->mig_revive_task =
         GNUNET_SCHEDULER_add_delayed (bt, &revive_migration, cp);
   }
-  fprintf (stderr, "FIX ATS DATA: %s:%u!\n", __FILE__, __LINE__);
-  update_atsi (cp, NULL, 0);
   return GNUNET_OK;
 }
 
@@ -1821,7 +1787,6 @@ void
 GSF_connected_peer_init_ ()
 {
   cp_map = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_YES);
-  ats = GNUNET_ATS_performance_init (GSF_cfg, NULL, NULL);
   GNUNET_assert (GNUNET_OK ==
                  GNUNET_CONFIGURATION_get_value_filename (GSF_cfg, "fs",
                                                           "RESPECT",
@@ -1860,8 +1825,6 @@ GSF_connected_peer_done_ ()
   cp_map = NULL;
   GNUNET_free (respectDirectory);
   respectDirectory = NULL;
-  GNUNET_ATS_performance_done (ats);
-  ats = NULL;
 }
 
 
index 3655486655c0a1d35bebe6af5f87af23984a68ff..84668d3015d87781c3201dfd63d45f48a1a3d286 100644 (file)
@@ -200,14 +200,10 @@ struct GSF_PeerTransmitHandle;
  * records.
  *
  * @param peer identity of peer that connected
- * @param atsi performance data for the connection
- * @param atsi_count number of records in 'atsi'
  * @return handle to connected peer entry
  */
 struct GSF_ConnectedPeer *
-GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer,
-                           const struct GNUNET_ATS_Information *atsi,
-                           unsigned int atsi_count);
+GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer);
 
 
 /**
@@ -220,6 +216,17 @@ struct GSF_ConnectedPeer *
 GSF_peer_get_ (const struct GNUNET_PeerIdentity *peer);
 
 
+/**
+ * Update the latency information kept for the given peer.
+ *
+ * @param id peer record to update
+ * @param latency current latency value
+ */
+void
+GSF_update_peer_latency_ (const struct GNUNET_PeerIdentity *id,
+                         struct GNUNET_TIME_Relative latency);
+
+
 /**
  * Transmit a message to the given peer as soon as possible.
  * If the peer disconnects before the transmission can happen,