dd648dd754689476a6df5aec1f6cd8014b3a52c7
[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  * TODO:
27  * - move GNUNET_TRANSPORT_ATS* in here and rename...
28  * - extend API to express communication preferences to ATS 
29  *   (to be called DIRECTLY from apps, not from transport/core!)
30  */
31 #ifndef GNUNET_ATS_SERVICE_H
32 #define GNUNET_ATS_SERVICE_H
33
34 #include "gnunet_constants.h"
35 #include "gnunet_util_lib.h"
36 #include "gnunet_transport_service.h"
37 #include "gnunet_transport_plugin.h"
38
39
40 /**
41  * Handle to the ATS subsystem.
42  */
43 struct GNUNET_ATS_Handle;
44
45
46 /**
47  * Signature of a function called by ATS to notify the callee that the
48  * assigned bandwidth or address for a given peer was changed.  If the
49  * callback is called with address/bandwidth assignments of zero, the
50  * ATS disconnect function will still be called once the disconnect 
51  * actually happened.
52  *
53  * @param cls closure
54  * @param peer identity of the peer
55  * @param plugin_name name of the transport plugin, NULL to disconnect
56  * @param session session to use (if available)
57  * @param plugin_addr address to use (if available)
58  * @param plugin_addr_len number of bytes in addr
59  * @param bandwidth assigned outbound bandwidth for the connection
60  */
61 typedef void (*GNUNET_TRANSPORT_ATS_AllocationNotification) (void *cls,
62                                                              const struct
63                                                              GNUNET_PeerIdentity
64                                                              * peer,
65                                                              const char
66                                                              *plugin_name,
67                                                              struct Session *
68                                                              session,
69                                                              const void
70                                                              *plugin_addr,
71                                                              size_t
72                                                              plugin_addr_len,
73                                                              struct
74                                                              GNUNET_BANDWIDTH_Value32NBO
75                                                              bandwidth);
76
77
78 /**
79  * Initialize the ATS subsystem.
80  *
81  * @param cfg configuration to use
82  * @param alloc_cb notification to call whenever the allocation changed
83  * @param alloc_cb_cls closure for 'alloc_cb'
84  * @return ats context
85  */
86 struct GNUNET_ATS_Handle *GNUNET_ATS_init (const struct
87                                            GNUNET_CONFIGURATION_Handle *cfg,
88                                            GNUNET_TRANSPORT_ATS_AllocationNotification
89                                            alloc_cb, void *alloc_cb_cls);
90
91
92 /**
93  * Shutdown the ATS subsystem.
94  *
95  * @param atc handle
96  */
97 void GNUNET_ATS_shutdown (struct GNUNET_ATS_Handle *atc);
98
99
100 /**
101  * Signature of a function that takes an address suggestion 
102  *
103  * @param cls closure
104  * @param peer identity of the new peer
105  * @param plugin_name name of the plugin, NULL if we have no suggestion
106  * @param plugin_addr suggested address, NULL if we have no suggestion
107  * @param plugin_addr_len number of bytes in plugin_addr
108  * @param bandwidth assigned outbound bandwidth for the connection
109  * @param ats performance data for the address (as far as known)
110  * @param ats_count number of performance records in 'ats'
111  */
112 typedef void (*GNUNET_ATS_AddressSuggestionCallback) (void *cls,
113                                                       const struct
114                                                       GNUNET_PeerIdentity *
115                                                       peer,
116                                                       const char *plugin_name,
117                                                       const void *plugin_addr,
118                                                       size_t plugin_addr_len,
119                                                       struct
120                                                       GNUNET_BANDWIDTH_Value32NBO
121                                                       bandwidth,
122                                                       const struct
123                                                       GNUNET_TRANSPORT_ATS_Information
124                                                       * ats,
125                                                       uint32_t ats_count);
126
127
128 /**
129  * Handle to cancel suggestion request.
130  */
131 struct GNUNET_ATS_SuggestionContext;
132
133
134 /**
135  * We would like to establish a new connection with a peer.
136  * ATS should suggest a good address to begin with.
137  *
138  * @param atc handle
139  * @param peer identity of the new peer
140  * @param cb function to call with the address
141  * @param cb_cls closure for cb
142  */
143 struct GNUNET_ATS_SuggestionContext *GNUNET_ATS_suggest_address (struct
144                                                                  GNUNET_ATS_Handle
145                                                                  *atc,
146                                                                  const struct
147                                                                  GNUNET_PeerIdentity
148                                                                  *peer,
149                                                                  GNUNET_ATS_AddressSuggestionCallback
150                                                                  cb,
151                                                                  void *cb_cls);
152
153
154 /**
155  * Cancel suggestion request.
156  *
157  * @param asc handle of the request to cancel
158  */
159 void GNUNET_ATS_suggest_address_cancel (struct GNUNET_ATS_SuggestionContext
160                                         *asc);
161
162
163 /**
164  * We established a new connection with a peer (for example, because
165  * core asked for it or because the other peer connected to us).
166  * Calculate bandwidth assignments including the new peer.
167  *
168  * @param atc handle
169  * @param peer identity of the new peer
170  * @param plugin_name name of the currently used transport plugin
171  * @param session session in use (if available)
172  * @param plugin_addr address in use (if available)
173  * @param plugin_addr_len number of bytes in plugin_addr
174  * @param ats performance data for the connection
175  * @param ats_count number of performance records in 'ats'
176  */
177 void GNUNET_ATS_peer_connect (struct GNUNET_ATS_Handle *atc,
178                               const struct GNUNET_PeerIdentity *peer,
179                               const char *plugin_name, struct Session *session,
180                               const void *plugin_addr, size_t plugin_addr_len,
181                               const struct GNUNET_TRANSPORT_ATS_Information
182                               *ats, uint32_t ats_count);
183
184
185 /**
186  * We disconnected from the given peer (for example, because ats, core
187  * or blacklist asked for it or because the other peer disconnected).
188  * Calculate bandwidth assignments without the peer.
189  *
190  * @param atc handle
191  * @param peer identity of the peer
192  */
193 void GNUNET_ATS_peer_disconnect (struct GNUNET_ATS_Handle *atc,
194                                  const struct GNUNET_PeerIdentity *peer);
195
196
197 /**
198  * A session got destroyed, stop including it as a valid address.
199  *
200  * @param atc handle
201  * @param peer identity of the peer
202  * @param session session handle that is no longer valid
203  */
204 void GNUNET_ATS_session_destroyed (struct GNUNET_ATS_Handle *atc,
205                                    const struct GNUNET_PeerIdentity *peer,
206                                    const struct Session *session);
207
208
209 /**
210  * We have updated performance statistics for a given address.  Note
211  * that this function can be called for addresses that are currently
212  * in use as well as addresses that are valid but not actively in use.
213  * Furthermore, the peer may not even be connected to us right now (in
214  * which case the call may be ignored or the information may be stored
215  * for later use).  Update bandwidth assignments.
216  *
217  * @param atc handle
218  * @param peer identity of the new peer
219  * @param valid_until how long is the address valid?
220  * @param plugin_name name of the transport plugin
221  * @param session session handle (if available)
222  * @param plugin_addr address  (if available)
223  * @param plugin_addr_len number of bytes in plugin_addr
224  * @param ats performance data for the address
225  * @param ats_count number of performance records in 'ats'
226  */
227 void GNUNET_ATS_address_update (struct GNUNET_ATS_Handle *atc,
228                                 const struct GNUNET_PeerIdentity *peer,
229                                 struct GNUNET_TIME_Absolute valid_until,
230                                 const char *plugin_name,
231                                 struct Session *session,
232                                 const void *plugin_addr, size_t plugin_addr_len,
233                                 const struct GNUNET_TRANSPORT_ATS_Information
234                                 *ats, uint32_t ats_count);
235
236
237 #endif
238 /* end of file gnunet-service-transport_ats.h */