summaryrefslogtreecommitdiff
path: root/src/ats/gnunet-service-ats_addresses.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ats/gnunet-service-ats_addresses.c')
-rw-r--r--src/ats/gnunet-service-ats_addresses.c627
1 files changed, 311 insertions, 316 deletions
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c
index efe968024..8ca245b1e 100644
--- a/src/ats/gnunet-service-ats_addresses.c
+++ b/src/ats/gnunet-service-ats_addresses.c
@@ -1,19 +1,19 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2011-2015 GNUnet e.V. 3 Copyright (C) 2011-2015 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License, 7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
@@ -41,12 +41,12 @@ struct GNUNET_CONTAINER_MultiPeerMap *GSA_addresses;
41 * Update statistic on number of addresses. 41 * Update statistic on number of addresses.
42 */ 42 */
43static void 43static void
44update_addresses_stat () 44update_addresses_stat()
45{ 45{
46 GNUNET_STATISTICS_set (GSA_stats, 46 GNUNET_STATISTICS_set(GSA_stats,
47 "# addresses", 47 "# addresses",
48 GNUNET_CONTAINER_multipeermap_size (GSA_addresses), 48 GNUNET_CONTAINER_multipeermap_size(GSA_addresses),
49 GNUNET_NO); 49 GNUNET_NO);
50} 50}
51 51
52 52
@@ -56,25 +56,25 @@ update_addresses_stat ()
56 * @param addr address to destroy 56 * @param addr address to destroy
57 */ 57 */
58static void 58static void
59free_address (struct ATS_Address *addr) 59free_address(struct ATS_Address *addr)
60{ 60{
61 GNUNET_assert (GNUNET_YES == 61 GNUNET_assert(GNUNET_YES ==
62 GNUNET_CONTAINER_multipeermap_remove (GSA_addresses, 62 GNUNET_CONTAINER_multipeermap_remove(GSA_addresses,
63 &addr->peer, 63 &addr->peer,
64 addr)); 64 addr));
65 update_addresses_stat (); 65 update_addresses_stat();
66 GAS_plugin_delete_address (addr); 66 GAS_plugin_delete_address(addr);
67 GAS_performance_notify_all_clients (&addr->peer, 67 GAS_performance_notify_all_clients(&addr->peer,
68 addr->plugin, 68 addr->plugin,
69 addr->addr, 69 addr->addr,
70 addr->addr_len, 70 addr->addr_len,
71 GNUNET_NO, 71 GNUNET_NO,
72 NULL, 72 NULL,
73 addr->local_address_info, 73 addr->local_address_info,
74 GNUNET_BANDWIDTH_ZERO, 74 GNUNET_BANDWIDTH_ZERO,
75 GNUNET_BANDWIDTH_ZERO); 75 GNUNET_BANDWIDTH_ZERO);
76 GNUNET_free (addr->plugin); 76 GNUNET_free(addr->plugin);
77 GNUNET_free (addr); 77 GNUNET_free(addr);
78} 78}
79 79
80 80
@@ -84,7 +84,7 @@ free_address (struct ATS_Address *addr)
84 * @param norm normalization data to initialize 84 * @param norm normalization data to initialize
85 */ 85 */
86static void 86static void
87init_norm (struct GAS_NormalizationInfo *norm) 87init_norm(struct GAS_NormalizationInfo *norm)
88{ 88{
89 unsigned int c; 89 unsigned int c;
90 90
@@ -105,29 +105,29 @@ init_norm (struct GAS_NormalizationInfo *norm)
105 * @return the ATS_Address 105 * @return the ATS_Address
106 */ 106 */
107static struct ATS_Address * 107static struct ATS_Address *
108create_address (const struct GNUNET_PeerIdentity *peer, 108create_address(const struct GNUNET_PeerIdentity *peer,
109 const char *plugin_name, 109 const char *plugin_name,
110 const void *plugin_addr, 110 const void *plugin_addr,
111 size_t plugin_addr_len, 111 size_t plugin_addr_len,
112 uint32_t local_address_info, 112 uint32_t local_address_info,
113 uint32_t session_id) 113 uint32_t session_id)
114{ 114{
115 struct ATS_Address *aa; 115 struct ATS_Address *aa;
116 116
117 aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len); 117 aa = GNUNET_malloc(sizeof(struct ATS_Address) + plugin_addr_len);
118 aa->peer = *peer; 118 aa->peer = *peer;
119 aa->addr_len = plugin_addr_len; 119 aa->addr_len = plugin_addr_len;
120 aa->addr = &aa[1]; 120 aa->addr = &aa[1];
121 GNUNET_memcpy (&aa[1], 121 GNUNET_memcpy(&aa[1],
122 plugin_addr, 122 plugin_addr,
123 plugin_addr_len); 123 plugin_addr_len);
124 aa->plugin = GNUNET_strdup (plugin_name); 124 aa->plugin = GNUNET_strdup(plugin_name);
125 aa->session_id = session_id; 125 aa->session_id = session_id;
126 aa->local_address_info = local_address_info; 126 aa->local_address_info = local_address_info;
127 init_norm (&aa->norm_delay); 127 init_norm(&aa->norm_delay);
128 init_norm (&aa->norm_distance); 128 init_norm(&aa->norm_distance);
129 init_norm (&aa->norm_utilization_in); 129 init_norm(&aa->norm_utilization_in);
130 init_norm (&aa->norm_utilization_out); 130 init_norm(&aa->norm_utilization_out);
131 return aa; 131 return aa;
132} 132}
133 133
@@ -135,8 +135,7 @@ create_address (const struct GNUNET_PeerIdentity *peer,
135/** 135/**
136 * Closure for #find_address_cb() 136 * Closure for #find_address_cb()
137 */ 137 */
138struct FindAddressContext 138struct FindAddressContext {
139{
140 /** 139 /**
141 * Session Id to look for. 140 * Session Id to look for.
142 */ 141 */
@@ -146,7 +145,6 @@ struct FindAddressContext
146 * Where to store matching address result. 145 * Where to store matching address result.
147 */ 146 */
148 struct ATS_Address *exact_address; 147 struct ATS_Address *exact_address;
149
150}; 148};
151 149
152 150
@@ -159,18 +157,18 @@ struct FindAddressContext
159 * @return #GNUNET_YES to continue, #GNUNET_NO if address is found 157 * @return #GNUNET_YES to continue, #GNUNET_NO if address is found
160 */ 158 */
161static int 159static int
162find_address_cb (void *cls, 160find_address_cb(void *cls,
163 const struct GNUNET_PeerIdentity *key, 161 const struct GNUNET_PeerIdentity *key,
164 void *value) 162 void *value)
165{ 163{
166 struct FindAddressContext *fac = cls; 164 struct FindAddressContext *fac = cls;
167 struct ATS_Address *aa = value; 165 struct ATS_Address *aa = value;
168 166
169 if (aa->session_id == fac->session_id) 167 if (aa->session_id == fac->session_id)
170 { 168 {
171 fac->exact_address = aa; 169 fac->exact_address = aa;
172 return GNUNET_NO; 170 return GNUNET_NO;
173 } 171 }
174 return GNUNET_YES; 172 return GNUNET_YES;
175} 173}
176 174
@@ -183,16 +181,16 @@ find_address_cb (void *cls,
183 * @return an ATS_address or NULL 181 * @return an ATS_address or NULL
184 */ 182 */
185static struct ATS_Address * 183static struct ATS_Address *
186find_exact_address (const struct GNUNET_PeerIdentity *peer, 184find_exact_address(const struct GNUNET_PeerIdentity *peer,
187 uint32_t session_id) 185 uint32_t session_id)
188{ 186{
189 struct FindAddressContext fac; 187 struct FindAddressContext fac;
190 188
191 fac.exact_address = NULL; 189 fac.exact_address = NULL;
192 fac.session_id = session_id; 190 fac.session_id = session_id;
193 GNUNET_CONTAINER_multipeermap_get_multiple (GSA_addresses, 191 GNUNET_CONTAINER_multipeermap_get_multiple(GSA_addresses,
194 peer, 192 peer,
195 &find_address_cb, &fac); 193 &find_address_cb, &fac);
196 return fac.exact_address; 194 return fac.exact_address;
197} 195}
198 196
@@ -209,58 +207,58 @@ find_exact_address (const struct GNUNET_PeerIdentity *peer,
209 * @param prop performance information for this address 207 * @param prop performance information for this address
210 */ 208 */
211void 209void
212GAS_addresses_add (const struct GNUNET_PeerIdentity *peer, 210GAS_addresses_add(const struct GNUNET_PeerIdentity *peer,
213 const char *plugin_name, 211 const char *plugin_name,
214 const void *plugin_addr, 212 const void *plugin_addr,
215 size_t plugin_addr_len, 213 size_t plugin_addr_len,
216 uint32_t local_address_info, 214 uint32_t local_address_info,
217 uint32_t session_id, 215 uint32_t session_id,
218 const struct GNUNET_ATS_Properties *prop) 216 const struct GNUNET_ATS_Properties *prop)
219{ 217{
220 struct ATS_Address *new_address; 218 struct ATS_Address *new_address;
221 219
222 if (NULL != find_exact_address (peer, 220 if (NULL != find_exact_address(peer,
223 session_id)) 221 session_id))
224 { 222 {
225 GNUNET_break (0); 223 GNUNET_break(0);
226 return; 224 return;
227 } 225 }
228 GNUNET_break (GNUNET_NT_UNSPECIFIED != prop->scope); 226 GNUNET_break(GNUNET_NT_UNSPECIFIED != prop->scope);
229 new_address = create_address (peer, 227 new_address = create_address(peer,
230 plugin_name, 228 plugin_name,
231 plugin_addr, 229 plugin_addr,
232 plugin_addr_len, 230 plugin_addr_len,
233 local_address_info, 231 local_address_info,
234 session_id); 232 session_id);
235 /* Add a new address */ 233 /* Add a new address */
236 new_address->properties = *prop; 234 new_address->properties = *prop;
237 new_address->t_added = GNUNET_TIME_absolute_get(); 235 new_address->t_added = GNUNET_TIME_absolute_get();
238 new_address->t_last_activity = GNUNET_TIME_absolute_get(); 236 new_address->t_last_activity = GNUNET_TIME_absolute_get();
239 GNUNET_assert(GNUNET_OK == 237 GNUNET_assert(GNUNET_OK ==
240 GNUNET_CONTAINER_multipeermap_put (GSA_addresses, 238 GNUNET_CONTAINER_multipeermap_put(GSA_addresses,
241 peer, 239 peer,
242 new_address, 240 new_address,
243 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 241 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
244 update_addresses_stat (); 242 update_addresses_stat();
245 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 243 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
246 "Adding new address for peer `%s' slot %u\n", 244 "Adding new address for peer `%s' slot %u\n",
247 GNUNET_i2s (peer), 245 GNUNET_i2s(peer),
248 session_id); 246 session_id);
249 /* Tell solver about new address */ 247 /* Tell solver about new address */
250 GAS_plugin_solver_lock (); 248 GAS_plugin_solver_lock();
251 GAS_plugin_new_address (new_address); 249 GAS_plugin_new_address(new_address);
252 GAS_normalization_update_property (new_address); // FIXME: needed? 250 GAS_normalization_update_property(new_address); // FIXME: needed?
253 GAS_plugin_solver_unlock (); 251 GAS_plugin_solver_unlock();
254 /* Notify performance clients about new address */ 252 /* Notify performance clients about new address */
255 GAS_performance_notify_all_clients (&new_address->peer, 253 GAS_performance_notify_all_clients(&new_address->peer,
256 new_address->plugin, 254 new_address->plugin,
257 new_address->addr, 255 new_address->addr,
258 new_address->addr_len, 256 new_address->addr_len,
259 new_address->active, 257 new_address->active,
260 &new_address->properties, 258 &new_address->properties,
261 new_address->local_address_info, 259 new_address->local_address_info,
262 GNUNET_BANDWIDTH_value_init (new_address->assigned_bw_out), 260 GNUNET_BANDWIDTH_value_init(new_address->assigned_bw_out),
263 GNUNET_BANDWIDTH_value_init (new_address->assigned_bw_in)); 261 GNUNET_BANDWIDTH_value_init(new_address->assigned_bw_in));
264} 262}
265 263
266 264
@@ -272,45 +270,45 @@ GAS_addresses_add (const struct GNUNET_PeerIdentity *peer,
272 * @param prop performance information for this address 270 * @param prop performance information for this address
273 */ 271 */
274void 272void
275GAS_addresses_update (const struct GNUNET_PeerIdentity *peer, 273GAS_addresses_update(const struct GNUNET_PeerIdentity *peer,
276 uint32_t session_id, 274 uint32_t session_id,
277 const struct GNUNET_ATS_Properties *prop) 275 const struct GNUNET_ATS_Properties *prop)
278{ 276{
279 struct ATS_Address *aa; 277 struct ATS_Address *aa;
280 278
281 /* Get existing address */ 279 /* Get existing address */
282 aa = find_exact_address (peer, 280 aa = find_exact_address(peer,
283 session_id); 281 session_id);
284 if (NULL == aa) 282 if (NULL == aa)
285 { 283 {
286 GNUNET_break (0); 284 GNUNET_break(0);
287 return; 285 return;
288 } 286 }
289 if (NULL == aa->solver_information) 287 if (NULL == aa->solver_information)
290 { 288 {
291 GNUNET_break (0); 289 GNUNET_break(0);
292 return; 290 return;
293 } 291 }
294 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 292 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
295 "Received ADDRESS_UPDATE for peer `%s' slot %u\n", 293 "Received ADDRESS_UPDATE for peer `%s' slot %u\n",
296 GNUNET_i2s (peer), 294 GNUNET_i2s(peer),
297 (unsigned int) session_id); 295 (unsigned int)session_id);
298 GNUNET_break (GNUNET_NT_UNSPECIFIED != prop->scope); 296 GNUNET_break(GNUNET_NT_UNSPECIFIED != prop->scope);
299 /* Update address */ 297 /* Update address */
300 aa->t_last_activity = GNUNET_TIME_absolute_get(); 298 aa->t_last_activity = GNUNET_TIME_absolute_get();
301 aa->properties = *prop; 299 aa->properties = *prop;
302 /* Notify performance clients about updated address */ 300 /* Notify performance clients about updated address */
303 GAS_performance_notify_all_clients (&aa->peer, 301 GAS_performance_notify_all_clients(&aa->peer,
304 aa->plugin, 302 aa->plugin,
305 aa->addr, 303 aa->addr,
306 aa->addr_len, 304 aa->addr_len,
307 aa->active, 305 aa->active,
308 prop, 306 prop,
309 aa->local_address_info, 307 aa->local_address_info,
310 GNUNET_BANDWIDTH_value_init (aa->assigned_bw_out), 308 GNUNET_BANDWIDTH_value_init(aa->assigned_bw_out),
311 GNUNET_BANDWIDTH_value_init (aa->assigned_bw_in)); 309 GNUNET_BANDWIDTH_value_init(aa->assigned_bw_in));
312 310
313 GAS_normalization_update_property (aa); 311 GAS_normalization_update_property(aa);
314} 312}
315 313
316 314
@@ -321,24 +319,24 @@ GAS_addresses_update (const struct GNUNET_PeerIdentity *peer,
321 * @param session_id session id, can never be 0 319 * @param session_id session id, can never be 0
322 */ 320 */
323void 321void
324GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer, 322GAS_addresses_destroy(const struct GNUNET_PeerIdentity *peer,
325 uint32_t session_id) 323 uint32_t session_id)
326{ 324{
327 struct ATS_Address *ea; 325 struct ATS_Address *ea;
328 326
329 /* Get existing address */ 327 /* Get existing address */
330 ea = find_exact_address (peer, 328 ea = find_exact_address(peer,
331 session_id); 329 session_id);
332 if (NULL == ea) 330 if (NULL == ea)
333 { 331 {
334 GNUNET_break (0); 332 GNUNET_break(0);
335 return; 333 return;
336 } 334 }
337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 335 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
338 "Received ADDRESS_DESTROYED for peer `%s' session %u\n", 336 "Received ADDRESS_DESTROYED for peer `%s' session %u\n",
339 GNUNET_i2s (peer), 337 GNUNET_i2s(peer),
340 session_id); 338 session_id);
341 free_address (ea); 339 free_address(ea);
342} 340}
343 341
344 342
@@ -349,12 +347,12 @@ GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer,
349 * and receives updates when the solver changes the resource allocation. 347 * and receives updates when the solver changes the resource allocation.
350 */ 348 */
351void 349void
352GAS_addresses_init () 350GAS_addresses_init()
353{ 351{
354 GSA_addresses 352 GSA_addresses
355 = GNUNET_CONTAINER_multipeermap_create (128, 353 = GNUNET_CONTAINER_multipeermap_create(128,
356 GNUNET_NO); 354 GNUNET_NO);
357 update_addresses_stat (); 355 update_addresses_stat();
358} 356}
359 357
360 358
@@ -367,13 +365,13 @@ GAS_addresses_init ()
367 * @return #GNUNET_OK (continue to iterate) 365 * @return #GNUNET_OK (continue to iterate)
368 */ 366 */
369static int 367static int
370destroy_all_address_it (void *cls, 368destroy_all_address_it(void *cls,
371 const struct GNUNET_PeerIdentity *key, 369 const struct GNUNET_PeerIdentity *key,
372 void *value) 370 void *value)
373{ 371{
374 struct ATS_Address *aa = value; 372 struct ATS_Address *aa = value;
375 373
376 free_address (aa); 374 free_address(aa);
377 return GNUNET_OK; 375 return GNUNET_OK;
378} 376}
379 377
@@ -382,18 +380,18 @@ destroy_all_address_it (void *cls,
382 * Remove all addresses 380 * Remove all addresses
383 */ 381 */
384void 382void
385GAS_addresses_destroy_all () 383GAS_addresses_destroy_all()
386{ 384{
387 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 385 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
388 "Destroying all addresses\n"); 386 "Destroying all addresses\n");
389 if (0 == 387 if (0 ==
390 GNUNET_CONTAINER_multipeermap_size (GSA_addresses)) 388 GNUNET_CONTAINER_multipeermap_size(GSA_addresses))
391 return; 389 return;
392 GAS_plugin_solver_lock (); 390 GAS_plugin_solver_lock();
393 GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses, 391 GNUNET_CONTAINER_multipeermap_iterate(GSA_addresses,
394 &destroy_all_address_it, 392 &destroy_all_address_it,
395 NULL); 393 NULL);
396 GAS_plugin_solver_unlock (); 394 GAS_plugin_solver_unlock();
397} 395}
398 396
399 397
@@ -401,14 +399,14 @@ GAS_addresses_destroy_all ()
401 * Shutdown address subsystem. 399 * Shutdown address subsystem.
402 */ 400 */
403void 401void
404GAS_addresses_done () 402GAS_addresses_done()
405{ 403{
406 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 404 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
407 "Shutting down addresses\n"); 405 "Shutting down addresses\n");
408 GAS_plugin_solver_lock (); 406 GAS_plugin_solver_lock();
409 GAS_addresses_destroy_all (); 407 GAS_addresses_destroy_all();
410 GAS_plugin_solver_unlock (); 408 GAS_plugin_solver_unlock();
411 GNUNET_CONTAINER_multipeermap_destroy (GSA_addresses); 409 GNUNET_CONTAINER_multipeermap_destroy(GSA_addresses);
412 GSA_addresses = NULL; 410 GSA_addresses = NULL;
413} 411}
414 412
@@ -416,8 +414,7 @@ GAS_addresses_done ()
416/** 414/**
417 * Closure for #peerinfo_it(). 415 * Closure for #peerinfo_it().
418 */ 416 */
419struct PeerInfoIteratorContext 417struct PeerInfoIteratorContext {
420{
421 /** 418 /**
422 * Function to call for each address. 419 * Function to call for each address.
423 */ 420 */
@@ -439,23 +436,23 @@ struct PeerInfoIteratorContext
439 * @return #GNUNET_OK to continue 436 * @return #GNUNET_OK to continue
440 */ 437 */
441static int 438static int
442peerinfo_it (void *cls, 439peerinfo_it(void *cls,
443 const struct GNUNET_PeerIdentity *key, 440 const struct GNUNET_PeerIdentity *key,
444 void *value) 441 void *value)
445{ 442{
446 struct PeerInfoIteratorContext *pi_ctx = cls; 443 struct PeerInfoIteratorContext *pi_ctx = cls;
447 struct ATS_Address *addr = value; 444 struct ATS_Address *addr = value;
448 445
449 pi_ctx->it (pi_ctx->it_cls, 446 pi_ctx->it(pi_ctx->it_cls,
450 &addr->peer, 447 &addr->peer,
451 addr->plugin, 448 addr->plugin,
452 addr->addr, 449 addr->addr,
453 addr->addr_len, 450 addr->addr_len,
454 addr->active, 451 addr->active,
455 &addr->properties, 452 &addr->properties,
456 addr->local_address_info, 453 addr->local_address_info,
457 GNUNET_BANDWIDTH_value_init (addr->assigned_bw_out), 454 GNUNET_BANDWIDTH_value_init(addr->assigned_bw_out),
458 GNUNET_BANDWIDTH_value_init (addr->assigned_bw_in)); 455 GNUNET_BANDWIDTH_value_init(addr->assigned_bw_in));
459 return GNUNET_OK; 456 return GNUNET_OK;
460} 457}
461 458
@@ -468,41 +465,41 @@ peerinfo_it (void *cls,
468 * @param pi_it_cls the closure for @a pi_it 465 * @param pi_it_cls the closure for @a pi_it
469 */ 466 */
470void 467void
471GAS_addresses_get_peer_info (const struct GNUNET_PeerIdentity *peer, 468GAS_addresses_get_peer_info(const struct GNUNET_PeerIdentity *peer,
472 GNUNET_ATS_PeerInfo_Iterator pi_it, 469 GNUNET_ATS_PeerInfo_Iterator pi_it,
473 void *pi_it_cls) 470 void *pi_it_cls)
474{ 471{
475 struct PeerInfoIteratorContext pi_ctx; 472 struct PeerInfoIteratorContext pi_ctx;
476 473
477 if (NULL == pi_it) 474 if (NULL == pi_it)
478 { 475 {
479 /* does not make sense without callback */ 476 /* does not make sense without callback */
480 GNUNET_break (0); 477 GNUNET_break(0);
481 return; 478 return;
482 } 479 }
483 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 480 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
484 "Returning information for %s from a total of %u known addresses\n", 481 "Returning information for %s from a total of %u known addresses\n",
485 (NULL == peer) 482 (NULL == peer)
486 ? "all peers" 483 ? "all peers"
487 : GNUNET_i2s (peer), 484 : GNUNET_i2s(peer),
488 (unsigned int) GNUNET_CONTAINER_multipeermap_size (GSA_addresses)); 485 (unsigned int)GNUNET_CONTAINER_multipeermap_size(GSA_addresses));
489 pi_ctx.it = pi_it; 486 pi_ctx.it = pi_it;
490 pi_ctx.it_cls = pi_it_cls; 487 pi_ctx.it_cls = pi_it_cls;
491 if (NULL == peer) 488 if (NULL == peer)
492 GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses, 489 GNUNET_CONTAINER_multipeermap_iterate(GSA_addresses,
493 &peerinfo_it, 490 &peerinfo_it,
494 &pi_ctx); 491 &pi_ctx);
495 else 492 else
496 GNUNET_CONTAINER_multipeermap_get_multiple (GSA_addresses, 493 GNUNET_CONTAINER_multipeermap_get_multiple(GSA_addresses,
497 peer, 494 peer,
498 &peerinfo_it, &pi_ctx); 495 &peerinfo_it, &pi_ctx);
499 pi_it (pi_it_cls, 496 pi_it(pi_it_cls,
500 NULL, NULL, NULL, 0, 497 NULL, NULL, NULL, 0,
501 GNUNET_NO, 498 GNUNET_NO,
502 NULL, 499 NULL,
503 GNUNET_HELLO_ADDRESS_INFO_NONE, 500 GNUNET_HELLO_ADDRESS_INFO_NONE,
504 GNUNET_BANDWIDTH_ZERO, 501 GNUNET_BANDWIDTH_ZERO,
505 GNUNET_BANDWIDTH_ZERO); 502 GNUNET_BANDWIDTH_ZERO);
506} 503}
507 504
508 505
@@ -510,8 +507,7 @@ GAS_addresses_get_peer_info (const struct GNUNET_PeerIdentity *peer,
510 * Information we need for the callbacks to return a list of addresses 507 * Information we need for the callbacks to return a list of addresses
511 * back to the client. 508 * back to the client.
512 */ 509 */
513struct AddressIteration 510struct AddressIteration {
514{
515 /** 511 /**
516 * Actual handle to the client. 512 * Actual handle to the client.
517 */ 513 */
@@ -526,7 +522,6 @@ struct AddressIteration
526 * Which ID should be included in the response? 522 * Which ID should be included in the response?
527 */ 523 */
528 uint32_t id; 524 uint32_t id;
529
530}; 525};
531 526
532 527
@@ -546,16 +541,16 @@ struct AddressIteration
546 * @param bandwidth_in current inbound bandwidth assigned to address 541 * @param bandwidth_in current inbound bandwidth assigned to address
547 */ 542 */
548static void 543static void
549transmit_req_addr (struct AddressIteration *ai, 544transmit_req_addr(struct AddressIteration *ai,
550 const struct GNUNET_PeerIdentity *id, 545 const struct GNUNET_PeerIdentity *id,
551 const char *plugin_name, 546 const char *plugin_name,
552 const void *plugin_addr, 547 const void *plugin_addr,
553 size_t plugin_addr_len, 548 size_t plugin_addr_len,
554 int active, 549 int active,
555 const struct GNUNET_ATS_Properties *prop, 550 const struct GNUNET_ATS_Properties *prop,
556 enum GNUNET_HELLO_AddressInfo local_address_info, 551 enum GNUNET_HELLO_AddressInfo local_address_info,
557 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 552 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
558 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) 553 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
559 554
560{ 555{
561 struct GNUNET_MQ_Envelope *env; 556 struct GNUNET_MQ_Envelope *env;
@@ -565,37 +560,37 @@ transmit_req_addr (struct AddressIteration *ai,
565 size_t msize; 560 size_t msize;
566 561
567 if (NULL != plugin_name) 562 if (NULL != plugin_name)
568 plugin_name_length = strlen (plugin_name) + 1; 563 plugin_name_length = strlen(plugin_name) + 1;
569 else 564 else
570 plugin_name_length = 0; 565 plugin_name_length = 0;
571 msize = plugin_addr_len + plugin_name_length; 566 msize = plugin_addr_len + plugin_name_length;
572 567
573 GNUNET_assert (sizeof (struct PeerInformationMessage) + msize 568 GNUNET_assert(sizeof(struct PeerInformationMessage) + msize
574 < GNUNET_MAX_MESSAGE_SIZE); 569 < GNUNET_MAX_MESSAGE_SIZE);
575 env = GNUNET_MQ_msg_extra (msg, 570 env = GNUNET_MQ_msg_extra(msg,
576 msize, 571 msize,
577 GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE); 572 GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE);
578 msg->id = htonl (ai->id); 573 msg->id = htonl(ai->id);
579 if (NULL != id) 574 if (NULL != id)
580 msg->peer = *id; 575 msg->peer = *id;
581 msg->address_length = htons (plugin_addr_len); 576 msg->address_length = htons(plugin_addr_len);
582 msg->address_active = ntohl (active); 577 msg->address_active = ntohl(active);
583 msg->plugin_name_length = htons (plugin_name_length); 578 msg->plugin_name_length = htons(plugin_name_length);
584 msg->bandwidth_out = bandwidth_out; 579 msg->bandwidth_out = bandwidth_out;
585 msg->bandwidth_in = bandwidth_in; 580 msg->bandwidth_in = bandwidth_in;
586 if (NULL != prop) 581 if (NULL != prop)
587 GNUNET_ATS_properties_hton (&msg->properties, 582 GNUNET_ATS_properties_hton(&msg->properties,
588 prop); 583 prop);
589 msg->address_local_info = htonl ((uint32_t) local_address_info); 584 msg->address_local_info = htonl((uint32_t)local_address_info);
590 addrp = (char *) &msg[1]; 585 addrp = (char *)&msg[1];
591 GNUNET_memcpy (addrp, 586 GNUNET_memcpy(addrp,
592 plugin_addr, 587 plugin_addr,
593 plugin_addr_len); 588 plugin_addr_len);
594 if (NULL != plugin_name) 589 if (NULL != plugin_name)
595 strcpy (&addrp[plugin_addr_len], 590 strcpy(&addrp[plugin_addr_len],
596 plugin_name); 591 plugin_name);
597 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (ai->client), 592 GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(ai->client),
598 env); 593 env);
599} 594}
600 595
601 596
@@ -615,48 +610,48 @@ transmit_req_addr (struct AddressIteration *ai,
615 * @param bandwidth_in current inbound bandwidth assigned to address 610 * @param bandwidth_in current inbound bandwidth assigned to address
616 */ 611 */
617static void 612static void
618req_addr_peerinfo_it (void *cls, 613req_addr_peerinfo_it(void *cls,
619 const struct GNUNET_PeerIdentity *id, 614 const struct GNUNET_PeerIdentity *id,
620 const char *plugin_name, 615 const char *plugin_name,
621 const void *plugin_addr, 616 const void *plugin_addr,
622 size_t plugin_addr_len, 617 size_t plugin_addr_len,
623 int active, 618 int active,
624 const struct GNUNET_ATS_Properties *prop, 619 const struct GNUNET_ATS_Properties *prop,
625 enum GNUNET_HELLO_AddressInfo local_address_info, 620 enum GNUNET_HELLO_AddressInfo local_address_info,
626 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 621 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
627 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) 622 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
628{ 623{
629 struct AddressIteration *ai = cls; 624 struct AddressIteration *ai = cls;
630 625
631 if ( (NULL == id) && 626 if ((NULL == id) &&
632 (NULL == plugin_name) && 627 (NULL == plugin_name) &&
633 (NULL == plugin_addr) ) 628 (NULL == plugin_addr))
634 { 629 {
635 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 630 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
636 "Address iteration done for one peer\n"); 631 "Address iteration done for one peer\n");
637 return; 632 return;
638 } 633 }
639 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 634 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
640 "Callback for %s peer `%s' plugin `%s' BW out %u, BW in %u\n", 635 "Callback for %s peer `%s' plugin `%s' BW out %u, BW in %u\n",
641 (active == GNUNET_YES) ? "ACTIVE" : "INACTIVE", 636 (active == GNUNET_YES) ? "ACTIVE" : "INACTIVE",
642 GNUNET_i2s (id), 637 GNUNET_i2s(id),
643 plugin_name, 638 plugin_name,
644 (unsigned int) ntohl (bandwidth_out.value__), 639 (unsigned int)ntohl(bandwidth_out.value__),
645 (unsigned int) ntohl (bandwidth_in.value__)); 640 (unsigned int)ntohl(bandwidth_in.value__));
646 /* Transmit result (either if address is active, or if 641 /* Transmit result (either if address is active, or if
647 client wanted all addresses) */ 642 client wanted all addresses) */
648 if ( (GNUNET_YES != ai->all) && 643 if ((GNUNET_YES != ai->all) &&
649 (GNUNET_YES != active)) 644 (GNUNET_YES != active))
650 return; 645 return;
651 transmit_req_addr (ai, 646 transmit_req_addr(ai,
652 id, 647 id,
653 plugin_name, 648 plugin_name,
654 plugin_addr, plugin_addr_len, 649 plugin_addr, plugin_addr_len,
655 active, 650 active,
656 prop, 651 prop,
657 local_address_info, 652 local_address_info,
658 bandwidth_out, 653 bandwidth_out,
659 bandwidth_in); 654 bandwidth_in);
660} 655}
661 656
662 657
@@ -667,45 +662,45 @@ req_addr_peerinfo_it (void *cls,
667 * @param alrm the request message 662 * @param alrm the request message
668 */ 663 */
669void 664void
670GAS_handle_request_address_list (struct GNUNET_SERVICE_Client *client, 665GAS_handle_request_address_list(struct GNUNET_SERVICE_Client *client,
671 const struct AddressListRequestMessage *alrm) 666 const struct AddressListRequestMessage *alrm)
672{ 667{
673 struct AddressIteration ai; 668 struct AddressIteration ai;
674 struct GNUNET_PeerIdentity allzeros; 669 struct GNUNET_PeerIdentity allzeros;
675 670
676 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 671 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
677 "Received ADDRESSLIST_REQUEST message\n"); 672 "Received ADDRESSLIST_REQUEST message\n");
678 ai.all = ntohl (alrm->all); 673 ai.all = ntohl(alrm->all);
679 ai.id = ntohl (alrm->id); 674 ai.id = ntohl(alrm->id);
680 ai.client = client; 675 ai.client = client;
681 676
682 memset (&allzeros, 677 memset(&allzeros,
683 '\0', 678 '\0',
684 sizeof (struct GNUNET_PeerIdentity)); 679 sizeof(struct GNUNET_PeerIdentity));
685 if (0 == GNUNET_is_zero (&alrm->peer)) 680 if (0 == GNUNET_is_zero(&alrm->peer))
686 { 681 {
687 /* Return addresses for all peers */ 682 /* Return addresses for all peers */
688 GAS_addresses_get_peer_info (NULL, 683 GAS_addresses_get_peer_info(NULL,
689 &req_addr_peerinfo_it, 684 &req_addr_peerinfo_it,
690 &ai); 685 &ai);
691 } 686 }
692 else 687 else
693 { 688 {
694 /* Return addresses for a specific peer */ 689 /* Return addresses for a specific peer */
695 GAS_addresses_get_peer_info (&alrm->peer, 690 GAS_addresses_get_peer_info(&alrm->peer,
696 &req_addr_peerinfo_it, 691 &req_addr_peerinfo_it,
697 &ai); 692 &ai);
698 } 693 }
699 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 694 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
700 "Finished handling `%s' message\n", 695 "Finished handling `%s' message\n",
701 "ADDRESSLIST_REQUEST"); 696 "ADDRESSLIST_REQUEST");
702 transmit_req_addr (&ai, 697 transmit_req_addr(&ai,
703 NULL, NULL, NULL, 698 NULL, NULL, NULL,
704 0, GNUNET_NO, 699 0, GNUNET_NO,
705 NULL, 700 NULL,
706 GNUNET_HELLO_ADDRESS_INFO_NONE, 701 GNUNET_HELLO_ADDRESS_INFO_NONE,
707 GNUNET_BANDWIDTH_ZERO, 702 GNUNET_BANDWIDTH_ZERO,
708 GNUNET_BANDWIDTH_ZERO); 703 GNUNET_BANDWIDTH_ZERO);
709} 704}
710 705
711 706