aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/fs/gnunet-service-fs.c65
-rw-r--r--src/fs/gnunet-service-fs.h7
-rw-r--r--src/fs/gnunet-service-fs_cp.c65
-rw-r--r--src/fs/gnunet-service-fs_cp.h17
4 files changed, 75 insertions, 79 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;
101struct GNUNET_TIME_Relative GSF_avg_latency = { 500 }; 101struct GNUNET_TIME_Relative GSF_avg_latency = { 500 };
102 102
103/** 103/**
104 * Handle to ATS service.
105 */
106struct 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 */
233static void 243static void
234update_latencies (const struct GNUNET_ATS_Information *atsi, 244update_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)) ||
diff --git a/src/fs/gnunet-service-fs.h b/src/fs/gnunet-service-fs.h
index 60075e097..8830058e9 100644
--- a/src/fs/gnunet-service-fs.h
+++ b/src/fs/gnunet-service-fs.h
@@ -31,6 +31,7 @@
31#include "gnunet_transport_service.h" 31#include "gnunet_transport_service.h"
32#include "gnunet_core_service.h" 32#include "gnunet_core_service.h"
33#include "gnunet_block_lib.h" 33#include "gnunet_block_lib.h"
34#include "gnunet_ats_service.h"
34#include "fs.h" 35#include "fs.h"
35 36
36 37
@@ -218,6 +219,12 @@ extern struct GNUNET_LOAD_Value *GSF_rt_entry_lifetime;
218extern struct GNUNET_TIME_Relative GSF_avg_latency; 219extern struct GNUNET_TIME_Relative GSF_avg_latency;
219 220
220/** 221/**
222 * Handle to ATS service.
223 */
224extern struct GNUNET_ATS_PerformanceHandle *GSF_ats;
225
226
227/**
221 * Typical priorities we're seeing from other peers right now. Since 228 * Typical priorities we're seeing from other peers right now. Since
222 * most priorities will be zero, this value is the weighted average of 229 * most priorities will be zero, this value is the weighted average of
223 * non-zero priorities seen "recently". In order to ensure that new 230 * 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 f33b97d81..c9e61d5d4 100644
--- a/src/fs/gnunet-service-fs_cp.c
+++ b/src/fs/gnunet-service-fs_cp.c
@@ -25,7 +25,6 @@
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_load_lib.h" 27#include "gnunet_load_lib.h"
28#include "gnunet_ats_service.h"
29#include "gnunet-service-fs.h" 28#include "gnunet-service-fs.h"
30#include "gnunet-service-fs_cp.h" 29#include "gnunet-service-fs_cp.h"
31#include "gnunet-service-fs_pe.h" 30#include "gnunet-service-fs_pe.h"
@@ -315,11 +314,6 @@ static struct GNUNET_CONTAINER_MultiHashMap *cp_map;
315 */ 314 */
316static char *respectDirectory; 315static char *respectDirectory;
317 316
318/**
319 * Handle to ATS service.
320 */
321static struct GNUNET_ATS_PerformanceHandle *ats;
322
323 317
324/** 318/**
325 * Get the filename under which we would store respect 319 * Get the filename under which we would store respect
@@ -341,39 +335,18 @@ get_respect_filename (const struct GNUNET_PeerIdentity *id)
341 335
342 336
343/** 337/**
344 * Find latency information in 'atsi'. 338 * Update the latency information kept for the given peer.
345 * 339 *
346 * @param atsi performance data 340 * @param id peer record to update
347 * @param atsi_count number of records in 'atsi' 341 * @param latency current latency value
348 * @return connection latency
349 */ 342 */
350static struct GNUNET_TIME_Relative 343void
351get_latency (const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) 344GSF_update_peer_latency_ (const struct GNUNET_PeerIdentity *id,
352{ 345 struct GNUNET_TIME_Relative latency)
353 unsigned int i;
354
355 for (i = 0; i < atsi_count; i++)
356 if (ntohl (atsi->type) == GNUNET_ATS_QUALITY_NET_DELAY)
357 return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
358 ntohl (atsi->value));
359 return GNUNET_TIME_UNIT_SECONDS;
360}
361
362
363/**
364 * Update the performance information kept for the given peer.
365 *
366 * @param cp peer record to update
367 * @param atsi transport performance data
368 * @param atsi_count number of records in 'atsi'
369 */
370static void
371update_atsi (struct GSF_ConnectedPeer *cp,
372 const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count)
373{ 346{
374 struct GNUNET_TIME_Relative latency; 347 struct GSF_ConnectedPeer *cp;
375 348
376 latency = get_latency (atsi, atsi_count); 349 cp = GSF_peer_get_ (id);
377 GNUNET_LOAD_value_set_decline (cp->ppd.transmission_delay, latency); 350 GNUNET_LOAD_value_set_decline (cp->ppd.transmission_delay, latency);
378 /* LATER: merge atsi into cp's performance data (if we ever care...) */ 351 /* LATER: merge atsi into cp's performance data (if we ever care...) */
379} 352}
@@ -439,7 +412,7 @@ schedule_transmission (struct GSF_PeerTransmitHandle *pth)
439 412
440 if (0 != cp->inc_preference) 413 if (0 != cp->inc_preference)
441 { 414 {
442 GNUNET_ATS_change_preference (ats, &target, GNUNET_ATS_PREFERENCE_BANDWIDTH, 415 GNUNET_ATS_change_preference (GSF_ats, &target, GNUNET_ATS_PREFERENCE_BANDWIDTH,
443 (double) cp->inc_preference, 416 (double) cp->inc_preference,
444 GNUNET_ATS_PREFERENCE_END); 417 GNUNET_ATS_PREFERENCE_END);
445 cp->inc_preference = 0; 418 cp->inc_preference = 0;
@@ -454,7 +427,7 @@ schedule_transmission (struct GSF_PeerTransmitHandle *pth)
454 /* reservation already done! */ 427 /* reservation already done! */
455 pth->was_reserved = GNUNET_YES; 428 pth->was_reserved = GNUNET_YES;
456 cp->rc = 429 cp->rc =
457 GNUNET_ATS_reserve_bandwidth (ats, &target, DBLOCK_SIZE, 430 GNUNET_ATS_reserve_bandwidth (GSF_ats, &target, DBLOCK_SIZE,
458 &ats_reserve_callback, cp); 431 &ats_reserve_callback, cp);
459 return; 432 return;
460 } 433 }
@@ -540,8 +513,8 @@ retry_reservation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
540 GNUNET_PEER_resolve (cp->ppd.pid, &target); 513 GNUNET_PEER_resolve (cp->ppd.pid, &target);
541 cp->rc_delay_task = GNUNET_SCHEDULER_NO_TASK; 514 cp->rc_delay_task = GNUNET_SCHEDULER_NO_TASK;
542 cp->rc = 515 cp->rc =
543 GNUNET_ATS_reserve_bandwidth (ats, &target, DBLOCK_SIZE, 516 GNUNET_ATS_reserve_bandwidth (GSF_ats, &target, DBLOCK_SIZE,
544 &ats_reserve_callback, cp); 517 &ats_reserve_callback, cp);
545} 518}
546 519
547 520
@@ -595,14 +568,10 @@ ats_reserve_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
595 * records. 568 * records.
596 * 569 *
597 * @param peer identity of peer that connected 570 * @param peer identity of peer that connected
598 * @param atsi performance data for the connection
599 * @param atsi_count number of records in 'atsi'
600 * @return handle to connected peer entry 571 * @return handle to connected peer entry
601 */ 572 */
602struct GSF_ConnectedPeer * 573struct GSF_ConnectedPeer *
603GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer, 574GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer)
604 const struct GNUNET_ATS_Information *atsi,
605 unsigned int atsi_count)
606{ 575{
607 struct GSF_ConnectedPeer *cp; 576 struct GSF_ConnectedPeer *cp;
608 char *fn; 577 char *fn;
@@ -614,7 +583,7 @@ GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer,
614 cp->ppd.pid = GNUNET_PEER_intern (peer); 583 cp->ppd.pid = GNUNET_PEER_intern (peer);
615 cp->ppd.transmission_delay = GNUNET_LOAD_value_init (GNUNET_TIME_UNIT_ZERO); 584 cp->ppd.transmission_delay = GNUNET_LOAD_value_init (GNUNET_TIME_UNIT_ZERO);
616 cp->rc = 585 cp->rc =
617 GNUNET_ATS_reserve_bandwidth (ats, peer, DBLOCK_SIZE, 586 GNUNET_ATS_reserve_bandwidth (GSF_ats, peer, DBLOCK_SIZE,
618 &ats_reserve_callback, cp); 587 &ats_reserve_callback, cp);
619 fn = get_respect_filename (peer); 588 fn = get_respect_filename (peer);
620 if ((GNUNET_YES == GNUNET_DISK_file_test (fn)) && 589 if ((GNUNET_YES == GNUNET_DISK_file_test (fn)) &&
@@ -630,7 +599,6 @@ GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer,
630 GNUNET_STATISTICS_set (GSF_stats, gettext_noop ("# peers connected"), 599 GNUNET_STATISTICS_set (GSF_stats, gettext_noop ("# peers connected"),
631 GNUNET_CONTAINER_multihashmap_size (cp_map), 600 GNUNET_CONTAINER_multihashmap_size (cp_map),
632 GNUNET_NO); 601 GNUNET_NO);
633 update_atsi (cp, atsi, atsi_count);
634 GSF_push_start_ (cp); 602 GSF_push_start_ (cp);
635 return cp; 603 return cp;
636} 604}
@@ -718,8 +686,6 @@ GSF_handle_p2p_migration_stop_ (void *cls,
718 cp->mig_revive_task = 686 cp->mig_revive_task =
719 GNUNET_SCHEDULER_add_delayed (bt, &revive_migration, cp); 687 GNUNET_SCHEDULER_add_delayed (bt, &revive_migration, cp);
720 } 688 }
721 fprintf (stderr, "FIX ATS DATA: %s:%u!\n", __FILE__, __LINE__);
722 update_atsi (cp, NULL, 0);
723 return GNUNET_OK; 689 return GNUNET_OK;
724} 690}
725 691
@@ -1821,7 +1787,6 @@ void
1821GSF_connected_peer_init_ () 1787GSF_connected_peer_init_ ()
1822{ 1788{
1823 cp_map = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_YES); 1789 cp_map = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_YES);
1824 ats = GNUNET_ATS_performance_init (GSF_cfg, NULL, NULL);
1825 GNUNET_assert (GNUNET_OK == 1790 GNUNET_assert (GNUNET_OK ==
1826 GNUNET_CONFIGURATION_get_value_filename (GSF_cfg, "fs", 1791 GNUNET_CONFIGURATION_get_value_filename (GSF_cfg, "fs",
1827 "RESPECT", 1792 "RESPECT",
@@ -1860,8 +1825,6 @@ GSF_connected_peer_done_ ()
1860 cp_map = NULL; 1825 cp_map = NULL;
1861 GNUNET_free (respectDirectory); 1826 GNUNET_free (respectDirectory);
1862 respectDirectory = NULL; 1827 respectDirectory = NULL;
1863 GNUNET_ATS_performance_done (ats);
1864 ats = NULL;
1865} 1828}
1866 1829
1867 1830
diff --git a/src/fs/gnunet-service-fs_cp.h b/src/fs/gnunet-service-fs_cp.h
index 365548665..84668d301 100644
--- a/src/fs/gnunet-service-fs_cp.h
+++ b/src/fs/gnunet-service-fs_cp.h
@@ -200,14 +200,10 @@ struct GSF_PeerTransmitHandle;
200 * records. 200 * records.
201 * 201 *
202 * @param peer identity of peer that connected 202 * @param peer identity of peer that connected
203 * @param atsi performance data for the connection
204 * @param atsi_count number of records in 'atsi'
205 * @return handle to connected peer entry 203 * @return handle to connected peer entry
206 */ 204 */
207struct GSF_ConnectedPeer * 205struct GSF_ConnectedPeer *
208GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer, 206GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer);
209 const struct GNUNET_ATS_Information *atsi,
210 unsigned int atsi_count);
211 207
212 208
213/** 209/**
@@ -221,6 +217,17 @@ GSF_peer_get_ (const struct GNUNET_PeerIdentity *peer);
221 217
222 218
223/** 219/**
220 * Update the latency information kept for the given peer.
221 *
222 * @param id peer record to update
223 * @param latency current latency value
224 */
225void
226GSF_update_peer_latency_ (const struct GNUNET_PeerIdentity *id,
227 struct GNUNET_TIME_Relative latency);
228
229
230/**
224 * Transmit a message to the given peer as soon as possible. 231 * Transmit a message to the given peer as soon as possible.
225 * If the peer disconnects before the transmission can happen, 232 * If the peer disconnects before the transmission can happen,
226 * the callback is invoked with a 'NULL' buffer. 233 * the callback is invoked with a 'NULL' buffer.