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();
}
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
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");
}
});
{

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

Loading…
Cancel
Save