gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r26593 - gnunet/src/fs


From: gnunet
Subject: [GNUnet-SVN] r26593 - gnunet/src/fs
Date: Mon, 25 Mar 2013 13:16:24 +0100

Author: grothoff
Date: 2013-03-25 13:16:24 +0100 (Mon, 25 Mar 2013)
New Revision: 26593

Modified:
   gnunet/src/fs/gnunet-service-fs.c
   gnunet/src/fs/gnunet-service-fs.h
   gnunet/src/fs/gnunet-service-fs_cp.c
   gnunet/src/fs/gnunet-service-fs_cp.h
Log:
-towards using ATS for latency info

Modified: gnunet/src/fs/gnunet-service-fs.c
===================================================================
--- gnunet/src/fs/gnunet-service-fs.c   2013-03-25 09:41:49 UTC (rev 26592)
+++ gnunet/src/fs/gnunet-service-fs.c   2013-03-25 12:16:24 UTC (rev 26593)
@@ -101,6 +101,12 @@
 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
  * non-zero priorities seen "recently".  In order to ensure that new
@@ -226,29 +232,41 @@
 /**
  * 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 @@
     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 @@
     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 @@
     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 @@
 
   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 @@
   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)) ||

Modified: gnunet/src/fs/gnunet-service-fs.h
===================================================================
--- gnunet/src/fs/gnunet-service-fs.h   2013-03-25 09:41:49 UTC (rev 26592)
+++ gnunet/src/fs/gnunet-service-fs.h   2013-03-25 12:16:24 UTC (rev 26593)
@@ -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"
 
 
@@ -218,6 +219,12 @@
 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
  * non-zero priorities seen "recently".  In order to ensure that new

Modified: gnunet/src/fs/gnunet-service-fs_cp.c
===================================================================
--- gnunet/src/fs/gnunet-service-fs_cp.c        2013-03-25 09:41:49 UTC (rev 
26592)
+++ gnunet/src/fs/gnunet-service-fs_cp.c        2013-03-25 12:16:24 UTC (rev 
26593)
@@ -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,12 +314,7 @@
  */
 static char *respectDirectory;
 
-/**
- * Handle to ATS service.
- */
-static struct GNUNET_ATS_PerformanceHandle *ats;
 
-
 /**
  * Get the filename under which we would store respect
  * for the given peer.
@@ -341,39 +335,18 @@
 
 
 /**
- * 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)
+void
+GSF_update_peer_latency_ (const struct GNUNET_PeerIdentity *id,
+                         struct GNUNET_TIME_Relative latency)
 {
-  unsigned int i;
+  struct GSF_ConnectedPeer *cp;
 
-  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)
-{
-  struct GNUNET_TIME_Relative latency;
-
-  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 @@
 
   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 @@
     /* 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 @@
   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 @@
  * 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 @@
   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 @@
   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 @@
     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 @@
 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 @@
   cp_map = NULL;
   GNUNET_free (respectDirectory);
   respectDirectory = NULL;
-  GNUNET_ATS_performance_done (ats);
-  ats = NULL;
 }
 
 

Modified: gnunet/src/fs/gnunet-service-fs_cp.h
===================================================================
--- gnunet/src/fs/gnunet-service-fs_cp.h        2013-03-25 09:41:49 UTC (rev 
26592)
+++ gnunet/src/fs/gnunet-service-fs_cp.h        2013-03-25 12:16:24 UTC (rev 
26593)
@@ -200,14 +200,10 @@
  * 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);
 
 
 /**
@@ -221,6 +217,17 @@
 
 
 /**
+ * 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,
  * the callback is invoked with a 'NULL' buffer.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]