diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-03-25 12:16:24 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-03-25 12:16:24 +0000 |
commit | f13909574bb89556bbb54e5555ed56ceee5a9f61 (patch) | |
tree | f3a294971445b5497f740c928dbacec28a450ed5 /src/fs/gnunet-service-fs.c | |
parent | f88dc96655c7d92efb65c80ebc85f55e64ec86b5 (diff) | |
download | gnunet-f13909574bb89556bbb54e5555ed56ceee5a9f61.tar.gz gnunet-f13909574bb89556bbb54e5555ed56ceee5a9f61.zip |
-towards using ATS for latency info
Diffstat (limited to 'src/fs/gnunet-service-fs.c')
-rw-r--r-- | src/fs/gnunet-service-fs.c | 65 |
1 files changed, 42 insertions, 23 deletions
diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c index 4a0a14f58..0f1f0ddbc 100644 --- a/src/fs/gnunet-service-fs.c +++ b/src/fs/gnunet-service-fs.c | |||
@@ -101,6 +101,12 @@ struct GNUNET_LOAD_Value *GSF_rt_entry_lifetime; | |||
101 | struct GNUNET_TIME_Relative GSF_avg_latency = { 500 }; | 101 | struct GNUNET_TIME_Relative GSF_avg_latency = { 500 }; |
102 | 102 | ||
103 | /** | 103 | /** |
104 | * Handle to ATS service. | ||
105 | */ | ||
106 | struct GNUNET_ATS_PerformanceHandle *GSF_ats; | ||
107 | |||
108 | |||
109 | /** | ||
104 | * Typical priorities we're seeing from other peers right now. Since | 110 | * Typical priorities we're seeing from other peers right now. Since |
105 | * most priorities will be zero, this value is the weighted average of | 111 | * most priorities will be zero, this value is the weighted average of |
106 | * non-zero priorities seen "recently". In order to ensure that new | 112 | * non-zero priorities seen "recently". In order to ensure that new |
@@ -226,29 +232,41 @@ GSF_test_get_load_too_high_ (uint32_t priority) | |||
226 | /** | 232 | /** |
227 | * We've received peer performance information. Update | 233 | * We've received peer performance information. Update |
228 | * our running average for the P2P latency. | 234 | * our running average for the P2P latency. |
229 | * | 235 | * |
230 | * @param atsi performance information | 236 | * @param cls closure |
231 | * @param atsi_count number of 'atsi' records | 237 | * @param address the address |
238 | * @param bandwidth_out assigned outbound bandwidth for the connection | ||
239 | * @param bandwidth_in assigned inbound bandwidth for the connection | ||
240 | * @param ats performance data for the address (as far as known) | ||
241 | * @param ats_count number of performance records in 'ats' | ||
232 | */ | 242 | */ |
233 | static void | 243 | static void |
234 | update_latencies (const struct GNUNET_ATS_Information *atsi, | 244 | update_latencies (void *cls, |
235 | unsigned int atsi_count) | 245 | const struct GNUNET_HELLO_Address *address, |
246 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
247 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | ||
248 | const struct GNUNET_ATS_Information *ats, | ||
249 | uint32_t ats_count) | ||
236 | { | 250 | { |
237 | unsigned int i; | 251 | unsigned int i; |
252 | struct GNUNET_TIME_Relative latency; | ||
238 | 253 | ||
239 | for (i = 0; i < atsi_count; i++) | 254 | // FIXME: if (GNUNET_YES != current_address) return; |
255 | for (i = 0; i < ats_count; i++) | ||
240 | { | 256 | { |
241 | if (ntohl (atsi[i].type) == GNUNET_ATS_QUALITY_NET_DELAY) | 257 | if (GNUNET_ATS_QUALITY_NET_DELAY != ntohl (ats[i].type)) |
242 | { | 258 | continue; |
243 | GSF_avg_latency.rel_value = | 259 | latency.rel_value = ntohl (ats[i].value); |
244 | (GSF_avg_latency.rel_value * 31 + | 260 | GSF_update_peer_latency_ (&address->peer, |
245 | GNUNET_MIN (5000, ntohl (atsi[i].value))) / 32; | 261 | latency); |
246 | GNUNET_STATISTICS_set (GSF_stats, | 262 | GSF_avg_latency.rel_value = |
247 | gettext_noop | 263 | (GSF_avg_latency.rel_value * 31 + |
248 | ("# running average P2P latency (ms)"), | 264 | GNUNET_MIN (5000, ntohl (ats[i].value))) / 32; |
249 | GSF_avg_latency.rel_value, GNUNET_NO); | 265 | GNUNET_STATISTICS_set (GSF_stats, |
250 | break; | 266 | gettext_noop |
251 | } | 267 | ("# running average P2P latency (ms)"), |
268 | GSF_avg_latency.rel_value, GNUNET_NO); | ||
269 | break; | ||
252 | } | 270 | } |
253 | } | 271 | } |
254 | 272 | ||
@@ -276,8 +294,6 @@ handle_p2p_put (void *cls, const struct GNUNET_PeerIdentity *other, | |||
276 | return GNUNET_OK; | 294 | return GNUNET_OK; |
277 | } | 295 | } |
278 | GSF_cover_content_count++; | 296 | GSF_cover_content_count++; |
279 | fprintf (stderr, "FIX ATS DATA: %s:%u!\n", __FILE__, __LINE__); | ||
280 | update_latencies (NULL, 0); | ||
281 | return GSF_handle_p2p_content_ (cp, message); | 297 | return GSF_handle_p2p_content_ (cp, message); |
282 | } | 298 | } |
283 | 299 | ||
@@ -353,8 +369,6 @@ handle_p2p_get (void *cls, const struct GNUNET_PeerIdentity *other, | |||
353 | return GNUNET_SYSERR; | 369 | return GNUNET_SYSERR; |
354 | GSF_pending_request_get_data_ (pr)->has_started = GNUNET_YES; | 370 | GSF_pending_request_get_data_ (pr)->has_started = GNUNET_YES; |
355 | GSF_local_lookup_ (pr, &consider_forwarding, NULL); | 371 | GSF_local_lookup_ (pr, &consider_forwarding, NULL); |
356 | fprintf (stderr, "FIX ATS DATA: %s:%u!\n", __FILE__, __LINE__); | ||
357 | update_latencies (NULL, 0); | ||
358 | return GNUNET_OK; | 372 | return GNUNET_OK; |
359 | } | 373 | } |
360 | 374 | ||
@@ -463,6 +477,11 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
463 | GNUNET_CORE_disconnect (GSF_core); | 477 | GNUNET_CORE_disconnect (GSF_core); |
464 | GSF_core = NULL; | 478 | GSF_core = NULL; |
465 | } | 479 | } |
480 | if (NULL != GSF_ats) | ||
481 | { | ||
482 | GNUNET_ATS_performance_done (GSF_ats); | ||
483 | GSF_ats = NULL; | ||
484 | } | ||
466 | GSF_put_done_ (); | 485 | GSF_put_done_ (); |
467 | GSF_push_done_ (); | 486 | GSF_push_done_ (); |
468 | GSF_pending_request_done_ (); | 487 | GSF_pending_request_done_ (); |
@@ -534,8 +553,7 @@ peer_connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
534 | 553 | ||
535 | if (0 == memcmp (&my_id, peer, sizeof (struct GNUNET_PeerIdentity))) | 554 | if (0 == memcmp (&my_id, peer, sizeof (struct GNUNET_PeerIdentity))) |
536 | return; | 555 | return; |
537 | fprintf (stderr, "FIX ATS DATA: %s:%u!\n", __FILE__, __LINE__); | 556 | cp = GSF_peer_connect_handler_ (peer); |
538 | cp = GSF_peer_connect_handler_ (peer, NULL, 0); | ||
539 | if (NULL == cp) | 557 | if (NULL == cp) |
540 | return; | 558 | return; |
541 | GSF_iterate_pending_requests_ (&consider_peer_for_forwarding, cp); | 559 | GSF_iterate_pending_requests_ (&consider_peer_for_forwarding, cp); |
@@ -672,6 +690,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
672 | GSF_plan_init (); | 690 | GSF_plan_init (); |
673 | GSF_pending_request_init_ (); | 691 | GSF_pending_request_init_ (); |
674 | GSF_connected_peer_init_ (); | 692 | GSF_connected_peer_init_ (); |
693 | GSF_ats = GNUNET_ATS_performance_init (GSF_cfg, &update_latencies, NULL); | ||
675 | GSF_push_init_ (); | 694 | GSF_push_init_ (); |
676 | GSF_put_init_ (); | 695 | GSF_put_init_ (); |
677 | if ((GNUNET_OK != GNUNET_FS_indexing_init (cfg, GSF_dsh)) || | 696 | if ((GNUNET_OK != GNUNET_FS_indexing_init (cfg, GSF_dsh)) || |