2 This file is part of GNUnet.
3 Copyright (C) 2010-2015 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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, 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
26 #ifndef GNUNET_ATS_SERVICE_H
27 #define GNUNET_ATS_SERVICE_H
29 #include "gnunet_constants.h"
30 #include "gnunet_util_lib.h"
31 #include "gnunet_hello_lib.h"
34 * Types of networks (with separate quotas) we support.
36 enum GNUNET_ATS_Network_Type
39 * Category of last resort.
41 GNUNET_ATS_NET_UNSPECIFIED = 0,
44 * Loopback (same host).
46 GNUNET_ATS_NET_LOOPBACK = 1,
51 GNUNET_ATS_NET_LAN = 2,
54 * Wide area network (i.e. Internet)
56 GNUNET_ATS_NET_WAN = 3,
59 * Wireless LAN (i.e. 802.11abgn)
61 GNUNET_ATS_NET_WLAN = 4,
69 * Number of network types supported by ATS
71 #define GNUNET_ATS_NetworkTypeCount 6
77 * Default bandwidth assigned to a network : 64 KB/s
79 #define GNUNET_ATS_DefaultBandwidth 65536
82 * Undefined value for an `enum GNUNET_ATS_Property`
84 #define GNUNET_ATS_VALUE_UNDEFINED UINT32_MAX
87 * String representation for GNUNET_ATS_VALUE_UNDEFINED
89 #define GNUNET_ATS_VALUE_UNDEFINED_STR "undefined"
92 * Maximum bandwidth assigned to a network : 4095 MB/s
94 #define GNUNET_ATS_MaxBandwidth UINT32_MAX
97 * Textual equivalent for GNUNET_ATS_MaxBandwidth
99 #define GNUNET_ATS_MaxBandwidthString "unlimited"
103 * ATS performance characteristics for an address.
105 struct GNUNET_ATS_Properties
109 * Delay. Time between when the time packet is sent and the packet
110 * arrives. FOREVER if we did not measure yet.
112 struct GNUNET_TIME_Relative delay;
115 * Actual traffic on this connection from this peer to the other peer.
116 * Includes transport overhead.
118 * Unit: [bytes/second]
120 uint32_t utilization_out;
123 * Actual traffic on this connection from the other peer to this peer.
124 * Includes transport overhead.
126 * Unit: [bytes/second]
128 uint32_t utilization_in;
131 * Distance on network layer (required for distance-vector routing)
132 * in hops. Zero for direct connections (i.e. plain TCP/UDP).
134 unsigned int distance;
137 * Which network scope does the respective address belong to?
138 * This property does not change.
140 enum GNUNET_ATS_Network_Type scope;
146 * ATS performance characteristics for an address in
147 * network byte order (for IPC).
149 struct GNUNET_ATS_PropertiesNBO
153 * Actual traffic on this connection from this peer to the other peer.
154 * Includes transport overhead.
156 * Unit: [bytes/second]
158 uint32_t utilization_out GNUNET_PACKED;
161 * Actual traffic on this connection from the other peer to this peer.
162 * Includes transport overhead.
164 * Unit: [bytes/second]
166 uint32_t utilization_in GNUNET_PACKED;
169 * Which network scope does the respective address belong to?
170 * This property does not change.
172 uint32_t scope GNUNET_PACKED;
175 * Distance on network layer (required for distance-vector routing)
176 * in hops. Zero for direct connections (i.e. plain TCP/UDP).
178 uint32_t distance GNUNET_PACKED;
181 * Delay. Time between when the time packet is sent and the packet
182 * arrives. FOREVER if we did not measure yet.
184 struct GNUNET_TIME_RelativeNBO delay;
190 /* ********************* LAN Characterization library ************************ */
191 /* Note: these functions do not really communicate with the ATS service */
195 * Convert ATS properties from host to network byte order.
197 * @param nbo[OUT] value written
198 * @param hbo value read
201 GNUNET_ATS_properties_hton (struct GNUNET_ATS_PropertiesNBO *nbo,
202 const struct GNUNET_ATS_Properties *hbo);
206 * Convert ATS properties from network to host byte order.
208 * @param hbo[OUT] value written
209 * @param nbo value read
212 GNUNET_ATS_properties_ntoh (struct GNUNET_ATS_Properties *hbo,
213 const struct GNUNET_ATS_PropertiesNBO *nbo);
218 * Convert a `enum GNUNET_ATS_Network_Type` to a string
220 * @param net the network type
221 * @return a string or NULL if invalid
224 GNUNET_ATS_print_network_type (enum GNUNET_ATS_Network_Type net);
228 * Handle for the LAN Characterization library.
230 struct GNUNET_ATS_InterfaceScanner;
234 * Returns where the address is located: loopback, LAN or WAN.
236 * @param is handle from #GNUNET_ATS_interface_scanner_init()
237 * @param addr address
238 * @param addrlen address length
239 * @return type of the network the address belongs to
241 enum GNUNET_ATS_Network_Type
242 GNUNET_ATS_scanner_address_get_type (struct GNUNET_ATS_InterfaceScanner *is,
243 const struct sockaddr *addr,
248 * Initialize the ATS address characterization client handle.
250 * @return scanner handle, NULL on error
252 struct GNUNET_ATS_InterfaceScanner *
253 GNUNET_ATS_scanner_init (void);
257 * Terminate interface scanner.
259 * @param is scanner we are done with
262 GNUNET_ATS_scanner_done (struct GNUNET_ATS_InterfaceScanner *is);
266 /* ********************Connection Suggestion API ***************************** */
269 * Handle to the ATS subsystem for making suggestions about
270 * connections the peer would like to have.
272 struct GNUNET_ATS_ConnectivityHandle;
275 * Handle for address suggestion requests.
277 struct GNUNET_ATS_ConnectivitySuggestHandle;
281 * Initialize the ATS connectivity suggestion client handle.
283 * @param cfg configuration to use
284 * @return ats connectivity handle, NULL on error
286 struct GNUNET_ATS_ConnectivityHandle *
287 GNUNET_ATS_connectivity_init (const struct GNUNET_CONFIGURATION_Handle *cfg);
291 * Shutdown ATS connectivity suggestion client.
293 * @param ch handle to destroy
296 GNUNET_ATS_connectivity_done (struct GNUNET_ATS_ConnectivityHandle *ch);
300 * We would like to establish a new connection with a peer. ATS
301 * should suggest a good address to begin with.
304 * @param peer identity of the peer we need an address for
305 * TODO: add argument to allow client to express 'strength's of request
306 * @return suggestion handle, NULL if request is already pending
308 struct GNUNET_ATS_ConnectivitySuggestHandle *
309 GNUNET_ATS_connectivity_suggest (struct GNUNET_ATS_ConnectivityHandle *ch,
310 const struct GNUNET_PeerIdentity *peer);
314 * We no longer care about being connected to a peer.
319 GNUNET_ATS_connectivity_suggest_cancel (struct GNUNET_ATS_ConnectivitySuggestHandle *sh);
322 /* ******************************** Scheduling API ***************************** */
325 * Handle to the ATS subsystem for bandwidth/transport scheduling information.
327 struct GNUNET_ATS_SchedulingHandle;
330 * Opaque session handle, defined by plugins. Contents not known to ATS.
332 struct GNUNET_ATS_Session;
336 * Signature of a function called by ATS with the current bandwidth
337 * and address preferences as determined by ATS. If our connection
338 * to ATS dies and thus all suggestions become invalid, this function
339 * is called ONCE with all arguments (except @a cls) being NULL/0.
342 * @param peer for which we suggest an address, NULL if ATS connection died
343 * @param address suggested address (including peer identity of the peer),
344 * may be NULL to signal disconnect from peer
345 * @param session session to use, NULL to establish a new outgoing session
346 * @param bandwidth_out assigned outbound bandwidth for the connection,
347 * 0 to signal disconnect
348 * @param bandwidth_in assigned inbound bandwidth for the connection,
349 * 0 to signal disconnect
352 (*GNUNET_ATS_AddressSuggestionCallback) (void *cls,
353 const struct GNUNET_PeerIdentity *peer,
354 const struct GNUNET_HELLO_Address *address,
355 struct GNUNET_ATS_Session *session,
356 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
357 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in);
361 * Initialize the ATS scheduling subsystem.
363 * @param cfg configuration to use
364 * @param suggest_cb notification to call whenever the suggestation changed
365 * @param suggest_cb_cls closure for @a suggest_cb
366 * @return ats context
368 struct GNUNET_ATS_SchedulingHandle *
369 GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
370 GNUNET_ATS_AddressSuggestionCallback suggest_cb,
371 void *suggest_cb_cls);
375 * Client is done with ATS scheduling, release resources.
377 * @param sh handle to release
380 GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh);
384 * Handle used within ATS to track an address.
386 struct GNUNET_ATS_AddressRecord;
390 * We have a new address ATS should know. Addresses have to be added with this
391 * function before they can be: updated, set in use and destroyed
394 * @param address the address
395 * @param session session handle (if available, i.e. for incoming connections)
396 * @param prop performance data for the address
397 * @return handle to the address representation inside ATS, NULL
398 * on error (i.e. ATS knows this exact address already, or
399 * address is invalid)
401 struct GNUNET_ATS_AddressRecord *
402 GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh,
403 const struct GNUNET_HELLO_Address *address,
404 struct GNUNET_ATS_Session *session,
405 const struct GNUNET_ATS_Properties *prop);
409 * An address was used to initiate a session.
411 * @param ar address record to update information for
412 * @param session session handle
415 GNUNET_ATS_address_add_session (struct GNUNET_ATS_AddressRecord *ar,
416 struct GNUNET_ATS_Session *session);
420 * A @a session was destroyed, disassociate it from the given address
421 * record. If this was an incoming addess, destroys the address as
424 * @param ar address record to update information for
425 * @param session session handle
426 * @return #GNUNET_YES if the @a ar was destroyed because
427 * it was an incoming address,
428 * #GNUNET_NO if the @ar was kept because we can
429 * use it still to establish a new session
432 GNUNET_ATS_address_del_session (struct GNUNET_ATS_AddressRecord *ar,
433 struct GNUNET_ATS_Session *session);
437 * We have updated performance statistics for a given address. Note
438 * that this function can be called for addresses that are currently
439 * in use as well as addresses that are valid but not actively in use.
440 * Furthermore, the peer may not even be connected to us right now (@a
441 * session value of NULL used to signal disconnect, or somehow we
442 * otherwise got updated on @a ats information). Based on the
443 * information provided, ATS may update bandwidth assignments and
444 * suggest to switch addresses.
446 * @param ar address record to update information for
447 * @param prop performance data for the address
450 GNUNET_ATS_address_update (struct GNUNET_ATS_AddressRecord *ar,
451 const struct GNUNET_ATS_Properties *prop);
455 * An address got destroyed, stop using it as a valid address.
457 * @param ar address record to destroy, it's validation has
458 * expired and ATS may no longer use it
461 GNUNET_ATS_address_destroy (struct GNUNET_ATS_AddressRecord *ar);
465 /* ******************************** Performance API ***************************** */
468 * ATS Handle to obtain and/or modify performance information.
470 struct GNUNET_ATS_PerformanceHandle;
473 * Signature of a function that is called with QoS information about an address.
476 * @param address the address, NULL if ATS service was disconnected or
477 * when the iteration is completed in the case of
478 * #GNUNET_ATS_performance_list_addresses()
479 * @param address_active #GNUNET_YES if this address is actively used
480 * to maintain a connection to a peer;
481 * #GNUNET_NO if the address is not actively used;
482 * #GNUNET_SYSERR if this address is no longer available for ATS
483 * @param bandwidth_out assigned outbound bandwidth for the connection
484 * @param bandwidth_in assigned inbound bandwidth for the connection
485 * @param prop performance data for the address
488 (*GNUNET_ATS_AddressInformationCallback) (void *cls,
489 const struct GNUNET_HELLO_Address *address,
491 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
492 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
493 const struct GNUNET_ATS_Properties *prop);
497 * Handle for an address listing operation
499 struct GNUNET_ATS_AddressListHandle;
503 * Get handle to access performance API of the ATS subsystem.
505 * @param cfg configuration to use
506 * @param addr_info_cb callback called when performance characteristics for
508 * @param addr_info_cb_cls closure for @a addr_info_cb
509 * @return ats performance context
511 struct GNUNET_ATS_PerformanceHandle *
512 GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
513 GNUNET_ATS_AddressInformationCallback addr_info_cb,
514 void *addr_info_cb_cls);
518 * Get information about addresses known to the ATS subsystem.
520 * @param handle the performance handle to use
521 * @param peer peer idm can be NULL for all peers
522 * @param all #GNUNET_YES to get information about all addresses or #GNUNET_NO to
523 * get only address currently used
524 * @param infocb callback to call with the addresses,
525 * will callback with address == NULL when done
526 * @param infocb_cls closure for @a infocb
527 * @return handle to abort the operation
529 struct GNUNET_ATS_AddressListHandle *
530 GNUNET_ATS_performance_list_addresses (struct GNUNET_ATS_PerformanceHandle *handle,
531 const struct GNUNET_PeerIdentity *peer,
533 GNUNET_ATS_AddressInformationCallback infocb,
538 * Cancel a pending address listing operation
540 * @param handle the `struct GNUNET_ATS_AddressListHandle` handle to cancel
543 GNUNET_ATS_performance_list_addresses_cancel (struct GNUNET_ATS_AddressListHandle *handle);
547 * Client is done using the ATS performance subsystem, release resources.
552 GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph);
556 * Function called with reservation result.
559 * @param peer identifies the peer
560 * @param amount set to the amount that was actually reserved or unreserved;
561 * either the full requested amount or zero (no partial reservations)
562 * @param res_delay if the reservation could not be satisfied (amount was 0), how
563 * long should the client wait until re-trying?
566 (*GNUNET_ATS_ReservationCallback) (void *cls,
567 const struct GNUNET_PeerIdentity *peer,
569 struct GNUNET_TIME_Relative res_delay);
573 * Context that can be used to cancel a peer information request.
575 struct GNUNET_ATS_ReservationContext;
579 * Reserve inbound bandwidth from the given peer. ATS will look at
580 * the current amount of traffic we receive from the peer and ensure
581 * that the peer could add 'amount' of data to its stream.
583 * @param ph performance handle
584 * @param peer identifies the peer
585 * @param amount reserve N bytes for receiving, negative
586 * amounts can be used to undo a (recent) reservation;
587 * @param rcb function to call with the resulting reservation information
588 * @param rcb_cls closure for @a rcb
589 * @return NULL on error
590 * @deprecated will be replaced soon
592 struct GNUNET_ATS_ReservationContext *
593 GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph,
594 const struct GNUNET_PeerIdentity *peer,
596 GNUNET_ATS_ReservationCallback rcb,
601 * Cancel request for reserving bandwidth.
603 * @param rc context returned by the original GNUNET_ATS_reserve_bandwidth call
606 GNUNET_ATS_reserve_bandwidth_cancel (struct GNUNET_ATS_ReservationContext *rc);
610 * ATS preference types as array initializer
612 #define GNUNET_ATS_PreferenceType {GNUNET_ATS_PREFERENCE_BANDWIDTH, GNUNET_ATS_PREFERENCE_LATENCY, GNUNET_ATS_PREFERENCE_END}
615 * ATS preference types as string array initializer
617 #define GNUNET_ATS_PreferenceTypeString {"BANDWIDTH", "LATENCY", "END" }
620 * Enum defining all known preference categories.
622 enum GNUNET_ATS_PreferenceKind
626 * Change the peer's bandwidth value (value per byte of bandwidth in
627 * the goal function) to the given amount. The argument is followed
628 * by a double value giving the desired value (can be negative).
629 * Preference changes are forgotten if peers disconnect.
631 GNUNET_ATS_PREFERENCE_BANDWIDTH = 0,
634 * Change the peer's latency value to the given amount. The
635 * argument is followed by a double value giving the desired value
636 * (can be negative). The absolute score in the goal function is
637 * the inverse of the latency in microseconds (minimum: 1
638 * microsecond) multiplied by the latency preferences.
640 GNUNET_ATS_PREFERENCE_LATENCY = 1,
643 * End of preference list.
645 GNUNET_ATS_PREFERENCE_END = 2
651 * Convert a GNUNET_ATS_PreferenceType to a string
653 * @param type the preference type
654 * @return a string or NULL if invalid
657 GNUNET_ATS_print_preference_type (enum GNUNET_ATS_PreferenceKind type);
661 * Change preferences for the given peer. Preference changes are forgotten if peers
664 * @param ph performance handle @param peer identifies the peer
665 * @param ... #GNUNET_ATS_PREFERENCE_END-terminated specification of the
669 GNUNET_ATS_performance_change_preference (struct GNUNET_ATS_PerformanceHandle *ph,
670 const struct GNUNET_PeerIdentity *peer,
675 * Application feedback on how good preference requirements are fulfilled
676 * for the preferences included in the given time scope [now - scope .. now]
678 * An application notifies ATS if (and only if) it has feedback information
679 * for specific properties. This values are valid until the feedback scores are
680 * updated by the application.
682 * If the application has no feedback for this preference kind the application
683 * will not explicitly call for this property and will not include it in this
686 * @param ph performance handle
687 * @param scope the time interval this valid for: [now - scope .. now]
688 * @param peer identifies the peer
689 * @param ... #GNUNET_ATS_PREFERENCE_END-terminated specification of the desired changes
692 GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph,
693 const struct GNUNET_PeerIdentity *peer,
694 const struct GNUNET_TIME_Relative scope,
698 /* end of file gnunet-service-transport_ats.h */