diff options
Diffstat (limited to 'src/ats/ats_api_performance.c')
-rw-r--r-- | src/ats/ats_api_performance.c | 776 |
1 files changed, 389 insertions, 387 deletions
diff --git a/src/ats/ats_api_performance.c b/src/ats/ats_api_performance.c index 0954c02d5..b30093f4c 100644 --- a/src/ats/ats_api_performance.c +++ b/src/ats/ats_api_performance.c | |||
@@ -1,19 +1,19 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2010, 2011, 2016 GNUnet e.V. | 3 | Copyright (C) 2010, 2011, 2016 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 | */ |
@@ -28,15 +28,13 @@ | |||
28 | #include "ats.h" | 28 | #include "ats.h" |
29 | 29 | ||
30 | 30 | ||
31 | #define LOG(kind,...) GNUNET_log_from(kind, "ats-performance-api", __VA_ARGS__) | 31 | #define LOG(kind, ...) GNUNET_log_from(kind, "ats-performance-api", __VA_ARGS__) |
32 | 32 | ||
33 | 33 | ||
34 | /** | 34 | /** |
35 | * Linked list of pending reservations. | 35 | * Linked list of pending reservations. |
36 | */ | 36 | */ |
37 | struct GNUNET_ATS_ReservationContext | 37 | struct GNUNET_ATS_ReservationContext { |
38 | { | ||
39 | |||
40 | /** | 38 | /** |
41 | * Kept in a DLL. | 39 | * Kept in a DLL. |
42 | */ | 40 | */ |
@@ -82,9 +80,7 @@ struct GNUNET_ATS_ReservationContext | |||
82 | /** | 80 | /** |
83 | * Linked list of pending reservations. | 81 | * Linked list of pending reservations. |
84 | */ | 82 | */ |
85 | struct GNUNET_ATS_AddressListHandle | 83 | struct GNUNET_ATS_AddressListHandle { |
86 | { | ||
87 | |||
88 | /** | 84 | /** |
89 | * Kept in a DLL. | 85 | * Kept in a DLL. |
90 | */ | 86 | */ |
@@ -135,9 +131,7 @@ struct GNUNET_ATS_AddressListHandle | |||
135 | /** | 131 | /** |
136 | * ATS Handle to obtain and/or modify performance information. | 132 | * ATS Handle to obtain and/or modify performance information. |
137 | */ | 133 | */ |
138 | struct GNUNET_ATS_PerformanceHandle | 134 | struct GNUNET_ATS_PerformanceHandle { |
139 | { | ||
140 | |||
141 | /** | 135 | /** |
142 | * Our configuration. | 136 | * Our configuration. |
143 | */ | 137 | */ |
@@ -215,7 +209,7 @@ struct GNUNET_ATS_PerformanceHandle | |||
215 | * @param ph handle to use to re-connect. | 209 | * @param ph handle to use to re-connect. |
216 | */ | 210 | */ |
217 | static void | 211 | static void |
218 | reconnect (struct GNUNET_ATS_PerformanceHandle *ph); | 212 | reconnect(struct GNUNET_ATS_PerformanceHandle *ph); |
219 | 213 | ||
220 | 214 | ||
221 | /** | 215 | /** |
@@ -224,12 +218,12 @@ reconnect (struct GNUNET_ATS_PerformanceHandle *ph); | |||
224 | * @param cls handle to use to re-connect. | 218 | * @param cls handle to use to re-connect. |
225 | */ | 219 | */ |
226 | static void | 220 | static void |
227 | reconnect_task (void *cls) | 221 | reconnect_task(void *cls) |
228 | { | 222 | { |
229 | struct GNUNET_ATS_PerformanceHandle *ph = cls; | 223 | struct GNUNET_ATS_PerformanceHandle *ph = cls; |
230 | 224 | ||
231 | ph->task = NULL; | 225 | ph->task = NULL; |
232 | reconnect (ph); | 226 | reconnect(ph); |
233 | } | 227 | } |
234 | 228 | ||
235 | 229 | ||
@@ -239,58 +233,58 @@ reconnect_task (void *cls) | |||
239 | * @param ph handle to reconnect | 233 | * @param ph handle to reconnect |
240 | */ | 234 | */ |
241 | static void | 235 | static void |
242 | do_reconnect (struct GNUNET_ATS_PerformanceHandle *ph) | 236 | do_reconnect(struct GNUNET_ATS_PerformanceHandle *ph) |
243 | { | 237 | { |
244 | struct GNUNET_ATS_ReservationContext *rc; | 238 | struct GNUNET_ATS_ReservationContext *rc; |
245 | struct GNUNET_ATS_AddressListHandle *alh; | 239 | struct GNUNET_ATS_AddressListHandle *alh; |
246 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_zero; | 240 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_zero; |
247 | 241 | ||
248 | if (NULL != ph->mq) | 242 | if (NULL != ph->mq) |
249 | { | 243 | { |
250 | GNUNET_MQ_destroy (ph->mq); | 244 | GNUNET_MQ_destroy(ph->mq); |
251 | ph->mq = NULL; | 245 | ph->mq = NULL; |
252 | } | 246 | } |
253 | while (NULL != (rc = ph->reservation_head)) | 247 | while (NULL != (rc = ph->reservation_head)) |
254 | { | 248 | { |
255 | GNUNET_CONTAINER_DLL_remove (ph->reservation_head, | 249 | GNUNET_CONTAINER_DLL_remove(ph->reservation_head, |
256 | ph->reservation_tail, | 250 | ph->reservation_tail, |
257 | rc); | 251 | rc); |
258 | if (NULL != rc->rcb) | 252 | if (NULL != rc->rcb) |
259 | rc->rcb (rc->rcb_cls, | 253 | rc->rcb(rc->rcb_cls, |
260 | NULL, | 254 | NULL, |
261 | 0, | 255 | 0, |
262 | GNUNET_TIME_UNIT_FOREVER_REL); | 256 | GNUNET_TIME_UNIT_FOREVER_REL); |
263 | GNUNET_free (rc); | 257 | GNUNET_free(rc); |
264 | } | 258 | } |
265 | bandwidth_zero.value__ = htonl (0); | 259 | bandwidth_zero.value__ = htonl(0); |
266 | while (NULL != (alh = ph->addresslist_head)) | 260 | while (NULL != (alh = ph->addresslist_head)) |
267 | { | 261 | { |
268 | GNUNET_CONTAINER_DLL_remove (ph->addresslist_head, | 262 | GNUNET_CONTAINER_DLL_remove(ph->addresslist_head, |
269 | ph->addresslist_tail, | 263 | ph->addresslist_tail, |
270 | alh); | 264 | alh); |
271 | if (NULL != alh->cb) | 265 | if (NULL != alh->cb) |
272 | alh->cb (alh->cb_cls, | 266 | alh->cb(alh->cb_cls, |
273 | NULL, | 267 | NULL, |
274 | GNUNET_NO, | 268 | GNUNET_NO, |
275 | bandwidth_zero, | 269 | bandwidth_zero, |
276 | bandwidth_zero, | 270 | bandwidth_zero, |
277 | NULL); | 271 | NULL); |
278 | GNUNET_free (alh); | 272 | GNUNET_free(alh); |
279 | } | 273 | } |
280 | if (NULL != ph->addr_info_cb) | 274 | if (NULL != ph->addr_info_cb) |
281 | { | 275 | { |
282 | /* Indicate reconnect */ | 276 | /* Indicate reconnect */ |
283 | ph->addr_info_cb (ph->addr_info_cb_cls, | 277 | ph->addr_info_cb(ph->addr_info_cb_cls, |
284 | NULL, | 278 | NULL, |
285 | GNUNET_NO, | 279 | GNUNET_NO, |
286 | bandwidth_zero, | 280 | bandwidth_zero, |
287 | bandwidth_zero, | 281 | bandwidth_zero, |
288 | NULL); | 282 | NULL); |
289 | } | 283 | } |
290 | ph->backoff = GNUNET_TIME_STD_BACKOFF (ph->backoff); | 284 | ph->backoff = GNUNET_TIME_STD_BACKOFF(ph->backoff); |
291 | ph->task = GNUNET_SCHEDULER_add_delayed (ph->backoff, | 285 | ph->task = GNUNET_SCHEDULER_add_delayed(ph->backoff, |
292 | &reconnect_task, | 286 | &reconnect_task, |
293 | ph); | 287 | ph); |
294 | } | 288 | } |
295 | 289 | ||
296 | 290 | ||
@@ -302,25 +296,25 @@ do_reconnect (struct GNUNET_ATS_PerformanceHandle *ph) | |||
302 | * @return #GNUNET_OK if the message was well-formed | 296 | * @return #GNUNET_OK if the message was well-formed |
303 | */ | 297 | */ |
304 | static int | 298 | static int |
305 | check_peer_information (void *cls, | 299 | check_peer_information(void *cls, |
306 | const struct PeerInformationMessage *pi) | 300 | const struct PeerInformationMessage *pi) |
307 | { | 301 | { |
308 | const char *plugin_address; | 302 | const char *plugin_address; |
309 | const char *plugin_name; | 303 | const char *plugin_name; |
310 | uint16_t plugin_address_length; | 304 | uint16_t plugin_address_length; |
311 | uint16_t plugin_name_length; | 305 | uint16_t plugin_name_length; |
312 | 306 | ||
313 | plugin_address_length = ntohs (pi->address_length); | 307 | plugin_address_length = ntohs(pi->address_length); |
314 | plugin_name_length = ntohs (pi->plugin_name_length); | 308 | plugin_name_length = ntohs(pi->plugin_name_length); |
315 | plugin_address = (const char *) &pi[1]; | 309 | plugin_address = (const char *)&pi[1]; |
316 | plugin_name = &plugin_address[plugin_address_length]; | 310 | plugin_name = &plugin_address[plugin_address_length]; |
317 | if ( (plugin_address_length + plugin_name_length | 311 | if ((plugin_address_length + plugin_name_length |
318 | + sizeof(struct PeerInformationMessage) != ntohs (pi->header.size)) || | 312 | + sizeof(struct PeerInformationMessage) != ntohs(pi->header.size)) || |
319 | (plugin_name[plugin_name_length - 1] != '\0')) | 313 | (plugin_name[plugin_name_length - 1] != '\0')) |
320 | { | 314 | { |
321 | GNUNET_break(0); | 315 | GNUNET_break(0); |
322 | return GNUNET_SYSERR; | 316 | return GNUNET_SYSERR; |
323 | } | 317 | } |
324 | return GNUNET_OK; | 318 | return GNUNET_OK; |
325 | } | 319 | } |
326 | 320 | ||
@@ -333,8 +327,8 @@ check_peer_information (void *cls, | |||
333 | * @return #GNUNET_OK if the message was well-formed | 327 | * @return #GNUNET_OK if the message was well-formed |
334 | */ | 328 | */ |
335 | static void | 329 | static void |
336 | handle_peer_information (void *cls, | 330 | handle_peer_information(void *cls, |
337 | const struct PeerInformationMessage *pi) | 331 | const struct PeerInformationMessage *pi) |
338 | { | 332 | { |
339 | struct GNUNET_ATS_PerformanceHandle *ph = cls; | 333 | struct GNUNET_ATS_PerformanceHandle *ph = cls; |
340 | const char *plugin_address; | 334 | const char *plugin_address; |
@@ -346,24 +340,24 @@ handle_peer_information (void *cls, | |||
346 | 340 | ||
347 | if (NULL == ph->addr_info_cb) | 341 | if (NULL == ph->addr_info_cb) |
348 | return; | 342 | return; |
349 | plugin_address_length = ntohs (pi->address_length); | 343 | plugin_address_length = ntohs(pi->address_length); |
350 | addr_active = (int) ntohl (pi->address_active); | 344 | addr_active = (int)ntohl(pi->address_active); |
351 | plugin_address = (const char *) &pi[1]; | 345 | plugin_address = (const char *)&pi[1]; |
352 | plugin_name = &plugin_address[plugin_address_length]; | 346 | plugin_name = &plugin_address[plugin_address_length]; |
353 | 347 | ||
354 | GNUNET_ATS_properties_ntoh (&prop, | 348 | GNUNET_ATS_properties_ntoh(&prop, |
355 | &pi->properties); | 349 | &pi->properties); |
356 | address.peer = pi->peer; | 350 | address.peer = pi->peer; |
357 | address.local_info = (enum GNUNET_HELLO_AddressInfo) ntohl (pi->address_local_info); | 351 | address.local_info = (enum GNUNET_HELLO_AddressInfo)ntohl(pi->address_local_info); |
358 | address.address = plugin_address; | 352 | address.address = plugin_address; |
359 | address.address_length = plugin_address_length; | 353 | address.address_length = plugin_address_length; |
360 | address.transport_name = plugin_name; | 354 | address.transport_name = plugin_name; |
361 | ph->addr_info_cb (ph->addr_info_cb_cls, | 355 | ph->addr_info_cb(ph->addr_info_cb_cls, |
362 | &address, | 356 | &address, |
363 | addr_active, | 357 | addr_active, |
364 | pi->bandwidth_out, | 358 | pi->bandwidth_out, |
365 | pi->bandwidth_in, | 359 | pi->bandwidth_in, |
366 | &prop); | 360 | &prop); |
367 | } | 361 | } |
368 | 362 | ||
369 | 363 | ||
@@ -374,48 +368,48 @@ handle_peer_information (void *cls, | |||
374 | * @param rr the message | 368 | * @param rr the message |
375 | */ | 369 | */ |
376 | static void | 370 | static void |
377 | handle_reservation_result (void *cls, | 371 | handle_reservation_result(void *cls, |
378 | const struct ReservationResultMessage *rr) | 372 | const struct ReservationResultMessage *rr) |
379 | { | 373 | { |
380 | struct GNUNET_ATS_PerformanceHandle *ph = cls; | 374 | struct GNUNET_ATS_PerformanceHandle *ph = cls; |
381 | struct GNUNET_ATS_ReservationContext *rc; | 375 | struct GNUNET_ATS_ReservationContext *rc; |
382 | int32_t amount; | 376 | int32_t amount; |
383 | 377 | ||
384 | amount = ntohl (rr->amount); | 378 | amount = ntohl(rr->amount); |
385 | rc = ph->reservation_head; | 379 | rc = ph->reservation_head; |
386 | if (0 != GNUNET_memcmp (&rr->peer, | 380 | if (0 != GNUNET_memcmp(&rr->peer, |
387 | &rc->peer)) | 381 | &rc->peer)) |
388 | { | 382 | { |
389 | GNUNET_break(0); | 383 | GNUNET_break(0); |
390 | reconnect (ph); | 384 | reconnect(ph); |
391 | return; | 385 | return; |
392 | } | 386 | } |
393 | GNUNET_CONTAINER_DLL_remove (ph->reservation_head, | 387 | GNUNET_CONTAINER_DLL_remove(ph->reservation_head, |
394 | ph->reservation_tail, | 388 | ph->reservation_tail, |
395 | rc); | 389 | rc); |
396 | if ( (0 == amount) || | 390 | if ((0 == amount) || |
397 | (NULL != rc->rcb) ) | 391 | (NULL != rc->rcb)) |
398 | { | 392 | { |
399 | /* tell client if not cancelled */ | 393 | /* tell client if not cancelled */ |
400 | if (NULL != rc->rcb) | 394 | if (NULL != rc->rcb) |
401 | rc->rcb (rc->rcb_cls, | 395 | rc->rcb(rc->rcb_cls, |
402 | &rr->peer, | 396 | &rr->peer, |
403 | amount, | 397 | amount, |
404 | GNUNET_TIME_relative_ntoh (rr->res_delay)); | 398 | GNUNET_TIME_relative_ntoh(rr->res_delay)); |
405 | GNUNET_free (rc); | 399 | GNUNET_free(rc); |
406 | return; | 400 | return; |
407 | } | 401 | } |
408 | /* amount non-zero, but client cancelled, consider undo! */ | 402 | /* amount non-zero, but client cancelled, consider undo! */ |
409 | if (GNUNET_YES != rc->undo) | 403 | if (GNUNET_YES != rc->undo) |
410 | { | 404 | { |
411 | GNUNET_free (rc); | 405 | GNUNET_free(rc); |
412 | return; /* do not try to undo failed undos or negative amounts */ | 406 | return; /* do not try to undo failed undos or negative amounts */ |
413 | } | 407 | } |
414 | GNUNET_free (rc); | 408 | GNUNET_free(rc); |
415 | (void) GNUNET_ATS_reserve_bandwidth (ph, | 409 | (void)GNUNET_ATS_reserve_bandwidth(ph, |
416 | &rr->peer, | 410 | &rr->peer, |
417 | -amount, | 411 | -amount, |
418 | NULL, NULL); | 412 | NULL, NULL); |
419 | } | 413 | } |
420 | 414 | ||
421 | 415 | ||
@@ -427,25 +421,25 @@ handle_reservation_result (void *cls, | |||
427 | * @return #GNUNET_OK if the message was well-formed | 421 | * @return #GNUNET_OK if the message was well-formed |
428 | */ | 422 | */ |
429 | static int | 423 | static int |
430 | check_address_list (void *cls, | 424 | check_address_list(void *cls, |
431 | const struct PeerInformationMessage *pi) | 425 | const struct PeerInformationMessage *pi) |
432 | { | 426 | { |
433 | const char *plugin_address; | 427 | const char *plugin_address; |
434 | const char *plugin_name; | 428 | const char *plugin_name; |
435 | uint16_t plugin_address_length; | 429 | uint16_t plugin_address_length; |
436 | uint16_t plugin_name_length; | 430 | uint16_t plugin_name_length; |
437 | 431 | ||
438 | plugin_address_length = ntohs (pi->address_length); | 432 | plugin_address_length = ntohs(pi->address_length); |
439 | plugin_name_length = ntohs (pi->plugin_name_length); | 433 | plugin_name_length = ntohs(pi->plugin_name_length); |
440 | plugin_address = (const char *) &pi[1]; | 434 | plugin_address = (const char *)&pi[1]; |
441 | plugin_name = &plugin_address[plugin_address_length]; | 435 | plugin_name = &plugin_address[plugin_address_length]; |
442 | if ( (plugin_address_length + plugin_name_length | 436 | if ((plugin_address_length + plugin_name_length |
443 | + sizeof (struct PeerInformationMessage) != ntohs (pi->header.size)) || | 437 | + sizeof(struct PeerInformationMessage) != ntohs(pi->header.size)) || |
444 | (plugin_name[plugin_name_length - 1] != '\0') ) | 438 | (plugin_name[plugin_name_length - 1] != '\0')) |
445 | { | 439 | { |
446 | GNUNET_break(0); | 440 | GNUNET_break(0); |
447 | return GNUNET_SYSERR; | 441 | return GNUNET_SYSERR; |
448 | } | 442 | } |
449 | return GNUNET_OK; | 443 | return GNUNET_OK; |
450 | } | 444 | } |
451 | 445 | ||
@@ -458,8 +452,8 @@ check_address_list (void *cls, | |||
458 | * @param pi the message | 452 | * @param pi the message |
459 | */ | 453 | */ |
460 | static void | 454 | static void |
461 | handle_address_list (void *cls, | 455 | handle_address_list(void *cls, |
462 | const struct PeerInformationMessage *pi) | 456 | const struct PeerInformationMessage *pi) |
463 | { | 457 | { |
464 | struct GNUNET_ATS_PerformanceHandle *ph = cls; | 458 | struct GNUNET_ATS_PerformanceHandle *ph = cls; |
465 | struct GNUNET_ATS_AddressListHandle *alh; | 459 | struct GNUNET_ATS_AddressListHandle *alh; |
@@ -475,67 +469,67 @@ handle_address_list (void *cls, | |||
475 | uint32_t active; | 469 | uint32_t active; |
476 | uint32_t id; | 470 | uint32_t id; |
477 | 471 | ||
478 | id = ntohl (pi->id); | 472 | id = ntohl(pi->id); |
479 | active = ntohl (pi->address_active); | 473 | active = ntohl(pi->address_active); |
480 | plugin_address_length = ntohs (pi->address_length); | 474 | plugin_address_length = ntohs(pi->address_length); |
481 | plugin_name_length = ntohs (pi->plugin_name_length); | 475 | plugin_name_length = ntohs(pi->plugin_name_length); |
482 | plugin_address = (const char *) &pi[1]; | 476 | plugin_address = (const char *)&pi[1]; |
483 | plugin_name = &plugin_address[plugin_address_length]; | 477 | plugin_name = &plugin_address[plugin_address_length]; |
484 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 478 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
485 | "Received ATS_ADDRESSLIST_RESPONSE message for peer %s and plugin %s\n", | 479 | "Received ATS_ADDRESSLIST_RESPONSE message for peer %s and plugin %s\n", |
486 | GNUNET_i2s (&pi->peer), | 480 | GNUNET_i2s(&pi->peer), |
487 | plugin_name); | 481 | plugin_name); |
488 | 482 | ||
489 | next = ph->addresslist_head; | 483 | next = ph->addresslist_head; |
490 | while (NULL != (alh = next)) | 484 | while (NULL != (alh = next)) |
491 | { | 485 | { |
492 | next = alh->next; | 486 | next = alh->next; |
493 | if (alh->id == id) | 487 | if (alh->id == id) |
494 | break; | 488 | break; |
495 | } | 489 | } |
496 | if (NULL == alh) | 490 | if (NULL == alh) |
497 | return; /* was canceled */ | 491 | return; /* was canceled */ |
498 | 492 | ||
499 | memset (&allzeros, '\0', sizeof (allzeros)); | 493 | memset(&allzeros, '\0', sizeof(allzeros)); |
500 | if ( (0 == GNUNET_is_zero (&pi->peer)) && | 494 | if ((0 == GNUNET_is_zero(&pi->peer)) && |
501 | (0 == plugin_name_length) && | 495 | (0 == plugin_name_length) && |
502 | (0 == plugin_address_length) ) | 496 | (0 == plugin_address_length)) |
503 | { | 497 | { |
504 | /* Done */ | 498 | /* Done */ |
505 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 499 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
506 | "Received last message for ATS_ADDRESSLIST_RESPONSE\n"); | 500 | "Received last message for ATS_ADDRESSLIST_RESPONSE\n"); |
507 | bandwidth_zero.value__ = htonl (0); | 501 | bandwidth_zero.value__ = htonl(0); |
508 | GNUNET_CONTAINER_DLL_remove (ph->addresslist_head, | 502 | GNUNET_CONTAINER_DLL_remove(ph->addresslist_head, |
509 | ph->addresslist_tail, | 503 | ph->addresslist_tail, |
510 | alh); | 504 | alh); |
511 | if (NULL != alh->cb) | 505 | if (NULL != alh->cb) |
512 | alh->cb (alh->cb_cls, | 506 | alh->cb(alh->cb_cls, |
513 | NULL, | 507 | NULL, |
514 | GNUNET_NO, | 508 | GNUNET_NO, |
515 | bandwidth_zero, | 509 | bandwidth_zero, |
516 | bandwidth_zero, | 510 | bandwidth_zero, |
517 | NULL); | 511 | NULL); |
518 | GNUNET_free (alh); | 512 | GNUNET_free(alh); |
519 | return; | 513 | return; |
520 | } | 514 | } |
521 | 515 | ||
522 | address.peer = pi->peer; | 516 | address.peer = pi->peer; |
523 | address.address = plugin_address; | 517 | address.address = plugin_address; |
524 | address.address_length = plugin_address_length; | 518 | address.address_length = plugin_address_length; |
525 | address.transport_name = plugin_name; | 519 | address.transport_name = plugin_name; |
526 | if ( ( (GNUNET_YES == alh->all_addresses) || | 520 | if (((GNUNET_YES == alh->all_addresses) || |
527 | (GNUNET_YES == active) ) && | 521 | (GNUNET_YES == active)) && |
528 | (NULL != alh->cb) ) | 522 | (NULL != alh->cb)) |
529 | { | 523 | { |
530 | GNUNET_ATS_properties_ntoh (&prop, | 524 | GNUNET_ATS_properties_ntoh(&prop, |
531 | &pi->properties); | 525 | &pi->properties); |
532 | alh->cb (alh->cb_cls, | 526 | alh->cb(alh->cb_cls, |
533 | &address, | 527 | &address, |
534 | active, | 528 | active, |
535 | pi->bandwidth_out, | 529 | pi->bandwidth_out, |
536 | pi->bandwidth_in, | 530 | pi->bandwidth_in, |
537 | &prop); | 531 | &prop); |
538 | } | 532 | } |
539 | } | 533 | } |
540 | 534 | ||
541 | 535 | ||
@@ -548,12 +542,12 @@ handle_address_list (void *cls, | |||
548 | * @param error error code | 542 | * @param error error code |
549 | */ | 543 | */ |
550 | static void | 544 | static void |
551 | mq_error_handler (void *cls, | 545 | mq_error_handler(void *cls, |
552 | enum GNUNET_MQ_Error error) | 546 | enum GNUNET_MQ_Error error) |
553 | { | 547 | { |
554 | struct GNUNET_ATS_PerformanceHandle *ph = cls; | 548 | struct GNUNET_ATS_PerformanceHandle *ph = cls; |
555 | 549 | ||
556 | do_reconnect (ph); | 550 | do_reconnect(ph); |
557 | } | 551 | } |
558 | 552 | ||
559 | 553 | ||
@@ -563,41 +557,41 @@ mq_error_handler (void *cls, | |||
563 | * @param ph handle to use to re-connect. | 557 | * @param ph handle to use to re-connect. |
564 | */ | 558 | */ |
565 | static void | 559 | static void |
566 | reconnect (struct GNUNET_ATS_PerformanceHandle *ph) | 560 | reconnect(struct GNUNET_ATS_PerformanceHandle *ph) |
567 | { | 561 | { |
568 | struct GNUNET_MQ_MessageHandler handlers[] = { | 562 | struct GNUNET_MQ_MessageHandler handlers[] = { |
569 | GNUNET_MQ_hd_var_size (peer_information, | 563 | GNUNET_MQ_hd_var_size(peer_information, |
570 | GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION, | 564 | GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION, |
571 | struct PeerInformationMessage, | 565 | struct PeerInformationMessage, |
572 | ph), | 566 | ph), |
573 | GNUNET_MQ_hd_fixed_size (reservation_result, | 567 | GNUNET_MQ_hd_fixed_size(reservation_result, |
574 | GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT, | 568 | GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT, |
575 | struct ReservationResultMessage, | 569 | struct ReservationResultMessage, |
576 | ph), | 570 | ph), |
577 | GNUNET_MQ_hd_var_size (address_list, | 571 | GNUNET_MQ_hd_var_size(address_list, |
578 | GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE, | 572 | GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE, |
579 | struct PeerInformationMessage, | 573 | struct PeerInformationMessage, |
580 | ph), | 574 | ph), |
581 | GNUNET_MQ_handler_end () | 575 | GNUNET_MQ_handler_end() |
582 | }; | 576 | }; |
583 | struct GNUNET_MQ_Envelope *env; | 577 | struct GNUNET_MQ_Envelope *env; |
584 | struct ClientStartMessage *init; | 578 | struct ClientStartMessage *init; |
585 | 579 | ||
586 | GNUNET_assert (NULL == ph->mq); | 580 | GNUNET_assert(NULL == ph->mq); |
587 | ph->mq = GNUNET_CLIENT_connect (ph->cfg, | 581 | ph->mq = GNUNET_CLIENT_connect(ph->cfg, |
588 | "ats", | 582 | "ats", |
589 | handlers, | 583 | handlers, |
590 | &mq_error_handler, | 584 | &mq_error_handler, |
591 | ph); | 585 | ph); |
592 | if (NULL == ph->mq) | 586 | if (NULL == ph->mq) |
593 | return; | 587 | return; |
594 | env = GNUNET_MQ_msg (init, | 588 | env = GNUNET_MQ_msg(init, |
595 | GNUNET_MESSAGE_TYPE_ATS_START); | 589 | GNUNET_MESSAGE_TYPE_ATS_START); |
596 | init->start_flag = htonl ( (NULL == ph->addr_info_cb) | 590 | init->start_flag = htonl((NULL == ph->addr_info_cb) |
597 | ? START_FLAG_PERFORMANCE_NO_PIC | 591 | ? START_FLAG_PERFORMANCE_NO_PIC |
598 | : START_FLAG_PERFORMANCE_WITH_PIC); | 592 | : START_FLAG_PERFORMANCE_WITH_PIC); |
599 | GNUNET_MQ_send (ph->mq, | 593 | GNUNET_MQ_send(ph->mq, |
600 | env); | 594 | env); |
601 | } | 595 | } |
602 | 596 | ||
603 | 597 | ||
@@ -606,27 +600,27 @@ reconnect (struct GNUNET_ATS_PerformanceHandle *ph) | |||
606 | * | 600 | * |
607 | * @param cfg configuration to use | 601 | * @param cfg configuration to use |
608 | * @param addr_info_cb callback called when performance characteristics for | 602 | * @param addr_info_cb callback called when performance characteristics for |
609 | * an address change | 603 | * an address change |
610 | * @param addr_info_cb_cls closure for @a addr_info_cb | 604 | * @param addr_info_cb_cls closure for @a addr_info_cb |
611 | * @return ats performance context | 605 | * @return ats performance context |
612 | */ | 606 | */ |
613 | struct GNUNET_ATS_PerformanceHandle * | 607 | struct GNUNET_ATS_PerformanceHandle * |
614 | GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | 608 | GNUNET_ATS_performance_init(const struct GNUNET_CONFIGURATION_Handle *cfg, |
615 | GNUNET_ATS_AddressInformationCallback addr_info_cb, | 609 | GNUNET_ATS_AddressInformationCallback addr_info_cb, |
616 | void *addr_info_cb_cls) | 610 | void *addr_info_cb_cls) |
617 | { | 611 | { |
618 | struct GNUNET_ATS_PerformanceHandle *ph; | 612 | struct GNUNET_ATS_PerformanceHandle *ph; |
619 | 613 | ||
620 | ph = GNUNET_new (struct GNUNET_ATS_PerformanceHandle); | 614 | ph = GNUNET_new(struct GNUNET_ATS_PerformanceHandle); |
621 | ph->cfg = cfg; | 615 | ph->cfg = cfg; |
622 | ph->addr_info_cb = addr_info_cb; | 616 | ph->addr_info_cb = addr_info_cb; |
623 | ph->addr_info_cb_cls = addr_info_cb_cls; | 617 | ph->addr_info_cb_cls = addr_info_cb_cls; |
624 | reconnect (ph); | 618 | reconnect(ph); |
625 | if (NULL == ph->mq) | 619 | if (NULL == ph->mq) |
626 | { | 620 | { |
627 | GNUNET_free (ph); | 621 | GNUNET_free(ph); |
628 | return NULL; | 622 | return NULL; |
629 | } | 623 | } |
630 | return ph; | 624 | return ph; |
631 | } | 625 | } |
632 | 626 | ||
@@ -637,37 +631,37 @@ GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
637 | * @param ph handle | 631 | * @param ph handle |
638 | */ | 632 | */ |
639 | void | 633 | void |
640 | GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph) | 634 | GNUNET_ATS_performance_done(struct GNUNET_ATS_PerformanceHandle *ph) |
641 | { | 635 | { |
642 | struct GNUNET_ATS_ReservationContext *rc; | 636 | struct GNUNET_ATS_ReservationContext *rc; |
643 | struct GNUNET_ATS_AddressListHandle *alh; | 637 | struct GNUNET_ATS_AddressListHandle *alh; |
644 | 638 | ||
645 | while (NULL != (alh = ph->addresslist_head)) | 639 | while (NULL != (alh = ph->addresslist_head)) |
646 | { | 640 | { |
647 | GNUNET_CONTAINER_DLL_remove (ph->addresslist_head, | 641 | GNUNET_CONTAINER_DLL_remove(ph->addresslist_head, |
648 | ph->addresslist_tail, | 642 | ph->addresslist_tail, |
649 | alh); | 643 | alh); |
650 | GNUNET_free (alh); | 644 | GNUNET_free(alh); |
651 | } | 645 | } |
652 | while (NULL != (rc = ph->reservation_head)) | 646 | while (NULL != (rc = ph->reservation_head)) |
653 | { | 647 | { |
654 | GNUNET_CONTAINER_DLL_remove (ph->reservation_head, | 648 | GNUNET_CONTAINER_DLL_remove(ph->reservation_head, |
655 | ph->reservation_tail, | 649 | ph->reservation_tail, |
656 | rc); | 650 | rc); |
657 | GNUNET_break (NULL == rc->rcb); | 651 | GNUNET_break(NULL == rc->rcb); |
658 | GNUNET_free (rc); | 652 | GNUNET_free(rc); |
659 | } | 653 | } |
660 | if (NULL != ph->task) | 654 | if (NULL != ph->task) |
661 | { | 655 | { |
662 | GNUNET_SCHEDULER_cancel (ph->task); | 656 | GNUNET_SCHEDULER_cancel(ph->task); |
663 | ph->task = NULL; | 657 | ph->task = NULL; |
664 | } | 658 | } |
665 | if (NULL != ph->mq) | 659 | if (NULL != ph->mq) |
666 | { | 660 | { |
667 | GNUNET_MQ_destroy (ph->mq); | 661 | GNUNET_MQ_destroy(ph->mq); |
668 | ph->mq = NULL; | 662 | ph->mq = NULL; |
669 | } | 663 | } |
670 | GNUNET_free (ph); | 664 | GNUNET_free(ph); |
671 | } | 665 | } |
672 | 666 | ||
673 | 667 | ||
@@ -686,11 +680,11 @@ GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph) | |||
686 | * @deprecated will be replaced soon | 680 | * @deprecated will be replaced soon |
687 | */ | 681 | */ |
688 | struct GNUNET_ATS_ReservationContext * | 682 | struct GNUNET_ATS_ReservationContext * |
689 | GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph, | 683 | GNUNET_ATS_reserve_bandwidth(struct GNUNET_ATS_PerformanceHandle *ph, |
690 | const struct GNUNET_PeerIdentity *peer, | 684 | const struct GNUNET_PeerIdentity *peer, |
691 | int32_t amount, | 685 | int32_t amount, |
692 | GNUNET_ATS_ReservationCallback rcb, | 686 | GNUNET_ATS_ReservationCallback rcb, |
693 | void *rcb_cls) | 687 | void *rcb_cls) |
694 | { | 688 | { |
695 | struct GNUNET_ATS_ReservationContext *rc; | 689 | struct GNUNET_ATS_ReservationContext *rc; |
696 | struct GNUNET_MQ_Envelope *env; | 690 | struct GNUNET_MQ_Envelope *env; |
@@ -698,23 +692,23 @@ GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph, | |||
698 | 692 | ||
699 | if (NULL == ph->mq) | 693 | if (NULL == ph->mq) |
700 | return NULL; | 694 | return NULL; |
701 | rc = GNUNET_new (struct GNUNET_ATS_ReservationContext); | 695 | rc = GNUNET_new(struct GNUNET_ATS_ReservationContext); |
702 | rc->size = amount; | 696 | rc->size = amount; |
703 | rc->peer = *peer; | 697 | rc->peer = *peer; |
704 | rc->rcb = rcb; | 698 | rc->rcb = rcb; |
705 | rc->rcb_cls = rcb_cls; | 699 | rc->rcb_cls = rcb_cls; |
706 | if ( (NULL != rcb) && | 700 | if ((NULL != rcb) && |
707 | (amount > 0) ) | 701 | (amount > 0)) |
708 | rc->undo = GNUNET_YES; | 702 | rc->undo = GNUNET_YES; |
709 | GNUNET_CONTAINER_DLL_insert_tail (ph->reservation_head, | 703 | GNUNET_CONTAINER_DLL_insert_tail(ph->reservation_head, |
710 | ph->reservation_tail, | 704 | ph->reservation_tail, |
711 | rc); | 705 | rc); |
712 | env = GNUNET_MQ_msg (m, | 706 | env = GNUNET_MQ_msg(m, |
713 | GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST); | 707 | GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST); |
714 | m->amount = htonl (amount); | 708 | m->amount = htonl(amount); |
715 | m->peer = *peer; | 709 | m->peer = *peer; |
716 | GNUNET_MQ_send (ph->mq, | 710 | GNUNET_MQ_send(ph->mq, |
717 | env); | 711 | env); |
718 | return rc; | 712 | return rc; |
719 | } | 713 | } |
720 | 714 | ||
@@ -725,7 +719,7 @@ GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph, | |||
725 | * @param rc context returned by the original #GNUNET_ATS_reserve_bandwidth() call | 719 | * @param rc context returned by the original #GNUNET_ATS_reserve_bandwidth() call |
726 | */ | 720 | */ |
727 | void | 721 | void |
728 | GNUNET_ATS_reserve_bandwidth_cancel (struct GNUNET_ATS_ReservationContext *rc) | 722 | GNUNET_ATS_reserve_bandwidth_cancel(struct GNUNET_ATS_ReservationContext *rc) |
729 | { | 723 | { |
730 | rc->rcb = NULL; | 724 | rc->rcb = NULL; |
731 | } | 725 | } |
@@ -744,11 +738,11 @@ GNUNET_ATS_reserve_bandwidth_cancel (struct GNUNET_ATS_ReservationContext *rc) | |||
744 | * @return ats performance context | 738 | * @return ats performance context |
745 | */ | 739 | */ |
746 | struct GNUNET_ATS_AddressListHandle* | 740 | struct GNUNET_ATS_AddressListHandle* |
747 | GNUNET_ATS_performance_list_addresses (struct GNUNET_ATS_PerformanceHandle *ph, | 741 | GNUNET_ATS_performance_list_addresses(struct GNUNET_ATS_PerformanceHandle *ph, |
748 | const struct GNUNET_PeerIdentity *peer, | 742 | const struct GNUNET_PeerIdentity *peer, |
749 | int all, | 743 | int all, |
750 | GNUNET_ATS_AddressInformationCallback infocb, | 744 | GNUNET_ATS_AddressInformationCallback infocb, |
751 | void *infocb_cls) | 745 | void *infocb_cls) |
752 | { | 746 | { |
753 | struct GNUNET_ATS_AddressListHandle *alh; | 747 | struct GNUNET_ATS_AddressListHandle *alh; |
754 | struct GNUNET_MQ_Envelope *env; | 748 | struct GNUNET_MQ_Envelope *env; |
@@ -757,36 +751,36 @@ GNUNET_ATS_performance_list_addresses (struct GNUNET_ATS_PerformanceHandle *ph, | |||
757 | if (NULL == ph->mq) | 751 | if (NULL == ph->mq) |
758 | return NULL; | 752 | return NULL; |
759 | if (NULL == infocb) | 753 | if (NULL == infocb) |
760 | { | 754 | { |
761 | GNUNET_break (0); | 755 | GNUNET_break(0); |
762 | return NULL; | 756 | return NULL; |
763 | } | 757 | } |
764 | alh = GNUNET_new (struct GNUNET_ATS_AddressListHandle); | 758 | alh = GNUNET_new(struct GNUNET_ATS_AddressListHandle); |
765 | alh->id = ph->id++; | 759 | alh->id = ph->id++; |
766 | alh->cb = infocb; | 760 | alh->cb = infocb; |
767 | alh->cb_cls = infocb_cls; | 761 | alh->cb_cls = infocb_cls; |
768 | alh->ph = ph; | 762 | alh->ph = ph; |
769 | alh->all_addresses = all; | 763 | alh->all_addresses = all; |
770 | if (NULL == peer) | 764 | if (NULL == peer) |
771 | { | 765 | { |
772 | alh->all_peers = GNUNET_YES; | 766 | alh->all_peers = GNUNET_YES; |
773 | } | 767 | } |
774 | else | 768 | else |
775 | { | 769 | { |
776 | alh->all_peers = GNUNET_NO; | 770 | alh->all_peers = GNUNET_NO; |
777 | alh->peer = *peer; | 771 | alh->peer = *peer; |
778 | } | 772 | } |
779 | GNUNET_CONTAINER_DLL_insert (ph->addresslist_head, | 773 | GNUNET_CONTAINER_DLL_insert(ph->addresslist_head, |
780 | ph->addresslist_tail, | 774 | ph->addresslist_tail, |
781 | alh); | 775 | alh); |
782 | env = GNUNET_MQ_msg (m, | 776 | env = GNUNET_MQ_msg(m, |
783 | GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_REQUEST); | 777 | GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_REQUEST); |
784 | m->all = htonl (all); | 778 | m->all = htonl(all); |
785 | m->id = htonl (alh->id); | 779 | m->id = htonl(alh->id); |
786 | if (NULL != peer) | 780 | if (NULL != peer) |
787 | m->peer = *peer; | 781 | m->peer = *peer; |
788 | GNUNET_MQ_send (ph->mq, | 782 | GNUNET_MQ_send(ph->mq, |
789 | env); | 783 | env); |
790 | return alh; | 784 | return alh; |
791 | } | 785 | } |
792 | 786 | ||
@@ -797,14 +791,14 @@ GNUNET_ATS_performance_list_addresses (struct GNUNET_ATS_PerformanceHandle *ph, | |||
797 | * @param alh the handle of the request to cancel | 791 | * @param alh the handle of the request to cancel |
798 | */ | 792 | */ |
799 | void | 793 | void |
800 | GNUNET_ATS_performance_list_addresses_cancel (struct GNUNET_ATS_AddressListHandle *alh) | 794 | GNUNET_ATS_performance_list_addresses_cancel(struct GNUNET_ATS_AddressListHandle *alh) |
801 | { | 795 | { |
802 | struct GNUNET_ATS_PerformanceHandle *ph = alh->ph; | 796 | struct GNUNET_ATS_PerformanceHandle *ph = alh->ph; |
803 | 797 | ||
804 | GNUNET_CONTAINER_DLL_remove (ph->addresslist_head, | 798 | GNUNET_CONTAINER_DLL_remove(ph->addresslist_head, |
805 | ph->addresslist_tail, | 799 | ph->addresslist_tail, |
806 | alh); | 800 | alh); |
807 | GNUNET_free (alh); | 801 | GNUNET_free(alh); |
808 | } | 802 | } |
809 | 803 | ||
810 | 804 | ||
@@ -815,7 +809,7 @@ GNUNET_ATS_performance_list_addresses_cancel (struct GNUNET_ATS_AddressListHandl | |||
815 | * @return a string or NULL if invalid | 809 | * @return a string or NULL if invalid |
816 | */ | 810 | */ |
817 | const char * | 811 | const char * |
818 | GNUNET_ATS_print_preference_type (enum GNUNET_ATS_PreferenceKind type) | 812 | GNUNET_ATS_print_preference_type(enum GNUNET_ATS_PreferenceKind type) |
819 | { | 813 | { |
820 | const char *prefs[] = GNUNET_ATS_PreferenceTypeString; | 814 | const char *prefs[] = GNUNET_ATS_PreferenceTypeString; |
821 | 815 | ||
@@ -834,9 +828,9 @@ GNUNET_ATS_print_preference_type (enum GNUNET_ATS_PreferenceKind type) | |||
834 | * @param ... #GNUNET_ATS_PREFERENCE_END-terminated specification of the desired changes | 828 | * @param ... #GNUNET_ATS_PREFERENCE_END-terminated specification of the desired changes |
835 | */ | 829 | */ |
836 | void | 830 | void |
837 | GNUNET_ATS_performance_change_preference (struct GNUNET_ATS_PerformanceHandle *ph, | 831 | GNUNET_ATS_performance_change_preference(struct GNUNET_ATS_PerformanceHandle *ph, |
838 | const struct GNUNET_PeerIdentity *peer, | 832 | const struct GNUNET_PeerIdentity *peer, |
839 | ...) | 833 | ...) |
840 | { | 834 | { |
841 | struct GNUNET_MQ_Envelope *env; | 835 | struct GNUNET_MQ_Envelope *env; |
842 | struct ChangePreferenceMessage *m; | 836 | struct ChangePreferenceMessage *m; |
@@ -850,54 +844,58 @@ GNUNET_ATS_performance_change_preference (struct GNUNET_ATS_PerformanceHandle *p | |||
850 | count = 0; | 844 | count = 0; |
851 | va_start(ap, peer); | 845 | va_start(ap, peer); |
852 | while (GNUNET_ATS_PREFERENCE_END != | 846 | while (GNUNET_ATS_PREFERENCE_END != |
853 | (kind = GNUNET_VA_ARG_ENUM (ap, GNUNET_ATS_PreferenceKind) )) | 847 | (kind = GNUNET_VA_ARG_ENUM(ap, GNUNET_ATS_PreferenceKind))) |
854 | { | ||
855 | switch (kind) | ||
856 | { | 848 | { |
857 | case GNUNET_ATS_PREFERENCE_BANDWIDTH: | 849 | switch (kind) |
858 | count++; | 850 | { |
859 | (void) va_arg (ap, double); | 851 | case GNUNET_ATS_PREFERENCE_BANDWIDTH: |
860 | break; | 852 | count++; |
861 | case GNUNET_ATS_PREFERENCE_LATENCY: | 853 | (void)va_arg(ap, double); |
862 | count++; | 854 | break; |
863 | (void) va_arg (ap, double); | 855 | |
864 | break; | 856 | case GNUNET_ATS_PREFERENCE_LATENCY: |
865 | default: | 857 | count++; |
866 | GNUNET_assert(0); | 858 | (void)va_arg(ap, double); |
859 | break; | ||
860 | |||
861 | default: | ||
862 | GNUNET_assert(0); | ||
863 | } | ||
867 | } | 864 | } |
868 | } | ||
869 | va_end(ap); | 865 | va_end(ap); |
870 | env = GNUNET_MQ_msg_extra (m, | 866 | env = GNUNET_MQ_msg_extra(m, |
871 | count * sizeof(struct PreferenceInformation), | 867 | count * sizeof(struct PreferenceInformation), |
872 | GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE); | 868 | GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE); |
873 | m->num_preferences = htonl (count); | 869 | m->num_preferences = htonl(count); |
874 | m->peer = *peer; | 870 | m->peer = *peer; |
875 | pi = (struct PreferenceInformation *) &m[1]; | 871 | pi = (struct PreferenceInformation *)&m[1]; |
876 | count = 0; | 872 | count = 0; |
877 | va_start(ap, peer); | 873 | va_start(ap, peer); |
878 | while (GNUNET_ATS_PREFERENCE_END != (kind = | 874 | while (GNUNET_ATS_PREFERENCE_END != (kind = |
879 | GNUNET_VA_ARG_ENUM (ap, GNUNET_ATS_PreferenceKind) )) | 875 | GNUNET_VA_ARG_ENUM(ap, GNUNET_ATS_PreferenceKind))) |
880 | { | ||
881 | pi[count].preference_kind = htonl (kind); | ||
882 | switch (kind) | ||
883 | { | 876 | { |
884 | case GNUNET_ATS_PREFERENCE_BANDWIDTH: | 877 | pi[count].preference_kind = htonl(kind); |
885 | pi[count].preference_value = (float) va_arg (ap, double); | 878 | switch (kind) |
886 | 879 | { | |
887 | count++; | 880 | case GNUNET_ATS_PREFERENCE_BANDWIDTH: |
888 | break; | 881 | pi[count].preference_value = (float)va_arg(ap, double); |
889 | case GNUNET_ATS_PREFERENCE_LATENCY: | 882 | |
890 | pi[count].preference_value = (float) va_arg (ap, double); | 883 | count++; |
891 | 884 | break; | |
892 | count++; | 885 | |
893 | break; | 886 | case GNUNET_ATS_PREFERENCE_LATENCY: |
894 | default: | 887 | pi[count].preference_value = (float)va_arg(ap, double); |
895 | GNUNET_assert(0); | 888 | |
889 | count++; | ||
890 | break; | ||
891 | |||
892 | default: | ||
893 | GNUNET_assert(0); | ||
894 | } | ||
896 | } | 895 | } |
897 | } | ||
898 | va_end(ap); | 896 | va_end(ap); |
899 | GNUNET_MQ_send (ph->mq, | 897 | GNUNET_MQ_send(ph->mq, |
900 | env); | 898 | env); |
901 | } | 899 | } |
902 | 900 | ||
903 | 901 | ||
@@ -911,10 +909,10 @@ GNUNET_ATS_performance_change_preference (struct GNUNET_ATS_PerformanceHandle *p | |||
911 | * @param ... #GNUNET_ATS_PREFERENCE_END-terminated specification of the desired changes | 909 | * @param ... #GNUNET_ATS_PREFERENCE_END-terminated specification of the desired changes |
912 | */ | 910 | */ |
913 | void | 911 | void |
914 | GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph, | 912 | GNUNET_ATS_performance_give_feedback(struct GNUNET_ATS_PerformanceHandle *ph, |
915 | const struct GNUNET_PeerIdentity *peer, | 913 | const struct GNUNET_PeerIdentity *peer, |
916 | const struct GNUNET_TIME_Relative scope, | 914 | const struct GNUNET_TIME_Relative scope, |
917 | ...) | 915 | ...) |
918 | { | 916 | { |
919 | struct GNUNET_MQ_Envelope *env; | 917 | struct GNUNET_MQ_Envelope *env; |
920 | struct FeedbackPreferenceMessage *m; | 918 | struct FeedbackPreferenceMessage *m; |
@@ -928,55 +926,59 @@ GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph, | |||
928 | count = 0; | 926 | count = 0; |
929 | va_start(ap, scope); | 927 | va_start(ap, scope); |
930 | while (GNUNET_ATS_PREFERENCE_END != | 928 | while (GNUNET_ATS_PREFERENCE_END != |
931 | (kind = GNUNET_VA_ARG_ENUM (ap, GNUNET_ATS_PreferenceKind) )) | 929 | (kind = GNUNET_VA_ARG_ENUM(ap, GNUNET_ATS_PreferenceKind))) |
932 | { | ||
933 | switch (kind) | ||
934 | { | 930 | { |
935 | case GNUNET_ATS_PREFERENCE_BANDWIDTH: | 931 | switch (kind) |
936 | count++; | 932 | { |
937 | (void) va_arg (ap, double); | 933 | case GNUNET_ATS_PREFERENCE_BANDWIDTH: |
938 | break; | 934 | count++; |
939 | case GNUNET_ATS_PREFERENCE_LATENCY: | 935 | (void)va_arg(ap, double); |
940 | count++; | 936 | break; |
941 | (void) va_arg (ap, double); | 937 | |
942 | break; | 938 | case GNUNET_ATS_PREFERENCE_LATENCY: |
943 | default: | 939 | count++; |
944 | GNUNET_assert(0); | 940 | (void)va_arg(ap, double); |
941 | break; | ||
942 | |||
943 | default: | ||
944 | GNUNET_assert(0); | ||
945 | } | ||
945 | } | 946 | } |
946 | } | ||
947 | va_end(ap); | 947 | va_end(ap); |
948 | env = GNUNET_MQ_msg_extra (m, | 948 | env = GNUNET_MQ_msg_extra(m, |
949 | count * sizeof(struct PreferenceInformation), | 949 | count * sizeof(struct PreferenceInformation), |
950 | GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_FEEDBACK); | 950 | GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_FEEDBACK); |
951 | m->scope = GNUNET_TIME_relative_hton (scope); | 951 | m->scope = GNUNET_TIME_relative_hton(scope); |
952 | m->num_feedback = htonl (count); | 952 | m->num_feedback = htonl(count); |
953 | m->peer = *peer; | 953 | m->peer = *peer; |
954 | pi = (struct PreferenceInformation *) &m[1]; | 954 | pi = (struct PreferenceInformation *)&m[1]; |
955 | count = 0; | 955 | count = 0; |
956 | va_start(ap, scope); | 956 | va_start(ap, scope); |
957 | while (GNUNET_ATS_PREFERENCE_END != (kind = | 957 | while (GNUNET_ATS_PREFERENCE_END != (kind = |
958 | GNUNET_VA_ARG_ENUM (ap, GNUNET_ATS_PreferenceKind) )) | 958 | GNUNET_VA_ARG_ENUM(ap, GNUNET_ATS_PreferenceKind))) |
959 | { | ||
960 | pi[count].preference_kind = htonl (kind); | ||
961 | switch (kind) | ||
962 | { | 959 | { |
963 | case GNUNET_ATS_PREFERENCE_BANDWIDTH: | 960 | pi[count].preference_kind = htonl(kind); |
964 | pi[count].preference_value = (float) va_arg (ap, double); | 961 | switch (kind) |
965 | 962 | { | |
966 | count++; | 963 | case GNUNET_ATS_PREFERENCE_BANDWIDTH: |
967 | break; | 964 | pi[count].preference_value = (float)va_arg(ap, double); |
968 | case GNUNET_ATS_PREFERENCE_LATENCY: | 965 | |
969 | pi[count].preference_value = (float) va_arg (ap, double); | 966 | count++; |
970 | 967 | break; | |
971 | count++; | 968 | |
972 | break; | 969 | case GNUNET_ATS_PREFERENCE_LATENCY: |
973 | default: | 970 | pi[count].preference_value = (float)va_arg(ap, double); |
974 | GNUNET_assert(0); | 971 | |
972 | count++; | ||
973 | break; | ||
974 | |||
975 | default: | ||
976 | GNUNET_assert(0); | ||
977 | } | ||
975 | } | 978 | } |
976 | } | ||
977 | va_end(ap); | 979 | va_end(ap); |
978 | GNUNET_MQ_send (ph->mq, | 980 | GNUNET_MQ_send(ph->mq, |
979 | env); | 981 | env); |
980 | } | 982 | } |
981 | 983 | ||
982 | /* end of ats_api_performance.c */ | 984 | /* end of ats_api_performance.c */ |