-doxygen, plus FIXME request for clarification
[oweals/gnunet.git] / src / include / gnunet_ats_service.h
1 /*
2  This file is part of GNUnet.
3  (C) 2010,2011 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  * ATS network types as array initializer
40  */
41 #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}
42
43 /**
44  * ATS network types as string array initializer
45  */
46 #define GNUNET_ATS_NetworkTypeString {"UNSPECIFIED", "LOOPBACK", "LAN", "WAN", "WLAN", "BLUETOOTH"}
47
48 enum GNUNET_ATS_Network_Type
49 {
50   GNUNET_ATS_NET_UNSPECIFIED = 0,
51   GNUNET_ATS_NET_LOOPBACK = 1,
52   GNUNET_ATS_NET_LAN = 2,
53   GNUNET_ATS_NET_WAN = 3,
54   GNUNET_ATS_NET_WLAN = 4,
55   GNUNET_ATS_NET_BT = 5
56 };
57
58 /**
59  * Default bandwidth assigned to a network : 64 KB/s
60  */
61 #define GNUNET_ATS_DefaultBandwidth 65536
62
63 /**
64  * Undefined value for a GNUNET_ATS_Property
65  */
66 #define GNUNET_ATS_VALUE_UNDEFINED UINT32_MAX
67
68 /**
69  * String representation for GNUNET_ATS_VALUE_UNDEFINED
70  */
71 #define GNUNET_ATS_VALUE_UNDEFINED_STR "undefined"
72
73 /**
74  * Maximum bandwidth assigned to a network : 4095 MB/s
75  */
76 #define GNUNET_ATS_MaxBandwidth UINT32_MAX
77
78 /**
79  * Textual equivalent for GNUNET_ATS_MaxBandwidth
80  */
81 #define GNUNET_ATS_MaxBandwidthString "unlimited"
82
83 /**
84  * Number of property types supported by ATS
85  */
86 #define GNUNET_ATS_PropertyCount 11
87
88 /**
89  * ATS properties types as string array initializer
90  */
91 #define GNUNET_ATS_PropertyStrings {"TERMINATOR", "UTILIZATION_UP", "UTILIZATION_DOWN", "UTILIZATION_PAYLOAD_UP", "UTILIZATION_PAYLOAD_DOWN", "NETWORK_TYPE", "DELAY", "DISTANCE", "COST_WAN", "COST_LAN", "COST_WLAN"}
92
93 /**
94  * Enum defining all known property types for ATS Enum values are used
95  * in the GNUNET_ATS_Information struct as
96  * (key,value)-pairs.
97  *
98  * Cost are always stored in uint32_t, so all units used to define costs
99  * have to be normalized to fit in uint32_t [0 .. UINT32_MAX-1]
100  *
101  * UINT32_MAX is reserved for uninitialized values GNUNET_ATS_VALUE_UNDEFINED
102  */
103 enum GNUNET_ATS_Property
104 {
105
106   /**
107    * End of the array.
108    * @deprecated
109    */
110   GNUNET_ATS_ARRAY_TERMINATOR = 0,
111
112   /**
113    * Actual traffic on this connection from this peer to the other peer.
114    * Includes transport overhead
115    *
116    * Unit: [bytes/second]
117    */
118   GNUNET_ATS_UTILIZATION_OUT,
119
120   /**
121    * Actual traffic on this connection from the other peer to this peer.
122    * Includes transport overhead
123    *
124    * Unit: [bytes/second]
125    */
126   GNUNET_ATS_UTILIZATION_IN,
127
128
129   /**
130    * Actual traffic on this connection from this peer to the other peer.
131    * Only payload from layers > transport
132    *
133    * Unit: [bytes/second]
134    */
135   GNUNET_ATS_UTILIZATION_PAYLOAD_OUT,
136
137   /**
138    * Actual traffic on this connection from the other peer to this peer.
139    * Only payload from layers > transport
140    *
141    * Unit: [bytes/second]
142    */
143   GNUNET_ATS_UTILIZATION_PAYLOAD_IN,
144
145   /**
146    * Is this address located in WAN, LAN or a loopback address
147    * Value is element of GNUNET_ATS_Network_Type
148    */
149   GNUNET_ATS_NETWORK_TYPE,
150
151   /**
152    * Delay
153    * Time between when the time packet is sent and the packet arrives
154    *
155    * Unit: [microseconds]
156    *
157    * Examples:
158    *
159    * LAN   :    1
160    * WLAN  :    2
161    * Dialup:  500
162    */
163   GNUNET_ATS_QUALITY_NET_DELAY,
164
165   /**
166    * Distance on network layer (required for distance-vector routing).
167    *
168    * Unit: [DV-hops]
169    */
170   GNUNET_ATS_QUALITY_NET_DISTANCE,
171
172   /**
173    * Network overhead on WAN (Wide-Area Network)
174    *
175    * How many bytes are sent on the WAN when 1 kilobyte (1024 bytes)
176    * of application data is transmitted?
177    * A factor used with connect cost, bandwidth cost and energy cost
178    * to describe the overhead produced by the transport protocol
179    *
180    * Unit: [bytes/kb]
181    *
182    * Interpretation: less is better
183    *
184    * Examples:
185    *
186    * TCP/IPv4 over Ethernet: 1024 + 38 + 20 + 20 = 1102 [bytes/kb]
187    * TCP/IPv6 over Ethernet: 1024 + 38 + 20 + 40 = 1122 [bytes/kb]
188    * UDP/IPv4 over Ethernet: 1024 + 38 + 20 + 8  = 1090 [bytes/kb]
189    * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8  = 1110 [bytes/kb]
190    */
191   GNUNET_ATS_COST_WAN,
192
193   /**
194    * Network overhead on LAN (Local-Area Network)
195    *
196    * How many bytes are sent on the LAN when 1 kilobyte (1024 bytes)
197    * of application data is transmitted?
198    * A factor used with connect cost, bandwidth cost and energy cost
199    * to describe the overhead produced by the transport protocol
200    *
201    * Unit: [bytes/kb]
202    *
203    * Interpretation: less is better
204    *
205    * Examples:
206    *
207    * TCP/IPv4 over Ethernet: 1024 + 38 + 20 + 20 = 1102 [bytes/kb]
208    * TCP/IPv6 over Ethernet: 1024 + 38 + 20 + 40 = 1122 [bytes/kb]
209    * UDP/IPv4 over Ethernet: 1024 + 38 + 20 + 8  = 1090 [bytes/kb]
210    * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8  = 1110 [bytes/kb]
211    */
212   GNUNET_ATS_COST_LAN,
213
214   /**
215    * Network overhead on WLAN (Wireless Local Area Network)
216    *
217    * How many bytes are sent on the LAN when 1 kilobyte (1024 bytes)
218    * of application data is transmitted?
219    * A factor used with connect cost, bandwidth cost and energy cost
220    * to describe the overhead produced by the transport protocol
221    *
222    * Unit: [bytes/kb]
223    *
224    * Interpretation: less is better
225    *
226    * Examples:
227    *
228    * TCP/IPv4 over Ethernet: 1024 + 38 + 20 + 20 = 1102 [bytes/kb]
229    * TCP/IPv6 over Ethernet: 1024 + 38 + 20 + 40 = 1122 [bytes/kb]
230    * UDP/IPv4 over Ethernet: 1024 + 38 + 20 + 8  = 1090 [bytes/kb]
231    * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8  = 1110 [bytes/kb]
232    */
233   GNUNET_ATS_COST_WLAN
234 /* Cost related values */
235 /* =================== */
236 /**
237  * Volume based cost in financial units to transmit data
238  *
239  * Note: This value is not bound to a specific currency or unit and only
240  * used locally.
241  * "cent" just refers the smallest amount of money in the respective
242  * currency.
243  *
244  * Unit: [cent/MB]
245  *
246  * Interpretation: less is better
247  *
248  * Examples:
249  * LAN:  0 [cent/MB]
250  * 2G : 10 [cent/MB]
251  */
252 // GNUNET_ATS_COST_FINANCIAL_PER_VOLUME = 1,
253 /**
254  * Time based cost in financial units to transmit data
255  *
256  * Note: This value is not bound to a specific currency or unit and only
257  * used locally.
258  * "cent" just refers the smallest amount of money in the respective
259  * currency.
260  *
261  * Unit: [cent/h]
262  *
263  * Interpretation: less is better
264  *
265  * Examples:
266  * LAN   :  0 [cent/h]
267  * Dialup: 10 [cent/h]
268  */
269 // GNUNET_ATS_COST_FINANCIAL_PER_TIME = 2,
270 /**
271  * Computational costs
272  *
273  * Effort of preparing data to be sent with this transport
274  * Includes encoding, encryption and conversion of data
275  * Partial values can be summed up: c_sum = c_enc + c_enc + c_conv
276  * Resulting values depend on local system properties, e.g. CPU
277  *
278  * Unit: [ms/GB]
279  *
280  * Interpretation: less is better
281  *
282  * Examples:
283  *
284  * HTTPS with AES CBC-256:      7,382
285  * HTTPS with AES CBC-128:      5,279
286  * HTTPS with RC4-1024:         2,652
287  */
288 // GNUNET_ATS_COST_COMPUTATIONAL = 3,
289 /**
290  * Energy consumption
291  *
292  * Energy consumption using this transport when sending with a certain
293  * power at a certain bitrate. This is only an approximation based on:
294  * Energy consumption E = P / D
295  *
296  * with:
297  * Power P in Watt (J/s)
298  * Datarate D in MBit/s
299  *
300  * Conversion between power P and dBm used by WLAN in radiotap's dBm TX power:
301  *
302  * Lp(dbm) = 10 log10 (P/ 1mW)
303  *
304  * => P = 1 mW  * 10^(Lp(dbm)/10)
305  *
306  * Unit: [mJ/MB]
307  *
308  * Interpretation: less is better
309  *
310  * Examples:
311  *
312  * LAN:       0
313  * WLAN:      89 (600 mW @ 802.11g /w 54 MBit/s)
314  * Bluetooth: 267 (100 mW @ BT2.0 EDR /w 3 MBit/s)
315  */
316 // GNUNET_ATS_COST_ENERGY_CONSUMPTION = 4,
317 /**
318  * Connect cost
319  * How many bytes are transmitted to initiate a new connection using
320  * this transport?
321  *
322  * Unit: [bytes]
323  *
324  * Interpretation: less is better
325  *
326  * Examples:
327  *
328  * UDP (No connection)      :
329  *     0 bytes
330  * TCP (TCP 3-Way handshake):
331  *   220 bytes Ethernet,  172 bytes TCP/IP,  122 bytes TCP
332  * HTTP (TCP + Header)      :
333  *   477 bytes Ethernet,  429 bytes TCP/IP,  374 bytes TCP,  278 bytes HTTP
334  * HTTPS  HTTP+TLS Handshake:
335  *  2129 bytes Ethernet, 1975 bytes TCP/IP, 1755 bytes TCP, 1403 bytes HTTPS
336  *
337  * */
338 // GNUNET_ATS_COST_CONNECT = 5,
339 /**
340  * Bandwidth cost
341  *
342  * How many bandwidth is available to consume?
343  * Used to calculate which impact sending data with this transport has
344  *
345  * Unit: [kB/s]
346  *
347  * Interpretation: more is better
348  *
349  * Examples:
350  * LAN:     12,800  (100 MBit/s)
351  * WLAN:    6,912   (54 MBit/s)
352  * Dial-up: 8       (64 Kbit/s)
353  *
354  */
355 // GNUNET_ATS_COST_BANDWITH_AVAILABLE = 6,
356 /**
357  *  Network overhead
358  *
359  * How many bytes are sent over the wire when 1 kilobyte (1024 bytes)
360  * of application data is transmitted?
361  * A factor used with connect cost, bandwidth cost and energy cost
362  * to describe the overhead produced by the transport protocol
363  *
364  * Unit: [bytes/kb]
365  *
366  * Interpretation: less is better
367  *
368  * Examples:
369  *
370  * TCP/IPv4 over Ethernet: 1024 + 38 + 20 + 20 = 1102 [bytes/kb]
371  * TCP/IPv6 over Ethernet: 1024 + 38 + 20 + 40 = 1122 [bytes/kb]
372  * UDP/IPv4 over Ethernet: 1024 + 38 + 20 + 8  = 1090 [bytes/kb]
373  * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8  = 1110 [bytes/kb]
374  */
375 // GNUNET_ATS_COST_NETWORK_OVERHEAD = 7,
376 /* Quality related values */
377 /* ====================== */
378 /* Physical layer quality properties */
379 /**
380  * Signal strength on physical layer
381  *
382  * Unit: [dBm]
383  */
384 // GNUNET_ATS_QUALITY_PHY_SIGNAL_STRENGTH = 1025,
385 /**
386  * Collision rate on physical layer
387  *
388  * Unit: [B/s]
389  */
390 // GNUNET_ATS_QUALITY_PHY_COLLISION_RATE = 1026,
391 /**
392  * Error rate on physical layer
393  *
394  * Unit: [B/s]
395  */
396 // GNUNET_ATS_QUALITY_PHY_ERROR_RATE = 1027,
397 /**
398  * Jitter
399  * Time variations of the delay
400  * 1st derivative of a delay function
401  *
402  * Unit: [ms]
403  */
404 // GNUNET_ATS_QUALITY_NET_JITTER = 1029,
405 /**
406  * Error rate on network layer
407  *
408  * Unit: [B/s]
409  *
410  * Examples:
411  *
412  * LAN       :    0
413  * WLAN      :  400
414  * Bluetooth :  100
415  * Note: This numbers are just assumptions as an example, not
416  * measured or somehow determined
417  */
418 // GNUNET_ATS_QUALITY_NET_ERRORRATE = 1030,
419 /**
420  * Drop rate on network layer
421  * Bytes actively dismissed by a network component during transmission
422  * Reasons for dropped data can be full queues, congestion, quota violations...
423  *
424  * Unit: [B/s]
425  *
426  * Examples:
427  *
428  * LAN       :    0
429  * WLAN      :  400
430  * Bluetooth :  100
431  * Note: This numbers are just assumptions as an example, not
432  * measured or somehow determined
433  */
434 // GNUNET_ATS_QUALITY_NET_DROPRATE = 1031,
435 /**
436  * Loss rate on network layer
437  * Bytes lost during transmission
438  * Reasons can be collisions, ...
439  *
440  * Unit: [B/s]
441  *
442  * Examples:
443  *
444  * LAN       :    0
445  * WLAN      :   40
446  * Bluetooth :   10
447  * Note: This numbers are just assumptions as an example, not measured
448  * or somehow determined
449  */
450 // GNUNET_ATS_QUALITY_NET_LOSSRATE = 1032,
451 /**
452  * Throughput on network layer
453  *
454  * Unit: [kB/s]
455  *
456  * Examples:
457  *
458  * LAN   : 3400
459  * WLAN  : 1200
460  * Dialup:        4
461  *
462  */
463 // GNUNET_ATS_QUALITY_NET_THROUGHPUT = 1033,
464 /* Availability related values */
465 /* =========================== */
466 /**
467  * Is a peer reachable?
468  */
469 // GNUNET_ATS_AVAILABILITY_REACHABLE = 2048,
470 /**
471  * Is there a connection established to a peer using this transport
472  */
473 // GNUNET_ATS_AVAILABILITY_CONNECTED = 2049
474 };
475
476 /**
477  * Number of ATS quality properties
478  */
479 #define GNUNET_ATS_QualityPropertiesCount 2
480
481 /**
482  * ATS quality properties as array initializer
483  */
484 #define GNUNET_ATS_QualityProperties {GNUNET_ATS_QUALITY_NET_DELAY, GNUNET_ATS_QUALITY_NET_DISTANCE}
485
486 /**
487  * ATS quality properties as string array initializer
488  */
489 #define GNUNET_ATS_QualityPropertiesString {"Delay", "Distance"}
490
491 GNUNET_NETWORK_STRUCT_BEGIN
492
493 /**
494  * struct used to communicate the transport's properties like cost and
495  * quality of service as well as high-level constraints on resource
496  * consumption.
497  *
498  *                             +---+
499  *  +-----------+ Constraints  |   |  Plugin properties +---------+
500  *  | Highlevel |------------> |ATS| <------------------|Transport|
501  *  | Component | ATS struct   |   |    ATS struct      | Plugin  |
502  *  +-----------+              |   |                    +---------+
503  *                             +---+
504  *
505  * This structure will be used by transport plugins to communicate
506  * costs to ATS or by higher level components to tell ATS their
507  * constraints.  Always a pair of (GNUNET_ATS_Property,
508  * uint32_t value).  Value is always uint32_t, so all units used to
509  * define costs have to be normalized to fit uint32_t.
510  */
511 struct GNUNET_ATS_Information
512 {
513   /**
514    * ATS property type, in network byte order.
515    */
516   uint32_t type GNUNET_PACKED;
517
518   /**
519    * ATS property value, in network byte order.
520    */
521   uint32_t value GNUNET_PACKED;
522 };
523 GNUNET_NETWORK_STRUCT_END
524
525 /* ******************************** Scheduling API ***************************** */
526
527 /**
528  * Handle to the ATS subsystem for bandwidth/transport scheduling information.
529  */
530 struct GNUNET_ATS_SchedulingHandle;
531
532 /**
533  * Handle for address suggestion requests
534  */
535 struct GNUNET_ATS_SuggestHandle;
536
537 /**
538  * Opaque session handle, defined by plugins.  Contents not known to ATS.
539  */
540 struct Session;
541
542 /**
543  * Signature of a function called by ATS with the current bandwidth
544  * and address preferences as determined by ATS.
545  *
546  * If an address is available immediately the address will be included. If no
547  * address can be suggested, address, session, bandwidth and ATS information will
548  * be NULL/0. ATS will suggest an address as soon as it can provide such an
549  * address
550  *
551  * @param cls closure
552  * @param address suggested address (including peer identity of the peer)
553  * @param session session to use
554  * @param bandwidth_out assigned outbound bandwidth for the connection
555  * @param bandwidth_in assigned inbound bandwidth for the connection
556  * @param ats performance data for the address (as far as known)
557  * @param ats_count number of performance records in @a ats
558  */
559 typedef void
560 (*GNUNET_ATS_AddressSuggestionCallback) (void *cls,
561     const struct GNUNET_PeerIdentity *peer,
562     const struct GNUNET_HELLO_Address *address, struct Session *session,
563     struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
564     struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
565     const struct GNUNET_ATS_Information *ats, uint32_t ats_count);
566
567
568 /**
569  * Initialize the ATS subsystem.
570  *
571  * @param cfg configuration to use
572  * @param suggest_cb notification to call whenever the suggestation changed
573  * @param suggest_cb_cls closure for 'suggest_cb'
574  * @return ats context
575  */
576 struct GNUNET_ATS_SchedulingHandle *
577 GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
578     GNUNET_ATS_AddressSuggestionCallback suggest_cb, void *suggest_cb_cls);
579
580 /**
581  * Client is done with ATS scheduling, release resources.
582  *
583  * @param sh handle to release
584  */
585 void
586 GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh);
587
588 /**
589  * We would like to reset the address suggestion block time for this
590  * peer
591  *
592  * @param sh handle
593  * @param peer identity of the peer we want to reset
594  */
595 void
596 GNUNET_ATS_reset_backoff (struct GNUNET_ATS_SchedulingHandle *sh,
597                           const struct GNUNET_PeerIdentity *peer);
598
599
600 /**
601  * We would like to establish a new connection with a peer.  ATS
602  * should suggest a good address to begin with.
603  *
604  * @param sh handle
605  * @param peer identity of the peer we need an address for
606  * @param cont the continuation to indicate success to call with the address
607  * @param cont_cls the cls for the continuation
608  * @return suggestion handle
609  */
610 struct GNUNET_ATS_SuggestHandle *
611 GNUNET_ATS_suggest_address (struct GNUNET_ATS_SchedulingHandle *sh,
612                             const struct GNUNET_PeerIdentity *peer,
613                             GNUNET_ATS_AddressSuggestionCallback cont,
614                             void *cont_cls);
615
616
617 /**
618  * We want to cancel ATS suggesting addresses for a peer.
619  *
620  * @param sh handle
621  * @param peer identity of the peer
622  */
623 void
624 GNUNET_ATS_suggest_address_cancel (struct GNUNET_ATS_SchedulingHandle *sh,
625                                    const struct GNUNET_PeerIdentity *peer);
626
627
628 /**
629  * Convert a ATS property to a string
630  *
631  * @param type the atsi type
632  * @return a string or NULL if invalid
633  */
634 const char *
635 GNUNET_ATS_print_property_type (uint32_t type);
636
637
638 /**
639  * Convert a GNUNET_ATS_NetworkType to a string
640  *
641  * @param net the network type
642  * @return a string or NULL if invalid
643  */
644 const char *
645 GNUNET_ATS_print_network_type (uint32_t net);
646
647
648 /**
649  * Returns where the address is located: LAN or WAN or ...
650  * @param sh the GNUNET_ATS_SchedulingHandle handle
651  * @param addr address
652  * @param addrlen address length
653  * @return location as GNUNET_ATS_Information
654  */
655 struct GNUNET_ATS_Information
656 GNUNET_ATS_address_get_type (struct GNUNET_ATS_SchedulingHandle *sh,
657                              const struct sockaddr * addr,
658                              socklen_t addrlen);
659
660
661 /**
662  * Test if a address and a session is known to ATS
663  *
664  * @param sh the scheduling handle
665  * @param address the address
666  * @param session the session
667  * @return #GNUNET_YES or #GNUNET_NO
668  */
669 int
670 GNUNET_ATS_session_known (struct GNUNET_ATS_SchedulingHandle *sh,
671                           const struct GNUNET_HELLO_Address *address,
672                           struct Session *session);
673
674
675 /**
676  * We have a new address ATS should know. Addresses have to be added with this
677  * function before they can be: updated, set in use and destroyed
678  *
679  * @param sh handle
680  * @param address the address
681  * @param session session handle (if available)
682  * @param ats performance data for the address
683  * @param ats_count number of performance records in @a ats
684  */
685 int
686 GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh,
687                         const struct GNUNET_HELLO_Address *address,
688                         struct Session *session,
689                         const struct GNUNET_ATS_Information *ats,
690                         uint32_t ats_count);
691
692
693 /**
694  * We have updated performance statistics for a given address.  Note
695  * that this function can be called for addresses that are currently
696  * in use as well as addresses that are valid but not actively in use.
697  * Furthermore, the peer may not even be connected to us right now (in
698  * which case the call may be ignored or the information may be stored
699  * for later use).  Update bandwidth assignments.
700  *
701  * @param sh handle
702  * @param address updated address
703  * @param session session handle (if available)
704  * @param ats performance data for the address
705  * @param ats_count number of performance records in @a ats
706  * @return #GNUNET_OK or #GNUNET_SYSERR
707  */
708 int
709 GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh,
710                            const struct GNUNET_HELLO_Address *address,
711                            struct Session *session,
712                            const struct GNUNET_ATS_Information *ats,
713                            uint32_t ats_count);
714
715
716 /**
717  * An address is now in use or not used any more.
718  *
719  * @param sh handle
720  * @param address the address
721  * @param session session handle
722  * @param in_use #GNUNET_YES if this address is now used, #GNUNET_NO
723  * if address is not used any more
724  */
725 void
726 GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh,
727                            const struct GNUNET_HELLO_Address *address,
728                            struct Session *session,
729                            int in_use);
730
731
732 /**
733  * An address got destroyed, stop including it as a valid address.
734  *
735  * If a session is given, only the session will be removed, if no session is
736  * given the full address will be deleted.
737  *
738  * @param sh handle
739  * @param address the address
740  * @param session session handle that is no longer valid (if available)
741  */
742 void
743 GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh,
744                               const struct GNUNET_HELLO_Address *address,
745                               struct Session *session);
746
747
748 /* ******************************** Performance API ***************************** */
749
750 /**
751  * ATS Handle to obtain and/or modify performance information.
752  */
753 struct GNUNET_ATS_PerformanceHandle;
754
755 /**
756  * Signature of a function that is called with QoS information about an address.
757  *
758  * @param cls closure
759  * @param address the address
760  * @param address_active is this address actively used to maintain a connection
761  *                              to a peer
762  * @param bandwidth_out assigned outbound bandwidth for the connection
763  * @param bandwidth_in assigned inbound bandwidth for the connection
764  * @param ats performance data for the address (as far as known)
765  * @param ats_count number of performance records in 'ats'
766  */
767 typedef void
768 (*GNUNET_ATS_AddressInformationCallback) (void *cls,
769     const struct GNUNET_HELLO_Address *address, int address_active,
770     struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
771     struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
772     const struct GNUNET_ATS_Information *ats, uint32_t ats_count);
773
774 /**
775  * Handle for an address listing operation
776  */
777 struct GNUNET_ATS_AddressListHandle;
778
779 /**
780  * Get handle to access performance API of the ATS subsystem.
781  *
782  * @param cfg configuration to use
783  * @param addr_info_cb callback called when performance characteristics for
784  *      an address change
785  * @param addr_info_cb_cls closure for infocb
786  * @return ats performance context
787  */
788 struct GNUNET_ATS_PerformanceHandle *
789 GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
790     GNUNET_ATS_AddressInformationCallback addr_info_cb, void *addr_info_cb_cls);
791
792 /**
793  * Get information about addresses known to the ATS subsystem.
794  *
795  * @param handle the performance handle to use
796  * @param peer peer idm can be NULL for all peers
797  * @param all GNUNET_YES to get information about all addresses or GNUNET_NO to
798  *        get only address currently used
799  * @param infocb callback to call with the addresses,
800  *        will callback with address == NULL when done
801  * @param infocb_cls closure for infocb
802  * @return ats performance context
803  */
804 struct GNUNET_ATS_AddressListHandle *
805 GNUNET_ATS_performance_list_addresses (
806     struct GNUNET_ATS_PerformanceHandle *handle,
807     const struct GNUNET_PeerIdentity *peer, int all,
808     GNUNET_ATS_AddressInformationCallback infocb, void *infocb_cls);
809
810 /**
811  * Cancel a pending address listing operation
812  *
813  * @param handle the GNUNET_ATS_AddressListHandle handle to cancel
814  */
815 void
816 GNUNET_ATS_performance_list_addresses_cancel (
817     struct GNUNET_ATS_AddressListHandle *handle);
818
819 /**
820  * Client is done using the ATS performance subsystem, release resources.
821  *
822  * @param ph handle
823  */
824 void
825 GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph);
826
827 /**
828  * Function called with reservation result.
829  *
830  * @param cls closure
831  * @param peer identifies the peer
832  * @param amount set to the amount that was actually reserved or unreserved;
833  *               either the full requested amount or zero (no partial reservations)
834  * @param res_delay if the reservation could not be satisfied (amount was 0), how
835  *        long should the client wait until re-trying?
836  */
837 typedef void
838 (*GNUNET_ATS_ReservationCallback) (void *cls,
839     const struct GNUNET_PeerIdentity * peer, int32_t amount,
840     struct GNUNET_TIME_Relative res_delay);
841
842 /**
843  * Context that can be used to cancel a peer information request.
844  */
845 struct GNUNET_ATS_ReservationContext;
846
847 /**
848  * Reserve inbound bandwidth from the given peer.  ATS will look at
849  * the current amount of traffic we receive from the peer and ensure
850  * that the peer could add 'amount' of data to its stream.
851  *
852  * @param ph performance handle
853  * @param peer identifies the peer
854  * @param amount reserve N bytes for receiving, negative
855  *                amounts can be used to undo a (recent) reservation;
856  * @param rcb function to call with the resulting reservation information
857  * @param rcb_cls closure for info
858  * @return NULL on error
859  * @deprecated will be replaced soon
860  */
861 struct GNUNET_ATS_ReservationContext *
862 GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph,
863     const struct GNUNET_PeerIdentity *peer, int32_t amount,
864     GNUNET_ATS_ReservationCallback rcb, void *rcb_cls);
865
866 /**
867  * Cancel request for reserving bandwidth.
868  *
869  * @param rc context returned by the original GNUNET_ATS_reserve_bandwidth call
870  */
871 void
872 GNUNET_ATS_reserve_bandwidth_cancel (struct GNUNET_ATS_ReservationContext *rc);
873
874 /**
875  * Number of preference types supported by ATS
876  */
877 #define GNUNET_ATS_PreferenceCount 3
878
879 /**
880  * ATS preference types as array initializer
881  */
882 #define GNUNET_ATS_PreferenceType {GNUNET_ATS_PREFERENCE_END, GNUNET_ATS_PREFERENCE_BANDWIDTH, GNUNET_ATS_PREFERENCE_LATENCY}
883
884 /**
885  * ATS preference types as string array initializer
886  */
887 #define GNUNET_ATS_PreferenceTypeString {"END", "BANDWIDTH", "LATENCY"}
888
889 /**
890  * Enum defining all known preference categories.
891  */
892 enum GNUNET_ATS_PreferenceKind
893 {
894
895   /**
896    * End of preference list.
897    */
898   GNUNET_ATS_PREFERENCE_END = 0,
899
900   /**
901    * Change the peer's bandwidth value (value per byte of bandwidth in
902    * the goal function) to the given amount.  The argument is followed
903    * by a double value giving the desired value (can be negative).
904    * Preference changes are forgotten if peers disconnect.
905    */
906   GNUNET_ATS_PREFERENCE_BANDWIDTH,
907
908   /**
909    * Change the peer's latency value to the given amount.  The
910    * argument is followed by a double value giving the desired value
911    * (can be negative).  The absolute score in the goal function is
912    * the inverse of the latency in microseconds (minimum: 1
913    * microsecond) multiplied by the latency preferences.
914    */
915   GNUNET_ATS_PREFERENCE_LATENCY
916 };
917
918 /**
919  * Convert a GNUNET_ATS_PreferenceType to a string
920  *
921  * @param type the preference type
922  * @return a string or NULL if invalid
923  */
924 const char *
925 GNUNET_ATS_print_preference_type (uint32_t type);
926
927 /**
928  * Change preferences for the given peer. Preference changes are forgotten if peers
929  * disconnect.
930  *
931  * @param ph performance handle
932  * @param peer identifies the peer
933  * @param ... 0-terminated specification of the desired changes
934  */
935 void
936 GNUNET_ATS_performance_change_preference (
937     struct GNUNET_ATS_PerformanceHandle *ph,
938     const struct GNUNET_PeerIdentity *peer, ...);
939
940 /**
941  * Application feedback on how good preference requirements are fulfilled
942  * for the preferences included in the given time scope [now - scope .. now]
943  *
944  * An application notifies ATS if (and only if) it has feedback information
945  * for specific properties. This values are valid until the feedback scores are
946  * updated by the application.
947  *
948  * If the application has no feedback for this preference kind the application
949  * will not explicitly call for this property and will not include it in this
950  * function call.
951  *
952  * @param ph performance handle
953  * @param scope the time interval this valid for: [now - scope .. now]
954  * @param peer identifies the peer
955  * @param ... 0-terminated specification of the desired changes
956  */
957 void
958 GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph,
959     const struct GNUNET_PeerIdentity *peer,
960     const struct GNUNET_TIME_Relative scope, ...);
961
962 #endif
963 /* end of file gnunet-service-transport_ats.h */