separate ATS interface scanning logic from ATS scheduling logic
[oweals/gnunet.git] / src / include / gnunet_ats_service.h
1 /*
2  This file is part of GNUnet.
3  (C) 2010-2015 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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.
19  */
20 /**
21  * @file include/gnunet_ats_service.h
22  * @brief automatic transport selection and outbound bandwidth determination
23  * @author Christian Grothoff
24  * @author Matthias Wachs
25  */
26 #ifndef GNUNET_ATS_SERVICE_H
27 #define GNUNET_ATS_SERVICE_H
28
29 #include "gnunet_constants.h"
30 #include "gnunet_util_lib.h"
31 #include "gnunet_hello_lib.h"
32
33 /**
34  * Number of network types supported by ATS
35  */
36 #define GNUNET_ATS_NetworkTypeCount 6
37
38
39 /**
40  * Types of networks (with separate quotas) we support.
41  */
42 enum GNUNET_ATS_Network_Type
43 {
44   /**
45    * Category of last resort.
46    */
47   GNUNET_ATS_NET_UNSPECIFIED = 0,
48
49   /**
50    * Loopback (same host).
51    */
52   GNUNET_ATS_NET_LOOPBACK = 1,
53
54   /**
55    * Local area network.
56    */
57   GNUNET_ATS_NET_LAN = 2,
58
59   /**
60    * Wide area network (i.e. Internet)
61    */
62   GNUNET_ATS_NET_WAN = 3,
63
64   /**
65    * Wireless LAN (i.e. 802.11abgn)
66    */
67   GNUNET_ATS_NET_WLAN = 4,
68
69   /**
70    * Bluetooth LAN
71    */
72   GNUNET_ATS_NET_BT = 5
73 };
74
75
76 /**
77  * ATS network types as array initializer
78  */
79 #define GNUNET_ATS_NetworkType { GNUNET_ATS_NET_UNSPECIFIED, GNUNET_ATS_NET_LOOPBACK, GNUNET_ATS_NET_LAN, GNUNET_ATS_NET_WAN, GNUNET_ATS_NET_WLAN, GNUNET_ATS_NET_BT }
80
81
82
83 /**
84  * Default bandwidth assigned to a network : 64 KB/s
85  */
86 #define GNUNET_ATS_DefaultBandwidth 65536
87
88 /**
89  * Undefined value for an `enum GNUNET_ATS_Property`
90  */
91 #define GNUNET_ATS_VALUE_UNDEFINED UINT32_MAX
92
93 /**
94  * String representation for GNUNET_ATS_VALUE_UNDEFINED
95  */
96 #define GNUNET_ATS_VALUE_UNDEFINED_STR "undefined"
97
98 /**
99  * Maximum bandwidth assigned to a network : 4095 MB/s
100  */
101 #define GNUNET_ATS_MaxBandwidth UINT32_MAX
102
103 /**
104  * Textual equivalent for GNUNET_ATS_MaxBandwidth
105  */
106 #define GNUNET_ATS_MaxBandwidthString "unlimited"
107
108 /**
109  * Number of property types supported by ATS
110  */
111 #define GNUNET_ATS_PropertyCount 11
112
113
114 /**
115  * Enum defining all known property types for ATS Enum values are used
116  * in the GNUNET_ATS_Information struct as
117  * (key,value)-pairs.
118  *
119  * Cost are always stored in uint32_t, so all units used to define costs
120  * have to be normalized to fit in uint32_t [0 .. UINT32_MAX-1]
121  *
122  * UINT32_MAX is reserved for uninitialized values #GNUNET_ATS_VALUE_UNDEFINED
123  */
124 enum GNUNET_ATS_Property
125 {
126
127   /**
128    * End of the array.
129    * @deprecated
130    */
131   GNUNET_ATS_ARRAY_TERMINATOR = 0,
132
133   /**
134    * Actual traffic on this connection from this peer to the other peer.
135    * Includes transport overhead
136    *
137    * Unit: [bytes/second]
138    */
139   GNUNET_ATS_UTILIZATION_OUT,
140
141   /**
142    * Actual traffic on this connection from the other peer to this peer.
143    * Includes transport overhead
144    *
145    * Unit: [bytes/second]
146    */
147   GNUNET_ATS_UTILIZATION_IN,
148
149   /**
150    * Actual traffic on this connection from this peer to the other peer.
151    * Only payload from layers > transport
152    *
153    * Unit: [bytes/second]
154    */
155   GNUNET_ATS_UTILIZATION_PAYLOAD_OUT,
156
157   /**
158    * Actual traffic on this connection from the other peer to this peer.
159    * Only payload from layers > transport
160    *
161    * Unit: [bytes/second]
162    */
163   GNUNET_ATS_UTILIZATION_PAYLOAD_IN,
164
165   /**
166    * Is this address located in WAN, LAN or a loopback address
167    * Value is element of GNUNET_ATS_Network_Type
168    */
169   GNUNET_ATS_NETWORK_TYPE,
170
171   /**
172    * Delay
173    * Time between when the time packet is sent and the packet arrives
174    *
175    * Unit: [microseconds]
176    *
177    * Examples:
178    *
179    * LAN   :    1
180    * WLAN  :    2
181    * Dialup:  500
182    */
183   GNUNET_ATS_QUALITY_NET_DELAY,
184
185   /**
186    * Distance on network layer (required for distance-vector routing).
187    *
188    * Unit: [DV-hops]
189    */
190   GNUNET_ATS_QUALITY_NET_DISTANCE,
191
192   /**
193    * Network overhead on WAN (Wide-Area Network)
194    *
195    * How many bytes are sent on the WAN when 1 kilobyte (1024 bytes)
196    * of application data is transmitted?
197    * A factor used with connect cost, bandwidth cost and energy cost
198    * to describe the overhead produced by the transport protocol
199    *
200    * Unit: [bytes/kb]
201    *
202    * Interpretation: less is better
203    *
204    * Examples:
205    *
206    * TCP/IPv4 over Ethernet: 1024 + 38 + 20 + 20 = 1102 [bytes/kb]
207    * TCP/IPv6 over Ethernet: 1024 + 38 + 20 + 40 = 1122 [bytes/kb]
208    * UDP/IPv4 over Ethernet: 1024 + 38 + 20 + 8  = 1090 [bytes/kb]
209    * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8  = 1110 [bytes/kb]
210    */
211   GNUNET_ATS_COST_WAN,
212
213   /**
214    * Network overhead on LAN (Local-Area Network)
215    *
216    * How many bytes are sent on the LAN when 1 kilobyte (1024 bytes)
217    * of application data is transmitted?
218    * A factor used with connect cost, bandwidth cost and energy cost
219    * to describe the overhead produced by the transport protocol
220    *
221    * Unit: [bytes/kb]
222    *
223    * Interpretation: less is better
224    *
225    * Examples:
226    *
227    * TCP/IPv4 over Ethernet: 1024 + 38 + 20 + 20 = 1102 [bytes/kb]
228    * TCP/IPv6 over Ethernet: 1024 + 38 + 20 + 40 = 1122 [bytes/kb]
229    * UDP/IPv4 over Ethernet: 1024 + 38 + 20 + 8  = 1090 [bytes/kb]
230    * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8  = 1110 [bytes/kb]
231    */
232   GNUNET_ATS_COST_LAN,
233
234   /**
235    * Network overhead on WLAN (Wireless Local Area Network)
236    *
237    * How many bytes are sent on the LAN when 1 kilobyte (1024 bytes)
238    * of application data is transmitted?
239    * A factor used with connect cost, bandwidth cost and energy cost
240    * to describe the overhead produced by the transport protocol
241    *
242    * Unit: [bytes/kb]
243    *
244    * Interpretation: less is better
245    *
246    * Examples:
247    *
248    * TCP/IPv4 over Ethernet: 1024 + 38 + 20 + 20 = 1102 [bytes/kb]
249    * TCP/IPv6 over Ethernet: 1024 + 38 + 20 + 40 = 1122 [bytes/kb]
250    * UDP/IPv4 over Ethernet: 1024 + 38 + 20 + 8  = 1090 [bytes/kb]
251    * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8  = 1110 [bytes/kb]
252    */
253   GNUNET_ATS_COST_WLAN
254
255 };
256
257
258 /**
259  * Number of ATS quality properties
260  */
261 #define GNUNET_ATS_QualityPropertiesCount 2
262
263 /**
264  * ATS quality properties as array initializer
265  */
266 #define GNUNET_ATS_QualityProperties { GNUNET_ATS_QUALITY_NET_DELAY, GNUNET_ATS_QUALITY_NET_DISTANCE }
267
268 /**
269  * ATS quality properties as string array initializer
270  */
271 #define GNUNET_ATS_QualityPropertiesString {"Delay", "Distance"}
272
273 GNUNET_NETWORK_STRUCT_BEGIN
274
275 /**
276  * struct used to communicate the transport's properties like cost and
277  * quality of service as well as high-level constraints on resource
278  * consumption.
279  *
280  *                             +---+
281  *  +-----------+ Constraints  |   |  Plugin properties +---------+
282  *  | Highlevel |------------> |ATS| <------------------|Transport|
283  *  | Component | ATS struct   |   |    ATS struct      | Plugin  |
284  *  +-----------+              |   |                    +---------+
285  *                             +---+
286  *
287  * This structure will be used by transport plugins to communicate
288  * costs to ATS or by higher level components to tell ATS their
289  * constraints.  Always a pair of (GNUNET_ATS_Property,
290  * uint32_t value).  Value is always uint32_t, so all units used to
291  * define costs have to be normalized to fit uint32_t.
292  */
293 struct GNUNET_ATS_Information
294 {
295   /**
296    * ATS property type, in network byte order.
297    */
298   uint32_t type GNUNET_PACKED;
299
300   /**
301    * ATS property value, in network byte order.
302    */
303   uint32_t value GNUNET_PACKED;
304 };
305 GNUNET_NETWORK_STRUCT_END
306
307
308 /* ********************* LAN Characterization library ************************ */
309 /* Note: these functions do not really communicate with the ATS service */
310
311 /**
312  * Convert a ATS property to a string
313  *
314  * @param type the property type
315  * @return a string or NULL if invalid
316  */
317 const char *
318 GNUNET_ATS_print_property_type (enum GNUNET_ATS_Property type);
319
320
321 /**
322  * Convert a `enum GNUNET_ATS_Network_Type` to a string
323  *
324  * @param net the network type
325  * @return a string or NULL if invalid
326  */
327 const char *
328 GNUNET_ATS_print_network_type (enum GNUNET_ATS_Network_Type net);
329
330
331 /**
332  * Handle for the LAN Characterization library.
333  */
334 struct GNUNET_ATS_InterfaceScanner;
335
336
337 /**
338  * Returns where the address is located: loopback, LAN or WAN.
339  *
340  * @param is handle from #GNUNET_ATS_interface_scanner_init()
341  * @param addr address
342  * @param addrlen address length
343  * @return type of the network the address belongs to
344  */
345 enum GNUNET_ATS_Network_Type
346 GNUNET_ATS_scanner_address_get_type (struct GNUNET_ATS_InterfaceScanner *is,
347                                      const struct sockaddr *addr,
348                                      socklen_t addrlen);
349
350
351 /**
352  * Initialize the ATS address characterization client handle.
353  *
354  * @return scanner handle, NULL on error
355  */
356 struct GNUNET_ATS_InterfaceScanner *
357 GNUNET_ATS_scanner_init (void);
358
359
360 /**
361  * Terminate interface scanner.
362  *
363  * @param is scanner we are done with
364  */
365 void
366 GNUNET_ATS_scanner_done (struct GNUNET_ATS_InterfaceScanner *is);
367
368
369
370 /* ********************Connection Suggestion API ***************************** */
371
372 /**
373  * Handle to the ATS subsystem for making suggestions about
374  * connections the peer would like to have.
375  */
376 struct GNUNET_ATS_ConnectivityHandle;
377
378 /**
379  * Handle for address suggestion requests.
380  */
381 struct GNUNET_ATS_ConnectivitySuggestHandle;
382
383
384 /**
385  * Initialize the ATS connectivity suggestion client handle.
386  *
387  * @param cfg configuration to use
388  * @return ats connectivity handle, NULL on error
389  */
390 struct GNUNET_ATS_ConnectivityHandle *
391 GNUNET_ATS_connectivity_init (const struct GNUNET_CONFIGURATION_Handle *cfg);
392
393
394 /**
395  * Shutdown ATS connectivity suggestion client.
396  *
397  * @param ch handle to destroy
398  */
399 void
400 GNUNET_ATS_connectivity_done (struct GNUNET_ATS_ConnectivityHandle *ch);
401
402
403 /**
404  * We would like to establish a new connection with a peer.  ATS
405  * should suggest a good address to begin with.
406  *
407  * @param ch handle
408  * @param peer identity of the peer we need an address for
409  * @return suggestion handle, NULL if request is already pending
410  */
411 struct GNUNET_ATS_ConnectivitySuggestHandle *
412 GNUNET_ATS_connectivity_suggest (struct GNUNET_ATS_ConnectivityHandle *ch,
413                                  const struct GNUNET_PeerIdentity *peer);
414
415
416 /**
417  * We no longer care about being connected to a peer.
418  *
419  * @param sh handle
420  */
421 void
422 GNUNET_ATS_connectivity_suggest_cancel (struct GNUNET_ATS_ConnectivitySuggestHandle *sh);
423
424
425 /* ******************************** Scheduling API ***************************** */
426
427 /**
428  * Handle to the ATS subsystem for bandwidth/transport scheduling information.
429  */
430 struct GNUNET_ATS_SchedulingHandle;
431
432 /**
433  * Opaque session handle, defined by plugins.  Contents not known to ATS.
434  */
435 struct Session;
436
437 /**
438  * Signature of a function called by ATS with the current bandwidth
439  * and address preferences as determined by ATS.
440  *
441  * @param cls closure
442  * @param address suggested address (including peer identity of the peer)
443  * @param session session to use, NULL to establish a new outgoing session
444  * @param bandwidth_out assigned outbound bandwidth for the connection,
445  *        0 to disconnect
446  * @param bandwidth_in assigned inbound bandwidth for the connection,
447  *        0 to disconnect
448  */
449 typedef void
450 (*GNUNET_ATS_AddressSuggestionCallback) (void *cls,
451     const struct GNUNET_PeerIdentity *peer,
452     const struct GNUNET_HELLO_Address *address,
453     struct Session *session,
454     struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
455     struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in);
456
457
458 /**
459  * Initialize the ATS scheduling subsystem.
460  *
461  * @param cfg configuration to use
462  * @param suggest_cb notification to call whenever the suggestation changed
463  * @param suggest_cb_cls closure for @a suggest_cb
464  * @return ats context
465  */
466 struct GNUNET_ATS_SchedulingHandle *
467 GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
468                             GNUNET_ATS_AddressSuggestionCallback suggest_cb,
469                             void *suggest_cb_cls);
470
471
472 /**
473  * Client is done with ATS scheduling, release resources.
474  *
475  * @param sh handle to release
476  */
477 void
478 GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh);
479
480
481 /**
482  * We would like to reset the address suggestion block time for this
483  * peer.
484  *
485  * @param sh handle
486  * @param peer identity of the peer we want to reset
487  */
488 void
489 GNUNET_ATS_reset_backoff (struct GNUNET_ATS_SchedulingHandle *sh,
490                           const struct GNUNET_PeerIdentity *peer);
491
492
493 /**
494  * Test if a address and a session is known to ATS.
495  *
496  * @param sh the scheduling handle
497  * @param address the address
498  * @param session the session
499  * @return #GNUNET_YES or #GNUNET_NO
500  */
501 int
502 GNUNET_ATS_session_known (struct GNUNET_ATS_SchedulingHandle *sh,
503                           const struct GNUNET_HELLO_Address *address,
504                           struct Session *session);
505
506
507 /**
508  * Handle used within ATS to track an address.
509  */
510 struct GNUNET_ATS_AddressRecord;
511
512
513 /**
514  * We have a new address ATS should know. Addresses have to be added with this
515  * function before they can be: updated, set in use and destroyed
516  *
517  * @param sh handle
518  * @param address the address
519  * @param session session handle (if available, i.e. for incoming connections)
520  * @param ats performance data for the address
521  * @param ats_count number of performance records in @a ats
522  * @return handle to the address representation inside ATS, NULL
523  *         on error (i.e. ATS knows this exact address already, or
524  *         address is invalid)
525  */
526 struct GNUNET_ATS_AddressRecord *
527 GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh,
528                         const struct GNUNET_HELLO_Address *address,
529                         struct Session *session,
530                         const struct GNUNET_ATS_Information *ats,
531                         uint32_t ats_count);
532
533
534 /**
535  * An address was used to initiate a session.
536  *
537  * @param ar address record to update information for
538  * @param session session handle
539  */
540 void
541 GNUNET_ATS_address_add_session (struct GNUNET_ATS_AddressRecord *ar,
542                                 struct Session *session);
543
544
545 /**
546  * A session was destroyed, disassociate it from the
547  * given address record.  If this was an incoming
548  * addess, destroy the address as well.
549  *
550  * @param ar address record to update information for
551  * @param session session handle
552  * @return #GNUNET_YES if the @a ar was destroyed because
553  *                     it was an incoming address,
554  *         #GNUNET_NO if the @ar was kept because we can
555  *                    use it still to establish a new session
556  */
557 int
558 GNUNET_ATS_address_del_session (struct GNUNET_ATS_AddressRecord *ar,
559                                 struct Session *session);
560
561
562 /**
563  * We have updated performance statistics for a given address.  Note
564  * that this function can be called for addresses that are currently
565  * in use as well as addresses that are valid but not actively in use.
566  * Furthermore, the peer may not even be connected to us right now (@a
567  * session value of NULL used to signal disconnect, or somehow we
568  * otherwise got updated on @a ats information).  Based on the
569  * information provided, ATS may update bandwidth assignments and
570  * suggest to switch addresses.
571  *
572  * @param ar address record to update information for
573  * @param ats performance data for the address
574  * @param ats_count number of performance records in @a ats
575  */
576 void
577 GNUNET_ATS_address_update (struct GNUNET_ATS_AddressRecord *ar,
578                            const struct GNUNET_ATS_Information *ats,
579                            uint32_t ats_count);
580
581
582 /**
583  * An address is now in use, or not used any more.
584  *
585  * @param ar address record for which to toggle the flag
586  * @param in_use #GNUNET_YES if this address is now used, #GNUNET_NO
587  *               if address is not used any more
588  */
589 void
590 GNUNET_ATS_address_set_in_use (struct GNUNET_ATS_AddressRecord *ar,
591                                int in_use);
592
593
594 /**
595  * An address got destroyed, stop using it as a valid address.
596  *
597  * @param ar address record to destroy, it's validation has
598  *           expired and ATS may no longer use it
599  */
600 void
601 GNUNET_ATS_address_destroy (struct GNUNET_ATS_AddressRecord *ar);
602
603
604
605 /* ******************************** Performance API ***************************** */
606
607 /**
608  * ATS Handle to obtain and/or modify performance information.
609  */
610 struct GNUNET_ATS_PerformanceHandle;
611
612 /**
613  * Signature of a function that is called with QoS information about an address.
614  *
615  * @param cls closure
616  * @param address the address, NULL if ATS service was disconnected
617  * @param address_active #GNUNET_YES if this address is actively used
618  *        to maintain a connection to a peer;
619  *        #GNUNET_NO if the address is not actively used;
620  *        #GNUNET_SYSERR if this address is no longer available for ATS
621  * @param bandwidth_out assigned outbound bandwidth for the connection
622  * @param bandwidth_in assigned inbound bandwidth for the connection
623  * @param ats performance data for the address (as far as known)
624  * @param ats_count number of performance records in @a ats
625  */
626 typedef void
627 (*GNUNET_ATS_AddressInformationCallback) (void *cls,
628                                           const struct GNUNET_HELLO_Address *address,
629                                           int address_active,
630                                           struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
631                                           struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
632                                           const struct GNUNET_ATS_Information *ats,
633                                           uint32_t ats_count);
634
635
636 /**
637  * Handle for an address listing operation
638  */
639 struct GNUNET_ATS_AddressListHandle;
640
641
642 /**
643  * Get handle to access performance API of the ATS subsystem.
644  *
645  * @param cfg configuration to use
646  * @param addr_info_cb callback called when performance characteristics for
647  *      an address change
648  * @param addr_info_cb_cls closure for @a addr_info_cb
649  * @return ats performance context
650  */
651 struct GNUNET_ATS_PerformanceHandle *
652 GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
653                              GNUNET_ATS_AddressInformationCallback addr_info_cb,
654                              void *addr_info_cb_cls);
655
656
657
658 /**
659  * Get information about addresses known to the ATS subsystem.
660  *
661  * @param handle the performance handle to use
662  * @param peer peer idm can be NULL for all peers
663  * @param all GNUNET_YES to get information about all addresses or GNUNET_NO to
664  *        get only address currently used
665  * @param infocb callback to call with the addresses,
666  *        will callback with address == NULL when done
667  * @param infocb_cls closure for @a infocb
668  * @return ats performance context
669  */
670 struct GNUNET_ATS_AddressListHandle *
671 GNUNET_ATS_performance_list_addresses (struct GNUNET_ATS_PerformanceHandle *handle,
672                                        const struct GNUNET_PeerIdentity *peer,
673                                        int all,
674                                        GNUNET_ATS_AddressInformationCallback infocb,
675                                        void *infocb_cls);
676
677
678 /**
679  * Cancel a pending address listing operation
680  *
681  * @param handle the `struct GNUNET_ATS_AddressListHandle` handle to cancel
682  */
683 void
684 GNUNET_ATS_performance_list_addresses_cancel (struct GNUNET_ATS_AddressListHandle *handle);
685
686
687 /**
688  * Client is done using the ATS performance subsystem, release resources.
689  *
690  * @param ph handle
691  */
692 void
693 GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph);
694
695
696 /**
697  * Function called with reservation result.
698  *
699  * @param cls closure
700  * @param peer identifies the peer
701  * @param amount set to the amount that was actually reserved or unreserved;
702  *               either the full requested amount or zero (no partial reservations)
703  * @param res_delay if the reservation could not be satisfied (amount was 0), how
704  *        long should the client wait until re-trying?
705  */
706 typedef void
707 (*GNUNET_ATS_ReservationCallback) (void *cls,
708                                    const struct GNUNET_PeerIdentity * peer,
709                                    int32_t amount,
710                                    struct GNUNET_TIME_Relative res_delay);
711
712
713 /**
714  * Context that can be used to cancel a peer information request.
715  */
716 struct GNUNET_ATS_ReservationContext;
717
718
719 /**
720  * Reserve inbound bandwidth from the given peer.  ATS will look at
721  * the current amount of traffic we receive from the peer and ensure
722  * that the peer could add 'amount' of data to its stream.
723  *
724  * @param ph performance handle
725  * @param peer identifies the peer
726  * @param amount reserve N bytes for receiving, negative
727  *                amounts can be used to undo a (recent) reservation;
728  * @param rcb function to call with the resulting reservation information
729  * @param rcb_cls closure for info
730  * @return NULL on error
731  * @deprecated will be replaced soon
732  */
733 struct GNUNET_ATS_ReservationContext *
734 GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph,
735     const struct GNUNET_PeerIdentity *peer, int32_t amount,
736     GNUNET_ATS_ReservationCallback rcb, void *rcb_cls);
737
738
739 /**
740  * Cancel request for reserving bandwidth.
741  *
742  * @param rc context returned by the original GNUNET_ATS_reserve_bandwidth call
743  */
744 void
745 GNUNET_ATS_reserve_bandwidth_cancel (struct GNUNET_ATS_ReservationContext *rc);
746
747 /**
748  * Number of preference types supported by ATS
749  */
750 #define GNUNET_ATS_PreferenceCount 3
751
752 /**
753  * ATS preference types as array initializer
754  */
755 #define GNUNET_ATS_PreferenceType {GNUNET_ATS_PREFERENCE_END, GNUNET_ATS_PREFERENCE_BANDWIDTH, GNUNET_ATS_PREFERENCE_LATENCY}
756
757 /**
758  * ATS preference types as string array initializer
759  */
760 #define GNUNET_ATS_PreferenceTypeString {"END", "BANDWIDTH", "LATENCY"}
761
762 /**
763  * Enum defining all known preference categories.
764  */
765 enum GNUNET_ATS_PreferenceKind
766 {
767
768   /**
769    * End of preference list.
770    */
771   GNUNET_ATS_PREFERENCE_END = 0,
772
773   /**
774    * Change the peer's bandwidth value (value per byte of bandwidth in
775    * the goal function) to the given amount.  The argument is followed
776    * by a double value giving the desired value (can be negative).
777    * Preference changes are forgotten if peers disconnect.
778    */
779   GNUNET_ATS_PREFERENCE_BANDWIDTH,
780
781   /**
782    * Change the peer's latency value to the given amount.  The
783    * argument is followed by a double value giving the desired value
784    * (can be negative).  The absolute score in the goal function is
785    * the inverse of the latency in microseconds (minimum: 1
786    * microsecond) multiplied by the latency preferences.
787    */
788   GNUNET_ATS_PREFERENCE_LATENCY
789 };
790
791 /**
792  * Convert a GNUNET_ATS_PreferenceType to a string
793  *
794  * @param type the preference type
795  * @return a string or NULL if invalid
796  */
797 const char *
798 GNUNET_ATS_print_preference_type (uint32_t type);
799
800
801 /**
802  * Change preferences for the given peer. Preference changes are forgotten if peers
803  * disconnect.
804  *
805  * @param ph performance handle
806  * @param peer identifies the peer
807  * @param ... 0-terminated specification of the desired changes
808  */
809 void
810 GNUNET_ATS_performance_change_preference (struct GNUNET_ATS_PerformanceHandle *ph,
811                                           const struct GNUNET_PeerIdentity *peer, ...);
812
813
814 /**
815  * Application feedback on how good preference requirements are fulfilled
816  * for the preferences included in the given time scope [now - scope .. now]
817  *
818  * An application notifies ATS if (and only if) it has feedback information
819  * for specific properties. This values are valid until the feedback scores are
820  * updated by the application.
821  *
822  * If the application has no feedback for this preference kind the application
823  * will not explicitly call for this property and will not include it in this
824  * function call.
825  *
826  * @param ph performance handle
827  * @param scope the time interval this valid for: [now - scope .. now]
828  * @param peer identifies the peer
829  * @param ... 0-terminated specification of the desired changes
830  */
831 void
832 GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph,
833     const struct GNUNET_PeerIdentity *peer,
834     const struct GNUNET_TIME_Relative scope, ...);
835
836 #endif
837 /* end of file gnunet-service-transport_ats.h */