diff --git a/llarp/handlers/exit.cpp b/llarp/handlers/exit.cpp index d9822ac4e..d45553ae2 100644 --- a/llarp/handlers/exit.cpp +++ b/llarp/handlers/exit.cpp @@ -185,6 +185,21 @@ namespace llarp return m_Router->Now(); } + bool + ExitEndpoint::VisitEndpointsFor(const PubKey & pk, std::function visit) + { + auto range = m_ActiveExits.equal_range(pk); + auto itr = range.first; + while(itr != range.second) + { + if(visit(itr->second.get())) + ++itr; + else + return true; + } + return false; + } + void ExitEndpoint::Flush() { @@ -213,21 +228,22 @@ namespace llarp return; } } - exit::Endpoint *ep = m_ChosenExits[pk]; - - if(ep == nullptr) - { - // we may have all dead sessions, wtf now? - LogWarn(Name(), " dropped inbound traffic for session ", pk, - " as we have no working endpoints"); - } - else + 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, + " as we have no working endpoints"); } }); { diff --git a/llarp/handlers/exit.hpp b/llarp/handlers/exit.hpp index 18dc28f42..0e46db555 100644 --- a/llarp/handlers/exit.hpp +++ b/llarp/handlers/exit.hpp @@ -25,6 +25,9 @@ namespace llarp std::string Name() const; + bool + VisitEndpointsFor(const PubKey & pk, std::function visit); + util::StatusObject ExtractStatus() const;