aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgrothoff <grothoff@140774ce-b5e7-0310-ab8b-a85725594a96>2011-11-04 13:32:45 +0000
committergrothoff <grothoff@140774ce-b5e7-0310-ab8b-a85725594a96>2011-11-04 13:32:45 +0000
commitd49cda2961d7b6207ad32d52a46c78aabaee7615 (patch)
treeaea05f924f38dc3a0336f6388b78d47b35ea5e87
parent06a684471fde02dd1d2cc4251838b0e93c795a7b (diff)
implementing #1785
git-svn-id: https://gnunet.org/svn/gnunet@17985 140774ce-b5e7-0310-ab8b-a85725594a96
-rw-r--r--src/core/gnunet-service-core_neighbours.c18
-rw-r--r--src/fs/gnunet-service-fs.c37
-rw-r--r--src/fs/gnunet-service-fs.h5
-rw-r--r--src/fs/gnunet-service-fs_cp.c4
4 files changed, 52 insertions, 12 deletions
diff --git a/src/core/gnunet-service-core_neighbours.c b/src/core/gnunet-service-core_neighbours.c
index 9b33a286ee..d7ce91a881 100644
--- a/src/core/gnunet-service-core_neighbours.c
+++ b/src/core/gnunet-service-core_neighbours.c
@@ -307,14 +307,14 @@ process_queue (struct Neighbour *n)
*
* @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 @@ handle_transport_notify_disconnect (void *cls,
* @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 @@ handle_transport_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
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,
diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c
index c5933d9896..4049931307 100644
--- a/src/fs/gnunet-service-fs.c
+++ b/src/fs/gnunet-service-fs.c
@@ -94,6 +94,12 @@ struct GNUNET_DHT_Handle *GSF_dht;
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 @@ age_cover_counters (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
}
-
/**
* We've just now completed a datastore request. Update our
* datastore load calculations.
@@ -213,6 +218,34 @@ 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
+ */
+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 @@ handle_p2p_put (void *cls, const struct GNUNET_PeerIdentity *other,
return GNUNET_OK;
}
GSF_cover_content_count++;
+ update_latencies (atsi, atsi_count);
return GSF_handle_p2p_content_ (cp, message);
}
@@ -317,6 +351,7 @@ handle_p2p_get (void *cls, const struct GNUNET_PeerIdentity *other,
if (NULL == pr)
return GNUNET_SYSERR;
GSF_local_lookup_ (pr, &consider_forwarding, NULL);
+ update_latencies (atsi, atsi_count);
return GNUNET_OK;
}
diff --git a/src/fs/gnunet-service-fs.h b/src/fs/gnunet-service-fs.h
index 8ba90dd226..e4efbb8f53 100644
--- a/src/fs/gnunet-service-fs.h
+++ b/src/fs/gnunet-service-fs.h
@@ -125,6 +125,11 @@ extern struct GNUNET_DHT_Handle *GSF_dht;
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
diff --git a/src/fs/gnunet-service-fs_cp.c b/src/fs/gnunet-service-fs_cp.c
index fc9c44785a..859d9275fe 100644
--- a/src/fs/gnunet-service-fs_cp.c
+++ b/src/fs/gnunet-service-fs_cp.c
@@ -838,11 +838,11 @@ get_randomized_delay ()
{
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)"),