diff options
Diffstat (limited to 'src/ats/gnunet-service-ats_addresses.c')
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 608 |
1 files changed, 308 insertions, 300 deletions
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 8ca245b1e..7c73cbf5b 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c | |||
@@ -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 | */ |
43 | static void | 43 | static void |
44 | update_addresses_stat() | 44 | update_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 | */ |
58 | static void | 58 | static void |
59 | free_address(struct ATS_Address *addr) | 59 | free_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 | */ |
86 | static void | 86 | static void |
87 | init_norm(struct GAS_NormalizationInfo *norm) | 87 | init_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 | */ |
107 | static struct ATS_Address * | 107 | static struct ATS_Address * |
108 | create_address(const struct GNUNET_PeerIdentity *peer, | 108 | create_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,7 +135,8 @@ create_address(const struct GNUNET_PeerIdentity *peer, | |||
135 | /** | 135 | /** |
136 | * Closure for #find_address_cb() | 136 | * Closure for #find_address_cb() |
137 | */ | 137 | */ |
138 | struct FindAddressContext { | 138 | struct FindAddressContext |
139 | { | ||
139 | /** | 140 | /** |
140 | * Session Id to look for. | 141 | * Session Id to look for. |
141 | */ | 142 | */ |
@@ -157,18 +158,18 @@ struct FindAddressContext { | |||
157 | * @return #GNUNET_YES to continue, #GNUNET_NO if address is found | 158 | * @return #GNUNET_YES to continue, #GNUNET_NO if address is found |
158 | */ | 159 | */ |
159 | static int | 160 | static int |
160 | find_address_cb(void *cls, | 161 | find_address_cb (void *cls, |
161 | const struct GNUNET_PeerIdentity *key, | 162 | const struct GNUNET_PeerIdentity *key, |
162 | void *value) | 163 | void *value) |
163 | { | 164 | { |
164 | struct FindAddressContext *fac = cls; | 165 | struct FindAddressContext *fac = cls; |
165 | struct ATS_Address *aa = value; | 166 | struct ATS_Address *aa = value; |
166 | 167 | ||
167 | if (aa->session_id == fac->session_id) | 168 | if (aa->session_id == fac->session_id) |
168 | { | 169 | { |
169 | fac->exact_address = aa; | 170 | fac->exact_address = aa; |
170 | return GNUNET_NO; | 171 | return GNUNET_NO; |
171 | } | 172 | } |
172 | return GNUNET_YES; | 173 | return GNUNET_YES; |
173 | } | 174 | } |
174 | 175 | ||
@@ -181,16 +182,16 @@ find_address_cb(void *cls, | |||
181 | * @return an ATS_address or NULL | 182 | * @return an ATS_address or NULL |
182 | */ | 183 | */ |
183 | static struct ATS_Address * | 184 | static struct ATS_Address * |
184 | find_exact_address(const struct GNUNET_PeerIdentity *peer, | 185 | find_exact_address (const struct GNUNET_PeerIdentity *peer, |
185 | uint32_t session_id) | 186 | uint32_t session_id) |
186 | { | 187 | { |
187 | struct FindAddressContext fac; | 188 | struct FindAddressContext fac; |
188 | 189 | ||
189 | fac.exact_address = NULL; | 190 | fac.exact_address = NULL; |
190 | fac.session_id = session_id; | 191 | fac.session_id = session_id; |
191 | GNUNET_CONTAINER_multipeermap_get_multiple(GSA_addresses, | 192 | GNUNET_CONTAINER_multipeermap_get_multiple (GSA_addresses, |
192 | peer, | 193 | peer, |
193 | &find_address_cb, &fac); | 194 | &find_address_cb, &fac); |
194 | return fac.exact_address; | 195 | return fac.exact_address; |
195 | } | 196 | } |
196 | 197 | ||
@@ -207,58 +208,60 @@ find_exact_address(const struct GNUNET_PeerIdentity *peer, | |||
207 | * @param prop performance information for this address | 208 | * @param prop performance information for this address |
208 | */ | 209 | */ |
209 | void | 210 | void |
210 | GAS_addresses_add(const struct GNUNET_PeerIdentity *peer, | 211 | GAS_addresses_add (const struct GNUNET_PeerIdentity *peer, |
211 | const char *plugin_name, | 212 | const char *plugin_name, |
212 | const void *plugin_addr, | 213 | const void *plugin_addr, |
213 | size_t plugin_addr_len, | 214 | size_t plugin_addr_len, |
214 | uint32_t local_address_info, | 215 | uint32_t local_address_info, |
215 | uint32_t session_id, | 216 | uint32_t session_id, |
216 | const struct GNUNET_ATS_Properties *prop) | 217 | const struct GNUNET_ATS_Properties *prop) |
217 | { | 218 | { |
218 | struct ATS_Address *new_address; | 219 | struct ATS_Address *new_address; |
219 | 220 | ||
220 | if (NULL != find_exact_address(peer, | 221 | if (NULL != find_exact_address (peer, |
221 | session_id)) | 222 | session_id)) |
222 | { | 223 | { |
223 | GNUNET_break(0); | 224 | GNUNET_break (0); |
224 | return; | 225 | return; |
225 | } | 226 | } |
226 | GNUNET_break(GNUNET_NT_UNSPECIFIED != prop->scope); | 227 | GNUNET_break (GNUNET_NT_UNSPECIFIED != prop->scope); |
227 | new_address = create_address(peer, | 228 | new_address = create_address (peer, |
228 | plugin_name, | 229 | plugin_name, |
229 | plugin_addr, | 230 | plugin_addr, |
230 | plugin_addr_len, | 231 | plugin_addr_len, |
231 | local_address_info, | 232 | local_address_info, |
232 | session_id); | 233 | session_id); |
233 | /* Add a new address */ | 234 | /* Add a new address */ |
234 | new_address->properties = *prop; | 235 | new_address->properties = *prop; |
235 | new_address->t_added = GNUNET_TIME_absolute_get(); | 236 | new_address->t_added = GNUNET_TIME_absolute_get (); |
236 | new_address->t_last_activity = GNUNET_TIME_absolute_get(); | 237 | new_address->t_last_activity = GNUNET_TIME_absolute_get (); |
237 | GNUNET_assert(GNUNET_OK == | 238 | GNUNET_assert (GNUNET_OK == |
238 | GNUNET_CONTAINER_multipeermap_put(GSA_addresses, | 239 | GNUNET_CONTAINER_multipeermap_put (GSA_addresses, |
239 | peer, | 240 | peer, |
240 | new_address, | 241 | new_address, |
241 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | 242 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
242 | update_addresses_stat(); | 243 | update_addresses_stat (); |
243 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 244 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
244 | "Adding new address for peer `%s' slot %u\n", | 245 | "Adding new address for peer `%s' slot %u\n", |
245 | GNUNET_i2s(peer), | 246 | GNUNET_i2s (peer), |
246 | session_id); | 247 | session_id); |
247 | /* Tell solver about new address */ | 248 | /* Tell solver about new address */ |
248 | GAS_plugin_solver_lock(); | 249 | GAS_plugin_solver_lock (); |
249 | GAS_plugin_new_address(new_address); | 250 | GAS_plugin_new_address (new_address); |
250 | GAS_normalization_update_property(new_address); // FIXME: needed? | 251 | GAS_normalization_update_property (new_address); // FIXME: needed? |
251 | GAS_plugin_solver_unlock(); | 252 | GAS_plugin_solver_unlock (); |
252 | /* Notify performance clients about new address */ | 253 | /* Notify performance clients about new address */ |
253 | GAS_performance_notify_all_clients(&new_address->peer, | 254 | GAS_performance_notify_all_clients (&new_address->peer, |
254 | new_address->plugin, | 255 | new_address->plugin, |
255 | new_address->addr, | 256 | new_address->addr, |
256 | new_address->addr_len, | 257 | new_address->addr_len, |
257 | new_address->active, | 258 | new_address->active, |
258 | &new_address->properties, | 259 | &new_address->properties, |
259 | new_address->local_address_info, | 260 | new_address->local_address_info, |
260 | GNUNET_BANDWIDTH_value_init(new_address->assigned_bw_out), | 261 | GNUNET_BANDWIDTH_value_init ( |
261 | GNUNET_BANDWIDTH_value_init(new_address->assigned_bw_in)); | 262 | new_address->assigned_bw_out), |
263 | GNUNET_BANDWIDTH_value_init ( | ||
264 | new_address->assigned_bw_in)); | ||
262 | } | 265 | } |
263 | 266 | ||
264 | 267 | ||
@@ -270,45 +273,47 @@ GAS_addresses_add(const struct GNUNET_PeerIdentity *peer, | |||
270 | * @param prop performance information for this address | 273 | * @param prop performance information for this address |
271 | */ | 274 | */ |
272 | void | 275 | void |
273 | GAS_addresses_update(const struct GNUNET_PeerIdentity *peer, | 276 | GAS_addresses_update (const struct GNUNET_PeerIdentity *peer, |
274 | uint32_t session_id, | 277 | uint32_t session_id, |
275 | const struct GNUNET_ATS_Properties *prop) | 278 | const struct GNUNET_ATS_Properties *prop) |
276 | { | 279 | { |
277 | struct ATS_Address *aa; | 280 | struct ATS_Address *aa; |
278 | 281 | ||
279 | /* Get existing address */ | 282 | /* Get existing address */ |
280 | aa = find_exact_address(peer, | 283 | aa = find_exact_address (peer, |
281 | session_id); | 284 | session_id); |
282 | if (NULL == aa) | 285 | if (NULL == aa) |
283 | { | 286 | { |
284 | GNUNET_break(0); | 287 | GNUNET_break (0); |
285 | return; | 288 | return; |
286 | } | 289 | } |
287 | if (NULL == aa->solver_information) | 290 | if (NULL == aa->solver_information) |
288 | { | 291 | { |
289 | GNUNET_break(0); | 292 | GNUNET_break (0); |
290 | return; | 293 | return; |
291 | } | 294 | } |
292 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 295 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
293 | "Received ADDRESS_UPDATE for peer `%s' slot %u\n", | 296 | "Received ADDRESS_UPDATE for peer `%s' slot %u\n", |
294 | GNUNET_i2s(peer), | 297 | GNUNET_i2s (peer), |
295 | (unsigned int)session_id); | 298 | (unsigned int) session_id); |
296 | GNUNET_break(GNUNET_NT_UNSPECIFIED != prop->scope); | 299 | GNUNET_break (GNUNET_NT_UNSPECIFIED != prop->scope); |
297 | /* Update address */ | 300 | /* Update address */ |
298 | aa->t_last_activity = GNUNET_TIME_absolute_get(); | 301 | aa->t_last_activity = GNUNET_TIME_absolute_get (); |
299 | aa->properties = *prop; | 302 | aa->properties = *prop; |
300 | /* Notify performance clients about updated address */ | 303 | /* Notify performance clients about updated address */ |
301 | GAS_performance_notify_all_clients(&aa->peer, | 304 | GAS_performance_notify_all_clients (&aa->peer, |
302 | aa->plugin, | 305 | aa->plugin, |
303 | aa->addr, | 306 | aa->addr, |
304 | aa->addr_len, | 307 | aa->addr_len, |
305 | aa->active, | 308 | aa->active, |
306 | prop, | 309 | prop, |
307 | aa->local_address_info, | 310 | aa->local_address_info, |
308 | GNUNET_BANDWIDTH_value_init(aa->assigned_bw_out), | 311 | GNUNET_BANDWIDTH_value_init ( |
309 | GNUNET_BANDWIDTH_value_init(aa->assigned_bw_in)); | 312 | aa->assigned_bw_out), |
310 | 313 | GNUNET_BANDWIDTH_value_init ( | |
311 | GAS_normalization_update_property(aa); | 314 | aa->assigned_bw_in)); |
315 | |||
316 | GAS_normalization_update_property (aa); | ||
312 | } | 317 | } |
313 | 318 | ||
314 | 319 | ||
@@ -319,24 +324,24 @@ GAS_addresses_update(const struct GNUNET_PeerIdentity *peer, | |||
319 | * @param session_id session id, can never be 0 | 324 | * @param session_id session id, can never be 0 |
320 | */ | 325 | */ |
321 | void | 326 | void |
322 | GAS_addresses_destroy(const struct GNUNET_PeerIdentity *peer, | 327 | GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer, |
323 | uint32_t session_id) | 328 | uint32_t session_id) |
324 | { | 329 | { |
325 | struct ATS_Address *ea; | 330 | struct ATS_Address *ea; |
326 | 331 | ||
327 | /* Get existing address */ | 332 | /* Get existing address */ |
328 | ea = find_exact_address(peer, | 333 | ea = find_exact_address (peer, |
329 | session_id); | 334 | session_id); |
330 | if (NULL == ea) | 335 | if (NULL == ea) |
331 | { | 336 | { |
332 | GNUNET_break(0); | 337 | GNUNET_break (0); |
333 | return; | 338 | return; |
334 | } | 339 | } |
335 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 340 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
336 | "Received ADDRESS_DESTROYED for peer `%s' session %u\n", | 341 | "Received ADDRESS_DESTROYED for peer `%s' session %u\n", |
337 | GNUNET_i2s(peer), | 342 | GNUNET_i2s (peer), |
338 | session_id); | 343 | session_id); |
339 | free_address(ea); | 344 | free_address (ea); |
340 | } | 345 | } |
341 | 346 | ||
342 | 347 | ||
@@ -347,12 +352,12 @@ GAS_addresses_destroy(const struct GNUNET_PeerIdentity *peer, | |||
347 | * and receives updates when the solver changes the resource allocation. | 352 | * and receives updates when the solver changes the resource allocation. |
348 | */ | 353 | */ |
349 | void | 354 | void |
350 | GAS_addresses_init() | 355 | GAS_addresses_init () |
351 | { | 356 | { |
352 | GSA_addresses | 357 | GSA_addresses |
353 | = GNUNET_CONTAINER_multipeermap_create(128, | 358 | = GNUNET_CONTAINER_multipeermap_create (128, |
354 | GNUNET_NO); | 359 | GNUNET_NO); |
355 | update_addresses_stat(); | 360 | update_addresses_stat (); |
356 | } | 361 | } |
357 | 362 | ||
358 | 363 | ||
@@ -365,13 +370,13 @@ GAS_addresses_init() | |||
365 | * @return #GNUNET_OK (continue to iterate) | 370 | * @return #GNUNET_OK (continue to iterate) |
366 | */ | 371 | */ |
367 | static int | 372 | static int |
368 | destroy_all_address_it(void *cls, | 373 | destroy_all_address_it (void *cls, |
369 | const struct GNUNET_PeerIdentity *key, | 374 | const struct GNUNET_PeerIdentity *key, |
370 | void *value) | 375 | void *value) |
371 | { | 376 | { |
372 | struct ATS_Address *aa = value; | 377 | struct ATS_Address *aa = value; |
373 | 378 | ||
374 | free_address(aa); | 379 | free_address (aa); |
375 | return GNUNET_OK; | 380 | return GNUNET_OK; |
376 | } | 381 | } |
377 | 382 | ||
@@ -380,18 +385,18 @@ destroy_all_address_it(void *cls, | |||
380 | * Remove all addresses | 385 | * Remove all addresses |
381 | */ | 386 | */ |
382 | void | 387 | void |
383 | GAS_addresses_destroy_all() | 388 | GAS_addresses_destroy_all () |
384 | { | 389 | { |
385 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 390 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
386 | "Destroying all addresses\n"); | 391 | "Destroying all addresses\n"); |
387 | if (0 == | 392 | if (0 == |
388 | GNUNET_CONTAINER_multipeermap_size(GSA_addresses)) | 393 | GNUNET_CONTAINER_multipeermap_size (GSA_addresses)) |
389 | return; | 394 | return; |
390 | GAS_plugin_solver_lock(); | 395 | GAS_plugin_solver_lock (); |
391 | GNUNET_CONTAINER_multipeermap_iterate(GSA_addresses, | 396 | GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses, |
392 | &destroy_all_address_it, | 397 | &destroy_all_address_it, |
393 | NULL); | 398 | NULL); |
394 | GAS_plugin_solver_unlock(); | 399 | GAS_plugin_solver_unlock (); |
395 | } | 400 | } |
396 | 401 | ||
397 | 402 | ||
@@ -399,14 +404,14 @@ GAS_addresses_destroy_all() | |||
399 | * Shutdown address subsystem. | 404 | * Shutdown address subsystem. |
400 | */ | 405 | */ |
401 | void | 406 | void |
402 | GAS_addresses_done() | 407 | GAS_addresses_done () |
403 | { | 408 | { |
404 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 409 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
405 | "Shutting down addresses\n"); | 410 | "Shutting down addresses\n"); |
406 | GAS_plugin_solver_lock(); | 411 | GAS_plugin_solver_lock (); |
407 | GAS_addresses_destroy_all(); | 412 | GAS_addresses_destroy_all (); |
408 | GAS_plugin_solver_unlock(); | 413 | GAS_plugin_solver_unlock (); |
409 | GNUNET_CONTAINER_multipeermap_destroy(GSA_addresses); | 414 | GNUNET_CONTAINER_multipeermap_destroy (GSA_addresses); |
410 | GSA_addresses = NULL; | 415 | GSA_addresses = NULL; |
411 | } | 416 | } |
412 | 417 | ||
@@ -414,7 +419,8 @@ GAS_addresses_done() | |||
414 | /** | 419 | /** |
415 | * Closure for #peerinfo_it(). | 420 | * Closure for #peerinfo_it(). |
416 | */ | 421 | */ |
417 | struct PeerInfoIteratorContext { | 422 | struct PeerInfoIteratorContext |
423 | { | ||
418 | /** | 424 | /** |
419 | * Function to call for each address. | 425 | * Function to call for each address. |
420 | */ | 426 | */ |
@@ -436,23 +442,23 @@ struct PeerInfoIteratorContext { | |||
436 | * @return #GNUNET_OK to continue | 442 | * @return #GNUNET_OK to continue |
437 | */ | 443 | */ |
438 | static int | 444 | static int |
439 | peerinfo_it(void *cls, | 445 | peerinfo_it (void *cls, |
440 | const struct GNUNET_PeerIdentity *key, | 446 | const struct GNUNET_PeerIdentity *key, |
441 | void *value) | 447 | void *value) |
442 | { | 448 | { |
443 | struct PeerInfoIteratorContext *pi_ctx = cls; | 449 | struct PeerInfoIteratorContext *pi_ctx = cls; |
444 | struct ATS_Address *addr = value; | 450 | struct ATS_Address *addr = value; |
445 | 451 | ||
446 | pi_ctx->it(pi_ctx->it_cls, | 452 | pi_ctx->it (pi_ctx->it_cls, |
447 | &addr->peer, | 453 | &addr->peer, |
448 | addr->plugin, | 454 | addr->plugin, |
449 | addr->addr, | 455 | addr->addr, |
450 | addr->addr_len, | 456 | addr->addr_len, |
451 | addr->active, | 457 | addr->active, |
452 | &addr->properties, | 458 | &addr->properties, |
453 | addr->local_address_info, | 459 | addr->local_address_info, |
454 | GNUNET_BANDWIDTH_value_init(addr->assigned_bw_out), | 460 | GNUNET_BANDWIDTH_value_init (addr->assigned_bw_out), |
455 | GNUNET_BANDWIDTH_value_init(addr->assigned_bw_in)); | 461 | GNUNET_BANDWIDTH_value_init (addr->assigned_bw_in)); |
456 | return GNUNET_OK; | 462 | return GNUNET_OK; |
457 | } | 463 | } |
458 | 464 | ||
@@ -465,41 +471,42 @@ peerinfo_it(void *cls, | |||
465 | * @param pi_it_cls the closure for @a pi_it | 471 | * @param pi_it_cls the closure for @a pi_it |
466 | */ | 472 | */ |
467 | void | 473 | void |
468 | GAS_addresses_get_peer_info(const struct GNUNET_PeerIdentity *peer, | 474 | GAS_addresses_get_peer_info (const struct GNUNET_PeerIdentity *peer, |
469 | GNUNET_ATS_PeerInfo_Iterator pi_it, | 475 | GNUNET_ATS_PeerInfo_Iterator pi_it, |
470 | void *pi_it_cls) | 476 | void *pi_it_cls) |
471 | { | 477 | { |
472 | struct PeerInfoIteratorContext pi_ctx; | 478 | struct PeerInfoIteratorContext pi_ctx; |
473 | 479 | ||
474 | if (NULL == pi_it) | 480 | if (NULL == pi_it) |
475 | { | 481 | { |
476 | /* does not make sense without callback */ | 482 | /* does not make sense without callback */ |
477 | GNUNET_break(0); | 483 | GNUNET_break (0); |
478 | return; | 484 | return; |
479 | } | 485 | } |
480 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 486 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
481 | "Returning information for %s from a total of %u known addresses\n", | 487 | "Returning information for %s from a total of %u known addresses\n", |
482 | (NULL == peer) | 488 | (NULL == peer) |
483 | ? "all peers" | 489 | ? "all peers" |
484 | : GNUNET_i2s(peer), | 490 | : GNUNET_i2s (peer), |
485 | (unsigned int)GNUNET_CONTAINER_multipeermap_size(GSA_addresses)); | 491 | (unsigned int) GNUNET_CONTAINER_multipeermap_size ( |
492 | GSA_addresses)); | ||
486 | pi_ctx.it = pi_it; | 493 | pi_ctx.it = pi_it; |
487 | pi_ctx.it_cls = pi_it_cls; | 494 | pi_ctx.it_cls = pi_it_cls; |
488 | if (NULL == peer) | 495 | if (NULL == peer) |
489 | GNUNET_CONTAINER_multipeermap_iterate(GSA_addresses, | 496 | GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses, |
490 | &peerinfo_it, | 497 | &peerinfo_it, |
491 | &pi_ctx); | 498 | &pi_ctx); |
492 | else | 499 | else |
493 | GNUNET_CONTAINER_multipeermap_get_multiple(GSA_addresses, | 500 | GNUNET_CONTAINER_multipeermap_get_multiple (GSA_addresses, |
494 | peer, | 501 | peer, |
495 | &peerinfo_it, &pi_ctx); | 502 | &peerinfo_it, &pi_ctx); |
496 | pi_it(pi_it_cls, | 503 | pi_it (pi_it_cls, |
497 | NULL, NULL, NULL, 0, | 504 | NULL, NULL, NULL, 0, |
498 | GNUNET_NO, | 505 | GNUNET_NO, |
499 | NULL, | 506 | NULL, |
500 | GNUNET_HELLO_ADDRESS_INFO_NONE, | 507 | GNUNET_HELLO_ADDRESS_INFO_NONE, |
501 | GNUNET_BANDWIDTH_ZERO, | 508 | GNUNET_BANDWIDTH_ZERO, |
502 | GNUNET_BANDWIDTH_ZERO); | 509 | GNUNET_BANDWIDTH_ZERO); |
503 | } | 510 | } |
504 | 511 | ||
505 | 512 | ||
@@ -507,7 +514,8 @@ GAS_addresses_get_peer_info(const struct GNUNET_PeerIdentity *peer, | |||
507 | * Information we need for the callbacks to return a list of addresses | 514 | * Information we need for the callbacks to return a list of addresses |
508 | * back to the client. | 515 | * back to the client. |
509 | */ | 516 | */ |
510 | struct AddressIteration { | 517 | struct AddressIteration |
518 | { | ||
511 | /** | 519 | /** |
512 | * Actual handle to the client. | 520 | * Actual handle to the client. |
513 | */ | 521 | */ |
@@ -541,16 +549,16 @@ struct AddressIteration { | |||
541 | * @param bandwidth_in current inbound bandwidth assigned to address | 549 | * @param bandwidth_in current inbound bandwidth assigned to address |
542 | */ | 550 | */ |
543 | static void | 551 | static void |
544 | transmit_req_addr(struct AddressIteration *ai, | 552 | transmit_req_addr (struct AddressIteration *ai, |
545 | const struct GNUNET_PeerIdentity *id, | 553 | const struct GNUNET_PeerIdentity *id, |
546 | const char *plugin_name, | 554 | const char *plugin_name, |
547 | const void *plugin_addr, | 555 | const void *plugin_addr, |
548 | size_t plugin_addr_len, | 556 | size_t plugin_addr_len, |
549 | int active, | 557 | int active, |
550 | const struct GNUNET_ATS_Properties *prop, | 558 | const struct GNUNET_ATS_Properties *prop, |
551 | enum GNUNET_HELLO_AddressInfo local_address_info, | 559 | enum GNUNET_HELLO_AddressInfo local_address_info, |
552 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 560 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
553 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | 561 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) |
554 | 562 | ||
555 | { | 563 | { |
556 | struct GNUNET_MQ_Envelope *env; | 564 | struct GNUNET_MQ_Envelope *env; |
@@ -560,37 +568,37 @@ transmit_req_addr(struct AddressIteration *ai, | |||
560 | size_t msize; | 568 | size_t msize; |
561 | 569 | ||
562 | if (NULL != plugin_name) | 570 | if (NULL != plugin_name) |
563 | plugin_name_length = strlen(plugin_name) + 1; | 571 | plugin_name_length = strlen (plugin_name) + 1; |
564 | else | 572 | else |
565 | plugin_name_length = 0; | 573 | plugin_name_length = 0; |
566 | msize = plugin_addr_len + plugin_name_length; | 574 | msize = plugin_addr_len + plugin_name_length; |
567 | 575 | ||
568 | GNUNET_assert(sizeof(struct PeerInformationMessage) + msize | 576 | GNUNET_assert (sizeof(struct PeerInformationMessage) + msize |
569 | < GNUNET_MAX_MESSAGE_SIZE); | 577 | < GNUNET_MAX_MESSAGE_SIZE); |
570 | env = GNUNET_MQ_msg_extra(msg, | 578 | env = GNUNET_MQ_msg_extra (msg, |
571 | msize, | 579 | msize, |
572 | GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE); | 580 | GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE); |
573 | msg->id = htonl(ai->id); | 581 | msg->id = htonl (ai->id); |
574 | if (NULL != id) | 582 | if (NULL != id) |
575 | msg->peer = *id; | 583 | msg->peer = *id; |
576 | msg->address_length = htons(plugin_addr_len); | 584 | msg->address_length = htons (plugin_addr_len); |
577 | msg->address_active = ntohl(active); | 585 | msg->address_active = ntohl (active); |
578 | msg->plugin_name_length = htons(plugin_name_length); | 586 | msg->plugin_name_length = htons (plugin_name_length); |
579 | msg->bandwidth_out = bandwidth_out; | 587 | msg->bandwidth_out = bandwidth_out; |
580 | msg->bandwidth_in = bandwidth_in; | 588 | msg->bandwidth_in = bandwidth_in; |
581 | if (NULL != prop) | 589 | if (NULL != prop) |
582 | GNUNET_ATS_properties_hton(&msg->properties, | 590 | GNUNET_ATS_properties_hton (&msg->properties, |
583 | prop); | 591 | prop); |
584 | msg->address_local_info = htonl((uint32_t)local_address_info); | 592 | msg->address_local_info = htonl ((uint32_t) local_address_info); |
585 | addrp = (char *)&msg[1]; | 593 | addrp = (char *) &msg[1]; |
586 | GNUNET_memcpy(addrp, | 594 | GNUNET_memcpy (addrp, |
587 | plugin_addr, | 595 | plugin_addr, |
588 | plugin_addr_len); | 596 | plugin_addr_len); |
589 | if (NULL != plugin_name) | 597 | if (NULL != plugin_name) |
590 | strcpy(&addrp[plugin_addr_len], | 598 | strcpy (&addrp[plugin_addr_len], |
591 | plugin_name); | 599 | plugin_name); |
592 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(ai->client), | 600 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (ai->client), |
593 | env); | 601 | env); |
594 | } | 602 | } |
595 | 603 | ||
596 | 604 | ||
@@ -610,48 +618,48 @@ transmit_req_addr(struct AddressIteration *ai, | |||
610 | * @param bandwidth_in current inbound bandwidth assigned to address | 618 | * @param bandwidth_in current inbound bandwidth assigned to address |
611 | */ | 619 | */ |
612 | static void | 620 | static void |
613 | req_addr_peerinfo_it(void *cls, | 621 | req_addr_peerinfo_it (void *cls, |
614 | const struct GNUNET_PeerIdentity *id, | 622 | const struct GNUNET_PeerIdentity *id, |
615 | const char *plugin_name, | 623 | const char *plugin_name, |
616 | const void *plugin_addr, | 624 | const void *plugin_addr, |
617 | size_t plugin_addr_len, | 625 | size_t plugin_addr_len, |
618 | int active, | 626 | int active, |
619 | const struct GNUNET_ATS_Properties *prop, | 627 | const struct GNUNET_ATS_Properties *prop, |
620 | enum GNUNET_HELLO_AddressInfo local_address_info, | 628 | enum GNUNET_HELLO_AddressInfo local_address_info, |
621 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 629 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
622 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | 630 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) |
623 | { | 631 | { |
624 | struct AddressIteration *ai = cls; | 632 | struct AddressIteration *ai = cls; |
625 | 633 | ||
626 | if ((NULL == id) && | 634 | if ((NULL == id) && |
627 | (NULL == plugin_name) && | 635 | (NULL == plugin_name) && |
628 | (NULL == plugin_addr)) | 636 | (NULL == plugin_addr)) |
629 | { | 637 | { |
630 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 638 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
631 | "Address iteration done for one peer\n"); | 639 | "Address iteration done for one peer\n"); |
632 | return; | 640 | return; |
633 | } | 641 | } |
634 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 642 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
635 | "Callback for %s peer `%s' plugin `%s' BW out %u, BW in %u\n", | 643 | "Callback for %s peer `%s' plugin `%s' BW out %u, BW in %u\n", |
636 | (active == GNUNET_YES) ? "ACTIVE" : "INACTIVE", | 644 | (active == GNUNET_YES) ? "ACTIVE" : "INACTIVE", |
637 | GNUNET_i2s(id), | 645 | GNUNET_i2s (id), |
638 | plugin_name, | 646 | plugin_name, |
639 | (unsigned int)ntohl(bandwidth_out.value__), | 647 | (unsigned int) ntohl (bandwidth_out.value__), |
640 | (unsigned int)ntohl(bandwidth_in.value__)); | 648 | (unsigned int) ntohl (bandwidth_in.value__)); |
641 | /* Transmit result (either if address is active, or if | 649 | /* Transmit result (either if address is active, or if |
642 | client wanted all addresses) */ | 650 | client wanted all addresses) */ |
643 | if ((GNUNET_YES != ai->all) && | 651 | if ((GNUNET_YES != ai->all) && |
644 | (GNUNET_YES != active)) | 652 | (GNUNET_YES != active)) |
645 | return; | 653 | return; |
646 | transmit_req_addr(ai, | 654 | transmit_req_addr (ai, |
647 | id, | 655 | id, |
648 | plugin_name, | 656 | plugin_name, |
649 | plugin_addr, plugin_addr_len, | 657 | plugin_addr, plugin_addr_len, |
650 | active, | 658 | active, |
651 | prop, | 659 | prop, |
652 | local_address_info, | 660 | local_address_info, |
653 | bandwidth_out, | 661 | bandwidth_out, |
654 | bandwidth_in); | 662 | bandwidth_in); |
655 | } | 663 | } |
656 | 664 | ||
657 | 665 | ||
@@ -662,45 +670,45 @@ req_addr_peerinfo_it(void *cls, | |||
662 | * @param alrm the request message | 670 | * @param alrm the request message |
663 | */ | 671 | */ |
664 | void | 672 | void |
665 | GAS_handle_request_address_list(struct GNUNET_SERVICE_Client *client, | 673 | GAS_handle_request_address_list (struct GNUNET_SERVICE_Client *client, |
666 | const struct AddressListRequestMessage *alrm) | 674 | const struct AddressListRequestMessage *alrm) |
667 | { | 675 | { |
668 | struct AddressIteration ai; | 676 | struct AddressIteration ai; |
669 | struct GNUNET_PeerIdentity allzeros; | 677 | struct GNUNET_PeerIdentity allzeros; |
670 | 678 | ||
671 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 679 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
672 | "Received ADDRESSLIST_REQUEST message\n"); | 680 | "Received ADDRESSLIST_REQUEST message\n"); |
673 | ai.all = ntohl(alrm->all); | 681 | ai.all = ntohl (alrm->all); |
674 | ai.id = ntohl(alrm->id); | 682 | ai.id = ntohl (alrm->id); |
675 | ai.client = client; | 683 | ai.client = client; |
676 | 684 | ||
677 | memset(&allzeros, | 685 | memset (&allzeros, |
678 | '\0', | 686 | '\0', |
679 | sizeof(struct GNUNET_PeerIdentity)); | 687 | sizeof(struct GNUNET_PeerIdentity)); |
680 | if (0 == GNUNET_is_zero(&alrm->peer)) | 688 | if (0 == GNUNET_is_zero (&alrm->peer)) |
681 | { | 689 | { |
682 | /* Return addresses for all peers */ | 690 | /* Return addresses for all peers */ |
683 | GAS_addresses_get_peer_info(NULL, | 691 | GAS_addresses_get_peer_info (NULL, |
684 | &req_addr_peerinfo_it, | 692 | &req_addr_peerinfo_it, |
685 | &ai); | 693 | &ai); |
686 | } | 694 | } |
687 | else | 695 | else |
688 | { | 696 | { |
689 | /* Return addresses for a specific peer */ | 697 | /* Return addresses for a specific peer */ |
690 | GAS_addresses_get_peer_info(&alrm->peer, | 698 | GAS_addresses_get_peer_info (&alrm->peer, |
691 | &req_addr_peerinfo_it, | 699 | &req_addr_peerinfo_it, |
692 | &ai); | 700 | &ai); |
693 | } | 701 | } |
694 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 702 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
695 | "Finished handling `%s' message\n", | 703 | "Finished handling `%s' message\n", |
696 | "ADDRESSLIST_REQUEST"); | 704 | "ADDRESSLIST_REQUEST"); |
697 | transmit_req_addr(&ai, | 705 | transmit_req_addr (&ai, |
698 | NULL, NULL, NULL, | 706 | NULL, NULL, NULL, |
699 | 0, GNUNET_NO, | 707 | 0, GNUNET_NO, |
700 | NULL, | 708 | NULL, |
701 | GNUNET_HELLO_ADDRESS_INFO_NONE, | 709 | GNUNET_HELLO_ADDRESS_INFO_NONE, |
702 | GNUNET_BANDWIDTH_ZERO, | 710 | GNUNET_BANDWIDTH_ZERO, |
703 | GNUNET_BANDWIDTH_ZERO); | 711 | GNUNET_BANDWIDTH_ZERO); |
704 | } | 712 | } |
705 | 713 | ||
706 | 714 | ||