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