c856b09b0083ac2b849213163eb5f8adf64d90fe
[oweals/gnunet.git] / src / ats / gnunet-service-ats_addresses.h
1 /*
2      This file is part of GNUnet.
3      (C) 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 /**
22  * @file ats/gnunet-service-ats_addresses.h
23  * @brief ats service address management
24  * @author Matthias Wachs
25  * @author Christian Grothoff
26  */
27 #ifndef GNUNET_SERVICE_ATS_ADDRESSES_H
28 #define GNUNET_SERVICE_ATS_ADDRESSES_H
29
30 #include "gnunet_util_lib.h"
31 #include "gnunet_ats_service.h"
32 #include "gnunet_statistics_service.h"
33 #include "ats.h"
34
35 #define ATS_BLOCKING_DELTA GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 100)
36
37 /**
38  * Address with additional information
39  */
40 struct ATS_Address
41 {
42   /**
43    * Next element in DLL
44    */
45   struct ATS_Address *next;
46
47   /**
48    * Previous element in DLL
49    */
50   struct ATS_Address *prev;
51
52   /**
53    * Peer ID
54    */
55   struct GNUNET_PeerIdentity peer;
56
57   /**
58    * Session ID, 0 if no session is given
59    */
60   uint32_t session_id;
61
62   /**
63    * Address
64    */
65   const void *addr;
66
67   /**
68    * Address length
69    */
70   size_t addr_len;
71
72   /**
73    * Plugin name
74    */
75   char *plugin;
76
77   /**
78    * MLP specific information
79    * TODO remove or rename
80    */
81   void *mlp_information;
82
83   /**
84    * ATS information
85    */
86   //struct GNUNET_ATS_Information *ats;
87
88   /**
89    * Number of ATS information
90    */
91   //uint32_t ats_count;
92
93   /* CHECK USAGE */
94   struct GNUNET_TIME_Relative atsp_latency;
95
96   /* CHECK USAGE */
97   struct GNUNET_BANDWIDTH_Value32NBO atsp_utilization_in;
98
99   /* CHECK USAGE */
100   struct GNUNET_BANDWIDTH_Value32NBO atsp_utilization_out;
101
102
103   /* CHECK USAGE */
104   uint32_t atsp_distance;
105
106   /* CHECK USAGE */
107   uint32_t atsp_cost_wan;
108
109   /* CHECK USAGE */
110   uint32_t atsp_cost_lan;
111
112   /* CHECK USAGE */
113   uint32_t atsp_cost_wlan;
114
115   /* CHECK USAGE */
116   uint32_t atsp_network_type;
117
118   /**
119    * Inbound bandwidth assigned by solver in NBO
120    */
121   struct GNUNET_BANDWIDTH_Value32NBO assigned_bw_in;
122
123   /**
124    * Outbound bandwidth assigned by solver in NBO
125    */
126   struct GNUNET_BANDWIDTH_Value32NBO assigned_bw_out;
127
128   /**
129    * Blocking interval
130    */
131   struct GNUNET_TIME_Relative block_interval;
132
133   /**
134    * Time when address can be suggested again
135    */
136   struct GNUNET_TIME_Absolute blocked_until;
137
138   /**
139    * Is this the active address for this peer?
140    */
141   int active;
142
143   /**
144    * Is this the address for this peer in use?
145    */
146   int used;
147 };
148
149
150 /**
151  * Callback to call from solver when bandwidth for address has changed
152  *
153  * @param address the with changed bandwidth assigned
154  */
155
156 typedef void
157  (*GAS_bandwidth_changed_cb) (struct ATS_Address *address);
158
159 /**
160  * Init the simplistic problem solving component
161  *
162  * Quotas:
163  * network[i] contains the network type as type GNUNET_ATS_NetworkType[i]
164  * out_quota[i] contains outbound quota for network type i
165  * in_quota[i] contains inbound quota for network type i
166  *
167  * Example
168  * network = {GNUNET_ATS_NET_UNSPECIFIED, GNUNET_ATS_NET_LOOPBACK, GNUNET_ATS_NET_LAN, GNUNET_ATS_NET_WAN, GNUNET_ATS_NET_WLAN}
169  * network[2]   == GNUNET_ATS_NET_LAN
170  * out_quota[2] == 65353
171  * in_quota[2]  == 65353
172  *
173  * @param cfg configuration handle
174  * @param stats the GNUNET_STATISTICS handle
175  * @param network array of GNUNET_ATS_NetworkType with length dest_length
176  * @param out_quota array of outbound quotas
177  * @param in_quota array of outbound quota
178  * @param bw_changed_cb callback to call when assigned changes
179  * @return handle for the solver on success, NULL on fail
180  */
181 typedef void *
182  (*GAS_solver_init) (const struct GNUNET_CONFIGURATION_Handle *cfg,
183                      const struct GNUNET_STATISTICS_Handle *stats,
184                      int *network,
185                      unsigned long long *out_quota,
186                      unsigned long long *in_quota,
187                      int dest_length,
188                      GAS_bandwidth_changed_cb bw_changed_cb);
189
190
191 typedef void
192 (*GAS_solver_address_change_preference) (void *solver,
193                                          const struct GNUNET_PeerIdentity *peer,
194                                          enum GNUNET_ATS_PreferenceKind kind,
195                                          float score);
196
197 /**
198  * Add a single address to the solver
199  *
200  * @param solver the solver Handle
201  * @param addresses the address hashmap containing all addresses
202  * @param address the address to add
203  */
204 typedef void
205 (*GAS_solver_address_add) (void *solver,
206                            struct GNUNET_CONTAINER_MultiHashMap * addresses,
207                            struct ATS_Address *address);
208
209
210
211 typedef void
212  (*GAS_solver_address_delete) (void *solver,
213                                struct GNUNET_CONTAINER_MultiHashMap *addresses,
214                                struct ATS_Address *address);
215
216 typedef void
217 (*GAS_solver_address_update) (void *solver,
218                               struct GNUNET_CONTAINER_MultiHashMap *addresses,
219                               struct ATS_Address *address);
220
221
222 typedef const struct ATS_Address *
223 (*GAS_solver_get_preferred_address) (void *solver,
224                                      struct GNUNET_CONTAINER_MultiHashMap *addresses,
225                                      const struct GNUNET_PeerIdentity *peer);
226
227
228 typedef void
229  (*GAS_solver_done) (void *solver);
230
231
232 /**
233  * Initialize address subsystem.
234  *
235  * @param cfg configuration to use
236  * @param stats the statistics handle to use
237  */
238 struct GAS_Addresses_Handle *
239 GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
240                     const struct GNUNET_STATISTICS_Handle *stats);
241
242 /**
243  * Shutdown address subsystem.
244  */
245 void
246 GAS_addresses_done (struct GAS_Addresses_Handle *handle);
247
248 void
249 GAS_addresses_handle_backoff_reset (const struct GNUNET_PeerIdentity *peer);
250
251 /**
252  * This address is now used or not used anymore
253  */
254 int
255 GAS_addresses_in_use (const struct GNUNET_PeerIdentity *peer,
256                       const char *plugin_name, const void *plugin_addr,
257                       size_t plugin_addr_len, uint32_t session_id, int in_use);
258
259 void
260 GAS_addresses_update (const struct GNUNET_PeerIdentity *peer,
261                       const char *plugin_name, const void *plugin_addr,
262                       size_t plugin_addr_len, uint32_t session_id,
263                       const struct GNUNET_ATS_Information *atsi,
264                       uint32_t atsi_count);
265
266
267 void
268 GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer,
269                        const char *plugin_name, const void *plugin_addr,
270                        size_t plugin_addr_len, uint32_t session_id);
271
272
273 void
274 GAS_addresses_destroy_all (void);
275
276
277 /**
278  * Cancel address suggestions for a peer
279  *
280  * @param peer the respective peer
281  */
282 void
283 GAS_addresses_request_address_cancel (const struct GNUNET_PeerIdentity *peer);
284
285 void
286 GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer);
287
288 void
289 GAS_addresses_change_preference (const struct GNUNET_PeerIdentity *peer,
290                                  enum GNUNET_ATS_PreferenceKind kind,
291                                  float score);
292
293 void
294 GAS_addresses_add (const struct GNUNET_PeerIdentity *peer,
295                       const char *plugin_name, const void *plugin_addr,
296                       size_t plugin_addr_len, uint32_t session_id,
297                       const struct GNUNET_ATS_Information *atsi,
298                       uint32_t atsi_count);
299
300
301 typedef void (*GNUNET_ATS_Peer_Iterator) (void *p_it_cls,
302                                           const struct GNUNET_PeerIdentity *id);
303
304 /**
305  * Return all peers currently known to ATS
306  *
307  * @param p_it the iterator to call for every peer
308  * @param p_it_cls the closure for the iterator
309  */
310 void
311 GAS_addresses_iterate_peers (GNUNET_ATS_Peer_Iterator p_it, void *p_it_cls);
312
313 typedef void (*GNUNET_ATS_PeerInfo_Iterator) (void *p_it_cls,
314     const struct GNUNET_PeerIdentity *id,
315     const char *plugin_name,
316     const void *plugin_addr, size_t plugin_addr_len,
317     const int address_active,
318     const struct GNUNET_ATS_Information *atsi,
319     uint32_t atsi_count,
320     struct GNUNET_BANDWIDTH_Value32NBO
321     bandwidth_out,
322     struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in);
323
324 /**
325  * Return information all peers currently known to ATS
326  *
327  * @param peer the respective peer
328  * @param pi_it the iterator to call for every peer
329  * @param pi_it_cls the closure for the iterator
330  */
331 void
332 GAS_addresses_get_peer_info (const struct GNUNET_PeerIdentity *peer, GNUNET_ATS_PeerInfo_Iterator pi_it, void *pi_it_cls);
333
334 #endif
335
336 /* end of gnunet-service-ats_addresses.h */