diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-02-10 16:45:26 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-02-10 16:45:26 +0000 |
commit | 75264ef067a70a1b0c01dcab46264d4f31217a5f (patch) | |
tree | 690c7ade80810c6cb33bd83e1562d30ca2a0fd06 /src/transport/gnunet-service-transport_manipulation.c | |
parent | 6cf96e80986552390556f36bd6e464d48c1a4b88 (diff) | |
download | gnunet-75264ef067a70a1b0c01dcab46264d4f31217a5f.tar.gz gnunet-75264ef067a70a1b0c01dcab46264d4f31217a5f.zip |
-fixing some memory leaks from #3667, also reindentation and code cleanup
Diffstat (limited to 'src/transport/gnunet-service-transport_manipulation.c')
-rw-r--r-- | src/transport/gnunet-service-transport_manipulation.c | 402 |
1 files changed, 232 insertions, 170 deletions
diff --git a/src/transport/gnunet-service-transport_manipulation.c b/src/transport/gnunet-service-transport_manipulation.c index 31b8a3a29..f52634edc 100644 --- a/src/transport/gnunet-service-transport_manipulation.c +++ b/src/transport/gnunet-service-transport_manipulation.c | |||
@@ -195,6 +195,7 @@ struct DelayQueueEntry *generic_dqe_tail; | |||
195 | */ | 195 | */ |
196 | struct GNUNET_SCHEDULER_Task * generic_send_delay_task; | 196 | struct GNUNET_SCHEDULER_Task * generic_send_delay_task; |
197 | 197 | ||
198 | |||
198 | static void | 199 | static void |
199 | set_metric(struct TM_Peer *dest, int direction, uint32_t type, uint32_t value) | 200 | set_metric(struct TM_Peer *dest, int direction, uint32_t type, uint32_t value) |
200 | { | 201 | { |
@@ -228,9 +229,9 @@ set_metric(struct TM_Peer *dest, int direction, uint32_t type, uint32_t value) | |||
228 | default: | 229 | default: |
229 | break; | 230 | break; |
230 | } | 231 | } |
231 | |||
232 | } | 232 | } |
233 | 233 | ||
234 | |||
234 | static uint32_t | 235 | static uint32_t |
235 | find_metric(struct TM_Peer *dest, uint32_t type, int direction) | 236 | find_metric(struct TM_Peer *dest, uint32_t type, int direction) |
236 | { | 237 | { |
@@ -245,10 +246,10 @@ find_metric(struct TM_Peer *dest, uint32_t type, int direction) | |||
245 | return UINT32_MAX; | 246 | return UINT32_MAX; |
246 | } | 247 | } |
247 | 248 | ||
249 | |||
248 | /** | 250 | /** |
249 | * Clean up metrics for a peer | 251 | * Clean up metrics for a peer |
250 | */ | 252 | */ |
251 | |||
252 | static void | 253 | static void |
253 | free_metric(struct TM_Peer *dest) | 254 | free_metric(struct TM_Peer *dest) |
254 | { | 255 | { |
@@ -263,6 +264,7 @@ free_metric(struct TM_Peer *dest) | |||
263 | } | 264 | } |
264 | } | 265 | } |
265 | 266 | ||
267 | |||
266 | /** | 268 | /** |
267 | * Set traffic metric to manipulate | 269 | * Set traffic metric to manipulate |
268 | * | 270 | * |
@@ -349,6 +351,7 @@ GST_manipulation_set_metric(void *cls, struct GNUNET_SERVER_Client *client, | |||
349 | GNUNET_SERVER_receive_done(client, GNUNET_OK); | 351 | GNUNET_SERVER_receive_done(client, GNUNET_OK); |
350 | } | 352 | } |
351 | 353 | ||
354 | |||
352 | static void | 355 | static void |
353 | send_delayed(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 356 | send_delayed(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
354 | { | 357 | { |
@@ -359,11 +362,18 @@ send_delayed(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
359 | 362 | ||
360 | if (NULL != tmp) | 363 | if (NULL != tmp) |
361 | { | 364 | { |
362 | GNUNET_break(GNUNET_YES == GST_neighbours_test_connected (&dqe->id)); | 365 | GNUNET_break (GNUNET_YES == |
366 | GST_neighbours_test_connected (&dqe->id)); | ||
363 | tmp->send_delay_task = NULL; | 367 | tmp->send_delay_task = NULL; |
364 | GNUNET_CONTAINER_DLL_remove(tmp->send_head, tmp->send_tail, dqe); | 368 | GNUNET_CONTAINER_DLL_remove (tmp->send_head, |
365 | GST_neighbours_send(&dqe->id, dqe->msg, dqe->msg_size, dqe->timeout, | 369 | tmp->send_tail, |
366 | dqe->cont, dqe->cont_cls); | 370 | dqe); |
371 | GST_neighbours_send (&dqe->id, | ||
372 | dqe->msg, | ||
373 | dqe->msg_size, | ||
374 | dqe->timeout, | ||
375 | dqe->cont, | ||
376 | dqe->cont_cls); | ||
367 | 377 | ||
368 | next = tmp->send_head; | 378 | next = tmp->send_head; |
369 | if (NULL != next) | 379 | if (NULL != next) |
@@ -394,90 +404,114 @@ send_delayed(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
394 | GNUNET_free(dqe); | 404 | GNUNET_free(dqe); |
395 | } | 405 | } |
396 | 406 | ||
407 | |||
397 | /** | 408 | /** |
398 | * Adapter function between transport's send function and transport plugins | 409 | * Adapter function between transport's send function and transport plugins. |
410 | * Delays message transmission if an artificial delay is configured. | ||
399 | * | 411 | * |
400 | * @param target the peer the message to send to | 412 | * @param target the peer the message to send to |
401 | * @param msg the message received | 413 | * @param msg the message received |
402 | * @param msg_size message size | 414 | * @param msg_size message size |
403 | * @param timeout timeout | 415 | * @param timeout timeout |
404 | * @param cont the continuation to call after sending | 416 | * @param cont the continuation to call after sending |
405 | * @param cont_cls cls for continuation | 417 | * @param cont_cls cls for @a cont |
406 | */ | 418 | */ |
407 | void | 419 | void |
408 | GST_manipulation_send(const struct GNUNET_PeerIdentity *target, const void *msg, | 420 | GST_manipulation_send (const struct GNUNET_PeerIdentity *target, |
409 | size_t msg_size, struct GNUNET_TIME_Relative timeout, | 421 | const void *msg, |
410 | GST_NeighbourSendContinuation cont, void *cont_cls) | 422 | size_t msg_size, |
423 | struct GNUNET_TIME_Relative timeout, | ||
424 | GST_NeighbourSendContinuation cont, | ||
425 | void *cont_cls) | ||
411 | { | 426 | { |
412 | struct TM_Peer *tmp; | 427 | struct TM_Peer *tmp; |
413 | struct DelayQueueEntry *dqe; | 428 | struct DelayQueueEntry *dqe; |
414 | struct GNUNET_TIME_Relative delay; | 429 | struct GNUNET_TIME_Relative delay; |
430 | int do_delay; | ||
415 | 431 | ||
416 | if (NULL | 432 | do_delay = GNUNET_NO; |
417 | != (tmp = GNUNET_CONTAINER_multipeermap_get(man_handle.peers, target))) | 433 | if (NULL != (tmp = |
418 | { | 434 | GNUNET_CONTAINER_multipeermap_get (man_handle.peers, |
419 | GNUNET_break(GNUNET_YES == GST_neighbours_test_connected(target)); | 435 | target))) |
420 | /* Manipulate here */ | 436 | { |
421 | /* Delay */ | 437 | GNUNET_break (GNUNET_YES == |
422 | if (UINT32_MAX != find_metric(tmp, GNUNET_ATS_QUALITY_NET_DELAY, TM_SEND)) | 438 | GST_neighbours_test_connected(target)); |
423 | { | 439 | /* check for peer-specific delay */ |
424 | /* We have a delay */ | 440 | if (UINT32_MAX != |
425 | delay.rel_value_us = find_metric(tmp, GNUNET_ATS_QUALITY_NET_DELAY, | 441 | find_metric (tmp, |
426 | TM_SEND); | 442 | GNUNET_ATS_QUALITY_NET_DELAY, |
427 | dqe = GNUNET_malloc (sizeof (struct DelayQueueEntry) + msg_size); | 443 | TM_SEND)) |
428 | dqe->id = *target; | ||
429 | dqe->tmp = tmp; | ||
430 | dqe->sent_at = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), | ||
431 | delay); | ||
432 | dqe->cont = cont; | ||
433 | dqe->cont_cls = cont_cls; | ||
434 | dqe->msg = &dqe[1]; | ||
435 | dqe->msg_size = msg_size; | ||
436 | dqe->timeout = timeout; | ||
437 | memcpy(dqe->msg, msg, msg_size); | ||
438 | GNUNET_CONTAINER_DLL_insert_tail(tmp->send_head, tmp->send_tail, dqe); | ||
439 | if (NULL == tmp->send_delay_task) | ||
440 | tmp->send_delay_task = GNUNET_SCHEDULER_add_delayed(delay, | ||
441 | &send_delayed, dqe); | ||
442 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
443 | "Delaying %u byte message to peer `%s' with generic delay for %ms\n", msg_size, GNUNET_i2s (target), GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); | ||
444 | return; | ||
445 | } | ||
446 | } | ||
447 | else if (UINT32_MAX | ||
448 | != find_metric(&man_handle.general, GNUNET_ATS_QUALITY_NET_DELAY, | ||
449 | TM_SEND)) | ||
450 | { | 444 | { |
451 | GNUNET_break(GNUNET_YES == GST_neighbours_test_connected(target)); | ||
452 | /* We have a delay */ | 445 | /* We have a delay */ |
453 | delay.rel_value_us = find_metric(&man_handle.general, | 446 | delay.rel_value_us = find_metric(tmp, GNUNET_ATS_QUALITY_NET_DELAY, |
454 | GNUNET_ATS_QUALITY_NET_DELAY, TM_SEND); | 447 | TM_SEND); |
455 | dqe = GNUNET_malloc (sizeof (struct DelayQueueEntry) + msg_size); | 448 | do_delay = GNUNET_YES; |
456 | dqe->id = *target; | ||
457 | dqe->tmp = NULL; | ||
458 | dqe->sent_at = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), | ||
459 | delay); | ||
460 | dqe->cont = cont; | ||
461 | dqe->cont_cls = cont_cls; | ||
462 | dqe->msg = &dqe[1]; | ||
463 | dqe->msg_size = msg_size; | ||
464 | dqe->timeout = timeout; | ||
465 | memcpy(dqe->msg, msg, msg_size); | ||
466 | GNUNET_CONTAINER_DLL_insert_tail(generic_dqe_head, generic_dqe_tail, dqe); | ||
467 | if (NULL == generic_send_delay_task) | ||
468 | { | ||
469 | generic_send_delay_task = GNUNET_SCHEDULER_add_delayed(delay, | ||
470 | &send_delayed, dqe); | ||
471 | } | ||
472 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
473 | "Delaying %u byte message to peer `%s' with peer specific delay for %s\n", msg_size, GNUNET_i2s (target), GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); | ||
474 | return; | ||
475 | } | 449 | } |
476 | 450 | } | |
477 | /* Normal sending */ | 451 | else if (UINT32_MAX != |
478 | GST_neighbours_send(target, msg, msg_size, timeout, cont, cont_cls); | 452 | find_metric(&man_handle.general, |
453 | GNUNET_ATS_QUALITY_NET_DELAY, | ||
454 | TM_SEND)) | ||
455 | { | ||
456 | GNUNET_break (GNUNET_YES == | ||
457 | GST_neighbours_test_connected (target)); | ||
458 | /* We have a delay */ | ||
459 | delay.rel_value_us = find_metric (&man_handle.general, | ||
460 | GNUNET_ATS_QUALITY_NET_DELAY, | ||
461 | TM_SEND); | ||
462 | do_delay = GNUNET_YES; | ||
463 | } | ||
464 | if (GNUNET_NO == do_delay) | ||
465 | { | ||
466 | /* Normal sending */ | ||
467 | GST_neighbours_send (target, | ||
468 | msg, | ||
469 | msg_size, | ||
470 | timeout, | ||
471 | cont, cont_cls); | ||
472 | return; | ||
473 | } | ||
474 | dqe = GNUNET_malloc (sizeof (struct DelayQueueEntry) + msg_size); | ||
475 | dqe->id = *target; | ||
476 | dqe->tmp = tmp; | ||
477 | dqe->sent_at = GNUNET_TIME_relative_to_absolute (delay); | ||
478 | dqe->cont = cont; | ||
479 | dqe->cont_cls = cont_cls; | ||
480 | dqe->msg = &dqe[1]; | ||
481 | dqe->msg_size = msg_size; | ||
482 | dqe->timeout = timeout; | ||
483 | memcpy (dqe->msg, | ||
484 | msg, | ||
485 | msg_size); | ||
486 | if (NULL == tmp) | ||
487 | { | ||
488 | GNUNET_CONTAINER_DLL_insert_tail (generic_dqe_head, | ||
489 | generic_dqe_tail, | ||
490 | dqe); | ||
491 | if (NULL == generic_send_delay_task) | ||
492 | generic_send_delay_task = GNUNET_SCHEDULER_add_delayed (delay, | ||
493 | &send_delayed, | ||
494 | dqe); | ||
495 | } | ||
496 | else | ||
497 | { | ||
498 | GNUNET_CONTAINER_DLL_insert_tail (tmp->send_head, | ||
499 | tmp->send_tail, | ||
500 | dqe); | ||
501 | if (NULL == tmp->send_delay_task) | ||
502 | tmp->send_delay_task = GNUNET_SCHEDULER_add_delayed (delay, | ||
503 | &send_delayed, | ||
504 | dqe); | ||
505 | } | ||
506 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
507 | "Delaying %u byte message to peer `%s' with peer specific delay for %s\n", | ||
508 | msg_size, | ||
509 | GNUNET_i2s (target), | ||
510 | GNUNET_STRINGS_relative_time_to_string (delay, | ||
511 | GNUNET_YES)); | ||
479 | } | 512 | } |
480 | 513 | ||
514 | |||
481 | /** | 515 | /** |
482 | * Function that will be called to manipulate ATS information according to | 516 | * Function that will be called to manipulate ATS information according to |
483 | * current manipulation settings | 517 | * current manipulation settings |
@@ -489,10 +523,10 @@ GST_manipulation_send(const struct GNUNET_PeerIdentity *target, const void *msg, | |||
489 | * @param ats_count the number of ats information | 523 | * @param ats_count the number of ats information |
490 | */ | 524 | */ |
491 | struct GNUNET_ATS_Information * | 525 | struct GNUNET_ATS_Information * |
492 | GST_manipulation_manipulate_metrics(const struct GNUNET_HELLO_Address *address, | 526 | GST_manipulation_manipulate_metrics (const struct GNUNET_HELLO_Address *address, |
493 | struct Session *session, | 527 | struct Session *session, |
494 | const struct GNUNET_ATS_Information *ats, | 528 | const struct GNUNET_ATS_Information *ats, |
495 | uint32_t ats_count) | 529 | uint32_t ats_count) |
496 | { | 530 | { |
497 | const struct GNUNET_PeerIdentity *peer = &address->peer; | 531 | const struct GNUNET_PeerIdentity *peer = &address->peer; |
498 | struct GNUNET_ATS_Information *ats_new; | 532 | struct GNUNET_ATS_Information *ats_new; |
@@ -510,8 +544,11 @@ GST_manipulation_manipulate_metrics(const struct GNUNET_HELLO_Address *address, | |||
510 | ats_new[d] = ats[d]; | 544 | ats_new[d] = ats[d]; |
511 | m_tmp = UINT32_MAX; | 545 | m_tmp = UINT32_MAX; |
512 | if (NULL != tmp) | 546 | if (NULL != tmp) |
513 | m_tmp = find_metric(tmp, ntohl(ats[d].type), TM_RECEIVE); | 547 | m_tmp = find_metric (tmp, ntohl(ats[d].type), |
514 | g_tmp = find_metric(&man_handle.general, ntohl(ats[d].type), TM_RECEIVE); | 548 | TM_RECEIVE); |
549 | g_tmp = find_metric (&man_handle.general, | ||
550 | ntohl(ats[d].type), | ||
551 | TM_RECEIVE); | ||
515 | 552 | ||
516 | if (UINT32_MAX != g_tmp) | 553 | if (UINT32_MAX != g_tmp) |
517 | ats_new[d].value = htonl(g_tmp); | 554 | ats_new[d].value = htonl(g_tmp); |
@@ -565,14 +602,15 @@ GST_manipulation_recv (void *cls, | |||
565 | if (quota_delay.rel_value_us > m_delay.rel_value_us) | 602 | if (quota_delay.rel_value_us > m_delay.rel_value_us) |
566 | m_delay = quota_delay; | 603 | m_delay = quota_delay; |
567 | 604 | ||
568 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 605 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
569 | "Delaying next receive for peer `%s' for %s\n", | 606 | "Delaying next receive for peer `%s' for %s\n", |
570 | GNUNET_i2s (&address->peer), | 607 | GNUNET_i2s (&address->peer), |
571 | GNUNET_STRINGS_relative_time_to_string (m_delay, GNUNET_YES)); | 608 | GNUNET_STRINGS_relative_time_to_string (m_delay, |
609 | GNUNET_YES)); | ||
572 | return m_delay; | 610 | return m_delay; |
573 | |||
574 | } | 611 | } |
575 | 612 | ||
613 | |||
576 | /** | 614 | /** |
577 | * Initialize traffic manipulation | 615 | * Initialize traffic manipulation |
578 | * | 616 | * |
@@ -584,15 +622,21 @@ GST_manipulation_init(const struct GNUNET_CONFIGURATION_Handle *GST_cfg) | |||
584 | unsigned long long tmp; | 622 | unsigned long long tmp; |
585 | struct GNUNET_TIME_Relative delay; | 623 | struct GNUNET_TIME_Relative delay; |
586 | 624 | ||
587 | if ((GNUNET_OK | 625 | if ( (GNUNET_OK == |
588 | == GNUNET_CONFIGURATION_get_value_number(GST_cfg, "transport", | 626 | GNUNET_CONFIGURATION_get_value_number(GST_cfg, |
589 | "MANIPULATE_DISTANCE_IN", &tmp)) && (tmp > 0)) | 627 | "transport", |
590 | { | 628 | "MANIPULATE_DISTANCE_IN", |
591 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 629 | &tmp)) && |
592 | "Setting inbound distance_in to %llu\n", (unsigned long long) tmp); | 630 | (tmp > 0) ) |
593 | set_metric(&man_handle.general, TM_RECEIVE, | 631 | { |
594 | GNUNET_ATS_QUALITY_NET_DISTANCE, tmp); | 632 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
595 | } | 633 | "Setting inbound distance_in to %llu\n", |
634 | (unsigned long long) tmp); | ||
635 | set_metric (&man_handle.general, | ||
636 | TM_RECEIVE, | ||
637 | GNUNET_ATS_QUALITY_NET_DISTANCE, | ||
638 | tmp); | ||
639 | } | ||
596 | 640 | ||
597 | if ((GNUNET_OK | 641 | if ((GNUNET_OK |
598 | == GNUNET_CONFIGURATION_get_value_number(GST_cfg, "transport", | 642 | == GNUNET_CONFIGURATION_get_value_number(GST_cfg, "transport", |
@@ -625,92 +669,106 @@ GST_manipulation_init(const struct GNUNET_CONFIGURATION_Handle *GST_cfg) | |||
625 | man_handle.peers = GNUNET_CONTAINER_multipeermap_create(10, GNUNET_NO); | 669 | man_handle.peers = GNUNET_CONTAINER_multipeermap_create(10, GNUNET_NO); |
626 | } | 670 | } |
627 | 671 | ||
672 | |||
628 | static int | 673 | static int |
629 | free_tmps(void *cls, const struct GNUNET_PeerIdentity *key, void *value) | 674 | free_tmps (void *cls, |
675 | const struct GNUNET_PeerIdentity *key, | ||
676 | void *value) | ||
630 | { | 677 | { |
678 | struct TM_Peer *tmp = value; | ||
631 | struct DelayQueueEntry *dqe; | 679 | struct DelayQueueEntry *dqe; |
632 | struct DelayQueueEntry *next; | ||
633 | 680 | ||
634 | if (NULL != value) | 681 | if (NULL == tmp) |
635 | { | 682 | return GNUNET_OK; |
636 | struct TM_Peer *tmp = (struct TM_Peer *) value; | 683 | GNUNET_break (GNUNET_YES == |
637 | 684 | GNUNET_CONTAINER_multipeermap_remove (man_handle.peers, | |
638 | if (GNUNET_YES | 685 | key, |
639 | != GNUNET_CONTAINER_multipeermap_remove(man_handle.peers, key, value)) | 686 | value)); |
640 | GNUNET_break(0); | 687 | free_metric (tmp); |
641 | free_metric(tmp); | 688 | while (NULL != (dqe = tmp->send_head)) |
642 | next = tmp->send_head; | 689 | { |
643 | while (NULL != (dqe = next)) | 690 | GNUNET_CONTAINER_DLL_remove (tmp->send_head, |
644 | { | 691 | tmp->send_tail, |
645 | next = dqe->next; | 692 | dqe); |
646 | GNUNET_CONTAINER_DLL_remove(tmp->send_head, tmp->send_tail, dqe); | 693 | if (NULL != dqe->cont) |
647 | if (NULL != dqe->cont) | 694 | dqe->cont (dqe->cont_cls, |
648 | dqe->cont(dqe->cont_cls, GNUNET_SYSERR, dqe->msg_size, 0); | 695 | GNUNET_SYSERR, |
649 | GNUNET_free(dqe); | 696 | dqe->msg_size, |
650 | } | 697 | 0); |
651 | if (NULL != tmp->send_delay_task) | 698 | GNUNET_free (dqe); |
652 | { | 699 | } |
653 | GNUNET_SCHEDULER_cancel(tmp->send_delay_task); | 700 | if (NULL != tmp->send_delay_task) |
654 | tmp->send_delay_task = NULL; | 701 | { |
655 | } | 702 | GNUNET_SCHEDULER_cancel(tmp->send_delay_task); |
656 | GNUNET_free(tmp); | 703 | tmp->send_delay_task = NULL; |
657 | } | 704 | } |
705 | GNUNET_free(tmp); | ||
658 | return GNUNET_OK; | 706 | return GNUNET_OK; |
659 | } | 707 | } |
660 | 708 | ||
709 | |||
661 | /** | 710 | /** |
662 | * Notify manipulation about disconnect so it can discard queued messages | 711 | * Notify manipulation about disconnect so it can discard queued messages |
663 | * | 712 | * |
664 | * @param peer the disconnecting peer | 713 | * @param peer the disconnecting peer |
665 | */ | 714 | */ |
666 | void | 715 | void |
667 | GST_manipulation_peer_disconnect(const struct GNUNET_PeerIdentity *peer) | 716 | GST_manipulation_peer_disconnect (const struct GNUNET_PeerIdentity *peer) |
668 | { | 717 | { |
669 | struct TM_Peer *tmp; | 718 | struct TM_Peer *tmp; |
670 | struct DelayQueueEntry *dqe; | 719 | struct DelayQueueEntry *dqe; |
671 | struct DelayQueueEntry *next; | 720 | struct DelayQueueEntry *next; |
672 | 721 | ||
673 | if (NULL != (tmp = GNUNET_CONTAINER_multipeermap_get(man_handle.peers, peer))) | 722 | if (NULL != (tmp = GNUNET_CONTAINER_multipeermap_get(man_handle.peers, peer))) |
723 | { | ||
724 | while (NULL != (dqe = tmp->send_head)) | ||
674 | { | 725 | { |
675 | next = tmp->send_head; | 726 | GNUNET_CONTAINER_DLL_remove (tmp->send_head, |
676 | while (NULL != (dqe = next)) | 727 | tmp->send_tail, |
677 | { | 728 | dqe); |
678 | next = dqe->next; | 729 | if (NULL != dqe->cont) |
679 | GNUNET_CONTAINER_DLL_remove(tmp->send_head, tmp->send_tail, dqe); | 730 | dqe->cont (dqe->cont_cls, |
680 | if (NULL != dqe->cont) | 731 | GNUNET_SYSERR, |
681 | dqe->cont(dqe->cont_cls, GNUNET_SYSERR, dqe->msg_size, 0); | 732 | dqe->msg_size, |
682 | GNUNET_free(dqe); | 733 | 0); |
683 | } | 734 | GNUNET_free(dqe); |
684 | } | 735 | } |
685 | else if (UINT32_MAX | 736 | } |
686 | != find_metric(&man_handle.general, GNUNET_ATS_QUALITY_NET_DELAY, | 737 | else if (UINT32_MAX != find_metric (&man_handle.general, |
687 | TM_SEND)) | 738 | GNUNET_ATS_QUALITY_NET_DELAY, |
739 | TM_SEND)) | ||
740 | { | ||
741 | next = generic_dqe_head; | ||
742 | while (NULL != (dqe = next)) | ||
688 | { | 743 | { |
689 | next = generic_dqe_head; | 744 | next = dqe->next; |
690 | while (NULL != (dqe = next)) | 745 | if (0 == memcmp(peer, &dqe->id, sizeof(dqe->id))) |
691 | { | 746 | { |
692 | next = dqe->next; | 747 | GNUNET_CONTAINER_DLL_remove (generic_dqe_head, |
693 | if (0 == memcmp(peer, &dqe->id, sizeof(dqe->id))) | 748 | generic_dqe_tail, |
694 | { | 749 | dqe); |
695 | GNUNET_CONTAINER_DLL_remove(generic_dqe_head, generic_dqe_tail, | 750 | if (NULL != dqe->cont) |
696 | dqe); | 751 | dqe->cont (dqe->cont_cls, |
697 | if (NULL != dqe->cont) | 752 | GNUNET_SYSERR, |
698 | dqe->cont(dqe->cont_cls, GNUNET_SYSERR, dqe->msg_size, 0); | 753 | dqe->msg_size, |
699 | GNUNET_free(dqe); | 754 | 0); |
700 | } | 755 | GNUNET_free(dqe); |
701 | } | 756 | } |
702 | if (NULL != generic_send_delay_task) | 757 | } |
703 | { | 758 | if (NULL != generic_send_delay_task) |
704 | GNUNET_SCHEDULER_cancel(generic_send_delay_task); | 759 | { |
705 | generic_send_delay_task = NULL; | 760 | GNUNET_SCHEDULER_cancel (generic_send_delay_task); |
706 | if (NULL != generic_dqe_head) | 761 | generic_send_delay_task = NULL; |
707 | generic_send_delay_task = GNUNET_SCHEDULER_add_delayed( | 762 | if (NULL != generic_dqe_head) |
708 | GNUNET_TIME_absolute_get_remaining(generic_dqe_head->sent_at), | 763 | generic_send_delay_task |
709 | &send_delayed, generic_dqe_head); | 764 | = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining(generic_dqe_head->sent_at), |
710 | } | 765 | &send_delayed, |
766 | generic_dqe_head); | ||
711 | } | 767 | } |
768 | } | ||
712 | } | 769 | } |
713 | 770 | ||
771 | |||
714 | /** | 772 | /** |
715 | * Stop traffic manipulation | 773 | * Stop traffic manipulation |
716 | */ | 774 | */ |
@@ -718,26 +776,30 @@ void | |||
718 | GST_manipulation_stop() | 776 | GST_manipulation_stop() |
719 | { | 777 | { |
720 | struct DelayQueueEntry *cur; | 778 | struct DelayQueueEntry *cur; |
721 | struct DelayQueueEntry *next; | ||
722 | GNUNET_CONTAINER_multipeermap_iterate(man_handle.peers, &free_tmps, NULL); | ||
723 | GNUNET_CONTAINER_multipeermap_destroy(man_handle.peers); | ||
724 | 779 | ||
725 | next = generic_dqe_head; | 780 | GNUNET_CONTAINER_multipeermap_iterate (man_handle.peers, |
726 | while (NULL != (cur = next)) | 781 | &free_tmps, |
727 | { | 782 | NULL); |
728 | next = cur->next; | 783 | GNUNET_CONTAINER_multipeermap_destroy (man_handle.peers); |
729 | GNUNET_CONTAINER_DLL_remove(generic_dqe_head, generic_dqe_tail, cur); | ||
730 | if (NULL != cur->cont) | ||
731 | cur->cont(cur->cont_cls, GNUNET_SYSERR, cur->msg_size, 0); | ||
732 | GNUNET_free(cur); | ||
733 | } | ||
734 | if (NULL != generic_send_delay_task) | ||
735 | { | ||
736 | GNUNET_SCHEDULER_cancel(generic_send_delay_task); | ||
737 | generic_send_delay_task = NULL; | ||
738 | } | ||
739 | 784 | ||
740 | free_metric(&man_handle.general); | 785 | while (NULL != (cur = generic_dqe_head)) |
786 | { | ||
787 | GNUNET_CONTAINER_DLL_remove (generic_dqe_head, | ||
788 | generic_dqe_tail, | ||
789 | cur); | ||
790 | if (NULL != cur->cont) | ||
791 | cur->cont (cur->cont_cls, | ||
792 | GNUNET_SYSERR, | ||
793 | cur->msg_size, | ||
794 | 0); | ||
795 | GNUNET_free (cur); | ||
796 | } | ||
797 | if (NULL != generic_send_delay_task) | ||
798 | { | ||
799 | GNUNET_SCHEDULER_cancel (generic_send_delay_task); | ||
800 | generic_send_delay_task = NULL; | ||
801 | } | ||
802 | free_metric (&man_handle.general); | ||
741 | man_handle.peers = NULL; | 803 | man_handle.peers = NULL; |
742 | } | 804 | } |
743 | 805 | ||