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