aboutsummaryrefslogtreecommitdiff
path: root/src/fs
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-11-04 13:32:45 +0000
committerChristian Grothoff <christian@grothoff.org>2011-11-04 13:32:45 +0000
commitf23af8a34c2abcc816cf67e6674fcf18041630b5 (patch)
treeaea05f924f38dc3a0336f6388b78d47b35ea5e87 /src/fs
parent77b6ff6328120de950fd5d7802819882455a4da1 (diff)
downloadgnunet-f23af8a34c2abcc816cf67e6674fcf18041630b5.tar.gz
gnunet-f23af8a34c2abcc816cf67e6674fcf18041630b5.zip
implementing #1785
Diffstat (limited to 'src/fs')
-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
3 files changed, 43 insertions, 3 deletions
diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c
index c5933d989..404993130 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;
94struct GNUNET_LOAD_Value *GSF_rt_entry_lifetime; 94struct GNUNET_LOAD_Value *GSF_rt_entry_lifetime;
95 95
96/** 96/**
97 * Running average of the observed latency to other peers (round trip).
98 * Initialized to 5s as the initial default.
99 */
100struct GNUNET_TIME_Relative GSF_avg_latency = { 5000 };
101
102/**
97 * Typical priorities we're seeing from other peers right now. Since 103 * Typical priorities we're seeing from other peers right now. Since
98 * most priorities will be zero, this value is the weighted average of 104 * most priorities will be zero, this value is the weighted average of
99 * non-zero priorities seen "recently". In order to ensure that new 105 * 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)
172} 178}
173 179
174 180
175
176/** 181/**
177 * We've just now completed a datastore request. Update our 182 * We've just now completed a datastore request. Update our
178 * datastore load calculations. 183 * datastore load calculations.
@@ -213,6 +218,34 @@ GSF_test_get_load_too_high_ (uint32_t priority)
213 218
214 219
215/** 220/**
221 * We've received peer performance information. Update
222 * our running average for the P2P latency.
223 *
224 * @param atsi performance information
225 * @param atsi_count number of 'atsi' records
226 */
227static void
228update_latencies (const struct GNUNET_ATS_Information *atsi,
229 unsigned int atsi_count)
230{
231 unsigned int i;
232
233 for (i=0;i<atsi_count;i++)
234 {
235 if (ntohl(atsi[i].type) == GNUNET_ATS_QUALITY_NET_DELAY)
236 {
237 GSF_avg_latency.rel_value = (GSF_avg_latency.rel_value * 31 + ntohl (atsi[i].value)) / 32;
238 GNUNET_STATISTICS_set (GSF_stats,
239 gettext_noop ("# running average P2P latency (ms)"),
240 GSF_avg_latency.rel_value,
241 GNUNET_NO);
242 break;
243 }
244 }
245}
246
247
248/**
216 * Handle P2P "PUT" message. 249 * Handle P2P "PUT" message.
217 * 250 *
218 * @param cls closure, always NULL 251 * @param cls closure, always NULL
@@ -239,6 +272,7 @@ handle_p2p_put (void *cls, const struct GNUNET_PeerIdentity *other,
239 return GNUNET_OK; 272 return GNUNET_OK;
240 } 273 }
241 GSF_cover_content_count++; 274 GSF_cover_content_count++;
275 update_latencies (atsi, atsi_count);
242 return GSF_handle_p2p_content_ (cp, message); 276 return GSF_handle_p2p_content_ (cp, message);
243} 277}
244 278
@@ -317,6 +351,7 @@ handle_p2p_get (void *cls, const struct GNUNET_PeerIdentity *other,
317 if (NULL == pr) 351 if (NULL == pr)
318 return GNUNET_SYSERR; 352 return GNUNET_SYSERR;
319 GSF_local_lookup_ (pr, &consider_forwarding, NULL); 353 GSF_local_lookup_ (pr, &consider_forwarding, NULL);
354 update_latencies (atsi, atsi_count);
320 return GNUNET_OK; 355 return GNUNET_OK;
321} 356}
322 357
diff --git a/src/fs/gnunet-service-fs.h b/src/fs/gnunet-service-fs.h
index 8ba90dd22..e4efbb8f5 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;
125extern struct GNUNET_LOAD_Value *GSF_rt_entry_lifetime; 125extern struct GNUNET_LOAD_Value *GSF_rt_entry_lifetime;
126 126
127/** 127/**
128 * Running average of the observed latency to other peers (round trip).
129 */
130extern struct GNUNET_TIME_Relative GSF_avg_latency;
131
132/**
128 * Typical priorities we're seeing from other peers right now. Since 133 * Typical priorities we're seeing from other peers right now. Since
129 * most priorities will be zero, this value is the weighted average of 134 * most priorities will be zero, this value is the weighted average of
130 * non-zero priorities seen "recently". In order to ensure that new 135 * 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 fc9c44785..859d9275f 100644
--- a/src/fs/gnunet-service-fs_cp.c
+++ b/src/fs/gnunet-service-fs_cp.c
@@ -838,11 +838,11 @@ get_randomized_delay ()
838{ 838{
839 struct GNUNET_TIME_Relative ret; 839 struct GNUNET_TIME_Relative ret;
840 840
841 /* FIXME: replace 5000 with something relating to current observed P2P message latency */
842 ret = 841 ret =
843 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 842 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
844 GNUNET_CRYPTO_random_u32 843 GNUNET_CRYPTO_random_u32
845 (GNUNET_CRYPTO_QUALITY_WEAK, 5000)); 844 (GNUNET_CRYPTO_QUALITY_WEAK,
845 2 * GSF_avg_latency.rel_value + 1));
846 GNUNET_STATISTICS_update (GSF_stats, 846 GNUNET_STATISTICS_update (GSF_stats,
847 gettext_noop 847 gettext_noop
848 ("# artificial delays introduced (ms)"), 848 ("# artificial delays introduced (ms)"),