2 This file is part of GNUnet.
3 (C) 2011 Christian Grothoff (and other contributing authors)
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.
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.
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.
22 * @file ats/gnunet-service-ats_addresses.h
23 * @brief ats service address management
24 * @author Matthias Wachs
25 * @author Christian Grothoff
27 #ifndef GNUNET_SERVICE_ATS_ADDRESSES_H
28 #define GNUNET_SERVICE_ATS_ADDRESSES_H
30 #include "gnunet_util_lib.h"
31 #include "gnunet_ats_service.h"
32 #include "gnunet_statistics_service.h"
35 #define ATS_BLOCKING_DELTA GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 100)
37 struct GAS_Addresses_Handle;
40 * Address with additional information
47 struct ATS_Address *next;
50 * Previous element in DLL
52 struct ATS_Address *prev;
57 struct GNUNET_PeerIdentity peer;
60 * Session ID, 0 if no session is given
80 * Solver specific information for this address
82 void *solver_information;
85 struct GNUNET_TIME_Relative atsp_latency;
88 struct GNUNET_BANDWIDTH_Value32NBO atsp_utilization_in;
91 struct GNUNET_BANDWIDTH_Value32NBO atsp_utilization_out;
95 uint32_t atsp_distance;
98 uint32_t atsp_cost_wan;
101 uint32_t atsp_cost_lan;
104 uint32_t atsp_cost_wlan;
107 uint32_t atsp_network_type;
110 * Inbound bandwidth assigned by solver in NBO
112 struct GNUNET_BANDWIDTH_Value32NBO assigned_bw_in;
115 * Outbound bandwidth assigned by solver in NBO
117 struct GNUNET_BANDWIDTH_Value32NBO assigned_bw_out;
122 struct GNUNET_TIME_Relative block_interval;
125 * Time when address can be suggested again
127 struct GNUNET_TIME_Absolute blocked_until;
130 * Is this the active address for this peer?
135 * Is this the address for this peer in use?
142 * Callback to call from solver when bandwidth for address has changed
144 * @param address the with changed bandwidth assigned
148 (*GAS_bandwidth_changed_cb) (void *cls, struct ATS_Address *address);
151 * Init the simplistic problem solving component
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
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
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
173 (*GAS_solver_init) (const struct GNUNET_CONFIGURATION_Handle *cfg,
174 const struct GNUNET_STATISTICS_Handle *stats,
176 unsigned long long *out_quota,
177 unsigned long long *in_quota,
179 GAS_bandwidth_changed_cb bw_changed_cb,
180 void *bw_changed_cb_cls);
184 (*GAS_solver_address_change_preference) (void *solver,
186 const struct GNUNET_PeerIdentity *peer,
187 enum GNUNET_ATS_PreferenceKind kind,
191 * Add a single address to the solver
193 * @param solver the solver Handle
194 * @param addresses the address hashmap containing all addresses
195 * @param address the address to add
198 (*GAS_solver_address_add) (void *solver,
199 struct GNUNET_CONTAINER_MultiHashMap * addresses,
200 struct ATS_Address *address);
205 (*GAS_solver_address_delete) (void *solver,
206 struct GNUNET_CONTAINER_MultiHashMap *addresses,
207 struct ATS_Address *address,
211 (*GAS_solver_address_update) (void *solver,
212 struct GNUNET_CONTAINER_MultiHashMap *addresses,
213 struct ATS_Address *address,
216 const struct GNUNET_ATS_Information *atsi,
217 uint32_t atsi_count);
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);
226 (*GAS_solver_stop_get_preferred_address) (void *solver,
227 struct GNUNET_CONTAINER_MultiHashMap *addresses,
228 const struct GNUNET_PeerIdentity *peer);
232 (*GAS_solver_done) (void *solver);
236 * Initialize address subsystem.
238 * @param cfg configuration to use
239 * @param stats the statistics handle to use
241 struct GAS_Addresses_Handle *
242 GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
243 const struct GNUNET_STATISTICS_Handle *stats);
246 * Shutdown address subsystem.
249 GAS_addresses_done (struct GAS_Addresses_Handle *handle);
252 GAS_addresses_handle_backoff_reset (struct GAS_Addresses_Handle *handle,
253 const struct GNUNET_PeerIdentity *peer);
256 * This address is now used or not used anymore
259 GAS_addresses_in_use (struct GAS_Addresses_Handle *handle,
260 const struct GNUNET_PeerIdentity *peer,
261 const char *plugin_name, const void *plugin_addr,
262 size_t plugin_addr_len, uint32_t session_id, int in_use);
265 GAS_addresses_update (struct GAS_Addresses_Handle *handle,
266 const struct GNUNET_PeerIdentity *peer,
267 const char *plugin_name, const void *plugin_addr,
268 size_t plugin_addr_len, uint32_t session_id,
269 const struct GNUNET_ATS_Information *atsi,
270 uint32_t atsi_count);
274 GAS_addresses_destroy (struct GAS_Addresses_Handle *handle,
275 const struct GNUNET_PeerIdentity *peer,
276 const char *plugin_name, const void *plugin_addr,
277 size_t plugin_addr_len, uint32_t session_id);
281 GAS_addresses_destroy_all (struct GAS_Addresses_Handle *handle);
285 * Cancel address suggestions for a peer
287 * @param peer the respective peer
290 GAS_addresses_request_address_cancel (struct GAS_Addresses_Handle *handle,
291 const struct GNUNET_PeerIdentity *peer);
294 GAS_addresses_request_address (struct GAS_Addresses_Handle *handle,
295 const struct GNUNET_PeerIdentity *peer);
298 GAS_addresses_change_preference (struct GAS_Addresses_Handle *handle,
300 const struct GNUNET_PeerIdentity *peer,
301 enum GNUNET_ATS_PreferenceKind kind,
305 GAS_addresses_add (struct GAS_Addresses_Handle *handle,
306 const struct GNUNET_PeerIdentity *peer,
307 const char *plugin_name, const void *plugin_addr,
308 size_t plugin_addr_len, uint32_t session_id,
309 const struct GNUNET_ATS_Information *atsi,
310 uint32_t atsi_count);
313 typedef void (*GNUNET_ATS_Peer_Iterator) (void *p_it_cls,
314 const struct GNUNET_PeerIdentity *id);
317 * Return all peers currently known to ATS
319 * @param p_it the iterator to call for every peer
320 * @param p_it_cls the closure for the iterator
323 GAS_addresses_iterate_peers (struct GAS_Addresses_Handle *handle,
324 GNUNET_ATS_Peer_Iterator p_it,
327 typedef void (*GNUNET_ATS_PeerInfo_Iterator) (void *p_it_cls,
328 const struct GNUNET_PeerIdentity *id,
329 const char *plugin_name,
330 const void *plugin_addr, size_t plugin_addr_len,
331 const int address_active,
332 const struct GNUNET_ATS_Information *atsi,
334 struct GNUNET_BANDWIDTH_Value32NBO
336 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in);
339 * Return information all peers currently known to ATS
341 * @param peer the respective peer
342 * @param pi_it the iterator to call for every peer
343 * @param pi_it_cls the closure for the iterator
346 GAS_addresses_get_peer_info (struct GAS_Addresses_Handle *handle,
347 const struct GNUNET_PeerIdentity *peer,
348 GNUNET_ATS_PeerInfo_Iterator pi_it,
353 /* end of gnunet-service-ats_addresses.h */