diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-01-26 18:34:29 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-01-26 18:34:29 +0100 |
commit | 6adc64ee122e9be37c6b83e9b745719b4d5940b8 (patch) | |
tree | aecaf99f25c4630c07573b7b34472fcf67c4d636 /src/cadet/gnunet-service-cadet-new_peer.c | |
parent | 356cd09ec4f7d2c02300d5eae8bec8e6b8e49635 (diff) | |
download | gnunet-6adc64ee122e9be37c6b83e9b745719b4d5940b8.tar.gz gnunet-6adc64ee122e9be37c6b83e9b745719b4d5940b8.zip |
implement random packet drop option, fix retransmission logic
Diffstat (limited to 'src/cadet/gnunet-service-cadet-new_peer.c')
-rw-r--r-- | src/cadet/gnunet-service-cadet-new_peer.c | 55 |
1 files changed, 48 insertions, 7 deletions
diff --git a/src/cadet/gnunet-service-cadet-new_peer.c b/src/cadet/gnunet-service-cadet-new_peer.c index fe40d76b6..97bb1378e 100644 --- a/src/cadet/gnunet-service-cadet-new_peer.c +++ b/src/cadet/gnunet-service-cadet-new_peer.c | |||
@@ -503,6 +503,34 @@ GCP_set_mq (struct CadetPeer *cp, | |||
503 | 503 | ||
504 | 504 | ||
505 | /** | 505 | /** |
506 | * Debug function should NEVER return true in production code, useful to | ||
507 | * simulate losses for testcases. | ||
508 | * | ||
509 | * @return #GNUNET_YES or #GNUNET_NO with the decision to drop. | ||
510 | */ | ||
511 | static int | ||
512 | should_I_drop (void) | ||
513 | { | ||
514 | if (0 == drop_percent) | ||
515 | return GNUNET_NO; | ||
516 | if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
517 | 101) < drop_percent) | ||
518 | return GNUNET_YES; | ||
519 | return GNUNET_NO; | ||
520 | } | ||
521 | |||
522 | |||
523 | /** | ||
524 | * Function called when CORE took one of the messages from | ||
525 | * a message queue manager and transmitted it. | ||
526 | * | ||
527 | * @param cls the `struct CadetPeeer` where we made progress | ||
528 | */ | ||
529 | static void | ||
530 | mqm_send_done (void *cls); | ||
531 | |||
532 | |||
533 | /** | ||
506 | * Transmit current envelope from this @a mqm. | 534 | * Transmit current envelope from this @a mqm. |
507 | * | 535 | * |
508 | * @param mqm mqm to transmit message for now | 536 | * @param mqm mqm to transmit message for now |
@@ -512,10 +540,6 @@ mqm_execute (struct GCP_MessageQueueManager *mqm) | |||
512 | { | 540 | { |
513 | struct CadetPeer *cp = mqm->cp; | 541 | struct CadetPeer *cp = mqm->cp; |
514 | 542 | ||
515 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
516 | "Sending to peer %s from MQM %p\n", | ||
517 | GCP_2s (cp), | ||
518 | mqm); | ||
519 | /* Move entry to the end of the DLL, to be fair. */ | 543 | /* Move entry to the end of the DLL, to be fair. */ |
520 | if (mqm != cp->mqm_tail) | 544 | if (mqm != cp->mqm_tail) |
521 | { | 545 | { |
@@ -526,10 +550,27 @@ mqm_execute (struct GCP_MessageQueueManager *mqm) | |||
526 | cp->mqm_tail, | 550 | cp->mqm_tail, |
527 | mqm); | 551 | mqm); |
528 | } | 552 | } |
529 | GNUNET_MQ_send (cp->core_mq, | ||
530 | mqm->env); | ||
531 | mqm->env = NULL; | ||
532 | cp->mqm_ready_counter--; | 553 | cp->mqm_ready_counter--; |
554 | if (GNUNET_YES == should_I_drop ()) | ||
555 | { | ||
556 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
557 | "DROPPING message to peer %s from MQM %p\n", | ||
558 | GCP_2s (cp), | ||
559 | mqm); | ||
560 | GNUNET_MQ_discard (mqm->env); | ||
561 | mqm->env = NULL; | ||
562 | mqm_send_done (cp); | ||
563 | } | ||
564 | else | ||
565 | { | ||
566 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
567 | "Sending to peer %s from MQM %p\n", | ||
568 | GCP_2s (cp), | ||
569 | mqm); | ||
570 | GNUNET_MQ_send (cp->core_mq, | ||
571 | mqm->env); | ||
572 | mqm->env = NULL; | ||
573 | } | ||
533 | mqm->cb (mqm->cb_cls, | 574 | mqm->cb (mqm->cb_cls, |
534 | GNUNET_YES); | 575 | GNUNET_YES); |
535 | } | 576 | } |