diff options
author | t3sserakt <t3ss@posteo.de> | 2024-02-08 14:20:34 +0100 |
---|---|---|
committer | t3sserakt <t3ss@posteo.de> | 2024-02-08 14:20:34 +0100 |
commit | aaf07c7eaf41b9e258b6dfcd8a9181e0521fd433 (patch) | |
tree | 63ba18df67b8e7b4377fb2ad4e3f9092a9bab2ee | |
parent | 25ffc8239fb80f2ad2fb50f1a1ab6fcab80153d1 (diff) | |
download | gnunet-aaf07c7eaf41b9e258b6dfcd8a9181e0521fd433.tar.gz gnunet-aaf07c7eaf41b9e258b6dfcd8a9181e0521fd433.zip |
Core: Added logic to decrease restart delay of connection to Transport depending on how long the connection to Transport lasted.
-rw-r--r-- | src/service/transport/transport_api2_core.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/service/transport/transport_api2_core.c b/src/service/transport/transport_api2_core.c index 3eb6c651e..598eef184 100644 --- a/src/service/transport/transport_api2_core.c +++ b/src/service/transport/transport_api2_core.c | |||
@@ -160,6 +160,11 @@ struct GNUNET_TRANSPORT_CoreHandle | |||
160 | struct GNUNET_TIME_Relative reconnect_delay; | 160 | struct GNUNET_TIME_Relative reconnect_delay; |
161 | 161 | ||
162 | /** | 162 | /** |
163 | * Transport connection started at. | ||
164 | */ | ||
165 | struct GNUNET_TIME_Absolute restarted_at; | ||
166 | |||
167 | /** | ||
163 | * Should we check that @e self matches what the service thinks? | 168 | * Should we check that @e self matches what the service thinks? |
164 | * (if #GNUNET_NO, then @e self is all zeros!). | 169 | * (if #GNUNET_NO, then @e self is all zeros!). |
165 | */ | 170 | */ |
@@ -628,6 +633,7 @@ reconnect (void *cls) | |||
628 | GNUNET_assert (NULL == h->mq); | 633 | GNUNET_assert (NULL == h->mq); |
629 | h->mq = | 634 | h->mq = |
630 | GNUNET_CLIENT_connect (h->cfg, "transport", handlers, &mq_error_handler, h); | 635 | GNUNET_CLIENT_connect (h->cfg, "transport", handlers, &mq_error_handler, h); |
636 | h->restarted_at = GNUNET_TIME_absolute_get (); | ||
631 | if (NULL == h->mq) | 637 | if (NULL == h->mq) |
632 | return; | 638 | return; |
633 | env = GNUNET_MQ_msg (s, GNUNET_MESSAGE_TYPE_TRANSPORT_START); | 639 | env = GNUNET_MQ_msg (s, GNUNET_MESSAGE_TYPE_TRANSPORT_START); |
@@ -670,6 +676,20 @@ disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h) | |||
670 | { | 676 | { |
671 | GNUNET_assert (NULL == h->reconnect_task); | 677 | GNUNET_assert (NULL == h->reconnect_task); |
672 | disconnect (h); | 678 | disconnect (h); |
679 | { | ||
680 | /* Reduce delay based on runtime of the connection, | ||
681 | so that there is a cool-down if a connection is up | ||
682 | for a while. */ | ||
683 | struct GNUNET_TIME_Relative runtime; | ||
684 | unsigned int minutes; | ||
685 | |||
686 | runtime = GNUNET_TIME_absolute_get_duration (h->restarted_at); | ||
687 | minutes = runtime.rel_value_us / GNUNET_TIME_UNIT_MINUTES.rel_value_us; | ||
688 | if (minutes > 31) | ||
689 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; | ||
690 | else | ||
691 | h->reconnect_delay.rel_value_us >>= minutes; | ||
692 | } | ||
673 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 693 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
674 | "Scheduling task to reconnect to transport service in %s.\n", | 694 | "Scheduling task to reconnect to transport service in %s.\n", |
675 | GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, GNUNET_YES)); | 695 | GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, GNUNET_YES)); |