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