persist on commit

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

@ -131,6 +131,9 @@ namespace llarp
llarp_time_t lifetime = DEFAULT_PATH_LIFETIME; llarp_time_t lifetime = DEFAULT_PATH_LIFETIME;
llarp_proto_version_t version; llarp_proto_version_t version;
llarp_time_t
ExpireTime() const;
llarp::routing::InboundMessageParser m_MessageParser; llarp::routing::InboundMessageParser m_MessageParser;
friend std::ostream& friend std::ostream&

@ -204,7 +204,9 @@ llarp_pathbuilder_context::SelectHop(llarp_nodedb* db, llarp_rc* prev,
llarp_rc* cur, size_t hop) llarp_rc* cur, size_t hop)
{ {
if(hop == 0) if(hop == 0)
{
return router->GetRandomConnectedRouter(cur); return router->GetRandomConnectedRouter(cur);
}
else else
llarp_nodedb_select_random_hop(db, prev, cur, hop); llarp_nodedb_select_random_hop(db, prev, cur, hop);
return true; return true;
@ -231,6 +233,7 @@ llarp_pathbuilder_context::BuildOne()
void void
llarp_pathbuilder_context::ManualRebuild(size_t num) llarp_pathbuilder_context::ManualRebuild(size_t num)
{ {
llarp::LogDebug("manual rebuild ", num);
while(num--) while(num--)
BuildOne(); BuildOne();
} }

@ -191,6 +191,10 @@ namespace llarp
SendLRCM(void* user) SendLRCM(void* user)
{ {
LRCMFrameDecrypt* self = static_cast< LRCMFrameDecrypt* >(user); LRCMFrameDecrypt* self = static_cast< LRCMFrameDecrypt* >(user);
self->context->Router()->PersistSessionUntil(self->hop->info.downstream,
self->hop->ExpireTime());
self->context->Router()->PersistSessionUntil(self->hop->info.upstream,
self->hop->ExpireTime());
self->context->ForwardLRCM(self->hop->info.upstream, self->frames); self->context->ForwardLRCM(self->hop->info.upstream, self->frames);
delete self; delete self;
} }

@ -59,7 +59,14 @@ void
llarp_router::PersistSessionUntil(const llarp::RouterID &remote, llarp_router::PersistSessionUntil(const llarp::RouterID &remote,
llarp_time_t until) llarp_time_t until)
{ {
m_PersistingSessions[remote] = until; llarp::LogDebug("persist session to ", remote, " until ", until);
if(m_PersistingSessions.find(remote) == m_PersistingSessions.end())
m_PersistingSessions[remote] = until;
else
{
if(m_PersistingSessions[remote] < until)
m_PersistingSessions[remote] = until;
}
} }
bool bool
@ -412,34 +419,37 @@ llarp_router::Tick()
// llarp::LogDebug("tick router"); // llarp::LogDebug("tick router");
auto now = llarp_time_now_ms(); auto now = llarp_time_now_ms();
paths.ExpirePaths(); paths.ExpirePaths();
if(inboundLinks.size() == 0)
{ {
auto itr = m_PersistingSessions.begin();
while(itr != m_PersistingSessions.end())
{ {
auto itr = m_PersistingSessions.begin(); auto link = GetLinkWithSessionByPubkey(itr->first);
while(itr != m_PersistingSessions.end()) if(now < itr->second)
{ {
auto link = GetLinkWithSessionByPubkey(itr->first); // persisting ended
if(now <= itr->second) if(link)
link->CloseSessionTo(itr->first);
itr = m_PersistingSessions.erase(itr);
}
else
{
if(link)
{ {
// persisting ended llarp::LogDebug("keepalive to ", itr->first);
if(link) link->KeepAliveSessionTo(itr->first);
link->CloseSessionTo(itr->first);
itr = m_PersistingSessions.erase(itr);
} }
else else
{ {
if(link) llarp::LogDebug("establish to ", itr->first);
{ TryEstablishTo(itr->first);
link->KeepAliveSessionTo(itr->first);
}
else
{
TryEstablishTo(itr->first);
}
++itr;
} }
++itr;
} }
} }
}
if(inboundLinks.size() == 0)
{
auto N = llarp_nodedb_num_loaded(nodedb); auto N = llarp_nodedb_num_loaded(nodedb);
if(N > 3) if(N > 3)
{ {

@ -98,8 +98,8 @@ namespace llarp
{ {
llarp::LogWarn("could not publish descriptors for endpoint ", Name(), llarp::LogWarn("could not publish descriptors for endpoint ", Name(),
" because we couldn't get any introductions"); " because we couldn't get any introductions");
if(ShouldBuildMore()) // if(ShouldBuildMore())
ManualRebuild(1); ManualRebuild(1);
return; return;
} }
m_IntroSet.I.clear(); m_IntroSet.I.clear();

@ -17,6 +17,12 @@ namespace llarp
return now - started > lifetime; return now - started > lifetime;
} }
llarp_time_t
TransitHop::ExpireTime() const
{
return started + lifetime;
}
TransitHopInfo::TransitHopInfo(const TransitHopInfo& other) TransitHopInfo::TransitHopInfo(const TransitHopInfo& other)
: txID(other.txID) : txID(other.txID)
, rxID(other.rxID) , rxID(other.rxID)

Loading…
Cancel
Save