From 9767d2478ccb8dcc3152cb617d84cd4cec2097c3 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 10 Oct 2011 11:06:33 +0000 Subject: [PATCH] renaming in code to use new ATS pref/reservation API --- src/dht/Makefile.am | 1 + src/dht/gnunet-service-dht_neighbours.c | 23 +++++++++++----- src/fs/Makefile.am | 1 + src/fs/gnunet-service-fs_cp.c | 36 +++++++++++++++---------- 4 files changed, 40 insertions(+), 21 deletions(-) diff --git a/src/dht/Makefile.am b/src/dht/Makefile.am index a88611fb3..ba8b8457c 100644 --- a/src/dht/Makefile.am +++ b/src/dht/Makefile.am @@ -44,6 +44,7 @@ gnunet_service_dht_LDADD = \ $(top_builddir)/src/statistics/libgnunetstatistics.la \ $(top_builddir)/src/core/libgnunetcore.la \ $(top_builddir)/src/nse/libgnunetnse.la \ + $(top_builddir)/src/ats/libgnunetats.la \ $(top_builddir)/src/transport/libgnunettransport.la \ $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \ $(top_builddir)/src/hello/libgnunethello.la \ diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c index 0623c0cb1..e1421e0f6 100644 --- a/src/dht/gnunet-service-dht_neighbours.c +++ b/src/dht/gnunet-service-dht_neighbours.c @@ -32,6 +32,7 @@ #include "gnunet_constants.h" #include "gnunet_protocols.h" #include "gnunet_nse_service.h" +#include "gnunet_ats_service.h" #include "gnunet_core_service.h" #include "gnunet_datacache_lib.h" #include "gnunet_transport_service.h" @@ -321,7 +322,7 @@ struct PeerInfo /** * Preference update context */ - struct GNUNET_CORE_InformationRequestContext *info_ctx; + struct GNUNET_ATS_InformationRequestContext *info_ctx; /** * Task for scheduling preference updates @@ -407,10 +408,15 @@ static GNUNET_SCHEDULER_TaskIdentifier find_peer_task; static struct GNUNET_PeerIdentity my_identity; /** - * Handle to GNUnet core. + * Handle to CORE. */ static struct GNUNET_CORE_Handle *coreAPI; +/** + * Handle to ATS. + */ +static struct GNUNET_ATS_Handle *atsAPI; + /** @@ -514,10 +520,10 @@ update_core_preference (void *cls, gettext_noop ("# Preference updates given to core"), 1, GNUNET_NO); peer->info_ctx = - GNUNET_CORE_peer_change_preference (coreAPI, &peer->id, - 0, - preference, - &update_core_preference_finish, peer); + GNUNET_ATS_peer_change_preference (atsAPI, &peer->id, + 0, + preference, + &update_core_preference_finish, peer); } @@ -725,7 +731,7 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) to_remove)); if (NULL != to_remove->info_ctx) { - GNUNET_CORE_peer_change_preference_cancel (to_remove->info_ctx); + GNUNET_ATS_peer_change_preference_cancel (to_remove->info_ctx); to_remove->info_ctx = NULL; } if (GNUNET_SCHEDULER_NO_TASK != to_remove->preference_task) @@ -2040,6 +2046,7 @@ GDS_NEIGHBOURS_init () GNUNET_CONFIGURATION_get_value_number (GDS_cfg, "DHT", "bucket_size", &temp_config_num)) bucket_size = (unsigned int) temp_config_num; + atsAPI = GNUNET_ATS_init (GDS_cfg, NULL, NULL); coreAPI = GNUNET_CORE_connect (GDS_cfg, 1, NULL, @@ -2067,6 +2074,8 @@ GDS_NEIGHBOURS_done () return; GNUNET_CORE_disconnect (coreAPI); coreAPI = NULL; + GNUNET_ATS_shutdown (atsAPI); + atsAPI = NULL; GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (all_known_peers)); GNUNET_CONTAINER_multihashmap_destroy (all_known_peers); all_known_peers = NULL; diff --git a/src/fs/Makefile.am b/src/fs/Makefile.am index ae8d699a1..85e3a4539 100644 --- a/src/fs/Makefile.am +++ b/src/fs/Makefile.am @@ -119,6 +119,7 @@ gnunet_service_fs_LDADD = \ $(top_builddir)/src/block/libgnunetblock.la \ $(top_builddir)/src/datastore/libgnunetdatastore.la \ $(top_builddir)/src/statistics/libgnunetstatistics.la \ + $(top_builddir)/src/ats/libgnunetats.la \ $(top_builddir)/src/core/libgnunetcore.la \ $(top_builddir)/src/util/libgnunetutil.la \ $(GN_LIBINTL) diff --git a/src/fs/gnunet-service-fs_cp.c b/src/fs/gnunet-service-fs_cp.c index ed855c42e..05e5bedef 100644 --- a/src/fs/gnunet-service-fs_cp.c +++ b/src/fs/gnunet-service-fs_cp.c @@ -25,6 +25,7 @@ */ #include "platform.h" #include "gnunet_load_lib.h" +#include "gnunet_ats_service.h" #include "gnunet-service-fs.h" #include "gnunet-service-fs_cp.h" #include "gnunet-service-fs_pe.h" @@ -240,9 +241,9 @@ struct GSF_ConnectedPeer struct GSF_PeerTransmitHandle *migration_pth; /** - * Context of our GNUNET_CORE_peer_change_preference call (or NULL). + * Context of our GNUNET_ATS_peer_change_preference call (or NULL). */ - struct GNUNET_CORE_InformationRequestContext *irc; + struct GNUNET_ATS_InformationRequestContext *irc; /** * Task scheduled if we need to retry bandwidth reservation later. @@ -301,6 +302,10 @@ static struct GNUNET_CONTAINER_MultiHashMap *cp_map; */ static char *trustDirectory; +/** + * Handle to ATS service. + */ +static struct GNUNET_ATS_Handle *ats; /** * Get the filename under which we would store the GNUNET_HELLO_Message @@ -399,7 +404,7 @@ peer_transmit_ready_cb (void *cls, size_t size, void *buf); * long should the client wait until re-trying? */ static void -core_reserve_callback (void *cls, const struct GNUNET_PeerIdentity *peer, +ats_reserve_callback (void *cls, const struct GNUNET_PeerIdentity *peer, int32_t amount, struct GNUNET_TIME_Relative res_delay); @@ -432,9 +437,9 @@ schedule_transmission (struct GSF_PeerTransmitHandle *pth) ip = cp->inc_preference; cp->inc_preference = 0; cp->irc = - GNUNET_CORE_peer_change_preference (GSF_core, &target, - DBLOCK_SIZE, ip, - &core_reserve_callback, cp); + GNUNET_ATS_peer_change_preference (ats, &target, + DBLOCK_SIZE, ip, + &ats_reserve_callback, cp); } GNUNET_assert (pth->cth == NULL); pth->cth_in_progress++; @@ -518,9 +523,9 @@ retry_reservation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) ip = cp->inc_preference; cp->inc_preference = 0; cp->irc = - GNUNET_CORE_peer_change_preference (GSF_core, &target, - DBLOCK_SIZE, ip, - &core_reserve_callback, cp); + GNUNET_ATS_peer_change_preference (ats, &target, + DBLOCK_SIZE, ip, + &ats_reserve_callback, cp); } @@ -535,7 +540,7 @@ retry_reservation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) * long should the client wait until re-trying? */ static void -core_reserve_callback (void *cls, const struct GNUNET_PeerIdentity *peer, +ats_reserve_callback (void *cls, const struct GNUNET_PeerIdentity *peer, int32_t amount, struct GNUNET_TIME_Relative res_delay) { struct GSF_ConnectedPeer *cp = cls; @@ -584,9 +589,9 @@ GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer, cp->ppd.pid = GNUNET_PEER_intern (peer); cp->ppd.transmission_delay = GNUNET_LOAD_value_init (GNUNET_TIME_UNIT_ZERO); cp->irc = - GNUNET_CORE_peer_change_preference (GSF_core, peer, - DBLOCK_SIZE, 0, - &core_reserve_callback, cp); + GNUNET_ATS_peer_change_preference (ats, peer, + DBLOCK_SIZE, 0, + &ats_reserve_callback, cp); fn = get_trust_filename (peer); if ((GNUNET_DISK_file_test (fn) == GNUNET_YES) && (sizeof (trust) == GNUNET_DISK_fn_read (fn, &trust, sizeof (trust)))) @@ -1551,7 +1556,7 @@ GSF_peer_disconnect_handler_ (void *cls, const struct GNUNET_PeerIdentity *peer) } if (NULL != cp->irc) { - GNUNET_CORE_peer_change_preference_cancel (cp->irc); + GNUNET_ATS_peer_change_preference_cancel (cp->irc); cp->irc = NULL; } if (GNUNET_SCHEDULER_NO_TASK != cp->irc_delay_task) @@ -1825,6 +1830,7 @@ void GSF_connected_peer_init_ () { cp_map = GNUNET_CONTAINER_multihashmap_create (128); + ats = GNUNET_ATS_init (GSF_cfg, NULL, NULL); GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (GSF_cfg, "fs", "TRUST", @@ -1863,6 +1869,8 @@ GSF_connected_peer_done_ () cp_map = NULL; GNUNET_free (trustDirectory); trustDirectory = NULL; + GNUNET_ATS_shutdown (ats); + ats = NULL; } -- 2.25.1