aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport_validation.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/gnunet-service-transport_validation.c')
-rw-r--r--src/transport/gnunet-service-transport_validation.c58
1 files changed, 28 insertions, 30 deletions
diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c
index 0c70ee9bb..95a7eb04a 100644
--- a/src/transport/gnunet-service-transport_validation.c
+++ b/src/transport/gnunet-service-transport_validation.c
@@ -1,6 +1,6 @@
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-2013 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
@@ -444,7 +444,7 @@ timeout_hello_validation (void *cls,
444 ve->timeout_task = GNUNET_SCHEDULER_NO_TASK; 444 ve->timeout_task = GNUNET_SCHEDULER_NO_TASK;
445 max = GNUNET_TIME_absolute_max (ve->valid_until, ve->revalidation_block); 445 max = GNUNET_TIME_absolute_max (ve->valid_until, ve->revalidation_block);
446 left = GNUNET_TIME_absolute_get_remaining (max); 446 left = GNUNET_TIME_absolute_get_remaining (max);
447 if (left.rel_value > 0) 447 if (left.rel_value_us > 0)
448 { 448 {
449 /* should wait a bit longer */ 449 /* should wait a bit longer */
450 ve->timeout_task = 450 ve->timeout_task =
@@ -494,7 +494,7 @@ transmit_ping_if_allowed (void *cls, const struct GNUNET_PeerIdentity *pid,
494 GNUNET_i2s (pid), GST_plugins_a2s (ve->address), ve->address->transport_name); 494 GNUNET_i2s (pid), GST_plugins_a2s (ve->address), ve->address->transport_name);
495 495
496 next = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get(), validation_delay); 496 next = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get(), validation_delay);
497 if (next.abs_value > validation_next.abs_value) 497 if (next.abs_value_us > validation_next.abs_value_us)
498 validation_next = next; /* We're going to send a PING so delay next validation */ 498 validation_next = next; /* We're going to send a PING so delay next validation */
499 499
500 slen = strlen (ve->address->transport_name) + 1; 500 slen = strlen (ve->address->transport_name) + 1;
@@ -607,15 +607,15 @@ revalidate_address (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
607 canonical_delay = 607 canonical_delay =
608 (ve->in_use == 608 (ve->in_use ==
609 GNUNET_YES) ? CONNECTED_PING_FREQUENCY 609 GNUNET_YES) ? CONNECTED_PING_FREQUENCY
610 : ((GNUNET_TIME_absolute_get_remaining (ve->valid_until).rel_value > 610 : ((GNUNET_TIME_absolute_get_remaining (ve->valid_until).rel_value_us >
611 0) ? VALIDATED_PING_FREQUENCY : UNVALIDATED_PING_KEEPALIVE); 611 0) ? VALIDATED_PING_FREQUENCY : UNVALIDATED_PING_KEEPALIVE);
612 if (delay.rel_value > canonical_delay.rel_value * 2) 612 if (delay.rel_value_us > canonical_delay.rel_value_us * 2)
613 { 613 {
614 /* situation changed, recalculate delay */ 614 /* situation changed, recalculate delay */
615 delay = canonical_delay; 615 delay = canonical_delay;
616 ve->revalidation_block = GNUNET_TIME_relative_to_absolute (delay); 616 ve->revalidation_block = GNUNET_TIME_relative_to_absolute (delay);
617 } 617 }
618 if (delay.rel_value > 0) 618 if (delay.rel_value_us > 0)
619 { 619 {
620 /* should wait a bit longer */ 620 /* should wait a bit longer */
621 ve->revalidation_task = 621 ve->revalidation_task =
@@ -624,7 +624,7 @@ revalidate_address (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
624 } 624 }
625 blocked_for = GNUNET_TIME_absolute_get_remaining(validation_next); 625 blocked_for = GNUNET_TIME_absolute_get_remaining(validation_next);
626 if ((validations_running > validations_fast_start_threshold) && 626 if ((validations_running > validations_fast_start_threshold) &&
627 (blocked_for.rel_value > 0)) 627 (blocked_for.rel_value_us > 0))
628 { 628 {
629 /* Validations are blocked, have to wait for blocked_for time */ 629 /* Validations are blocked, have to wait for blocked_for time */
630 ve->revalidation_task = 630 ve->revalidation_task =
@@ -636,24 +636,20 @@ revalidate_address (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
636 /* schedule next PINGing with some extra random delay to avoid synchronous re-validations */ 636 /* schedule next PINGing with some extra random delay to avoid synchronous re-validations */
637 rdelay = 637 rdelay =
638 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 638 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
639 canonical_delay.rel_value); 639 canonical_delay.rel_value_us);
640 640
641 /* Debug code for mantis 0002726*/ 641 /* Debug code for mantis 0002726 */
642 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value == 642 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us ==
643 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, rdelay).rel_value) 643 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, rdelay).rel_value_us)
644 { 644 {
645 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 645 GNUNET_break (0);
646 "Revalidation interval for peer `%s' for is FOREVER (debug: rdelay: %llu, canonical delay %llu)\n",
647 GNUNET_i2s (&ve->pid),
648 (unsigned long long) delay.rel_value,
649 (unsigned long long) canonical_delay.rel_value);
650 delay = canonical_delay; 646 delay = canonical_delay;
651 } 647 }
652 else 648 else
653 { 649 {
654 delay = GNUNET_TIME_relative_add (canonical_delay, 650 delay = GNUNET_TIME_relative_add (canonical_delay,
655 GNUNET_TIME_relative_multiply 651 GNUNET_TIME_relative_multiply
656 (GNUNET_TIME_UNIT_MILLISECONDS, rdelay)); 652 (GNUNET_TIME_UNIT_MICROSECONDS, rdelay));
657 } 653 }
658 /* End debug code for mantis 0002726*/ 654 /* End debug code for mantis 0002726*/
659 ve->revalidation_task = 655 ve->revalidation_task =
@@ -739,7 +735,7 @@ add_valid_address (void *cls, const struct GNUNET_HELLO_Address *address,
739 struct GNUNET_ATS_Information ats; 735 struct GNUNET_ATS_Information ats;
740 struct GNUNET_CRYPTO_EccPublicKey public_key; 736 struct GNUNET_CRYPTO_EccPublicKey public_key;
741 737
742 if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value == 0) 738 if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us)
743 return GNUNET_OK; /* expired */ 739 return GNUNET_OK; /* expired */
744 if ((GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid)) || 740 if ((GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid)) ||
745 (GNUNET_OK != GNUNET_HELLO_get_key (hello, &public_key))) 741 (GNUNET_OK != GNUNET_HELLO_get_key (hello, &public_key)))
@@ -806,16 +802,18 @@ GST_validation_start (unsigned int max_fds)
806 * when doing to many validations in parallel: 802 * when doing to many validations in parallel:
807 * if (running validations < (max_fds / 2)) 803 * if (running validations < (max_fds / 2))
808 * - "fast start": run validation immediately 804 * - "fast start": run validation immediately
809 * - have delay of (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value) / (max_fds / 2) 805 * - have delay of (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us) / (max_fds / 2)
810 * (300 sec / ~150 == ~2 sec.) between two validations 806 * (300 sec / ~150 == ~2 sec.) between two validations
811 */ 807 */
812 808
813 validation_next = GNUNET_TIME_absolute_get(); 809 validation_next = GNUNET_TIME_absolute_get();
814 validation_delay.rel_value = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value) / (max_fds / 2); 810 validation_delay.rel_value_us = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us) / (max_fds / 2);
815 validations_fast_start_threshold = (max_fds / 2); 811 validations_fast_start_threshold = (max_fds / 2);
816 validations_running = 0; 812 validations_running = 0;
817 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Validation uses a fast start threshold of %u connections and a delay between of %u ms\n ", 813 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Validation uses a fast start threshold of %u connections and a delay between of %s\n ",
818 validations_fast_start_threshold, validation_delay.rel_value); 814 validations_fast_start_threshold,
815 GNUNET_STRINGS_relative_time_to_string (validation_delay,
816 GNUNET_YES));
819 validation_map = GNUNET_CONTAINER_multihashmap_create (VALIDATION_MAP_SIZE, 817 validation_map = GNUNET_CONTAINER_multihashmap_create (VALIDATION_MAP_SIZE,
820 GNUNET_NO); 818 GNUNET_NO);
821 pnc = GNUNET_PEERINFO_notify (GST_cfg, GNUNET_YES, &process_peerinfo_hello, NULL); 819 pnc = GNUNET_PEERINFO_notify (GST_cfg, GNUNET_YES, &process_peerinfo_hello, NULL);
@@ -1056,8 +1054,8 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
1056 GNUNET_assert (NULL != addrend); 1054 GNUNET_assert (NULL != addrend);
1057 memcpy (&((char *) &pong[1])[slen], addrend, alen); 1055 memcpy (&((char *) &pong[1])[slen], addrend, alen);
1058 } 1056 }
1059 if (GNUNET_TIME_absolute_get_remaining (*sig_cache_exp).rel_value < 1057 if (GNUNET_TIME_absolute_get_remaining (*sig_cache_exp).rel_value_us <
1060 PONG_SIGNATURE_LIFETIME.rel_value / 4) 1058 PONG_SIGNATURE_LIFETIME.rel_value_us / 4)
1061 { 1059 {
1062 /* create / update cached sig */ 1060 /* create / update cached sig */
1063 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1061 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1164,7 +1162,7 @@ validate_address_iterator (void *cls,
1164 const struct ValidateAddressContext *vac = cls; 1162 const struct ValidateAddressContext *vac = cls;
1165 struct ValidationEntry *ve; 1163 struct ValidationEntry *ve;
1166 1164
1167 if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value == 0) 1165 if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us)
1168 return GNUNET_OK; /* expired */ 1166 return GNUNET_OK; /* expired */
1169 ve = find_validation_entry (&vac->public_key, address); 1167 ve = find_validation_entry (&vac->public_key, address);
1170 if (GNUNET_SCHEDULER_NO_TASK == ve->revalidation_task) 1168 if (GNUNET_SCHEDULER_NO_TASK == ve->revalidation_task)
@@ -1261,7 +1259,7 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
1261 return; 1259 return;
1262 } 1260 }
1263 if (GNUNET_TIME_absolute_get_remaining 1261 if (GNUNET_TIME_absolute_get_remaining
1264 (GNUNET_TIME_absolute_ntoh (pong->expiration)).rel_value == 0) 1262 (GNUNET_TIME_absolute_ntoh (pong->expiration)).rel_value_us == 0)
1265 { 1263 {
1266 GNUNET_STATISTICS_update (GST_stats, 1264 GNUNET_STATISTICS_update (GST_stats,
1267 gettext_noop 1265 gettext_noop
@@ -1272,7 +1270,7 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
1272 1270
1273 sig_res = GNUNET_SYSERR; 1271 sig_res = GNUNET_SYSERR;
1274 do_verify = GNUNET_YES; 1272 do_verify = GNUNET_YES;
1275 if (0 != GNUNET_TIME_absolute_get_remaining(ve->pong_sig_valid_until).rel_value) 1273 if (0 != GNUNET_TIME_absolute_get_remaining(ve->pong_sig_valid_until).rel_value_us)
1276 { 1274 {
1277 /* We have a cached and valid signature for this peer, 1275 /* We have a cached and valid signature for this peer,
1278 * try to compare instead of verify */ 1276 * try to compare instead of verify */
@@ -1316,7 +1314,7 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
1316 { 1314 {
1317 struct GNUNET_ATS_Information ats[2]; 1315 struct GNUNET_ATS_Information ats[2];
1318 ats[0].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY); 1316 ats[0].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
1319 ats[0].value = htonl ((uint32_t) ve->latency.rel_value); 1317 ats[0].value = htonl ((uint32_t) ve->latency.rel_value_us);
1320 ats[1].type = htonl (GNUNET_ATS_NETWORK_TYPE); 1318 ats[1].type = htonl (GNUNET_ATS_NETWORK_TYPE);
1321 ats[1].value = htonl ((uint32_t) ve->network); 1319 ats[1].value = htonl ((uint32_t) ve->network);
1322 GNUNET_ATS_address_add (GST_ats, ve->address, NULL, ats, 2); 1320 GNUNET_ATS_address_add (GST_ats, ve->address, NULL, ats, 2);