2 This file is part of GNUnet.
3 (C) 2010,2011 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file include/gnunet_ats_service.h
22 * @brief automatic transport selection and outbound bandwidth determination
23 * @author Christian Grothoff
24 * @author Matthias Wachs
27 * - move GNUNET_TRANSPORT_ATS* in here and rename...
29 #ifndef GNUNET_ATS_SERVICE_H
30 #define GNUNET_ATS_SERVICE_H
32 #include "gnunet_constants.h"
33 #include "gnunet_util_lib.h"
34 #include "gnunet_transport_service.h"
35 #include "gnunet_transport_plugin.h"
38 /* ******************************** Scheduling API ***************************** */
41 * Handle to the ATS subsystem for bandwidth/transport scheduling information.
43 struct GNUNET_ATS_SchedulingHandle;
47 * Opaque session handle, defined by plugins. Contents not known to ATS.
53 * Signature of a function called by ATS with the current bandwidth
54 * and address preferences as determined by ATS.
57 * @param peer identity of the new peer
58 * @param plugin_name name of the plugin, NULL if we have no suggestion
59 * @param plugin_addr suggested address, NULL if we have no suggestion
60 * @param plugin_addr_len number of bytes in plugin_addr
61 * @param session session to use
62 * @param bandwidth_out assigned outbound bandwidth for the connection
63 * @param bandwidth_in assigned inbound bandwidth for the connection
64 * @param ats performance data for the address (as far as known)
65 * @param ats_count number of performance records in 'ats'
67 typedef void (*GNUNET_ATS_AddressSuggestionCallback) (void *cls,
71 const char *plugin_name,
72 const void *plugin_addr,
73 size_t plugin_addr_len,
74 struct Session * session,
76 GNUNET_BANDWIDTH_Value32NBO
79 GNUNET_BANDWIDTH_Value32NBO
82 GNUNET_TRANSPORT_ATS_Information
88 * Initialize the ATS subsystem.
90 * @param cfg configuration to use
91 * @param suggest_cb notification to call whenever the suggestation changed
92 * @param suggest_cb_cls closure for 'suggest_cb'
95 struct GNUNET_ATS_SchedulingHandle *
96 GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
97 GNUNET_ATS_AddressSuggestionCallback suggest_cb,
98 void *suggest_cb_cls);
102 * Client is done with ATS scheduling, release resources.
104 * @param sh handle to release
107 GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh);
111 * We would like to establish a new connection with a peer. ATS
112 * should suggest a good address to begin with.
115 * @param peer identity of the peer we need an address for
118 GNUNET_ATS_suggest_address (struct GNUNET_ATS_SchedulingHandle *sh,
119 const struct GNUNET_PeerIdentity *peer);
123 * We have updated performance statistics for a given address. Note
124 * that this function can be called for addresses that are currently
125 * in use as well as addresses that are valid but not actively in use.
126 * Furthermore, the peer may not even be connected to us right now (in
127 * which case the call may be ignored or the information may be stored
128 * for later use). Update bandwidth assignments.
131 * @param peer identity of the new peer
132 * @param plugin_name name of the transport plugin
133 * @param plugin_addr address (if available)
134 * @param plugin_addr_len number of bytes in plugin_addr
135 * @param session session handle (if available)
136 * @param ats performance data for the address
137 * @param ats_count number of performance records in 'ats'
140 GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh,
141 const struct GNUNET_PeerIdentity *peer,
142 const char *plugin_name,
143 const void *plugin_addr, size_t plugin_addr_len,
144 struct Session *session,
145 const struct GNUNET_TRANSPORT_ATS_Information *ats,
150 * A session got destroyed, stop including it as a valid address.
153 * @param peer identity of the peer
154 * @param plugin_name name of the transport plugin
155 * @param plugin_addr address (if available)
156 * @param plugin_addr_len number of bytes in plugin_addr
157 * @param session session handle that is no longer valid (if available)
160 GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh,
161 const struct GNUNET_PeerIdentity *peer,
162 const char *plugin_name,
163 const void *plugin_addr,
164 size_t plugin_addr_len,
165 struct Session *session);
168 /* ******************************** Performance API ***************************** */
171 * ATS Handle to obtain and/or modify performance information.
173 struct GNUNET_ATS_PerformanceHandle;
177 * Signature of a function that is called with QoS information about a peer.
180 * @param peer identity of the new peer
181 * @param plugin_name name of the plugin, NULL if we have no suggestion
182 * @param plugin_addr suggested address, NULL if we have no suggestion
183 * @param plugin_addr_len number of bytes in plugin_addr
184 * @param bandwidth_out assigned outbound bandwidth for the connection
185 * @param bandwidth_in assigned inbound bandwidth for the connection
186 * @param ats performance data for the address (as far as known)
187 * @param ats_count number of performance records in 'ats'
189 typedef void (*GNUNET_ATS_PeerInformationCallback) (void *cls,
191 GNUNET_PeerIdentity *
193 const char *plugin_name,
194 const void *plugin_addr,
195 size_t plugin_addr_len,
197 GNUNET_BANDWIDTH_Value32NBO
200 GNUNET_BANDWIDTH_Value32NBO
203 GNUNET_TRANSPORT_ATS_Information
209 * Get handle to access performance API of the ATS subsystem.
211 * @param cfg configuration to use
212 * @param infocb function to call on performance changes, can be NULL
213 * @param infocb_cls closure for infocb
214 * @return ats performance context
216 struct GNUNET_ATS_PerformanceHandle *
217 GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
218 GNUNET_ATS_PeerInformationCallback infocb,
223 * Client is done using the ATS performance subsystem, release resources.
228 GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph);
232 * Function called with reservation result.
235 * @param peer identifies the peer
236 * @param amount set to the amount that was actually reserved or unreserved;
237 * either the full requested amount or zero (no partial reservations)
238 * @param res_delay if the reservation could not be satisfied (amount was 0), how
239 * long should the client wait until re-trying?
241 typedef void (*GNUNET_ATS_ReservationCallback) (void *cls,
243 GNUNET_PeerIdentity *
253 * Context that can be used to cancel a peer information request.
255 struct GNUNET_ATS_ReservationContext;
259 * Reserve inbound bandwidth from the given peer. ATS will look at
260 * the current amount of traffic we receive from the peer and ensure
261 * that the peer could add 'amount' of data to its stream.
263 * @param ph performance handle
264 * @param peer identifies the peer
265 * @param amount reserve N bytes for receiving, negative
266 * amounts can be used to undo a (recent) reservation;
267 * @param rcb function to call with the resulting reservation information
268 * @param rcb_cls closure for info
269 * @return NULL on error
270 * @deprecated will be replaced soon
272 struct GNUNET_ATS_ReservationContext *
273 GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph,
274 const struct GNUNET_PeerIdentity *peer,
276 GNUNET_ATS_ReservationCallback rcb,
281 * Cancel request for reserving bandwidth.
283 * @param rc context returned by the original GNUNET_ATS_reserve_bandwidth call
286 GNUNET_ATS_reserve_bandwidth_cancel (struct
287 GNUNET_ATS_ReservationContext *rc);
292 * Enum defining all known preference categories.
294 enum GNUNET_ATS_PreferenceKind
298 * End of preference list.
300 GNUNET_ATS_PREFERENCE_END = 0,
303 * Change the peer's bandwidth value (value per byte of bandwidth in
304 * the goal function) to the given amount. The argument is followed
305 * by a double value giving the desired value (can be negative).
306 * Preference changes are forgotten if peers disconnect.
308 GNUNET_ATS_PREFERENCE_BANDWIDTH,
311 * Change the peer's latency value to the given amount. The
312 * argument is followed by a double value giving the desired value
313 * (can be negative). The absolute score in the goal function is
314 * the inverse of the latency in ms (minimum: 1 ms) multiplied by
315 * the latency preferences.
317 GNUNET_ATS_PREFERENCE_LATENCY
323 * Change preferences for the given peer. Preference changes are forgotten if peers
326 * @param ph performance handle
327 * @param peer identifies the peer
328 * @param ... 0-terminated specification of the desired changes
331 GNUNET_ATS_change_preference (struct GNUNET_ATS_PerformanceHandle *ph,
332 const struct GNUNET_PeerIdentity *peer,
338 /* end of file gnunet-service-transport_ats.h */