gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r17985 - in gnunet/src: core fs


From: gnunet
Subject: [GNUnet-SVN] r17985 - in gnunet/src: core fs
Date: Fri, 4 Nov 2011 14:32:45 +0100

Author: grothoff
Date: 2011-11-04 14:32:45 +0100 (Fri, 04 Nov 2011)
New Revision: 17985

Modified:
   gnunet/src/core/gnunet-service-core_neighbours.c
   gnunet/src/fs/gnunet-service-fs.c
   gnunet/src/fs/gnunet-service-fs.h
   gnunet/src/fs/gnunet-service-fs_cp.c
Log:
implementing #1785

Modified: gnunet/src/core/gnunet-service-core_neighbours.c
===================================================================
--- gnunet/src/core/gnunet-service-core_neighbours.c    2011-11-04 12:35:18 UTC 
(rev 17984)
+++ gnunet/src/core/gnunet-service-core_neighbours.c    2011-11-04 13:32:45 UTC 
(rev 17985)
@@ -307,14 +307,14 @@
  *
  * @param cls closure
  * @param peer the peer that connected
- * @param ats performance data
- * @param ats_count number of entries in ats (excluding 0-termination)
+ * @param atsi performance data
+ * @param atsi_count number of entries in ats (excluding 0-termination)
  */
 static void
 handle_transport_notify_connect (void *cls,
                                  const struct GNUNET_PeerIdentity *peer,
                                  const struct GNUNET_ATS_Information
-                                 *ats, uint32_t ats_count)
+                                 *atsi, uint32_t atsi_count)
 {
   struct Neighbour *n;
 
@@ -381,14 +381,14 @@
  * @param cls closure
  * @param peer (claimed) identity of the other peer
  * @param message the message
- * @param ats performance data
- * @param ats_count number of entries in ats (excluding 0-termination)
+ * @param atsi performance data
+ * @param atsi_count number of entries in ats (excluding 0-termination)
  */
 static void
 handle_transport_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
                           const struct GNUNET_MessageHeader *message,
-                          const struct GNUNET_ATS_Information *ats,
-                          uint32_t ats_count)
+                          const struct GNUNET_ATS_Information *atsi,
+                          uint32_t atsi_count)
 {
   struct Neighbour *n;
   uint16_t type;
@@ -424,8 +424,8 @@
     break;
   case GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE:
     GSC_KX_handle_encrypted_message (n->kxinfo,
-                                    message, ats,
-                                    ats_count);
+                                    message, atsi,
+                                    atsi_count);
     break;
   default:
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,

Modified: gnunet/src/fs/gnunet-service-fs.c
===================================================================
--- gnunet/src/fs/gnunet-service-fs.c   2011-11-04 12:35:18 UTC (rev 17984)
+++ gnunet/src/fs/gnunet-service-fs.c   2011-11-04 13:32:45 UTC (rev 17985)
@@ -94,6 +94,12 @@
 struct GNUNET_LOAD_Value *GSF_rt_entry_lifetime;
 
 /**
+ * Running average of the observed latency to other peers (round trip).
+ * Initialized to 5s as the initial default.
+ */
+struct GNUNET_TIME_Relative GSF_avg_latency = { 5000 };
+
+/**
  * 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
@@ -172,7 +178,6 @@
 }
 
 
-
 /**
  * We've just now completed a datastore request.  Update our
  * datastore load calculations.
@@ -213,6 +218,34 @@
 
 
 /**
+ * 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
+ */
+static void
+update_latencies (const struct GNUNET_ATS_Information *atsi,
+                 unsigned int atsi_count)
+{
+  unsigned int i;
+
+  for (i=0;i<atsi_count;i++)
+  {
+    if (ntohl(atsi[i].type) == GNUNET_ATS_QUALITY_NET_DELAY)
+    {
+      GSF_avg_latency.rel_value = (GSF_avg_latency.rel_value * 31 + 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;
+    }
+  }
+}
+
+
+/**
  * Handle P2P "PUT" message.
  *
  * @param cls closure, always NULL
@@ -239,6 +272,7 @@
     return GNUNET_OK;
   }
   GSF_cover_content_count++;
+  update_latencies (atsi, atsi_count);
   return GSF_handle_p2p_content_ (cp, message);
 }
 
@@ -317,6 +351,7 @@
   if (NULL == pr)
     return GNUNET_SYSERR;
   GSF_local_lookup_ (pr, &consider_forwarding, NULL);
+  update_latencies (atsi, atsi_count);
   return GNUNET_OK;
 }
 

Modified: gnunet/src/fs/gnunet-service-fs.h
===================================================================
--- gnunet/src/fs/gnunet-service-fs.h   2011-11-04 12:35:18 UTC (rev 17984)
+++ gnunet/src/fs/gnunet-service-fs.h   2011-11-04 13:32:45 UTC (rev 17985)
@@ -125,6 +125,11 @@
 extern struct GNUNET_LOAD_Value *GSF_rt_entry_lifetime;
 
 /**
+ * Running average of the observed latency to other peers (round trip).
+ */
+extern struct GNUNET_TIME_Relative GSF_avg_latency;
+
+/**
  * 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        2011-11-04 12:35:18 UTC (rev 
17984)
+++ gnunet/src/fs/gnunet-service-fs_cp.c        2011-11-04 13:32:45 UTC (rev 
17985)
@@ -838,11 +838,11 @@
 {
   struct GNUNET_TIME_Relative ret;
 
-  /* FIXME: replace 5000 with something relating to current observed P2P 
message latency */
   ret =
       GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
                                      GNUNET_CRYPTO_random_u32
-                                     (GNUNET_CRYPTO_QUALITY_WEAK, 5000));
+                                     (GNUNET_CRYPTO_QUALITY_WEAK, 
+                                     2 * GSF_avg_latency.rel_value + 1));
   GNUNET_STATISTICS_update (GSF_stats,
                             gettext_noop
                             ("# artificial delays introduced (ms)"),




reply via email to

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