diff --git a/llarp/context.cpp b/llarp/context.cpp index 449906676..43891ac25 100644 --- a/llarp/context.cpp +++ b/llarp/context.cpp @@ -348,8 +348,15 @@ __ ___ ____ _ _ ___ _ _ ____ llarp::LogInfo("SIGHUP"); if(router) { + router->hiddenServiceContext().ForEachService( + [](const std::string &name, + const llarp::service::Endpoint_ptr &ep) -> bool { + ep->ResetInternalState(); + llarp::LogInfo("Reset internal state for ", name); + return true; + }); Config newconfig; - if(newconfig.Load(configfile.c_str())) + if(!newconfig.Load(configfile.c_str())) { llarp::LogError("failed to load config file ", configfile); return; diff --git a/llarp/exit/endpoint.cpp b/llarp/exit/endpoint.cpp index 1d493f463..91c836eb1 100644 --- a/llarp/exit/endpoint.cpp +++ b/llarp/exit/endpoint.cpp @@ -141,7 +141,7 @@ namespace llarp uint8_t queue_idx = pktbuf.sz / llarp::routing::ExitPadSize; if(m_DownstreamQueues.find(queue_idx) == m_DownstreamQueues.end()) m_DownstreamQueues.emplace(queue_idx, InboundTrafficQueue_t{}); - auto& queue = m_DownstreamQueues[queue_idx]; + auto& queue = m_DownstreamQueues[queue_idx]; if(queue.size() == 0) { queue.emplace_back(); diff --git a/llarp/exit/session.hpp b/llarp/exit/session.hpp index 076bf7099..fe2e4d3ce 100644 --- a/llarp/exit/session.hpp +++ b/llarp/exit/session.hpp @@ -48,8 +48,7 @@ namespace llarp return m_BundleRC; } - bool - UrgentBuild(llarp_time_t) const override; + bool UrgentBuild(llarp_time_t) const override; void HandlePathDied(llarp::path::Path_ptr p) override; diff --git a/llarp/handlers/exit.cpp b/llarp/handlers/exit.cpp index d45553ae2..f47d1bb8f 100644 --- a/llarp/handlers/exit.cpp +++ b/llarp/handlers/exit.cpp @@ -186,10 +186,11 @@ namespace llarp } bool - ExitEndpoint::VisitEndpointsFor(const PubKey & pk, std::function visit) + ExitEndpoint::VisitEndpointsFor( + const PubKey &pk, std::function< bool(exit::Endpoint *const) > visit) { auto range = m_ActiveExits.equal_range(pk); - auto itr = range.first; + auto itr = range.first; while(itr != range.second) { if(visit(itr->second.get())) @@ -228,18 +229,17 @@ namespace llarp return; } } - if(!VisitEndpointsFor(pk, [&](exit::Endpoint * const ep) -> bool - { - if(!ep->QueueInboundTraffic(ManagedBuffer{pkt.Buffer()})) - { - LogWarn(Name(), " dropped inbound traffic for session ", pk, - " as we are overloaded (probably)"); - // continue iteration - return true; - } - // break iteration - return false; - })) + if(!VisitEndpointsFor(pk, [&](exit::Endpoint *const ep) -> bool { + if(!ep->QueueInboundTraffic(ManagedBuffer{pkt.Buffer()})) + { + LogWarn(Name(), " dropped inbound traffic for session ", pk, + " as we are overloaded (probably)"); + // continue iteration + return true; + } + // break iteration + return false; + })) { // we may have all dead sessions, wtf now? LogWarn(Name(), " dropped inbound traffic for session ", pk, diff --git a/llarp/handlers/exit.hpp b/llarp/handlers/exit.hpp index 0e46db555..f6ccf2d11 100644 --- a/llarp/handlers/exit.hpp +++ b/llarp/handlers/exit.hpp @@ -26,7 +26,8 @@ namespace llarp Name() const; bool - VisitEndpointsFor(const PubKey & pk, std::function visit); + VisitEndpointsFor(const PubKey& pk, + std::function< bool(exit::Endpoint* const) > visit); util::StatusObject ExtractStatus() const; diff --git a/llarp/handlers/tun.cpp b/llarp/handlers/tun.cpp index c19f31b54..8ad4a3cf0 100644 --- a/llarp/handlers/tun.cpp +++ b/llarp/handlers/tun.cpp @@ -433,6 +433,14 @@ namespace llarp return true; } + void + TunEndpoint::ResetInternalState() + { + service::Endpoint::ResetInternalState(); + if(m_Exit) + m_Exit->ResetInternalState(); + } + // FIXME: pass in which question it should be addressing bool TunEndpoint::ShouldHookDNSMessage(const dns::Message &msg) const diff --git a/llarp/handlers/tun.hpp b/llarp/handlers/tun.hpp index 676003081..27981a139 100644 --- a/llarp/handlers/tun.hpp +++ b/llarp/handlers/tun.hpp @@ -153,6 +153,9 @@ namespace llarp void Flush(); + void + ResetInternalState() override; + protected: using PacketQueue_t = llarp::util::CoDelQueue< net::IPv4Packet, net::IPv4Packet::GetTime, net::IPv4Packet::PutTime, diff --git a/llarp/path/pathbuilder.cpp b/llarp/path/pathbuilder.cpp index 58324d1de..2b721c83c 100644 --- a/llarp/path/pathbuilder.cpp +++ b/llarp/path/pathbuilder.cpp @@ -181,6 +181,12 @@ namespace llarp { } + void + Builder::ResetInternalState() + { + buildIntervalLimit = MIN_PATH_BUILD_INTERVAL; + } + void Builder::Tick(llarp_time_t now) { diff --git a/llarp/path/pathbuilder.hpp b/llarp/path/pathbuilder.hpp index a29c69687..4647c9b2f 100644 --- a/llarp/path/pathbuilder.hpp +++ b/llarp/path/pathbuilder.hpp @@ -52,6 +52,9 @@ namespace llarp virtual bool ShouldBundleRC() const = 0; + virtual void + ResetInternalState() override; + /// return true if we hit our soft limit for building paths too fast bool BuildCooldownHit(llarp_time_t now) const; diff --git a/llarp/path/pathset.hpp b/llarp/path/pathset.hpp index fbca87cd1..94702fa5b 100644 --- a/llarp/path/pathset.hpp +++ b/llarp/path/pathset.hpp @@ -216,6 +216,10 @@ namespace llarp return false; } + /// reset all cooldown timers + virtual void + ResetInternalState() = 0; + virtual bool SelectHop(llarp_nodedb* db, const RouterContact& prev, RouterContact& cur, size_t hop, PathRole roles) = 0; diff --git a/llarp/service/endpoint.cpp b/llarp/service/endpoint.cpp index 27aec463d..7928e674d 100644 --- a/llarp/service/endpoint.cpp +++ b/llarp/service/endpoint.cpp @@ -596,6 +596,19 @@ namespace llarp return false; } + void + Endpoint::ResetInternalState() + { + path::Builder::ResetInternalState(); + static auto resetState = [](auto& container) { + std::for_each(container.begin(), container.end(), + [](auto& item) { item.second->ResetInternalState(); }); + }; + + resetState(m_RemoteSessions); + resetState(m_SNodeSessions); + } + bool Endpoint::ShouldPublishDescriptors(llarp_time_t now) const { diff --git a/llarp/service/endpoint.hpp b/llarp/service/endpoint.hpp index 6314e2ba4..a9a3b9beb 100644 --- a/llarp/service/endpoint.hpp +++ b/llarp/service/endpoint.hpp @@ -82,6 +82,9 @@ namespace llarp return huint32_t{0}; } + virtual void + ResetInternalState() override; + /// router's logic /// use when sending any data on a path Logic*