round robin the exit endpoints on exit handler

pull/598/head
Jeff Becker 5 years ago
parent 32363ea622
commit 7c782440fb
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -185,6 +185,21 @@ namespace llarp
return m_Router->Now(); return m_Router->Now();
} }
bool
ExitEndpoint::VisitEndpointsFor(const PubKey & pk, std::function<bool(exit::Endpoint * const)> 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 void
ExitEndpoint::Flush() ExitEndpoint::Flush()
{ {
@ -213,21 +228,22 @@ namespace llarp
return; return;
} }
} }
exit::Endpoint *ep = m_ChosenExits[pk]; if(!VisitEndpointsFor(pk, [&](exit::Endpoint * const ep) -> bool
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(!ep->QueueInboundTraffic(ManagedBuffer{pkt.Buffer()})) if(!ep->QueueInboundTraffic(ManagedBuffer{pkt.Buffer()}))
{ {
LogWarn(Name(), " dropped inbound traffic for session ", pk, LogWarn(Name(), " dropped inbound traffic for session ", pk,
" as we are overloaded (probably)"); " 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");
} }
}); });
{ {

@ -25,6 +25,9 @@ namespace llarp
std::string std::string
Name() const; Name() const;
bool
VisitEndpointsFor(const PubKey & pk, std::function<bool(exit::Endpoint * const)> visit);
util::StatusObject util::StatusObject
ExtractStatus() const; ExtractStatus() const;

Loading…
Cancel
Save