From 38c6d99375f925dea025378365f95129900710d5 Mon Sep 17 00:00:00 2001 From: Jeff Date: Thu, 27 Jan 2022 09:57:43 -0500 Subject: [PATCH 1/3] wire up sigusr1 to trigger a network thaw on non win32 platforms --- llarp/context.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/llarp/context.cpp b/llarp/context.cpp index 59a54dc28..ecba8ee09 100644 --- a/llarp/context.cpp +++ b/llarp/context.cpp @@ -166,6 +166,14 @@ namespace llarp SigINT(); } #ifndef _WIN32 + if (sig == SIGUSR1) + { + if (router and not router->IsServiceNode()) + { + LogInfo("SIGUSR1: resetting network state"); + router->Thaw(); + } + } if (sig == SIGHUP) { Reload(); From 5fac6c84d857a19f8076957611229475b6ba7e4b Mon Sep 17 00:00:00 2001 From: Jeff Date: Thu, 27 Jan 2022 10:59:04 -0500 Subject: [PATCH 2/3] detect timeskip and thaw network when we think it happened. --- llarp/router/router.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index 2204e4766..94110689b 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -807,6 +807,13 @@ namespace llarp return; // LogDebug("tick router"); const auto now = Now(); + constexpr auto TimeskipDetectedDuration = 1min; + if (const auto delta = now - _lastTick; _lastTick != 0s and delta > TimeskipDetectedDuration) + { + // we detected a time skip into the futre, thaw the network + LogWarn("Timeskip of ", delta, " detected. Resetting network state"); + Thaw(); + } #if defined(WITH_SYSTEMD) { From fc444741f1c179a12e1a380005c15253877d13b4 Mon Sep 17 00:00:00 2001 From: Jeff Date: Thu, 27 Jan 2022 11:11:57 -0500 Subject: [PATCH 3/3] move constant to new header create llarp/constants/time.hpp for time/duration constants --- llarp/constants/time.hpp | 10 ++++++++++ llarp/router/router.cpp | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 llarp/constants/time.hpp diff --git a/llarp/constants/time.hpp b/llarp/constants/time.hpp new file mode 100644 index 000000000..69866e2c8 --- /dev/null +++ b/llarp/constants/time.hpp @@ -0,0 +1,10 @@ +#pragma once + +#include + +namespace llarp +{ + using namespace std::literals; + /// how big of a time skip before we reset network state + constexpr auto TimeskipDetectedDuration = 1min; +} // namespace llarp diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index 94110689b..835850e75 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -807,7 +808,6 @@ namespace llarp return; // LogDebug("tick router"); const auto now = Now(); - constexpr auto TimeskipDetectedDuration = 1min; if (const auto delta = now - _lastTick; _lastTick != 0s and delta > TimeskipDetectedDuration) { // we detected a time skip into the futre, thaw the network