diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-10-08 16:34:07 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-10-08 16:34:07 +0000 |
commit | 8929c943f1f57aaf48a1bc3f6edc9939698e688b (patch) | |
tree | 6c7c3c01b13826a72b7cc9e2d71923304f00f061 /src/ats/ats_api_performance.c | |
parent | e6c06a3f18b4c3a5a3cae2aa572c927d737ce532 (diff) | |
download | gnunet-8929c943f1f57aaf48a1bc3f6edc9939698e688b.tar.gz gnunet-8929c943f1f57aaf48a1bc3f6edc9939698e688b.zip |
ats solver are now implemented as plugins
initial commit: tests pass, no crashes with tests ...
Diffstat (limited to 'src/ats/ats_api_performance.c')
-rw-r--r-- | src/ats/ats_api_performance.c | 390 |
1 files changed, 178 insertions, 212 deletions
diff --git a/src/ats/ats_api_performance.c b/src/ats/ats_api_performance.c index 838acca2f..390531d9f 100644 --- a/src/ats/ats_api_performance.c +++ b/src/ats/ats_api_performance.c | |||
@@ -1,33 +1,32 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2010,2011 Christian Grothoff (and other contributing authors) | 3 | (C) 2010,2011 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation; either version 3, or (at your |
8 | option) any later version. | 8 | 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 | General Public License for more details. | 13 | General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with GNUnet; see the file COPYING. If not, write to the |
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file ats/ats_api_performance.c | 21 | * @file ats/ats_api_performance.c |
22 | * @brief automatic transport selection and outbound bandwidth determination | 22 | * @brief automatic transport selection and outbound bandwidth determination |
23 | * @author Christian Grothoff | 23 | * @author Christian Grothoff |
24 | * @author Matthias Wachs | 24 | * @author Matthias Wachs |
25 | */ | 25 | */ |
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_ats_service.h" | 27 | #include "gnunet_ats_service.h" |
28 | #include "ats.h" | 28 | #include "ats.h" |
29 | 29 | ||
30 | |||
31 | /** | 30 | /** |
32 | * Message in linked list we should send to the ATS service. The | 31 | * Message in linked list we should send to the ATS service. The |
33 | * actual binary message follows this struct. | 32 | * actual binary message follows this struct. |
@@ -56,7 +55,6 @@ struct PendingMessage | |||
56 | int is_init; | 55 | int is_init; |
57 | }; | 56 | }; |
58 | 57 | ||
59 | |||
60 | /** | 58 | /** |
61 | * Linked list of pending reservations. | 59 | * Linked list of pending reservations. |
62 | */ | 60 | */ |
@@ -104,7 +102,6 @@ struct GNUNET_ATS_ReservationContext | |||
104 | int undo; | 102 | int undo; |
105 | }; | 103 | }; |
106 | 104 | ||
107 | |||
108 | /** | 105 | /** |
109 | * Linked list of pending reservations. | 106 | * Linked list of pending reservations. |
110 | */ | 107 | */ |
@@ -157,8 +154,6 @@ struct GNUNET_ATS_AddressListHandle | |||
157 | uint32_t id; | 154 | uint32_t id; |
158 | }; | 155 | }; |
159 | 156 | ||
160 | |||
161 | |||
162 | /** | 157 | /** |
163 | * ATS Handle to obtain and/or modify performance information. | 158 | * ATS Handle to obtain and/or modify performance information. |
164 | */ | 159 | */ |
@@ -215,7 +210,6 @@ struct GNUNET_ATS_PerformanceHandle | |||
215 | */ | 210 | */ |
216 | struct GNUNET_ATS_AddressListHandle *addresslist_tail; | 211 | struct GNUNET_ATS_AddressListHandle *addresslist_tail; |
217 | 212 | ||
218 | |||
219 | /** | 213 | /** |
220 | * Current request for transmission to ATS. | 214 | * Current request for transmission to ATS. |
221 | */ | 215 | */ |
@@ -237,7 +231,6 @@ struct GNUNET_ATS_PerformanceHandle | |||
237 | uint32_t id; | 231 | uint32_t id; |
238 | }; | 232 | }; |
239 | 233 | ||
240 | |||
241 | /** | 234 | /** |
242 | * Re-establish the connection to the ATS service. | 235 | * Re-establish the connection to the ATS service. |
243 | * | 236 | * |
@@ -246,7 +239,6 @@ struct GNUNET_ATS_PerformanceHandle | |||
246 | static void | 239 | static void |
247 | reconnect (struct GNUNET_ATS_PerformanceHandle *ph); | 240 | reconnect (struct GNUNET_ATS_PerformanceHandle *ph); |
248 | 241 | ||
249 | |||
250 | /** | 242 | /** |
251 | * Re-establish the connection to the ATS service. | 243 | * Re-establish the connection to the ATS service. |
252 | * | 244 | * |
@@ -262,7 +254,6 @@ reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
262 | reconnect (ph); | 254 | reconnect (ph); |
263 | } | 255 | } |
264 | 256 | ||
265 | |||
266 | /** | 257 | /** |
267 | * Transmit messages from the message queue to the service | 258 | * Transmit messages from the message queue to the service |
268 | * (if there are any, and if we are not already trying). | 259 | * (if there are any, and if we are not already trying). |
@@ -272,7 +263,6 @@ reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
272 | static void | 263 | static void |
273 | do_transmit (struct GNUNET_ATS_PerformanceHandle *ph); | 264 | do_transmit (struct GNUNET_ATS_PerformanceHandle *ph); |
274 | 265 | ||
275 | |||
276 | /** | 266 | /** |
277 | * Type of a function to call when we receive a message | 267 | * Type of a function to call when we receive a message |
278 | * from the service. | 268 | * from the service. |
@@ -307,14 +297,13 @@ transmit_message_to_ats (void *cls, size_t size, void *buf) | |||
307 | memcpy (&cbuf[ret], &p[1], p->size); | 297 | memcpy (&cbuf[ret], &p[1], p->size); |
308 | ret += p->size; | 298 | ret += p->size; |
309 | size -= p->size; | 299 | size -= p->size; |
310 | GNUNET_CONTAINER_DLL_remove (ph->pending_head, ph->pending_tail, p); | 300 | GNUNET_CONTAINER_DLL_remove(ph->pending_head, ph->pending_tail, p); |
311 | GNUNET_free (p); | 301 | GNUNET_free(p); |
312 | } | 302 | } |
313 | do_transmit (ph); | 303 | do_transmit (ph); |
314 | return ret; | 304 | return ret; |
315 | } | 305 | } |
316 | 306 | ||
317 | |||
318 | /** | 307 | /** |
319 | * Transmit messages from the message queue to the service | 308 | * Transmit messages from the message queue to the service |
320 | * (if there are any, and if we are not already trying). | 309 | * (if there are any, and if we are not already trying). |
@@ -331,15 +320,11 @@ do_transmit (struct GNUNET_ATS_PerformanceHandle *ph) | |||
331 | if (NULL == (p = ph->pending_head)) | 320 | if (NULL == (p = ph->pending_head)) |
332 | return; | 321 | return; |
333 | if (NULL == ph->client) | 322 | if (NULL == ph->client) |
334 | return; /* currently reconnecting */ | 323 | return; /* currently reconnecting */ |
335 | ph->th = | 324 | ph->th = GNUNET_CLIENT_notify_transmit_ready (ph->client, p->size, |
336 | GNUNET_CLIENT_notify_transmit_ready (ph->client, p->size, | 325 | GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, &transmit_message_to_ats, ph); |
337 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
338 | GNUNET_YES, &transmit_message_to_ats, | ||
339 | ph); | ||
340 | } | 326 | } |
341 | 327 | ||
342 | |||
343 | /** | 328 | /** |
344 | * We received a peer information message. Validate and process it. | 329 | * We received a peer information message. Validate and process it. |
345 | * | 330 | * |
@@ -349,7 +334,7 @@ do_transmit (struct GNUNET_ATS_PerformanceHandle *ph) | |||
349 | */ | 334 | */ |
350 | static int | 335 | static int |
351 | process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph, | 336 | process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph, |
352 | const struct GNUNET_MessageHeader *msg) | 337 | const struct GNUNET_MessageHeader *msg) |
353 | { | 338 | { |
354 | const struct PeerInformationMessage *pi; | 339 | const struct PeerInformationMessage *pi; |
355 | const struct GNUNET_ATS_Information *atsi; | 340 | const struct GNUNET_ATS_Information *atsi; |
@@ -361,9 +346,9 @@ process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
361 | uint32_t ats_count; | 346 | uint32_t ats_count; |
362 | int addr_active; | 347 | int addr_active; |
363 | 348 | ||
364 | if (ntohs (msg->size) < sizeof (struct PeerInformationMessage)) | 349 | if (ntohs (msg->size) < sizeof(struct PeerInformationMessage)) |
365 | { | 350 | { |
366 | GNUNET_break (0); | 351 | GNUNET_break(0); |
367 | return GNUNET_SYSERR; | 352 | return GNUNET_SYSERR; |
368 | } | 353 | } |
369 | 354 | ||
@@ -375,31 +360,31 @@ process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
375 | atsi = (const struct GNUNET_ATS_Information *) &pi[1]; | 360 | atsi = (const struct GNUNET_ATS_Information *) &pi[1]; |
376 | plugin_address = (const char *) &atsi[ats_count]; | 361 | plugin_address = (const char *) &atsi[ats_count]; |
377 | plugin_name = &plugin_address[plugin_address_length]; | 362 | plugin_name = &plugin_address[plugin_address_length]; |
378 | if ((plugin_address_length + plugin_name_length + | 363 | if ((plugin_address_length + plugin_name_length |
379 | ats_count * sizeof (struct GNUNET_ATS_Information) + | 364 | + ats_count * sizeof(struct GNUNET_ATS_Information) |
380 | sizeof (struct PeerInformationMessage) != ntohs (msg->size)) || | 365 | + sizeof(struct PeerInformationMessage) != ntohs (msg->size)) |
381 | (ats_count > | 366 | || (ats_count |
382 | GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)) | 367 | > GNUNET_SERVER_MAX_MESSAGE_SIZE |
368 | / sizeof(struct GNUNET_ATS_Information)) | ||
383 | || (plugin_name[plugin_name_length - 1] != '\0')) | 369 | || (plugin_name[plugin_name_length - 1] != '\0')) |
384 | { | 370 | { |
385 | GNUNET_break (0); | 371 | GNUNET_break(0); |
386 | return GNUNET_SYSERR; | 372 | return GNUNET_SYSERR; |
387 | } | 373 | } |
388 | 374 | ||
389 | if (NULL != ph->addr_info_cb) | 375 | if (NULL != ph->addr_info_cb) |
390 | { | 376 | { |
391 | address.peer = pi->peer; | 377 | address.peer = pi->peer; |
392 | address.address = plugin_address; | 378 | address.address = plugin_address; |
393 | address.address_length = plugin_address_length; | 379 | address.address_length = plugin_address_length; |
394 | address.transport_name = plugin_name; | 380 | address.transport_name = plugin_name; |
395 | 381 | ||
396 | ph->addr_info_cb (ph->addr_info_cb_cls, &address, addr_active, pi->bandwidth_out, pi->bandwidth_in, | 382 | ph->addr_info_cb (ph->addr_info_cb_cls, &address, addr_active, |
397 | atsi, ats_count); | 383 | pi->bandwidth_out, pi->bandwidth_in, atsi, ats_count); |
398 | } | 384 | } |
399 | return GNUNET_OK; | 385 | return GNUNET_OK; |
400 | } | 386 | } |
401 | 387 | ||
402 | |||
403 | /** | 388 | /** |
404 | * We received a reservation result message. Validate and process it. | 389 | * We received a reservation result message. Validate and process it. |
405 | * | 390 | * |
@@ -409,47 +394,46 @@ process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
409 | */ | 394 | */ |
410 | static int | 395 | static int |
411 | process_rr_message (struct GNUNET_ATS_PerformanceHandle *ph, | 396 | process_rr_message (struct GNUNET_ATS_PerformanceHandle *ph, |
412 | const struct GNUNET_MessageHeader *msg) | 397 | const struct GNUNET_MessageHeader *msg) |
413 | { | 398 | { |
414 | const struct ReservationResultMessage *rr; | 399 | const struct ReservationResultMessage *rr; |
415 | struct GNUNET_ATS_ReservationContext *rc; | 400 | struct GNUNET_ATS_ReservationContext *rc; |
416 | int32_t amount; | 401 | int32_t amount; |
417 | 402 | ||
418 | if (ntohs (msg->size) < sizeof (struct ReservationResultMessage)) | 403 | if (ntohs (msg->size) < sizeof(struct ReservationResultMessage)) |
419 | { | 404 | { |
420 | GNUNET_break (0); | 405 | GNUNET_break(0); |
421 | return GNUNET_SYSERR; | 406 | return GNUNET_SYSERR; |
422 | } | 407 | } |
423 | rr = (const struct ReservationResultMessage *) msg; | 408 | rr = (const struct ReservationResultMessage *) msg; |
424 | amount = ntohl (rr->amount); | 409 | amount = ntohl (rr->amount); |
425 | rc = ph->reservation_head; | 410 | rc = ph->reservation_head; |
426 | if (0 != memcmp (&rr->peer, &rc->peer, sizeof (struct GNUNET_PeerIdentity))) | 411 | if (0 != memcmp (&rr->peer, &rc->peer, sizeof(struct GNUNET_PeerIdentity))) |
427 | { | 412 | { |
428 | GNUNET_break (0); | 413 | GNUNET_break(0); |
429 | return GNUNET_SYSERR; | 414 | return GNUNET_SYSERR; |
430 | } | 415 | } |
431 | GNUNET_CONTAINER_DLL_remove (ph->reservation_head, ph->reservation_tail, rc); | 416 | GNUNET_CONTAINER_DLL_remove(ph->reservation_head, ph->reservation_tail, rc); |
432 | if ((amount == 0) || (rc->rcb != NULL)) | 417 | if ((amount == 0) || (rc->rcb != NULL )) |
433 | { | 418 | { |
434 | /* tell client if not cancelled */ | 419 | /* tell client if not cancelled */ |
435 | if (rc->rcb != NULL) | 420 | if (rc->rcb != NULL ) |
436 | rc->rcb (rc->rcb_cls, &rr->peer, amount, | 421 | rc->rcb (rc->rcb_cls, &rr->peer, amount, |
437 | GNUNET_TIME_relative_ntoh (rr->res_delay)); | 422 | GNUNET_TIME_relative_ntoh (rr->res_delay)); |
438 | GNUNET_free (rc); | 423 | GNUNET_free(rc); |
439 | return GNUNET_OK; | 424 | return GNUNET_OK; |
440 | } | 425 | } |
441 | /* amount non-zero, but client cancelled, consider undo! */ | 426 | /* amount non-zero, but client cancelled, consider undo! */ |
442 | if (GNUNET_YES != rc->undo) | 427 | if (GNUNET_YES != rc->undo) |
443 | { | 428 | { |
444 | GNUNET_free (rc); | 429 | GNUNET_free(rc); |
445 | return GNUNET_OK; /* do not try to undo failed undos or negative amounts */ | 430 | return GNUNET_OK; /* do not try to undo failed undos or negative amounts */ |
446 | } | 431 | } |
447 | GNUNET_free (rc); | 432 | GNUNET_free(rc); |
448 | (void) GNUNET_ATS_reserve_bandwidth (ph, &rr->peer, -amount, NULL, NULL); | 433 | (void) GNUNET_ATS_reserve_bandwidth (ph, &rr->peer, -amount, NULL, NULL ); |
449 | return GNUNET_OK; | 434 | return GNUNET_OK; |
450 | } | 435 | } |
451 | 436 | ||
452 | |||
453 | /** | 437 | /** |
454 | * We received a reservation result message. Validate and process it. | 438 | * We received a reservation result message. Validate and process it. |
455 | * | 439 | * |
@@ -459,7 +443,7 @@ process_rr_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
459 | */ | 443 | */ |
460 | static int | 444 | static int |
461 | process_ar_message (struct GNUNET_ATS_PerformanceHandle *ph, | 445 | process_ar_message (struct GNUNET_ATS_PerformanceHandle *ph, |
462 | const struct GNUNET_MessageHeader *msg) | 446 | const struct GNUNET_MessageHeader *msg) |
463 | { | 447 | { |
464 | const struct PeerInformationMessage *pi; | 448 | const struct PeerInformationMessage *pi; |
465 | struct GNUNET_ATS_AddressListHandle *alh; | 449 | struct GNUNET_ATS_AddressListHandle *alh; |
@@ -476,13 +460,13 @@ process_ar_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
476 | uint32_t active; | 460 | uint32_t active; |
477 | uint32_t id; | 461 | uint32_t id; |
478 | 462 | ||
479 | if (ntohs (msg->size) < sizeof (struct PeerInformationMessage)) | 463 | if (ntohs (msg->size) < sizeof(struct PeerInformationMessage)) |
480 | { | 464 | { |
481 | GNUNET_break (0); | 465 | GNUNET_break(0); |
482 | return GNUNET_SYSERR; | 466 | return GNUNET_SYSERR; |
483 | } | 467 | } |
484 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 468 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, _("Received %s message\n"), |
485 | _("Received %s message\n"), "ATS_ADDRESSLIST_RESPONSE"); | 469 | "ATS_ADDRESSLIST_RESPONSE"); |
486 | 470 | ||
487 | pi = (const struct PeerInformationMessage *) msg; | 471 | pi = (const struct PeerInformationMessage *) msg; |
488 | id = ntohl (pi->id); | 472 | id = ntohl (pi->id); |
@@ -493,49 +477,47 @@ process_ar_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
493 | atsi = (const struct GNUNET_ATS_Information *) &pi[1]; | 477 | atsi = (const struct GNUNET_ATS_Information *) &pi[1]; |
494 | plugin_address = (const char *) &atsi[ats_count]; | 478 | plugin_address = (const char *) &atsi[ats_count]; |
495 | plugin_name = &plugin_address[plugin_address_length]; | 479 | plugin_name = &plugin_address[plugin_address_length]; |
496 | if ((plugin_address_length + plugin_name_length + | 480 | if ((plugin_address_length + plugin_name_length |
497 | ats_count * sizeof (struct GNUNET_ATS_Information) + | 481 | + ats_count * sizeof(struct GNUNET_ATS_Information) |
498 | sizeof (struct PeerInformationMessage) != ntohs (msg->size)) || | 482 | + sizeof(struct PeerInformationMessage) != ntohs (msg->size)) |
499 | (ats_count > | 483 | || (ats_count |
500 | GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)) | 484 | > GNUNET_SERVER_MAX_MESSAGE_SIZE |
485 | / sizeof(struct GNUNET_ATS_Information)) | ||
501 | || (plugin_name[plugin_name_length - 1] != '\0')) | 486 | || (plugin_name[plugin_name_length - 1] != '\0')) |
502 | { | 487 | { |
503 | GNUNET_break (0); | 488 | GNUNET_break(0); |
504 | return GNUNET_SYSERR; | 489 | return GNUNET_SYSERR; |
505 | } | 490 | } |
506 | 491 | ||
507 | next = ph->addresslist_head; | 492 | next = ph->addresslist_head; |
508 | while (NULL != (alh = next)) | 493 | while (NULL != (alh = next)) |
509 | { | 494 | { |
510 | next = alh->next; | 495 | next = alh->next; |
511 | if (alh->id == id) | 496 | if (alh->id == id) |
512 | break; | 497 | break; |
513 | } | 498 | } |
514 | if (NULL == alh) | 499 | if (NULL == alh) |
515 | { | 500 | { |
516 | /* was canceled */ | 501 | /* was canceled */ |
517 | return GNUNET_SYSERR; | 502 | return GNUNET_SYSERR; |
518 | } | 503 | } |
519 | 504 | ||
520 | memset (&allzeros, '\0', sizeof (allzeros)); | 505 | memset (&allzeros, '\0', sizeof(allzeros)); |
521 | if ((0 == memcmp (&allzeros, &pi->peer, sizeof (allzeros))) && | 506 | if ((0 == memcmp (&allzeros, &pi->peer, sizeof(allzeros))) |
522 | (0 == plugin_name_length) && | 507 | && (0 == plugin_name_length) && (0 == plugin_address_length) |
523 | (0 == plugin_address_length) && | 508 | && (0 == ats_count)) |
524 | (0 == ats_count)) | ||
525 | { | 509 | { |
526 | /* Done */ | 510 | /* Done */ |
527 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 511 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, _("Received last message for %s \n"), |
528 | _("Received last message for %s \n"), "ATS_ADDRESSLIST_RESPONSE"); | 512 | "ATS_ADDRESSLIST_RESPONSE"); |
529 | bandwidth_zero.value__ = htonl (0); | 513 | bandwidth_zero.value__ = htonl (0); |
530 | if (NULL != alh->cb) | 514 | if (NULL != alh->cb) |
531 | alh->cb (ph->addr_info_cb_cls, | 515 | alh->cb (ph->addr_info_cb_cls, NULL, GNUNET_NO, bandwidth_zero, |
532 | NULL, | 516 | bandwidth_zero, NULL, 0); |
533 | GNUNET_NO, | 517 | GNUNET_CONTAINER_DLL_remove(ph->addresslist_head, ph->addresslist_tail, |
534 | bandwidth_zero, bandwidth_zero, | 518 | alh); |
535 | NULL, 0); | 519 | GNUNET_free(alh); |
536 | GNUNET_CONTAINER_DLL_remove (ph->addresslist_head, ph->addresslist_tail, alh); | 520 | return GNUNET_OK; |
537 | GNUNET_free (alh); | ||
538 | return GNUNET_OK; | ||
539 | } | 521 | } |
540 | 522 | ||
541 | address.peer = pi->peer; | 523 | address.peer = pi->peer; |
@@ -546,16 +528,12 @@ process_ar_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
546 | if ((GNUNET_YES == alh->all_addresses) || (GNUNET_YES == active)) | 528 | if ((GNUNET_YES == alh->all_addresses) || (GNUNET_YES == active)) |
547 | { | 529 | { |
548 | if (NULL != alh->cb) | 530 | if (NULL != alh->cb) |
549 | alh->cb (ph->addr_info_cb_cls, | 531 | alh->cb (ph->addr_info_cb_cls, &address, active, pi->bandwidth_out, |
550 | &address, | 532 | pi->bandwidth_in, atsi, ats_count); |
551 | active, | ||
552 | pi->bandwidth_out, pi->bandwidth_in, | ||
553 | atsi, ats_count); | ||
554 | } | 533 | } |
555 | return GNUNET_OK; | 534 | return GNUNET_OK; |
556 | } | 535 | } |
557 | 536 | ||
558 | |||
559 | /** | 537 | /** |
560 | * Type of a function to call when we receive a message | 538 | * Type of a function to call when we receive a message |
561 | * from the service. | 539 | * from the service. |
@@ -585,26 +563,23 @@ process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg) | |||
585 | goto reconnect; | 563 | goto reconnect; |
586 | break; | 564 | break; |
587 | default: | 565 | default: |
588 | GNUNET_break (0); | 566 | GNUNET_break(0); |
589 | goto reconnect; | 567 | goto reconnect; |
590 | } | 568 | } |
591 | GNUNET_CLIENT_receive (ph->client, &process_ats_message, ph, | 569 | GNUNET_CLIENT_receive (ph->client, &process_ats_message, ph, |
592 | GNUNET_TIME_UNIT_FOREVER_REL); | 570 | GNUNET_TIME_UNIT_FOREVER_REL); |
593 | return; | 571 | return; |
594 | reconnect: | 572 | reconnect: if (NULL != ph->th) |
595 | if (NULL != ph->th) | ||
596 | { | 573 | { |
597 | GNUNET_CLIENT_notify_transmit_ready_cancel (ph->th); | 574 | GNUNET_CLIENT_notify_transmit_ready_cancel (ph->th); |
598 | ph->th = NULL; | 575 | ph->th = NULL; |
599 | } | 576 | } |
600 | GNUNET_CLIENT_disconnect (ph->client); | 577 | GNUNET_CLIENT_disconnect (ph->client); |
601 | ph->client = NULL; | 578 | ph->client = NULL; |
602 | ph->task = | 579 | ph->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
603 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &reconnect_task, | 580 | &reconnect_task, ph); |
604 | ph); | ||
605 | } | 581 | } |
606 | 582 | ||
607 | |||
608 | /** | 583 | /** |
609 | * Re-establish the connection to the ATS service. | 584 | * Re-establish the connection to the ATS service. |
610 | * | 585 | * |
@@ -616,30 +591,28 @@ reconnect (struct GNUNET_ATS_PerformanceHandle *ph) | |||
616 | struct PendingMessage *p; | 591 | struct PendingMessage *p; |
617 | struct ClientStartMessage *init; | 592 | struct ClientStartMessage *init; |
618 | 593 | ||
619 | GNUNET_assert (NULL == ph->client); | 594 | GNUNET_assert(NULL == ph->client); |
620 | ph->client = GNUNET_CLIENT_connect ("ats", ph->cfg); | 595 | ph->client = GNUNET_CLIENT_connect ("ats", ph->cfg); |
621 | GNUNET_assert (NULL != ph->client); | 596 | GNUNET_assert(NULL != ph->client); |
622 | GNUNET_CLIENT_receive (ph->client, &process_ats_message, ph, | 597 | GNUNET_CLIENT_receive (ph->client, &process_ats_message, ph, |
623 | GNUNET_TIME_UNIT_FOREVER_REL); | 598 | GNUNET_TIME_UNIT_FOREVER_REL); |
624 | if ((NULL == (p = ph->pending_head)) || (GNUNET_YES != p->is_init)) | 599 | if ((NULL == (p = ph->pending_head)) || (GNUNET_YES != p->is_init)) |
625 | { | 600 | { |
626 | p = GNUNET_malloc (sizeof (struct PendingMessage) + | 601 | p = GNUNET_malloc (sizeof (struct PendingMessage) + |
627 | sizeof (struct ClientStartMessage)); | 602 | sizeof (struct ClientStartMessage)); |
628 | p->size = sizeof (struct ClientStartMessage); | 603 | p->size = sizeof(struct ClientStartMessage); |
629 | p->is_init = GNUNET_YES; | 604 | p->is_init = GNUNET_YES; |
630 | init = (struct ClientStartMessage *) &p[1]; | 605 | init = (struct ClientStartMessage *) &p[1]; |
631 | init->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_START); | 606 | init->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_START); |
632 | init->header.size = htons (sizeof (struct ClientStartMessage)); | 607 | init->header.size = htons (sizeof(struct ClientStartMessage)); |
633 | init->start_flag = | 608 | init->start_flag = htonl ( |
634 | htonl ((NULL ==ph->addr_info_cb) ? | 609 | (NULL == ph->addr_info_cb) ? |
635 | START_FLAG_PERFORMANCE_NO_PIC : START_FLAG_PERFORMANCE_WITH_PIC); | 610 | START_FLAG_PERFORMANCE_NO_PIC : START_FLAG_PERFORMANCE_WITH_PIC); |
636 | GNUNET_CONTAINER_DLL_insert (ph->pending_head, ph->pending_tail, p); | 611 | GNUNET_CONTAINER_DLL_insert(ph->pending_head, ph->pending_tail, p); |
637 | } | 612 | } |
638 | do_transmit (ph); | 613 | do_transmit (ph); |
639 | } | 614 | } |
640 | 615 | ||
641 | |||
642 | |||
643 | /** | 616 | /** |
644 | * Get handle to access performance API of the ATS subsystem. | 617 | * Get handle to access performance API of the ATS subsystem. |
645 | * | 618 | * |
@@ -651,8 +624,7 @@ reconnect (struct GNUNET_ATS_PerformanceHandle *ph) | |||
651 | */ | 624 | */ |
652 | struct GNUNET_ATS_PerformanceHandle * | 625 | struct GNUNET_ATS_PerformanceHandle * |
653 | GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | 626 | GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg, |
654 | GNUNET_ATS_AddressInformationCallback addr_info_cb, | 627 | GNUNET_ATS_AddressInformationCallback addr_info_cb, void *addr_info_cb_cls) |
655 | void *addr_info_cb_cls) | ||
656 | { | 628 | { |
657 | struct GNUNET_ATS_PerformanceHandle *ph; | 629 | struct GNUNET_ATS_PerformanceHandle *ph; |
658 | 630 | ||
@@ -660,7 +632,7 @@ GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
660 | ph->cfg = cfg; | 632 | ph->cfg = cfg; |
661 | ph->addr_info_cb = addr_info_cb; | 633 | ph->addr_info_cb = addr_info_cb; |
662 | ph->addr_info_cb_cls = addr_info_cb_cls; | 634 | ph->addr_info_cb_cls = addr_info_cb_cls; |
663 | ph->id = 0; | 635 | ph->id = 0; |
664 | reconnect (ph); | 636 | reconnect (ph); |
665 | return ph; | 637 | return ph; |
666 | } | 638 | } |
@@ -679,21 +651,20 @@ GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph) | |||
679 | 651 | ||
680 | while (NULL != (p = ph->pending_head)) | 652 | while (NULL != (p = ph->pending_head)) |
681 | { | 653 | { |
682 | GNUNET_CONTAINER_DLL_remove (ph->pending_head, ph->pending_tail, p); | 654 | GNUNET_CONTAINER_DLL_remove(ph->pending_head, ph->pending_tail, p); |
683 | GNUNET_free (p); | 655 | GNUNET_free(p); |
684 | } | 656 | } |
685 | while (NULL != (alh = ph->addresslist_head)) | 657 | while (NULL != (alh = ph->addresslist_head)) |
686 | { | 658 | { |
687 | GNUNET_CONTAINER_DLL_remove (ph->addresslist_head, ph->addresslist_tail, | 659 | GNUNET_CONTAINER_DLL_remove(ph->addresslist_head, ph->addresslist_tail, |
688 | alh); | 660 | alh); |
689 | GNUNET_free (alh); | 661 | GNUNET_free(alh); |
690 | } | 662 | } |
691 | while (NULL != (rc = ph->reservation_head)) | 663 | while (NULL != (rc = ph->reservation_head)) |
692 | { | 664 | { |
693 | GNUNET_CONTAINER_DLL_remove (ph->reservation_head, ph->reservation_tail, | 665 | GNUNET_CONTAINER_DLL_remove(ph->reservation_head, ph->reservation_tail, rc); |
694 | rc); | 666 | GNUNET_break(NULL == rc->rcb); |
695 | GNUNET_break (NULL == rc->rcb); | 667 | GNUNET_free(rc); |
696 | GNUNET_free (rc); | ||
697 | } | 668 | } |
698 | 669 | ||
699 | if (GNUNET_SCHEDULER_NO_TASK != ph->task) | 670 | if (GNUNET_SCHEDULER_NO_TASK != ph->task) |
@@ -706,10 +677,9 @@ GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph) | |||
706 | GNUNET_CLIENT_disconnect (ph->client); | 677 | GNUNET_CLIENT_disconnect (ph->client); |
707 | ph->client = NULL; | 678 | ph->client = NULL; |
708 | } | 679 | } |
709 | GNUNET_free (ph); | 680 | GNUNET_free(ph); |
710 | } | 681 | } |
711 | 682 | ||
712 | |||
713 | /** | 683 | /** |
714 | * Reserve inbound bandwidth from the given peer. ATS will look at | 684 | * Reserve inbound bandwidth from the given peer. ATS will look at |
715 | * the current amount of traffic we receive from the peer and ensure | 685 | * the current amount of traffic we receive from the peer and ensure |
@@ -726,9 +696,8 @@ GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph) | |||
726 | */ | 696 | */ |
727 | struct GNUNET_ATS_ReservationContext * | 697 | struct GNUNET_ATS_ReservationContext * |
728 | GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph, | 698 | GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph, |
729 | const struct GNUNET_PeerIdentity *peer, | 699 | const struct GNUNET_PeerIdentity *peer, int32_t amount, |
730 | int32_t amount, | 700 | GNUNET_ATS_ReservationCallback rcb, void *rcb_cls) |
731 | GNUNET_ATS_ReservationCallback rcb, void *rcb_cls) | ||
732 | { | 701 | { |
733 | struct GNUNET_ATS_ReservationContext *rc; | 702 | struct GNUNET_ATS_ReservationContext *rc; |
734 | struct PendingMessage *p; | 703 | struct PendingMessage *p; |
@@ -739,26 +708,24 @@ GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph, | |||
739 | rc->peer = *peer; | 708 | rc->peer = *peer; |
740 | rc->rcb = rcb; | 709 | rc->rcb = rcb; |
741 | rc->rcb_cls = rcb_cls; | 710 | rc->rcb_cls = rcb_cls; |
742 | if ((rcb != NULL) && (amount > 0)) | 711 | if ((rcb != NULL )&& (amount > 0))rc->undo = GNUNET_YES; |
743 | rc->undo = GNUNET_YES; | 712 | GNUNET_CONTAINER_DLL_insert_tail(ph->reservation_head, ph->reservation_tail, |
744 | GNUNET_CONTAINER_DLL_insert_tail (ph->reservation_head, ph->reservation_tail, | 713 | rc); |
745 | rc); | ||
746 | 714 | ||
747 | p = GNUNET_malloc (sizeof (struct PendingMessage) + | 715 | p = GNUNET_malloc (sizeof (struct PendingMessage) + |
748 | sizeof (struct ReservationRequestMessage)); | 716 | sizeof (struct ReservationRequestMessage)); |
749 | p->size = sizeof (struct ReservationRequestMessage); | 717 | p->size = sizeof(struct ReservationRequestMessage); |
750 | p->is_init = GNUNET_NO; | 718 | p->is_init = GNUNET_NO; |
751 | m = (struct ReservationRequestMessage *) &p[1]; | 719 | m = (struct ReservationRequestMessage *) &p[1]; |
752 | m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST); | 720 | m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST); |
753 | m->header.size = htons (sizeof (struct ReservationRequestMessage)); | 721 | m->header.size = htons (sizeof(struct ReservationRequestMessage)); |
754 | m->amount = htonl (amount); | 722 | m->amount = htonl (amount); |
755 | m->peer = *peer; | 723 | m->peer = *peer; |
756 | GNUNET_CONTAINER_DLL_insert_tail (ph->pending_head, ph->pending_tail, p); | 724 | GNUNET_CONTAINER_DLL_insert_tail(ph->pending_head, ph->pending_tail, p); |
757 | do_transmit (ph); | 725 | do_transmit (ph); |
758 | return rc; | 726 | return rc; |
759 | } | 727 | } |
760 | 728 | ||
761 | |||
762 | /** | 729 | /** |
763 | * Cancel request for reserving bandwidth. | 730 | * Cancel request for reserving bandwidth. |
764 | * | 731 | * |
@@ -783,23 +750,22 @@ GNUNET_ATS_reserve_bandwidth_cancel (struct GNUNET_ATS_ReservationContext *rc) | |||
783 | * @return ats performance context | 750 | * @return ats performance context |
784 | */ | 751 | */ |
785 | struct GNUNET_ATS_AddressListHandle* | 752 | struct GNUNET_ATS_AddressListHandle* |
786 | GNUNET_ATS_performance_list_addresses (struct GNUNET_ATS_PerformanceHandle *handle, | 753 | GNUNET_ATS_performance_list_addresses ( |
787 | const struct GNUNET_PeerIdentity *peer, | 754 | struct GNUNET_ATS_PerformanceHandle *handle, |
788 | int all, | 755 | const struct GNUNET_PeerIdentity *peer, int all, |
789 | GNUNET_ATS_AddressInformationCallback infocb, | 756 | GNUNET_ATS_AddressInformationCallback infocb, void *infocb_cls) |
790 | void *infocb_cls) | ||
791 | { | 757 | { |
792 | struct GNUNET_ATS_AddressListHandle *alh; | 758 | struct GNUNET_ATS_AddressListHandle *alh; |
793 | struct PendingMessage *p; | 759 | struct PendingMessage *p; |
794 | struct AddressListRequestMessage *m; | 760 | struct AddressListRequestMessage *m; |
795 | 761 | ||
796 | GNUNET_assert (NULL != handle); | 762 | GNUNET_assert(NULL != handle); |
797 | if (NULL == infocb) | 763 | if (NULL == infocb) |
798 | return NULL; | 764 | return NULL ; |
799 | 765 | ||
800 | alh = GNUNET_malloc (sizeof (struct GNUNET_ATS_AddressListHandle)); | 766 | alh = GNUNET_malloc (sizeof (struct GNUNET_ATS_AddressListHandle)); |
801 | alh->id = handle->id; | 767 | alh->id = handle->id; |
802 | handle->id ++; | 768 | handle->id++; |
803 | alh->cb = infocb; | 769 | alh->cb = infocb; |
804 | alh->cb_cls = infocb_cls; | 770 | alh->cb_cls = infocb_cls; |
805 | alh->ph = handle; | 771 | alh->ph = handle; |
@@ -808,49 +774,51 @@ GNUNET_ATS_performance_list_addresses (struct GNUNET_ATS_PerformanceHandle *hand | |||
808 | alh->all_peers = GNUNET_YES; | 774 | alh->all_peers = GNUNET_YES; |
809 | else | 775 | else |
810 | { | 776 | { |
811 | alh->all_peers = GNUNET_NO; | 777 | alh->all_peers = GNUNET_NO; |
812 | alh->peer = (*peer); | 778 | alh->peer = (*peer); |
813 | } | 779 | } |
814 | 780 | ||
815 | GNUNET_CONTAINER_DLL_insert (handle->addresslist_head, handle->addresslist_tail, alh); | 781 | GNUNET_CONTAINER_DLL_insert(handle->addresslist_head, |
782 | handle->addresslist_tail, alh); | ||
816 | 783 | ||
817 | p = GNUNET_malloc (sizeof (struct PendingMessage) + | 784 | p = GNUNET_malloc (sizeof (struct PendingMessage) + |
818 | sizeof (struct AddressListRequestMessage)); | 785 | sizeof (struct AddressListRequestMessage)); |
819 | p->size = sizeof (struct AddressListRequestMessage); | 786 | p->size = sizeof(struct AddressListRequestMessage); |
820 | m = (struct AddressListRequestMessage *) &p[1]; | 787 | m = (struct AddressListRequestMessage *) &p[1]; |
821 | m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_REQUEST); | 788 | m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_REQUEST); |
822 | m->header.size = htons (sizeof (struct AddressListRequestMessage)); | 789 | m->header.size = htons (sizeof(struct AddressListRequestMessage)); |
823 | m->all = htonl (all); | 790 | m->all = htonl (all); |
824 | m->id = htonl (alh->id); | 791 | m->id = htonl (alh->id); |
825 | if (NULL != peer) | 792 | if (NULL != peer) |
826 | m->peer = *peer; | 793 | m->peer = *peer; |
827 | else | 794 | else |
828 | { | 795 | { |
829 | memset (&m->peer, '\0', sizeof (struct GNUNET_PeerIdentity)); | 796 | memset (&m->peer, '\0', sizeof(struct GNUNET_PeerIdentity)); |
830 | } | 797 | } |
831 | GNUNET_CONTAINER_DLL_insert_tail (handle->pending_head, handle->pending_tail, p); | 798 | GNUNET_CONTAINER_DLL_insert_tail(handle->pending_head, handle->pending_tail, |
799 | p); | ||
832 | 800 | ||
833 | do_transmit (handle); | 801 | do_transmit (handle); |
834 | 802 | ||
835 | return alh; | 803 | return alh; |
836 | } | 804 | } |
837 | 805 | ||
838 | |||
839 | /** | 806 | /** |
840 | * Cancel a pending address listing operation | 807 | * Cancel a pending address listing operation |
841 | * | 808 | * |
842 | * @param handle the GNUNET_ATS_AddressListHandle handle to cancel | 809 | * @param handle the GNUNET_ATS_AddressListHandle handle to cancel |
843 | */ | 810 | */ |
844 | void | 811 | void |
845 | GNUNET_ATS_performance_list_addresses_cancel (struct GNUNET_ATS_AddressListHandle *handle) | 812 | GNUNET_ATS_performance_list_addresses_cancel ( |
813 | struct GNUNET_ATS_AddressListHandle *handle) | ||
846 | { | 814 | { |
847 | GNUNET_assert (NULL != handle); | 815 | GNUNET_assert(NULL != handle); |
848 | 816 | ||
849 | GNUNET_CONTAINER_DLL_remove (handle->ph->addresslist_head, handle->ph->addresslist_tail, handle); | 817 | GNUNET_CONTAINER_DLL_remove(handle->ph->addresslist_head, |
850 | GNUNET_free (handle); | 818 | handle->ph->addresslist_tail, handle); |
819 | GNUNET_free(handle); | ||
851 | } | 820 | } |
852 | 821 | ||
853 | |||
854 | /** | 822 | /** |
855 | * Convert a GNUNET_ATS_PreferenceType to a string | 823 | * Convert a GNUNET_ATS_PreferenceType to a string |
856 | * | 824 | * |
@@ -863,10 +831,9 @@ GNUNET_ATS_print_preference_type (uint32_t type) | |||
863 | char *prefs[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceTypeString; | 831 | char *prefs[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceTypeString; |
864 | if (type < GNUNET_ATS_PreferenceCount) | 832 | if (type < GNUNET_ATS_PreferenceCount) |
865 | return prefs[type]; | 833 | return prefs[type]; |
866 | return NULL; | 834 | return NULL ; |
867 | } | 835 | } |
868 | 836 | ||
869 | |||
870 | /** | 837 | /** |
871 | * Change preferences for the given peer. Preference changes are forgotten if peers | 838 | * Change preferences for the given peer. Preference changes are forgotten if peers |
872 | * disconnect. | 839 | * disconnect. |
@@ -876,8 +843,9 @@ GNUNET_ATS_print_preference_type (uint32_t type) | |||
876 | * @param ... 0-terminated specification of the desired changes | 843 | * @param ... 0-terminated specification of the desired changes |
877 | */ | 844 | */ |
878 | void | 845 | void |
879 | GNUNET_ATS_performance_change_preference (struct GNUNET_ATS_PerformanceHandle *ph, | 846 | GNUNET_ATS_performance_change_preference ( |
880 | const struct GNUNET_PeerIdentity *peer, ...) | 847 | struct GNUNET_ATS_PerformanceHandle *ph, |
848 | const struct GNUNET_PeerIdentity *peer, ...) | ||
881 | { | 849 | { |
882 | struct PendingMessage *p; | 850 | struct PendingMessage *p; |
883 | struct ChangePreferenceMessage *m; | 851 | struct ChangePreferenceMessage *m; |
@@ -888,9 +856,9 @@ GNUNET_ATS_performance_change_preference (struct GNUNET_ATS_PerformanceHandle *p | |||
888 | enum GNUNET_ATS_PreferenceKind kind; | 856 | enum GNUNET_ATS_PreferenceKind kind; |
889 | 857 | ||
890 | count = 0; | 858 | count = 0; |
891 | va_start (ap, peer); | 859 | va_start(ap, peer); |
892 | while (GNUNET_ATS_PREFERENCE_END != | 860 | while (GNUNET_ATS_PREFERENCE_END != (kind = |
893 | (kind = va_arg (ap, enum GNUNET_ATS_PreferenceKind))) | 861 | va_arg (ap, enum GNUNET_ATS_PreferenceKind) )) |
894 | { | 862 | { |
895 | switch (kind) | 863 | switch (kind) |
896 | { | 864 | { |
@@ -905,13 +873,12 @@ GNUNET_ATS_performance_change_preference (struct GNUNET_ATS_PerformanceHandle *p | |||
905 | 873 | ||
906 | break; | 874 | break; |
907 | default: | 875 | default: |
908 | GNUNET_assert (0); | 876 | GNUNET_assert(0); |
909 | } | 877 | } |
910 | } | 878 | } |
911 | va_end (ap); | 879 | va_end(ap); |
912 | msize = | 880 | msize = count * sizeof(struct PreferenceInformation) |
913 | count * sizeof (struct PreferenceInformation) + | 881 | + sizeof(struct ChangePreferenceMessage); |
914 | sizeof (struct ChangePreferenceMessage); | ||
915 | p = GNUNET_malloc (sizeof (struct PendingMessage) + msize); | 882 | p = GNUNET_malloc (sizeof (struct PendingMessage) + msize); |
916 | p->size = msize; | 883 | p->size = msize; |
917 | p->is_init = GNUNET_NO; | 884 | p->is_init = GNUNET_NO; |
@@ -922,9 +889,9 @@ GNUNET_ATS_performance_change_preference (struct GNUNET_ATS_PerformanceHandle *p | |||
922 | m->peer = *peer; | 889 | m->peer = *peer; |
923 | pi = (struct PreferenceInformation *) &m[1]; | 890 | pi = (struct PreferenceInformation *) &m[1]; |
924 | count = 0; | 891 | count = 0; |
925 | va_start (ap, peer); | 892 | va_start(ap, peer); |
926 | while (GNUNET_ATS_PREFERENCE_END != | 893 | while (GNUNET_ATS_PREFERENCE_END != (kind = |
927 | (kind = va_arg (ap, enum GNUNET_ATS_PreferenceKind))) | 894 | va_arg (ap, enum GNUNET_ATS_PreferenceKind) )) |
928 | { | 895 | { |
929 | pi[count].preference_kind = htonl (kind); | 896 | pi[count].preference_kind = htonl (kind); |
930 | switch (kind) | 897 | switch (kind) |
@@ -940,11 +907,11 @@ GNUNET_ATS_performance_change_preference (struct GNUNET_ATS_PerformanceHandle *p | |||
940 | count++; | 907 | count++; |
941 | break; | 908 | break; |
942 | default: | 909 | default: |
943 | GNUNET_assert (0); | 910 | GNUNET_assert(0); |
944 | } | 911 | } |
945 | } | 912 | } |
946 | va_end (ap); | 913 | va_end(ap); |
947 | GNUNET_CONTAINER_DLL_insert_tail (ph->pending_head, ph->pending_tail, p); | 914 | GNUNET_CONTAINER_DLL_insert_tail(ph->pending_head, ph->pending_tail, p); |
948 | do_transmit (ph); | 915 | do_transmit (ph); |
949 | } | 916 | } |
950 | 917 | ||
@@ -959,8 +926,8 @@ GNUNET_ATS_performance_change_preference (struct GNUNET_ATS_PerformanceHandle *p | |||
959 | */ | 926 | */ |
960 | void | 927 | void |
961 | GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph, | 928 | GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph, |
962 | const struct GNUNET_PeerIdentity *peer, | 929 | const struct GNUNET_PeerIdentity *peer, |
963 | const struct GNUNET_TIME_Relative scope, ...) | 930 | const struct GNUNET_TIME_Relative scope, ...) |
964 | { | 931 | { |
965 | struct PendingMessage *p; | 932 | struct PendingMessage *p; |
966 | struct FeedbackPreferenceMessage *m; | 933 | struct FeedbackPreferenceMessage *m; |
@@ -971,9 +938,9 @@ GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph, | |||
971 | enum GNUNET_ATS_PreferenceKind kind; | 938 | enum GNUNET_ATS_PreferenceKind kind; |
972 | 939 | ||
973 | count = 0; | 940 | count = 0; |
974 | va_start (ap, scope); | 941 | va_start(ap, scope); |
975 | while (GNUNET_ATS_PREFERENCE_END != | 942 | while (GNUNET_ATS_PREFERENCE_END != (kind = |
976 | (kind = va_arg (ap, enum GNUNET_ATS_PreferenceKind))) | 943 | va_arg (ap, enum GNUNET_ATS_PreferenceKind) )) |
977 | { | 944 | { |
978 | switch (kind) | 945 | switch (kind) |
979 | { | 946 | { |
@@ -988,13 +955,12 @@ GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph, | |||
988 | 955 | ||
989 | break; | 956 | break; |
990 | default: | 957 | default: |
991 | GNUNET_assert (0); | 958 | GNUNET_assert(0); |
992 | } | 959 | } |
993 | } | 960 | } |
994 | va_end (ap); | 961 | va_end(ap); |
995 | msize = | 962 | msize = count * sizeof(struct PreferenceInformation) |
996 | count * sizeof (struct PreferenceInformation) + | 963 | + sizeof(struct FeedbackPreferenceMessage); |
997 | sizeof (struct FeedbackPreferenceMessage); | ||
998 | p = GNUNET_malloc (sizeof (struct PendingMessage) + msize); | 964 | p = GNUNET_malloc (sizeof (struct PendingMessage) + msize); |
999 | p->size = msize; | 965 | p->size = msize; |
1000 | p->is_init = GNUNET_NO; | 966 | p->is_init = GNUNET_NO; |
@@ -1006,9 +972,9 @@ GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph, | |||
1006 | m->peer = *peer; | 972 | m->peer = *peer; |
1007 | pi = (struct PreferenceInformation *) &m[1]; | 973 | pi = (struct PreferenceInformation *) &m[1]; |
1008 | count = 0; | 974 | count = 0; |
1009 | va_start (ap, scope); | 975 | va_start(ap, scope); |
1010 | while (GNUNET_ATS_PREFERENCE_END != | 976 | while (GNUNET_ATS_PREFERENCE_END != (kind = |
1011 | (kind = va_arg (ap, enum GNUNET_ATS_PreferenceKind))) | 977 | va_arg (ap, enum GNUNET_ATS_PreferenceKind) )) |
1012 | { | 978 | { |
1013 | pi[count].preference_kind = htonl (kind); | 979 | pi[count].preference_kind = htonl (kind); |
1014 | switch (kind) | 980 | switch (kind) |
@@ -1024,11 +990,11 @@ GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph, | |||
1024 | count++; | 990 | count++; |
1025 | break; | 991 | break; |
1026 | default: | 992 | default: |
1027 | GNUNET_assert (0); | 993 | GNUNET_assert(0); |
1028 | } | 994 | } |
1029 | } | 995 | } |
1030 | va_end (ap); | 996 | va_end(ap); |
1031 | GNUNET_CONTAINER_DLL_insert_tail (ph->pending_head, ph->pending_tail, p); | 997 | GNUNET_CONTAINER_DLL_insert_tail(ph->pending_head, ph->pending_tail, p); |
1032 | do_transmit (ph); | 998 | do_transmit (ph); |
1033 | } | 999 | } |
1034 | 1000 | ||