Merge pull request #1844 from majestrate/sigusr1-wire-up-thaw-2022-01-27

wire up sigusr1 to trigger a network thaw on non win32 platforms
This commit is contained in:
majestrate 2022-01-27 11:22:09 -05:00 committed by GitHub
commit 36925d0576
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 0 deletions

10
llarp/constants/time.hpp Normal file
View File

@ -0,0 +1,10 @@
#pragma once
#include <chrono>
namespace llarp
{
using namespace std::literals;
/// how big of a time skip before we reset network state
constexpr auto TimeskipDetectedDuration = 1min;
} // namespace llarp

View File

@ -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();

View File

@ -4,6 +4,7 @@
#include <llarp/config/config.hpp>
#include <llarp/constants/proto.hpp>
#include <llarp/constants/files.hpp>
#include <llarp/constants/time.hpp>
#include <llarp/crypto/crypto_libsodium.hpp>
#include <llarp/crypto/crypto.hpp>
#include <llarp/dht/context.hpp>
@ -807,6 +808,12 @@ namespace llarp
return;
// LogDebug("tick router");
const auto now = Now();
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)
{