diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-10-13 17:00:28 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-10-13 17:00:28 +0000 |
commit | 84f3cda88dcd6a8e53a207072e53355d6036a9eb (patch) | |
tree | 3c5796faacdb1f68b8bfeaee5e7faeb667395987 | |
parent | a60505ab28e2278e8d1e438005bb877fcf5e0710 (diff) | |
download | gnunet-84f3cda88dcd6a8e53a207072e53355d6036a9eb.tar.gz gnunet-84f3cda88dcd6a8e53a207072e53355d6036a9eb.zip |
adapting code to new ATS APIs
-rw-r--r-- | src/dht/gnunet-service-dht_neighbours.c | 66 | ||||
-rw-r--r-- | src/fs/gnunet-service-fs_cp.c | 73 |
2 files changed, 51 insertions, 88 deletions
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c index 902f3029c..265bcdeef 100644 --- a/src/dht/gnunet-service-dht_neighbours.c +++ b/src/dht/gnunet-service-dht_neighbours.c | |||
@@ -320,11 +320,6 @@ struct PeerInfo | |||
320 | struct GNUNET_CORE_TransmitHandle *th; | 320 | struct GNUNET_CORE_TransmitHandle *th; |
321 | 321 | ||
322 | /** | 322 | /** |
323 | * Preference update context | ||
324 | */ | ||
325 | struct GNUNET_ATS_InformationRequestContext *info_ctx; | ||
326 | |||
327 | /** | ||
328 | * Task for scheduling preference updates | 323 | * Task for scheduling preference updates |
329 | */ | 324 | */ |
330 | GNUNET_SCHEDULER_TaskIdentifier preference_task; | 325 | GNUNET_SCHEDULER_TaskIdentifier preference_task; |
@@ -415,7 +410,7 @@ static struct GNUNET_CORE_Handle *coreAPI; | |||
415 | /** | 410 | /** |
416 | * Handle to ATS. | 411 | * Handle to ATS. |
417 | */ | 412 | */ |
418 | static struct GNUNET_ATS_SchedulingHandle *atsAPI; | 413 | static struct GNUNET_ATS_PerformanceHandle *atsAPI; |
419 | 414 | ||
420 | 415 | ||
421 | 416 | ||
@@ -450,42 +445,6 @@ find_bucket (const GNUNET_HashCode * hc) | |||
450 | */ | 445 | */ |
451 | static void | 446 | static void |
452 | update_core_preference (void *cls, | 447 | update_core_preference (void *cls, |
453 | const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
454 | |||
455 | |||
456 | /** | ||
457 | * Function called with statistics about the given peer. | ||
458 | * | ||
459 | * @param cls closure | ||
460 | * @param peer identifies the peer | ||
461 | * @param amount set to the amount that was actually reserved or unreserved; | ||
462 | * either the full requested amount or zero (no partial reservations) | ||
463 | * @param res_delay if the reservation could not be satisfied (amount was 0), how | ||
464 | * long should the client wait until re-trying? | ||
465 | */ | ||
466 | static void | ||
467 | update_core_preference_finish (void *cls, | ||
468 | const struct GNUNET_PeerIdentity *peer, | ||
469 | int32_t amount, | ||
470 | struct GNUNET_TIME_Relative res_delay) | ||
471 | { | ||
472 | struct PeerInfo *peer_info = cls; | ||
473 | |||
474 | peer_info->info_ctx = NULL; | ||
475 | peer_info->preference_task | ||
476 | = GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PREFERENCE_INTERVAL, | ||
477 | &update_core_preference, peer_info); | ||
478 | } | ||
479 | |||
480 | |||
481 | /** | ||
482 | * Let GNUnet core know that we like the given peer. | ||
483 | * | ||
484 | * @param cls the 'struct PeerInfo' of the peer | ||
485 | * @param tc scheduler context. | ||
486 | */ | ||
487 | static void | ||
488 | update_core_preference (void *cls, | ||
489 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 448 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
490 | { | 449 | { |
491 | struct PeerInfo *peer = cls; | 450 | struct PeerInfo *peer = cls; |
@@ -519,11 +478,15 @@ update_core_preference (void *cls, | |||
519 | GNUNET_STATISTICS_update (GDS_stats, | 478 | GNUNET_STATISTICS_update (GDS_stats, |
520 | gettext_noop ("# Preference updates given to core"), 1, | 479 | gettext_noop ("# Preference updates given to core"), 1, |
521 | GNUNET_NO); | 480 | GNUNET_NO); |
522 | peer->info_ctx = | 481 | GNUNET_ATS_change_preference (atsAPI, &peer->id, |
523 | GNUNET_ATS_peer_change_preference (atsAPI, &peer->id, | 482 | GNUNET_ATS_PREFERENCE_BANDWIDTH, |
524 | 0, | 483 | (double) preference, |
525 | preference, | 484 | GNUNET_ATS_PREFERENCE_END); |
526 | &update_core_preference_finish, peer); | 485 | peer->preference_task |
486 | = GNUNET_SCHEDULER_add_delayed (DHT_DEFAULT_PREFERENCE_INTERVAL, | ||
487 | &update_core_preference, peer); | ||
488 | |||
489 | |||
527 | } | 490 | } |
528 | 491 | ||
529 | 492 | ||
@@ -729,11 +692,6 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
729 | GNUNET_CONTAINER_multihashmap_remove (all_known_peers, | 692 | GNUNET_CONTAINER_multihashmap_remove (all_known_peers, |
730 | &peer->hashPubKey, | 693 | &peer->hashPubKey, |
731 | to_remove)); | 694 | to_remove)); |
732 | if (NULL != to_remove->info_ctx) | ||
733 | { | ||
734 | GNUNET_ATS_peer_change_preference_cancel (to_remove->info_ctx); | ||
735 | to_remove->info_ctx = NULL; | ||
736 | } | ||
737 | if (GNUNET_SCHEDULER_NO_TASK != to_remove->preference_task) | 695 | if (GNUNET_SCHEDULER_NO_TASK != to_remove->preference_task) |
738 | { | 696 | { |
739 | GNUNET_SCHEDULER_cancel (to_remove->preference_task); | 697 | GNUNET_SCHEDULER_cancel (to_remove->preference_task); |
@@ -2050,7 +2008,7 @@ GDS_NEIGHBOURS_init () | |||
2050 | GNUNET_CONFIGURATION_get_value_number (GDS_cfg, "DHT", "bucket_size", | 2008 | GNUNET_CONFIGURATION_get_value_number (GDS_cfg, "DHT", "bucket_size", |
2051 | &temp_config_num)) | 2009 | &temp_config_num)) |
2052 | bucket_size = (unsigned int) temp_config_num; | 2010 | bucket_size = (unsigned int) temp_config_num; |
2053 | atsAPI = GNUNET_ATS_init (GDS_cfg, NULL, NULL); | 2011 | atsAPI = GNUNET_ATS_performance_init (GDS_cfg, NULL, NULL); |
2054 | coreAPI = GNUNET_CORE_connect (GDS_cfg, | 2012 | coreAPI = GNUNET_CORE_connect (GDS_cfg, |
2055 | 1, | 2013 | 1, |
2056 | NULL, | 2014 | NULL, |
@@ -2077,7 +2035,7 @@ GDS_NEIGHBOURS_done () | |||
2077 | return; | 2035 | return; |
2078 | GNUNET_CORE_disconnect (coreAPI); | 2036 | GNUNET_CORE_disconnect (coreAPI); |
2079 | coreAPI = NULL; | 2037 | coreAPI = NULL; |
2080 | GNUNET_ATS_shutdown (atsAPI); | 2038 | GNUNET_ATS_performance_done (atsAPI); |
2081 | atsAPI = NULL; | 2039 | atsAPI = NULL; |
2082 | GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (all_known_peers)); | 2040 | GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (all_known_peers)); |
2083 | GNUNET_CONTAINER_multihashmap_destroy (all_known_peers); | 2041 | GNUNET_CONTAINER_multihashmap_destroy (all_known_peers); |
diff --git a/src/fs/gnunet-service-fs_cp.c b/src/fs/gnunet-service-fs_cp.c index 8f4528cfb..3a2bdac70 100644 --- a/src/fs/gnunet-service-fs_cp.c +++ b/src/fs/gnunet-service-fs_cp.c | |||
@@ -241,14 +241,14 @@ struct GSF_ConnectedPeer | |||
241 | struct GSF_PeerTransmitHandle *migration_pth; | 241 | struct GSF_PeerTransmitHandle *migration_pth; |
242 | 242 | ||
243 | /** | 243 | /** |
244 | * Context of our GNUNET_ATS_peer_change_preference call (or NULL). | 244 | * Context of our GNUNET_ATS_reserve_bandwidth call (or NULL). |
245 | */ | 245 | */ |
246 | struct GNUNET_ATS_InformationRequestContext *irc; | 246 | struct GNUNET_ATS_ReservationContext *rc; |
247 | 247 | ||
248 | /** | 248 | /** |
249 | * Task scheduled if we need to retry bandwidth reservation later. | 249 | * Task scheduled if we need to retry bandwidth reservation later. |
250 | */ | 250 | */ |
251 | GNUNET_SCHEDULER_TaskIdentifier irc_delay_task; | 251 | GNUNET_SCHEDULER_TaskIdentifier rc_delay_task; |
252 | 252 | ||
253 | /** | 253 | /** |
254 | * Active requests from this neighbour, map of query to 'struct PeerRequest'. | 254 | * Active requests from this neighbour, map of query to 'struct PeerRequest'. |
@@ -305,7 +305,7 @@ static char *trustDirectory; | |||
305 | /** | 305 | /** |
306 | * Handle to ATS service. | 306 | * Handle to ATS service. |
307 | */ | 307 | */ |
308 | static struct GNUNET_ATS_SchedulingHandle *ats; | 308 | static struct GNUNET_ATS_PerformanceHandle *ats; |
309 | 309 | ||
310 | /** | 310 | /** |
311 | * Get the filename under which we would store the GNUNET_HELLO_Message | 311 | * Get the filename under which we would store the GNUNET_HELLO_Message |
@@ -419,13 +419,23 @@ schedule_transmission (struct GSF_PeerTransmitHandle *pth) | |||
419 | { | 419 | { |
420 | struct GSF_ConnectedPeer *cp; | 420 | struct GSF_ConnectedPeer *cp; |
421 | struct GNUNET_PeerIdentity target; | 421 | struct GNUNET_PeerIdentity target; |
422 | uint64_t ip; | ||
423 | 422 | ||
424 | if ((NULL != pth->cth) || (0 != pth->cth_in_progress)) | 423 | if ((NULL != pth->cth) || (0 != pth->cth_in_progress)) |
425 | return; /* already done */ | 424 | return; /* already done */ |
426 | cp = pth->cp; | 425 | cp = pth->cp; |
427 | GNUNET_assert (0 != cp->ppd.pid); | 426 | GNUNET_assert (0 != cp->ppd.pid); |
428 | GNUNET_PEER_resolve (cp->ppd.pid, &target); | 427 | GNUNET_PEER_resolve (cp->ppd.pid, &target); |
428 | |||
429 | if (0 != cp->inc_preference) | ||
430 | { | ||
431 | GNUNET_ATS_change_preference (ats, | ||
432 | &target, | ||
433 | GNUNET_ATS_PREFERENCE_BANDWIDTH, | ||
434 | (double) cp->inc_preference, | ||
435 | GNUNET_ATS_PREFERENCE_END); | ||
436 | cp->inc_preference = 0; | ||
437 | } | ||
438 | |||
429 | if ((GNUNET_YES == pth->is_query) && (GNUNET_YES != pth->was_reserved)) | 439 | if ((GNUNET_YES == pth->is_query) && (GNUNET_YES != pth->was_reserved)) |
430 | { | 440 | { |
431 | /* query, need reservation */ | 441 | /* query, need reservation */ |
@@ -434,12 +444,10 @@ schedule_transmission (struct GSF_PeerTransmitHandle *pth) | |||
434 | cp->did_reserve = GNUNET_NO; | 444 | cp->did_reserve = GNUNET_NO; |
435 | /* reservation already done! */ | 445 | /* reservation already done! */ |
436 | pth->was_reserved = GNUNET_YES; | 446 | pth->was_reserved = GNUNET_YES; |
437 | ip = cp->inc_preference; | 447 | cp->rc = |
438 | cp->inc_preference = 0; | 448 | GNUNET_ATS_reserve_bandwidth (ats, &target, |
439 | cp->irc = | 449 | DBLOCK_SIZE, |
440 | GNUNET_ATS_peer_change_preference (ats, &target, | 450 | &ats_reserve_callback, cp); |
441 | DBLOCK_SIZE, ip, | ||
442 | &ats_reserve_callback, cp); | ||
443 | } | 451 | } |
444 | GNUNET_assert (pth->cth == NULL); | 452 | GNUNET_assert (pth->cth == NULL); |
445 | pth->cth_in_progress++; | 453 | pth->cth_in_progress++; |
@@ -515,17 +523,14 @@ static void | |||
515 | retry_reservation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 523 | retry_reservation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
516 | { | 524 | { |
517 | struct GSF_ConnectedPeer *cp = cls; | 525 | struct GSF_ConnectedPeer *cp = cls; |
518 | uint64_t ip; | ||
519 | struct GNUNET_PeerIdentity target; | 526 | struct GNUNET_PeerIdentity target; |
520 | 527 | ||
521 | GNUNET_PEER_resolve (cp->ppd.pid, &target); | 528 | GNUNET_PEER_resolve (cp->ppd.pid, &target); |
522 | cp->irc_delay_task = GNUNET_SCHEDULER_NO_TASK; | 529 | cp->rc_delay_task = GNUNET_SCHEDULER_NO_TASK; |
523 | ip = cp->inc_preference; | 530 | cp->rc = |
524 | cp->inc_preference = 0; | 531 | GNUNET_ATS_reserve_bandwidth (ats, &target, |
525 | cp->irc = | 532 | DBLOCK_SIZE, |
526 | GNUNET_ATS_peer_change_preference (ats, &target, | 533 | &ats_reserve_callback, cp); |
527 | DBLOCK_SIZE, ip, | ||
528 | &ats_reserve_callback, cp); | ||
529 | } | 534 | } |
530 | 535 | ||
531 | 536 | ||
@@ -541,15 +546,15 @@ retry_reservation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
541 | */ | 546 | */ |
542 | static void | 547 | static void |
543 | ats_reserve_callback (void *cls, const struct GNUNET_PeerIdentity *peer, | 548 | ats_reserve_callback (void *cls, const struct GNUNET_PeerIdentity *peer, |
544 | int32_t amount, struct GNUNET_TIME_Relative res_delay) | 549 | int32_t amount, struct GNUNET_TIME_Relative res_delay) |
545 | { | 550 | { |
546 | struct GSF_ConnectedPeer *cp = cls; | 551 | struct GSF_ConnectedPeer *cp = cls; |
547 | struct GSF_PeerTransmitHandle *pth; | 552 | struct GSF_PeerTransmitHandle *pth; |
548 | 553 | ||
549 | cp->irc = NULL; | 554 | cp->rc = NULL; |
550 | if (0 == amount) | 555 | if (0 == amount) |
551 | { | 556 | { |
552 | cp->irc_delay_task = | 557 | cp->rc_delay_task = |
553 | GNUNET_SCHEDULER_add_delayed (res_delay, &retry_reservation, cp); | 558 | GNUNET_SCHEDULER_add_delayed (res_delay, &retry_reservation, cp); |
554 | return; | 559 | return; |
555 | } | 560 | } |
@@ -588,10 +593,10 @@ GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer, | |||
588 | cp = GNUNET_malloc (sizeof (struct GSF_ConnectedPeer)); | 593 | cp = GNUNET_malloc (sizeof (struct GSF_ConnectedPeer)); |
589 | cp->ppd.pid = GNUNET_PEER_intern (peer); | 594 | cp->ppd.pid = GNUNET_PEER_intern (peer); |
590 | cp->ppd.transmission_delay = GNUNET_LOAD_value_init (GNUNET_TIME_UNIT_ZERO); | 595 | cp->ppd.transmission_delay = GNUNET_LOAD_value_init (GNUNET_TIME_UNIT_ZERO); |
591 | cp->irc = | 596 | cp->rc = |
592 | GNUNET_ATS_peer_change_preference (ats, peer, | 597 | GNUNET_ATS_reserve_bandwidth (ats, peer, |
593 | DBLOCK_SIZE, 0, | 598 | DBLOCK_SIZE, |
594 | &ats_reserve_callback, cp); | 599 | &ats_reserve_callback, cp); |
595 | fn = get_trust_filename (peer); | 600 | fn = get_trust_filename (peer); |
596 | if ((GNUNET_DISK_file_test (fn) == GNUNET_YES) && | 601 | if ((GNUNET_DISK_file_test (fn) == GNUNET_YES) && |
597 | (sizeof (trust) == GNUNET_DISK_fn_read (fn, &trust, sizeof (trust)))) | 602 | (sizeof (trust) == GNUNET_DISK_fn_read (fn, &trust, sizeof (trust)))) |
@@ -1528,15 +1533,15 @@ GSF_peer_disconnect_handler_ (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
1528 | GSF_peer_transmit_cancel_ (cp->migration_pth); | 1533 | GSF_peer_transmit_cancel_ (cp->migration_pth); |
1529 | cp->migration_pth = NULL; | 1534 | cp->migration_pth = NULL; |
1530 | } | 1535 | } |
1531 | if (NULL != cp->irc) | 1536 | if (NULL != cp->rc) |
1532 | { | 1537 | { |
1533 | GNUNET_ATS_peer_change_preference_cancel (cp->irc); | 1538 | GNUNET_ATS_reserve_bandwidth_cancel (cp->rc); |
1534 | cp->irc = NULL; | 1539 | cp->rc = NULL; |
1535 | } | 1540 | } |
1536 | if (GNUNET_SCHEDULER_NO_TASK != cp->irc_delay_task) | 1541 | if (GNUNET_SCHEDULER_NO_TASK != cp->rc_delay_task) |
1537 | { | 1542 | { |
1538 | GNUNET_SCHEDULER_cancel (cp->irc_delay_task); | 1543 | GNUNET_SCHEDULER_cancel (cp->rc_delay_task); |
1539 | cp->irc_delay_task = GNUNET_SCHEDULER_NO_TASK; | 1544 | cp->rc_delay_task = GNUNET_SCHEDULER_NO_TASK; |
1540 | } | 1545 | } |
1541 | GNUNET_CONTAINER_multihashmap_iterate (cp->request_map, | 1546 | GNUNET_CONTAINER_multihashmap_iterate (cp->request_map, |
1542 | &cancel_pending_request, cp); | 1547 | &cancel_pending_request, cp); |
@@ -1804,7 +1809,7 @@ void | |||
1804 | GSF_connected_peer_init_ () | 1809 | GSF_connected_peer_init_ () |
1805 | { | 1810 | { |
1806 | cp_map = GNUNET_CONTAINER_multihashmap_create (128); | 1811 | cp_map = GNUNET_CONTAINER_multihashmap_create (128); |
1807 | ats = GNUNET_ATS_init (GSF_cfg, NULL, NULL); | 1812 | ats = GNUNET_ATS_performance_init (GSF_cfg, NULL, NULL); |
1808 | GNUNET_assert (GNUNET_OK == | 1813 | GNUNET_assert (GNUNET_OK == |
1809 | GNUNET_CONFIGURATION_get_value_filename (GSF_cfg, "fs", | 1814 | GNUNET_CONFIGURATION_get_value_filename (GSF_cfg, "fs", |
1810 | "TRUST", | 1815 | "TRUST", |
@@ -1843,7 +1848,7 @@ GSF_connected_peer_done_ () | |||
1843 | cp_map = NULL; | 1848 | cp_map = NULL; |
1844 | GNUNET_free (trustDirectory); | 1849 | GNUNET_free (trustDirectory); |
1845 | trustDirectory = NULL; | 1850 | trustDirectory = NULL; |
1846 | GNUNET_ATS_shutdown (ats); | 1851 | GNUNET_ATS_performance_done (ats); |
1847 | ats = NULL; | 1852 | ats = NULL; |
1848 | } | 1853 | } |
1849 | 1854 | ||