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