diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-01-05 14:57:33 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-01-05 14:57:33 +0000 |
commit | 56342b51c42bba7f627de23cde834994171fb267 (patch) | |
tree | 0064b754293c093cf77b069edee4a376664ebe88 /src/transport/gnunet-service-transport_validation.c | |
parent | 1859c7baeba4dc594a79da78a40f93f5aff4a236 (diff) | |
download | gnunet-56342b51c42bba7f627de23cde834994171fb267.tar.gz gnunet-56342b51c42bba7f627de23cde834994171fb267.zip |
-docu, style fixes
Diffstat (limited to 'src/transport/gnunet-service-transport_validation.c')
-rw-r--r-- | src/transport/gnunet-service-transport_validation.c | 67 |
1 files changed, 39 insertions, 28 deletions
diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c index a15d7a094..e7ede0b07 100644 --- a/src/transport/gnunet-service-transport_validation.c +++ b/src/transport/gnunet-service-transport_validation.c | |||
@@ -274,6 +274,9 @@ struct ValidationEntry | |||
274 | */ | 274 | */ |
275 | int expecting_pong; | 275 | int expecting_pong; |
276 | 276 | ||
277 | /** | ||
278 | * Which network type does our address belong to? | ||
279 | */ | ||
277 | enum GNUNET_ATS_Network_Type network; | 280 | enum GNUNET_ATS_Network_Type network; |
278 | }; | 281 | }; |
279 | 282 | ||
@@ -331,7 +334,9 @@ static struct GNUNET_PEERINFO_NotifyContext *pnc; | |||
331 | static struct GNUNET_TIME_Relative validation_delay; | 334 | static struct GNUNET_TIME_Relative validation_delay; |
332 | 335 | ||
333 | /** | 336 | /** |
334 | * Number of validations running | 337 | * Number of validations running; any PING that was not yet |
338 | * matched by a PONG and for which we have not yet hit the | ||
339 | * timeout is considered a running 'validation'. | ||
335 | */ | 340 | */ |
336 | static unsigned int validations_running; | 341 | static unsigned int validations_running; |
337 | 342 | ||
@@ -472,7 +477,7 @@ cleanup_validation_entry (void *cls, | |||
472 | * Address validation cleanup task. Assesses if the record is no | 477 | * Address validation cleanup task. Assesses if the record is no |
473 | * longer valid and then possibly triggers its removal. | 478 | * longer valid and then possibly triggers its removal. |
474 | * | 479 | * |
475 | * @param cls the 'struct ValidationEntry' | 480 | * @param cls the `struct ValidationEntry` |
476 | * @param tc scheduler context (unused) | 481 | * @param tc scheduler context (unused) |
477 | */ | 482 | */ |
478 | static void | 483 | static void |
@@ -484,7 +489,8 @@ timeout_hello_validation (void *cls, | |||
484 | struct GNUNET_TIME_Relative left; | 489 | struct GNUNET_TIME_Relative left; |
485 | 490 | ||
486 | ve->timeout_task = NULL; | 491 | ve->timeout_task = NULL; |
487 | max = GNUNET_TIME_absolute_max (ve->valid_until, ve->revalidation_block); | 492 | max = GNUNET_TIME_absolute_max (ve->valid_until, |
493 | ve->revalidation_block); | ||
488 | left = GNUNET_TIME_absolute_get_remaining (max); | 494 | left = GNUNET_TIME_absolute_get_remaining (max); |
489 | if (left.rel_value_us > 0) | 495 | if (left.rel_value_us > 0) |
490 | { | 496 | { |
@@ -504,7 +510,7 @@ timeout_hello_validation (void *cls, | |||
504 | * Function called with the result from blacklisting. | 510 | * Function called with the result from blacklisting. |
505 | * Send a PING to the other peer if a communication is allowed. | 511 | * Send a PING to the other peer if a communication is allowed. |
506 | * | 512 | * |
507 | * @param cls our 'struct ValidationEntry' | 513 | * @param cls our `struct ValidationEntry` |
508 | * @param pid identity of the other peer | 514 | * @param pid identity of the other peer |
509 | * @param result #GNUNET_OK if the connection is allowed, #GNUNET_NO if not | 515 | * @param result #GNUNET_OK if the connection is allowed, #GNUNET_NO if not |
510 | */ | 516 | */ |
@@ -557,10 +563,7 @@ transmit_ping_if_allowed (void *cls, | |||
557 | 563 | ||
558 | if (tsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 564 | if (tsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
559 | { | 565 | { |
560 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 566 | GNUNET_break (0); |
561 | _("Not transmitting `%s' with `%s', message too big (%u bytes!). This should not happen.\n"), | ||
562 | "HELLO", "PING", (unsigned int) tsize); | ||
563 | /* message too big (!?), get rid of HELLO */ | ||
564 | hsize = 0; | 567 | hsize = 0; |
565 | tsize = | 568 | tsize = |
566 | sizeof (struct TransportPingMessage) + ve->address->address_length + | 569 | sizeof (struct TransportPingMessage) + ve->address->address_length + |
@@ -623,11 +626,11 @@ transmit_ping_if_allowed (void *cls, | |||
623 | if (-1 != ret) | 626 | if (-1 != ret) |
624 | { | 627 | { |
625 | next = GNUNET_TIME_relative_to_absolute (validation_delay); | 628 | next = GNUNET_TIME_relative_to_absolute (validation_delay); |
626 | validation_next = GNUNET_MAX (next, | 629 | validation_next = GNUNET_TIME_absolute_max (next, |
627 | validation_next); | 630 | validation_next); |
628 | ve->send_time = GNUNET_TIME_absolute_get (); | 631 | ve->send_time = GNUNET_TIME_absolute_get (); |
629 | GNUNET_STATISTICS_update (GST_stats, | 632 | GNUNET_STATISTICS_update (GST_stats, |
630 | gettext_noop ("# PING for validation (without HELLO) sent"), | 633 | gettext_noop ("# PINGs for address validation sent"), |
631 | 1, | 634 | 1, |
632 | GNUNET_NO); | 635 | GNUNET_NO); |
633 | ve->network = network; | 636 | ve->network = network; |
@@ -649,7 +652,7 @@ transmit_ping_if_allowed (void *cls, | |||
649 | /** | 652 | /** |
650 | * Do address validation again to keep address valid. | 653 | * Do address validation again to keep address valid. |
651 | * | 654 | * |
652 | * @param cls the 'struct ValidationEntry' | 655 | * @param cls the `struct ValidationEntry` |
653 | * @param tc scheduler context (unused) | 656 | * @param tc scheduler context (unused) |
654 | */ | 657 | */ |
655 | static void | 658 | static void |
@@ -665,20 +668,22 @@ revalidate_address (void *cls, | |||
665 | 668 | ||
666 | ve->revalidation_task = NULL; | 669 | ve->revalidation_task = NULL; |
667 | delay = GNUNET_TIME_absolute_get_remaining (ve->revalidation_block); | 670 | delay = GNUNET_TIME_absolute_get_remaining (ve->revalidation_block); |
668 | /* How long until we can possibly permit the next PING? */ | 671 | /* Considering current connectivity situation, what is the maximum |
672 | block period permitted? */ | ||
669 | if (GNUNET_YES == ve->in_use) | 673 | if (GNUNET_YES == ve->in_use) |
670 | canonical_delay = CONNECTED_PING_FREQUENCY; | 674 | canonical_delay = CONNECTED_PING_FREQUENCY; |
671 | else if (GNUNET_TIME_absolute_get_remaining (ve->valid_until).rel_value_us > 0) | 675 | else if (GNUNET_TIME_absolute_get_remaining (ve->valid_until).rel_value_us > 0) |
672 | canonical_delay = VALIDATED_PING_FREQUENCY; | 676 | canonical_delay = VALIDATED_PING_FREQUENCY; |
673 | else | 677 | else |
674 | canonical_delay = UNVALIDATED_PING_KEEPALIVE; | 678 | canonical_delay = UNVALIDATED_PING_KEEPALIVE; |
675 | 679 | /* Use delay that is MIN of original delay and possibly adjusted | |
676 | if (delay.rel_value_us > canonical_delay.rel_value_us * 2) | 680 | new maximum delay (which may be lower); the real delay |
677 | { | 681 | is originally randomized between "canonical_delay" and "2 * canonical_delay", |
678 | /* situation changed, recalculate delay */ | 682 | so continue to permit that window for the operation. */ |
679 | delay = canonical_delay; | 683 | delay = GNUNET_TIME_relative_min (delay, |
680 | ve->revalidation_block = GNUNET_TIME_relative_to_absolute (delay); | 684 | GNUNET_TIME_relative_multiply (canonical_delay, |
681 | } | 685 | 2)); |
686 | ve->revalidation_block = GNUNET_TIME_relative_to_absolute (delay); | ||
682 | if (delay.rel_value_us > 0) | 687 | if (delay.rel_value_us > 0) |
683 | { | 688 | { |
684 | /* should wait a bit longer */ | 689 | /* should wait a bit longer */ |
@@ -693,9 +698,11 @@ revalidate_address (void *cls, | |||
693 | ve->next_validation = GNUNET_TIME_relative_to_absolute (delay); | 698 | ve->next_validation = GNUNET_TIME_relative_to_absolute (delay); |
694 | return; | 699 | return; |
695 | } | 700 | } |
696 | blocked_for = GNUNET_TIME_absolute_get_remaining(validation_next); | 701 | /* check if globally we have too many active validations at a |
697 | if ((validations_running > validations_fast_start_threshold) && | 702 | too high rate, if so, delay ours */ |
698 | (blocked_for.rel_value_us > 0)) | 703 | blocked_for = GNUNET_TIME_absolute_get_remaining (validation_next); |
704 | if ( (validations_running > validations_fast_start_threshold) && | ||
705 | (blocked_for.rel_value_us > 0) ) | ||
699 | { | 706 | { |
700 | /* Validations are blocked, have to wait for blocked_for time */ | 707 | /* Validations are blocked, have to wait for blocked_for time */ |
701 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 708 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -708,8 +715,10 @@ revalidate_address (void *cls, | |||
708 | ve->next_validation = GNUNET_TIME_relative_to_absolute (blocked_for); | 715 | ve->next_validation = GNUNET_TIME_relative_to_absolute (blocked_for); |
709 | return; | 716 | return; |
710 | } | 717 | } |
711 | ve->revalidation_block = GNUNET_TIME_relative_to_absolute (canonical_delay); | ||
712 | 718 | ||
719 | /* We are good to go; remember to not go again for `canonical_delay` time; | ||
720 | add up to `canonical_delay` to randomize start time */ | ||
721 | ve->revalidation_block = GNUNET_TIME_relative_to_absolute (canonical_delay); | ||
713 | /* schedule next PINGing with some extra random delay to avoid synchronous re-validations */ | 722 | /* schedule next PINGing with some extra random delay to avoid synchronous re-validations */ |
714 | rdelay = | 723 | rdelay = |
715 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 724 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
@@ -726,7 +735,7 @@ revalidate_address (void *cls, | |||
726 | GST_plugins_a2s (ve->address)); | 735 | GST_plugins_a2s (ve->address)); |
727 | ve->revalidation_task = | 736 | ve->revalidation_task = |
728 | GNUNET_SCHEDULER_add_delayed (delay, &revalidate_address, ve); | 737 | GNUNET_SCHEDULER_add_delayed (delay, &revalidate_address, ve); |
729 | ve->next_validation = GNUNET_TIME_relative_to_absolute (delay); | 738 | ve->next_validation = GNUNET_TIME_relative_to_absolute (delay); |
730 | 739 | ||
731 | /* start PINGing by checking blacklist */ | 740 | /* start PINGing by checking blacklist */ |
732 | GNUNET_STATISTICS_update (GST_stats, | 741 | GNUNET_STATISTICS_update (GST_stats, |
@@ -764,7 +773,7 @@ find_validation_entry (const struct GNUNET_CRYPTO_EddsaPublicKey *public_key, | |||
764 | &validation_entry_match, &vemc); | 773 | &validation_entry_match, &vemc); |
765 | if (NULL != (ve = vemc.ve)) | 774 | if (NULL != (ve = vemc.ve)) |
766 | return ve; | 775 | return ve; |
767 | if (public_key == NULL) | 776 | if (NULL == public_key) |
768 | return NULL; | 777 | return NULL; |
769 | ve = GNUNET_new (struct ValidationEntry); | 778 | ve = GNUNET_new (struct ValidationEntry); |
770 | ve->in_use = GNUNET_SYSERR; /* not defined */ | 779 | ve->in_use = GNUNET_SYSERR; /* not defined */ |
@@ -783,7 +792,6 @@ find_validation_entry (const struct GNUNET_CRYPTO_EddsaPublicKey *public_key, | |||
783 | ve, | 792 | ve, |
784 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 793 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
785 | validation_entry_changed (ve, GNUNET_TRANSPORT_VS_NEW); | 794 | validation_entry_changed (ve, GNUNET_TRANSPORT_VS_NEW); |
786 | ve->expecting_pong = GNUNET_NO; | ||
787 | return ve; | 795 | return ve; |
788 | } | 796 | } |
789 | 797 | ||
@@ -1599,7 +1607,10 @@ iterate_addresses (void *cls, | |||
1599 | struct IteratorContext *ic = cls; | 1607 | struct IteratorContext *ic = cls; |
1600 | struct ValidationEntry *ve = value; | 1608 | struct ValidationEntry *ve = value; |
1601 | 1609 | ||
1602 | ic->cb (ic->cb_cls, &ve->public_key, ve->valid_until, ve->revalidation_block, | 1610 | ic->cb (ic->cb_cls, |
1611 | &ve->public_key, | ||
1612 | ve->valid_until, | ||
1613 | ve->revalidation_block, | ||
1603 | ve->address); | 1614 | ve->address); |
1604 | return GNUNET_OK; | 1615 | return GNUNET_OK; |
1605 | } | 1616 | } |