expire old snode sessions

pull/145/head
Jeff Becker 6 years ago
parent bb0cd81f02
commit e787165da9
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -13,6 +13,7 @@ namespace llarp
, m_ExitRouter(router)
, m_WritePacket(writepkt)
, m_Counter(0)
, m_LastUse(0)
{
r->crypto.identity_keygen(m_ExitIdentity);
}
@ -76,10 +77,10 @@ namespace llarp
bool
BaseSession::HandleGotExit(llarp::path::Path* p, llarp_time_t b)
{
m_LastUse = router->Now();
if(b == 0)
{
llarp::LogInfo("obtained an exit via ", p->Endpoint());
}
return true;
}
@ -88,7 +89,13 @@ namespace llarp
{
(void)p;
if(m_WritePacket)
return m_WritePacket(pkt);
{
if(!m_WritePacket(pkt))
return false;
m_LastUse = router->Now();
return true;
}
return false;
}
@ -133,9 +140,16 @@ namespace llarp
return AvailablePaths(llarp::path::ePathRoleExit) > 0;
}
bool
BaseSession::IsExpired(llarp_time_t now) const
{
return m_LastUse && now > m_LastUse && now - m_LastUse > LifeSpan;
}
bool
BaseSession::FlushUpstreamTraffic()
{
auto now = router->Now();
auto path = PickRandomEstablishedPath(llarp::path::ePathRoleExit);
if(!path)
{
@ -151,7 +165,8 @@ namespace llarp
{
auto& msg = queue.front();
msg.S = path->NextSeqNo();
path->SendRoutingMessage(&msg, router);
if(path->SendRoutingMessage(&msg, router))
m_LastUse = now;
queue.pop_front();
}
}

@ -16,6 +16,7 @@ namespace llarp
struct BaseSession : public llarp::path::Builder
{
static constexpr size_t MaxUpstreamQueueLength = 256;
static constexpr llarp_time_t LifeSpan = 60 * 10 * 1000;
BaseSession(const llarp::RouterID& exitRouter,
std::function< bool(llarp_buffer_t) > writepkt,
@ -48,6 +49,9 @@ namespace llarp
return m_ExitRouter;
}
bool
IsExpired(llarp_time_t now) const;
protected:
llarp::RouterID m_ExitRouter;
std::function< bool(llarp_buffer_t) > m_WritePacket;
@ -72,6 +76,7 @@ namespace llarp
TieredQueue_t m_Upstream;
uint64_t m_Counter;
llarp::SecretKey m_ExitIdentity;
llarp_time_t m_LastUse;
};
struct ExitSession final : public BaseSession

@ -142,6 +142,17 @@ namespace llarp
{
RegenAndPublishIntroSet(now);
}
// expire snode sessions
{
auto itr = m_SNodeSessions.begin();
while(itr != m_SNodeSessions.end())
{
if(itr->second->IsExpired(now))
itr = m_SNodeSessions.erase(itr);
else
++itr;
}
}
// expire pending tx
{
std::set< service::IntroSet > empty;

Loading…
Cancel
Save