From 86ad1393cdf6c8b37437c330fce25ebfffbc8ffd Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 13 Oct 2011 11:59:13 +0000 Subject: [PATCH] new ATS API -- code won't compile --- src/ats/Makefile.am | 4 +- src/ats/ats.h | 210 ++++++++++++++++ src/ats/ats_api.c | 34 +-- src/ats/ats_api.h | 2 +- src/ats/ats_api_new.c | 129 ++++++++++ src/ats/ats_api_peer_change_preference.c | 10 +- src/ats/ats_api_performance.c | 128 ++++++++++ src/ats/test_ats_api.c | 2 +- src/ats/test_ats_api_update_address.c | 2 +- src/dht/gnunet-service-dht_neighbours.c | 2 +- src/fs/gnunet-service-fs_cp.c | 2 +- src/include/gnunet_ats_service.h | 294 +++++++++++++---------- src/include/gnunet_protocols.h | 21 ++ src/transport/gnunet-service-transport.c | 2 +- src/transport/gnunet-service-transport.h | 2 +- 15 files changed, 687 insertions(+), 157 deletions(-) create mode 100644 src/ats/ats.h create mode 100644 src/ats/ats_api_new.c create mode 100644 src/ats/ats_api_performance.c diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am index ca896147e..5adb5f3ef 100644 --- a/src/ats/Makefile.am +++ b/src/ats/Makefile.am @@ -11,8 +11,8 @@ endif lib_LTLIBRARIES = libgnunetats.la libgnunetats_la_SOURCES = \ - ats_api.c ats_api.h \ - ats_api_peer_change_preference.c + ats_api_new.c \ + ats_api_performance.c libgnunetats_la_LIBADD = \ $(top_builddir)/src/util/libgnunetutil.la diff --git a/src/ats/ats.h b/src/ats/ats.h new file mode 100644 index 000000000..317528cad --- /dev/null +++ b/src/ats/ats.h @@ -0,0 +1,210 @@ +/* + This file is part of GNUnet. + (C) 2010,2011 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +/** + * @file ats/ats.h + * @brief automatic transport selection messages + * @author Christian Grothoff + * @author Matthias Wachs + */ +#ifndef ATS_H +#define ATS_H + +#include "gnunet_util_lib.h" + + +enum StartFlag +{ + + START_FLAG_SCHEDULING = 0, + + START_FLAG_PERFORMANCE_WITH_PIC = 1, + + START_FLAG_PERFORMANCE_NO_PIC = 2 + +}; + + + +struct ClientStart +{ + struct GNUNET_MessageHeader header; + + /** + * NBO value of an 'enum StartFlag'. + */ + uint32_t start_flag; +}; + + + +struct RequestAddressMessage +{ + struct GNUNET_MessageHeader header; + + uint32_t reserved GNUNET_PACKED; + + struct GNUNET_PeerIdentity peer; +}; + +struct AddressUpdateMessage +{ + struct GNUNET_MessageHeader header; + + uint32_t ats_count GNUNET_PACKED; + + struct GNUNET_PeerIdentity peer; + + uint16_t address_length GNUNET_PACKED; + + uint16_t plugin_name_length GNUNET_PACKED; + + uint32_t session_id GNUNET_PACKED; + + /* followed by: + - struct GNUNET_TRANSPORT_ATS_Information [ats_count]; + - char address[address_length] + - char plugin_name[plugin_name_length] (including '\0'-termination). + */ + +}; + +struct AddressDestroyedMessage +{ + struct GNUNET_MessageHeader header; + + uint32_t reserved GNUNET_PACKED; + + struct GNUNET_PeerIdentity peer; + + uint16_t address_length GNUNET_PACKED; + + uint16_t plugin_name_length GNUNET_PACKED; + + uint32_t session_id GNUNET_PACKED; + + /* followed by: + - char address[address_length] + - char plugin_name[plugin_name_length] (including '\0'-termination). + */ + +}; + + +struct AddressSuggestionMessage +{ + struct GNUNET_MessageHeader header; + + uint32_t reserved GNUNET_PACKED; + + struct GNUNET_PeerIdentity peer; + + uint16_t address_length GNUNET_PACKED; + + uint16_t plugin_name_length GNUNET_PACKED; + + uint32_t session_id GNUNET_PACKED; + + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out; + + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in; + + /* followed by: + - char address[address_length] + - char plugin_name[plugin_name_length] (including '\0'-termination). + */ + +}; + + + +struct PeerInformationMessage +{ + struct GNUNET_MessageHeader header; + + uint32_t ats_count GNUNET_PACKED; + + struct GNUNET_PeerIdentity peer; + + uint16_t address_length GNUNET_PACKED; + + uint16_t plugin_name_length GNUNET_PACKED; + + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out; + + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in; + + /* followed by: + - struct GNUNET_TRANSPORT_ATS_Information [ats_count]; + - char address[address_length] + - char plugin_name[plugin_name_length] (including '\0'-termination). + */ + +}; + + + + +struct ReservationRequestMessage +{ + struct GNUNET_MessageHeader header; + + int32_t amount GNUNET_PACKED; + + struct GNUNET_PeerIdentity peer; +}; + + +struct ReservationResultMessage +{ + struct GNUNET_MessageHeader header; + + int32_t amount GNUNET_PACKED; + + struct GNUNET_PeerIdentity peer; + + struct GNUNET_TIME_RelativeNBO res_delay; +}; + + +struct PreferenceInformation +{ + + uint32_t preference_kind GNUNET_PACKED; + + float preference_value GNUNET_PACKED; + +}; + + +struct ChangePreferenceMessage +{ + struct GNUNET_MessageHeader header; + + uint32_t num_preferences GNUNET_PACKED; + + struct GNUNET_PeerIdentity peer; + + /* followed by 'num_preferences' + struct PreferenceInformation values */ +}; + + + +#endif diff --git a/src/ats/ats_api.c b/src/ats/ats_api.c index ef2fa1bed..29a273e3e 100644 --- a/src/ats/ats_api.c +++ b/src/ats/ats_api.c @@ -70,7 +70,7 @@ struct GNUNET_ATS_SuggestionContext /** * Global ATS handle. */ - struct GNUNET_ATS_Handle *atc; + struct GNUNET_ATS_SchedulingHandle *atc; /** * Which peer are we monitoring? @@ -108,7 +108,7 @@ struct SetBandwidthContext /** * ATS handle. */ - struct GNUNET_ATS_Handle *atc; + struct GNUNET_ATS_SchedulingHandle *atc; /** * Inbound bandwidth to assign. @@ -184,13 +184,13 @@ set_bw_connections (void *cls, const GNUNET_HashCode * key, void *value) /** * Task run to update bandwidth assignments. * - * @param cls the 'struct GNUNET_ATS_Handle' + * @param cls the 'struct GNUNET_ATS_SchedulingHandle' * @param tc scheduler context */ static void update_bandwidth_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - struct GNUNET_ATS_Handle *atc = cls; + struct GNUNET_ATS_SchedulingHandle *atc = cls; unsigned int ac = 0; struct SetBandwidthContext bwc; @@ -218,7 +218,7 @@ update_bandwidth_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) * @param change which allocation record changed? */ static void -update_bandwidth_assignment (struct GNUNET_ATS_Handle *atc, +update_bandwidth_assignment (struct GNUNET_ATS_SchedulingHandle *atc, struct AllocationRecord *change) { /* FIXME: based on the 'change', update the LP-problem... */ @@ -277,7 +277,7 @@ map_it (void *cls, const GNUNET_HashCode * key, void *value) * @param cb_cls closure for cb */ struct GNUNET_ATS_SuggestionContext * -GNUNET_ATS_suggest_address (struct GNUNET_ATS_Handle *atc, +GNUNET_ATS_suggest_address (struct GNUNET_ATS_SchedulingHandle *atc, const struct GNUNET_PeerIdentity *peer, GNUNET_ATS_AddressSuggestionCallback cb, void *cb_cls) @@ -332,17 +332,17 @@ GNUNET_ATS_suggest_address_cancel (struct GNUNET_ATS_SuggestionContext *asc) * @param alloc_cb_cls closure for 'alloc_cb' * @return ats context */ -struct GNUNET_ATS_Handle * +struct GNUNET_ATS_SchedulingHandle * GNUNET_ATS_init (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_ATS_AddressSuggestionCallback alloc_cb, void *alloc_cb_cls) { - struct GNUNET_ATS_Handle *atc; + struct GNUNET_ATS_SchedulingHandle *atc; #if DEBUG_ATS LOG (GNUNET_ERROR_TYPE_DEBUG, "ATS init\n"); #endif - atc = GNUNET_malloc (sizeof (struct GNUNET_ATS_Handle)); + atc = GNUNET_malloc (sizeof (struct GNUNET_ATS_SchedulingHandle)); atc->cfg = cfg; atc->alloc_cb = alloc_cb; atc->alloc_cb_cls = alloc_cb_cls; @@ -382,7 +382,7 @@ destroy_allocation_record (void *cls, const GNUNET_HashCode * key, void *value) * @param atc handle */ void -GNUNET_ATS_shutdown (struct GNUNET_ATS_Handle *atc) +GNUNET_ATS_shutdown (struct GNUNET_ATS_SchedulingHandle *atc) { #if DEBUG_ATS LOG (GNUNET_ERROR_TYPE_DEBUG, "ATS shutdown\n"); @@ -410,7 +410,7 @@ struct UpdateSessionContext /** * Ats handle. */ - struct GNUNET_ATS_Handle *atc; + struct GNUNET_ATS_SchedulingHandle *atc; /** * Allocation record with new information. @@ -556,7 +556,7 @@ create_allocation_record (const char *plugin_name, struct Session *session, static int disconnect_peer (void *cls, const GNUNET_HashCode * key, void *value) { - struct GNUNET_ATS_Handle *atc = cls; + struct GNUNET_ATS_SchedulingHandle *atc = cls; struct AllocationRecord *ar = value; if (GNUNET_YES == ar->connected) @@ -583,7 +583,7 @@ disconnect_peer (void *cls, const GNUNET_HashCode * key, void *value) * @param ats_count number of performance records in 'ats' */ void -GNUNET_ATS_peer_connect (struct GNUNET_ATS_Handle *atc, +GNUNET_ATS_peer_connect (struct GNUNET_ATS_SchedulingHandle *atc, const struct GNUNET_PeerIdentity *peer, const char *plugin_name, struct Session *session, const void *plugin_addr, size_t plugin_addr_len, @@ -628,7 +628,7 @@ GNUNET_ATS_peer_connect (struct GNUNET_ATS_Handle *atc, * @param peer identity of the new peer */ void -GNUNET_ATS_peer_disconnect (struct GNUNET_ATS_Handle *atc, +GNUNET_ATS_peer_disconnect (struct GNUNET_ATS_SchedulingHandle *atc, const struct GNUNET_PeerIdentity *peer) { #if DEBUG_ATS @@ -650,7 +650,7 @@ struct SessionDestroyContext /** * Ats handle. */ - struct GNUNET_ATS_Handle *atc; + struct GNUNET_ATS_SchedulingHandle *atc; /** * Session being destroyed. @@ -699,7 +699,7 @@ destroy_session (void *cls, const GNUNET_HashCode * key, void *value) * @param session session handle that is no longer valid */ void -GNUNET_ATS_session_destroyed (struct GNUNET_ATS_Handle *atc, +GNUNET_ATS_session_destroyed (struct GNUNET_ATS_SchedulingHandle *atc, const struct GNUNET_PeerIdentity *peer, const struct Session *session) { @@ -756,7 +756,7 @@ notify_valid (void *cls, const GNUNET_HashCode * key, void *value) * @param ats_count number of performance records in 'ats' */ void -GNUNET_ATS_address_update (struct GNUNET_ATS_Handle *atc, +GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *atc, const struct GNUNET_PeerIdentity *peer, struct GNUNET_TIME_Absolute valid_until, const char *plugin_name, struct Session *session, diff --git a/src/ats/ats_api.h b/src/ats/ats_api.h index a2c248cd8..2c98194be 100644 --- a/src/ats/ats_api.h +++ b/src/ats/ats_api.h @@ -91,7 +91,7 @@ struct AllocationRecord /** * Handle to the ATS subsystem. */ -struct GNUNET_ATS_Handle +struct GNUNET_ATS_SchedulingHandle { /** * Configuration. diff --git a/src/ats/ats_api_new.c b/src/ats/ats_api_new.c new file mode 100644 index 000000000..dc06d901d --- /dev/null +++ b/src/ats/ats_api_new.c @@ -0,0 +1,129 @@ +/* + This file is part of GNUnet. + (C) 2010,2011 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +/** + * @file include/gnunet_ats_service.h + * @brief automatic transport selection and outbound bandwidth determination + * @author Christian Grothoff + * @author Matthias Wachs + */ +#include "platform.h" +#include "gnunet_ats_service.h" + + +/** + * Handle to the ATS subsystem for bandwidth/transport scheduling information. + */ +struct GNUNET_ATS_SchedulingHandle +{ +}; + + +/** + * Initialize the ATS subsystem. + * + * @param cfg configuration to use + * @param alloc_cb notification to call whenever the allocation changed + * @param alloc_cb_cls closure for 'alloc_cb' + * @return ats context + */ +struct GNUNET_ATS_SchedulingHandle * +GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg, + GNUNET_ATS_AddressSuggestionCallback alloc_cb, + void *alloc_cb_cls) +{ + return NULL; +} + + +/** + * Client is done with ATS scheduling, release resources. + * + * @param atc handle to release + */ +void +GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *atc) +{ +} + + +/** + * We would like to establish a new connection with a peer. ATS + * should suggest a good address to begin with. + * + * @param atc handle + * @param peer identity of the peer we need an address for + */ +void +GNUNET_ATS_suggest_address (struct GNUNET_ATS_SchedulingHandle *atc, + const struct GNUNET_PeerIdentity *peer) +{ +} + + +/** + * We have updated performance statistics for a given address. Note + * that this function can be called for addresses that are currently + * in use as well as addresses that are valid but not actively in use. + * Furthermore, the peer may not even be connected to us right now (in + * which case the call may be ignored or the information may be stored + * for later use). Update bandwidth assignments. + * + * @param atc handle + * @param peer identity of the new peer + * @param plugin_name name of the transport plugin + * @param plugin_addr address (if available) + * @param plugin_addr_len number of bytes in plugin_addr + * @param session session handle (if available) + * @param ats performance data for the address + * @param ats_count number of performance records in 'ats' + */ +void +GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *atc, + const struct GNUNET_PeerIdentity *peer, + const char *plugin_name, + const void *plugin_addr, size_t plugin_addr_len, + struct Session *session, + const struct GNUNET_TRANSPORT_ATS_Information *ats, + uint32_t ats_count) +{ +} + + +/** + * A session got destroyed, stop including it as a valid address. + * + * @param atc handle + * @param peer identity of the peer + * @param plugin_name name of the transport plugin + * @param plugin_addr address (if available) + * @param plugin_addr_len number of bytes in plugin_addr + * @param session session handle that is no longer valid + */ +void +GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *atc, + const struct GNUNET_PeerIdentity *peer, + const char *plugin_name, + const void *plugin_addr, + size_t plugin_addr_len, + const struct Session *session) +{ +} + +/* end of ats_api_new.c */ diff --git a/src/ats/ats_api_peer_change_preference.c b/src/ats/ats_api_peer_change_preference.c index 76e8364fc..322727e63 100644 --- a/src/ats/ats_api_peer_change_preference.c +++ b/src/ats/ats_api_peer_change_preference.c @@ -40,7 +40,7 @@ struct GNUNET_ATS_InformationRequestContext /** * Our connection to the service. */ - struct GNUNET_ATS_Handle *h; + struct GNUNET_ATS_SchedulingHandle *h; int32_t amount; @@ -124,7 +124,7 @@ exec_pcp (void *cls, * @return NULL on error */ struct GNUNET_ATS_InformationRequestContext * -GNUNET_ATS_peer_change_preference (struct GNUNET_ATS_Handle *h, +GNUNET_ATS_peer_change_preference (struct GNUNET_ATS_SchedulingHandle *h, const struct GNUNET_PeerIdentity *peer, int32_t amount, uint64_t preference, GNUNET_ATS_PeerConfigurationInfoCallback @@ -173,7 +173,7 @@ struct GNUNET_ATS_InformationRequestContext /** * Our connection to the service. */ - struct GNUNET_ATS_Handle *h; + struct GNUNET_ATS_SchedulingHandle *h; /** * Link to control message, NULL if CM was sent. @@ -218,7 +218,7 @@ change_preference_send_continuation (void *cls, int success) * @return NULL on error */ struct GNUNET_ATS_InformationRequestContext * -GNUNET_ATS_peer_change_preference (struct GNUNET_ATS_Handle *h, +GNUNET_ATS_peer_change_preference (struct GNUNET_ATS_SchedulingHandle *h, const struct GNUNET_PeerIdentity *peer, int32_t amount, uint64_t preference, GNUNET_ATS_PeerConfigurationInfoCallback @@ -290,7 +290,7 @@ GNUNET_ATS_peer_change_preference_cancel (struct GNUNET_ATS_InformationRequestContext *irc) { - struct GNUNET_ATS_Handle *h = irc->h; + struct GNUNET_ATS_SchedulingHandle *h = irc->h; struct PeerRecord *pr = irc->pr; GNUNET_assert (pr->pcic_ptr == irc); diff --git a/src/ats/ats_api_performance.c b/src/ats/ats_api_performance.c new file mode 100644 index 000000000..0b0bd1042 --- /dev/null +++ b/src/ats/ats_api_performance.c @@ -0,0 +1,128 @@ +/* + This file is part of GNUnet. + (C) 2010,2011 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +/** + * @file include/gnunet_ats_service.h + * @brief automatic transport selection and outbound bandwidth determination + * @author Christian Grothoff + * @author Matthias Wachs + */ +#include "platform.h" +#include "gnunet_ats_service.h" + +/* ******************************** Performance API ***************************** */ + +/** + * ATS Handle to obtain and/or modify performance information. + */ +struct GNUNET_ATS_PerformanceHandle +{ +}; + + +/** + * Get handle to access performance API of the ATS subsystem. + * + * @param cfg configuration to use + * @param infocb function to call on allocation changes, can be NULL + * @param infocb_cls closure for infocb + * @return ats performance context + */ +struct GNUNET_ATS_PerformanceHandle * +GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg, + GNUNET_ATS_PeerInformationCallback infocb, + void *infocb_cls) +{ + return NULL; +} + + +/** + * Client is done using the ATS performance subsystem, release resources. + * + * @param atc handle + */ +void +GNUNET_ATS_performance_done (struct GNUNET_ATS_SchedulingHandle *atc) +{ +} + + +/** + * Context that can be used to cancel a peer information request. + */ +struct GNUNET_ATS_ReservationContext +{ +}; + + +/** + * Reserve inbound bandwidth from the given peer. ATS will look at + * the current amount of traffic we receive from the peer and ensure + * that the peer could add 'amount' of data to its stream. + * + * @param h core handle + * @param peer identifies the peer + * @param amount reserve N bytes for receiving, negative + * amounts can be used to undo a (recent) reservation; + * @param info function to call with the resulting reservation information + * @param info_cls closure for info + * @return NULL on error + * @deprecated will be replaced soon + */ +struct GNUNET_ATS_ReservationContext * +GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *h, + const struct GNUNET_PeerIdentity *peer, + int32_t amount, + GNUNET_ATS_ReservationCallback info, + void *info_cls) +{ + return NULL; +} + + +/** + * Cancel request for reserving bandwidth. + * + * @param rc context returned by the original GNUNET_ATS_reserve_bandwidth call + */ +void +GNUNET_ATS_reserve_bandwidth_cancel (struct + GNUNET_ATS_ReservationContext *rc) +{ +} + + +/** + * Change preferences for the given peer. Preference changes are forgotten if peers + * disconnect. + * + * @param cls closure + * @param peer identifies the peer + * @param ... 0-terminated specification of the desired changes + */ +void +GNUNET_ATS_change_preference (struct GNUNET_ATS_PerformanceHandle *h, + const struct GNUNET_PeerIdentity *peer, + ...) +{ +} + +/* end of ats_api_performance.c */ + diff --git a/src/ats/test_ats_api.c b/src/ats/test_ats_api.c index 42d485994..4a4bf9772 100644 --- a/src/ats/test_ats_api.c +++ b/src/ats/test_ats_api.c @@ -42,7 +42,7 @@ static struct GNUNET_CONFIGURATION_Handle *cfg; -static struct GNUNET_ATS_Handle *ats; +static struct GNUNET_ATS_SchedulingHandle *ats; static void alloc_cb (void *cls, const struct GNUNET_PeerIdentity *peer, diff --git a/src/ats/test_ats_api_update_address.c b/src/ats/test_ats_api_update_address.c index 556f13ce4..54383c1d3 100644 --- a/src/ats/test_ats_api_update_address.c +++ b/src/ats/test_ats_api_update_address.c @@ -44,7 +44,7 @@ #define VALID GNUNET_TIME_absolute_get_forever () -static struct GNUNET_ATS_Handle *ats; +static struct GNUNET_ATS_SchedulingHandle *ats; static struct GNUNET_ATS_SuggestionContext *asc; diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c index 6de93c0eb..902f3029c 100644 --- a/src/dht/gnunet-service-dht_neighbours.c +++ b/src/dht/gnunet-service-dht_neighbours.c @@ -415,7 +415,7 @@ static struct GNUNET_CORE_Handle *coreAPI; /** * Handle to ATS. */ -static struct GNUNET_ATS_Handle *atsAPI; +static struct GNUNET_ATS_SchedulingHandle *atsAPI; diff --git a/src/fs/gnunet-service-fs_cp.c b/src/fs/gnunet-service-fs_cp.c index 0fed7b855..8f4528cfb 100644 --- a/src/fs/gnunet-service-fs_cp.c +++ b/src/fs/gnunet-service-fs_cp.c @@ -305,7 +305,7 @@ static char *trustDirectory; /** * Handle to ATS service. */ -static struct GNUNET_ATS_Handle *ats; +static struct GNUNET_ATS_SchedulingHandle *ats; /** * Get the filename under which we would store the GNUNET_HELLO_Message diff --git a/src/include/gnunet_ats_service.h b/src/include/gnunet_ats_service.h index 713178411..12446991a 100644 --- a/src/include/gnunet_ats_service.h +++ b/src/include/gnunet_ats_service.h @@ -25,8 +25,6 @@ * * TODO: * - move GNUNET_TRANSPORT_ATS* in here and rename... - * - extend API to express communication preferences to ATS - * (to be called DIRECTLY from apps, not from transport/core!) */ #ifndef GNUNET_ATS_SERVICE_H #define GNUNET_ATS_SERVICE_H @@ -37,24 +35,26 @@ #include "gnunet_transport_plugin.h" +/* ******************************** Scheduling API ***************************** */ + /** - * Handle to the ATS subsystem. + * Handle to the ATS subsystem for bandwidth/transport scheduling information. */ -struct GNUNET_ATS_Handle; +struct GNUNET_ATS_SchedulingHandle; /** - * Signature of a function that takes an address suggestion + * Signature of a function called by ATS with the current bandwidth + * and address preferences as determined by ATS. * * @param cls closure * @param peer identity of the new peer * @param plugin_name name of the plugin, NULL if we have no suggestion * @param plugin_addr suggested address, NULL if we have no suggestion * @param plugin_addr_len number of bytes in plugin_addr + * @param session session to use * @param bandwidth_out assigned outbound bandwidth for the connection * @param bandwidth_in assigned inbound bandwidth for the connection - * @param ats performance data for the address (as far as known) - * @param ats_count number of performance records in 'ats' */ typedef void (*GNUNET_ATS_AddressSuggestionCallback) (void *cls, const struct @@ -69,11 +69,7 @@ typedef void (*GNUNET_ATS_AddressSuggestionCallback) (void *cls, bandwidth_out, struct GNUNET_BANDWIDTH_Value32NBO - bandwidth_in, - const struct - GNUNET_TRANSPORT_ATS_Information - * ats, - uint32_t ats_count); + bandwidth_in); /** @@ -84,86 +80,58 @@ typedef void (*GNUNET_ATS_AddressSuggestionCallback) (void *cls, * @param alloc_cb_cls closure for 'alloc_cb' * @return ats context */ -struct GNUNET_ATS_Handle * -GNUNET_ATS_init (const struct GNUNET_CONFIGURATION_Handle *cfg, - GNUNET_ATS_AddressSuggestionCallback alloc_cb, - void *alloc_cb_cls); +struct GNUNET_ATS_SchedulingHandle * +GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg, + GNUNET_ATS_AddressSuggestionCallback alloc_cb, + void *alloc_cb_cls); /** - * Shutdown the ATS subsystem. + * Client is done with ATS scheduling, release resources. * - * @param atc handle + * @param atc handle to release */ void -GNUNET_ATS_shutdown (struct GNUNET_ATS_Handle *atc); - - -/** - * Handle to cancel suggestion request. - */ -struct GNUNET_ATS_SuggestionContext; +GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *atc); /** - * We would like to establish a new connection with a peer. - * ATS should suggest a good address to begin with. + * We would like to establish a new connection with a peer. ATS + * should suggest a good address to begin with. * * @param atc handle - * @param peer identity of the new peer - * @param cb function to call with the address - * @param cb_cls closure for cb - */ -struct GNUNET_ATS_SuggestionContext * -GNUNET_ATS_suggest_address (struct GNUNET_ATS_Handle *atc, - const struct GNUNET_PeerIdentity *peer, - GNUNET_ATS_AddressSuggestionCallback cb, - void *cb_cls); - - -/** - * Cancel suggestion request. - * - * @param asc handle of the request to cancel + * @param peer identity of the peer we need an address for */ void -GNUNET_ATS_suggest_address_cancel (struct GNUNET_ATS_SuggestionContext *asc); +GNUNET_ATS_suggest_address (struct GNUNET_ATS_SchedulingHandle *atc, + const struct GNUNET_PeerIdentity *peer); /** - * We established a new connection with a peer (for example, because - * core asked for it or because the other peer connected to us). - * Calculate bandwidth assignments including the new peer. + * We have updated performance statistics for a given address. Note + * that this function can be called for addresses that are currently + * in use as well as addresses that are valid but not actively in use. + * Furthermore, the peer may not even be connected to us right now (in + * which case the call may be ignored or the information may be stored + * for later use). Update bandwidth assignments. * * @param atc handle * @param peer identity of the new peer - * @param plugin_name name of the currently used transport plugin - * @param session session in use (if available) - * @param plugin_addr address in use (if available) + * @param plugin_name name of the transport plugin + * @param plugin_addr address (if available) * @param plugin_addr_len number of bytes in plugin_addr - * @param ats performance data for the connection + * @param session session handle (if available) + * @param ats performance data for the address * @param ats_count number of performance records in 'ats' */ void -GNUNET_ATS_peer_connect (struct GNUNET_ATS_Handle *atc, - const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, struct Session *session, - const void *plugin_addr, size_t plugin_addr_len, - const struct GNUNET_TRANSPORT_ATS_Information *ats, - uint32_t ats_count); - - -/** - * We disconnected from the given peer (for example, because ats, core - * or blacklist asked for it or because the other peer disconnected). - * Calculate bandwidth assignments without the peer. - * - * @param atc handle - * @param peer identity of the peer - */ -void -GNUNET_ATS_peer_disconnect (struct GNUNET_ATS_Handle *atc, - const struct GNUNET_PeerIdentity *peer); +GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *atc, + const struct GNUNET_PeerIdentity *peer, + const char *plugin_name, + const void *plugin_addr, size_t plugin_addr_len, + struct Session *session, + const struct GNUNET_TRANSPORT_ATS_Information *ats, + uint32_t ats_count); /** @@ -171,45 +139,85 @@ GNUNET_ATS_peer_disconnect (struct GNUNET_ATS_Handle *atc, * * @param atc handle * @param peer identity of the peer + * @param plugin_name name of the transport plugin + * @param plugin_addr address (if available) + * @param plugin_addr_len number of bytes in plugin_addr * @param session session handle that is no longer valid */ void -GNUNET_ATS_session_destroyed (struct GNUNET_ATS_Handle *atc, +GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *atc, const struct GNUNET_PeerIdentity *peer, + const char *plugin_name, + const void *plugin_addr, + size_t plugin_addr_len, const struct Session *session); +/* ******************************** Performance API ***************************** */ + /** - * We have updated performance statistics for a given address. Note - * that this function can be called for addresses that are currently - * in use as well as addresses that are valid but not actively in use. - * Furthermore, the peer may not even be connected to us right now (in - * which case the call may be ignored or the information may be stored - * for later use). Update bandwidth assignments. + * ATS Handle to obtain and/or modify performance information. + */ +struct GNUNET_ATS_PerformanceHandle; + + +/** + * Signature of a function that is called with QoS information about a peer. * - * @param atc handle + * @param cls closure * @param peer identity of the new peer - * @param valid_until how long is the address valid? - * @param plugin_name name of the transport plugin - * @param session session handle (if available) - * @param plugin_addr address (if available) + * @param plugin_name name of the plugin, NULL if we have no suggestion + * @param plugin_addr suggested address, NULL if we have no suggestion * @param plugin_addr_len number of bytes in plugin_addr - * @param ats performance data for the address + * @param bandwidth_out assigned outbound bandwidth for the connection + * @param bandwidth_in assigned inbound bandwidth for the connection + * @param ats performance data for the address (as far as known) * @param ats_count number of performance records in 'ats' */ -void -GNUNET_ATS_address_update (struct GNUNET_ATS_Handle *atc, - const struct GNUNET_PeerIdentity *peer, - struct GNUNET_TIME_Absolute valid_until, - const char *plugin_name, struct Session *session, - const void *plugin_addr, size_t plugin_addr_len, - const struct GNUNET_TRANSPORT_ATS_Information *ats, - uint32_t ats_count); +typedef void (*GNUNET_ATS_PeerInformationCallback) (void *cls, + const struct + GNUNET_PeerIdentity * + peer, + const char *plugin_name, + const void *plugin_addr, + size_t plugin_addr_len, + struct + GNUNET_BANDWIDTH_Value32NBO + bandwidth_out, + struct + GNUNET_BANDWIDTH_Value32NBO + bandwidth_in, + const struct + GNUNET_TRANSPORT_ATS_Information + * ats, + uint32_t ats_count); +/** + * Get handle to access performance API of the ATS subsystem. + * + * @param cfg configuration to use + * @param infocb function to call on allocation changes, can be NULL + * @param infocb_cls closure for infocb + * @return ats performance context + */ +struct GNUNET_ATS_PerformanceHandle * +GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg, + GNUNET_ATS_PeerInformationCallback infocb, + void *infocb_cls); + + +/** + * Client is done using the ATS performance subsystem, release resources. + * + * @param atc handle + */ +void +GNUNET_ATS_performance_done (struct GNUNET_ATS_SchedulingHandle *atc); + /** - * Function called with perference change information about the given peer. + * Function called with reservation result. * * @param cls closure * @param peer identifies the peer @@ -218,65 +226,99 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_Handle *atc, * @param res_delay if the reservation could not be satisfied (amount was 0), how * long should the client wait until re-trying? */ -typedef void (*GNUNET_ATS_PeerConfigurationInfoCallback) (void *cls, - const struct - GNUNET_PeerIdentity * - peer, - int32_t amount, - struct - GNUNET_TIME_Relative - res_delay); +typedef void (*GNUNET_ATS_ReservationCallback) (void *cls, + const struct + GNUNET_PeerIdentity * + peer, + int32_t amount, + struct + GNUNET_TIME_Relative + res_delay); /** * Context that can be used to cancel a peer information request. */ -struct GNUNET_ATS_InformationRequestContext; +struct GNUNET_ATS_ReservationContext; /** - * Obtain statistics and/or change preferences for the given peer. - * You can only have one such pending request per peer. + * Reserve inbound bandwidth from the given peer. ATS will look at + * the current amount of traffic we receive from the peer and ensure + * that the peer could add 'amount' of data to its stream. * * @param h core handle * @param peer identifies the peer * @param amount reserve N bytes for receiving, negative * amounts can be used to undo a (recent) reservation; - * @param preference increase incoming traffic share preference by this amount; - * in the absence of "amount" reservations, we use this - * preference value to assign proportional bandwidth shares - * to all connected peers; in the future, this should be - * replaced with more specific QoS expressions... - * @param info function to call with the resulting configuration information + * @param info function to call with the resulting reservation information * @param info_cls closure for info * @return NULL on error * @deprecated will be replaced soon */ -struct GNUNET_ATS_InformationRequestContext * -GNUNET_ATS_peer_change_preference (struct GNUNET_ATS_Handle *h, - const struct GNUNET_PeerIdentity *peer, - int32_t amount, uint64_t preference, - GNUNET_ATS_PeerConfigurationInfoCallback - info, void *info_cls); +struct GNUNET_ATS_ReservationContext * +GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *h, + const struct GNUNET_PeerIdentity *peer, + int32_t amount, + GNUNET_ATS_ReservationCallback info, + void *info_cls); /** - * Cancel request for getting information about a peer. - * Note that an eventual change in preference, trust or bandwidth - * assignment MAY have already been committed at the time, - * so cancelling a request is NOT sure to undo the original - * request. The original request may or may not still commit. - * The only thing cancellation ensures is that the callback - * from the original request will no longer be called. + * Cancel request for reserving bandwidth. * - * @param irc context returned by the original GNUNET_ATS_peer_get_info call - * @deprecated will be replaced soon + * @param rc context returned by the original GNUNET_ATS_reserve_bandwidth call + */ +void +GNUNET_ATS_reserve_bandwidth_cancel (struct + GNUNET_ATS_ReservationContext *rc); + + + +/** + * Enum defining all known preference categories. + */ +enum GNUNET_ATS_PreferenceKind +{ + + /** + * End of preference list. + */ + GNUNET_ATS_PREFERENCE_END = 0, + + /** + * Change the peer's bandwidth value (value per byte of bandwidth in + * the goal function) to the given amount. The argument is followed + * by a double value giving the desired value (can be negative). + * Preference changes are forgotten if peers disconnect. + */ + GNUNET_ATS_PREFERENCE_BANDWIDTH, + + /** + * Change the peer's latency value to the given amount. The + * argument is followed by a double value giving the desired value + * (can be negative). The absolute score in the goal function is + * the inverse of the latency in ms (minimum: 1 ms) multiplied by + * the latency preferences. + */ + GNUNET_ATS_PREFERENCE_LATENCY + +}; + + +/** + * Change preferences for the given peer. Preference changes are forgotten if peers + * disconnect. + * + * @param cls closure + * @param peer identifies the peer + * @param ... 0-terminated specification of the desired changes */ void -GNUNET_ATS_peer_change_preference_cancel (struct - GNUNET_ATS_InformationRequestContext - *irc); +GNUNET_ATS_change_preference (struct GNUNET_ATS_PerformanceHandle *h, + const struct GNUNET_PeerIdentity *peer, + ...); diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index 418c9f8ef..9f106c3a9 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h @@ -986,6 +986,27 @@ extern "C" */ #define GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY 334 +/******************************************************************************* + * ATS message types + ******************************************************************************/ + +#define GNUNET_MESSAGE_TYPE_ATS_START 340 + +#define GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS 341 + +#define GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE 342 + +#define GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED 343 + +#define GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION 344 + +#define GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST 345 + +#define GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT 346 + +#define GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE 347 + + /******************************************************************************* * TODO: we need a way to register message types centrally (via some webpage). * For now: unofficial extensions should start at 48k, internal extensions diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index fb5a5c5e6..ce4c240a7 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c @@ -73,7 +73,7 @@ struct GNUNET_CRYPTO_RsaPrivateKey *GST_my_private_key; /** * ATS handle. */ -struct GNUNET_ATS_Handle *GST_ats; +struct GNUNET_ATS_SchedulingHandle *GST_ats; /** diff --git a/src/transport/gnunet-service-transport.h b/src/transport/gnunet-service-transport.h index 36469df06..adc28ba6d 100644 --- a/src/transport/gnunet-service-transport.h +++ b/src/transport/gnunet-service-transport.h @@ -65,7 +65,7 @@ extern struct GNUNET_CRYPTO_RsaPrivateKey *GST_my_private_key; /** * ATS handle. */ -extern struct GNUNET_ATS_Handle *GST_ats; +extern struct GNUNET_ATS_SchedulingHandle *GST_ats; #endif -- 2.25.1