mirror of https://github.com/oxen-io/lokinet
persist on commit
This commit is contained in:
parent
b7039f6e5c
commit
b77525b72d
|
@ -131,6 +131,9 @@ namespace llarp
|
|||
llarp_time_t lifetime = DEFAULT_PATH_LIFETIME;
|
||||
llarp_proto_version_t version;
|
||||
|
||||
llarp_time_t
|
||||
ExpireTime() const;
|
||||
|
||||
llarp::routing::InboundMessageParser m_MessageParser;
|
||||
|
||||
friend std::ostream&
|
||||
|
|
|
@ -204,7 +204,9 @@ llarp_pathbuilder_context::SelectHop(llarp_nodedb* db, llarp_rc* prev,
|
|||
llarp_rc* cur, size_t hop)
|
||||
{
|
||||
if(hop == 0)
|
||||
{
|
||||
return router->GetRandomConnectedRouter(cur);
|
||||
}
|
||||
else
|
||||
llarp_nodedb_select_random_hop(db, prev, cur, hop);
|
||||
return true;
|
||||
|
@ -231,6 +233,7 @@ llarp_pathbuilder_context::BuildOne()
|
|||
void
|
||||
llarp_pathbuilder_context::ManualRebuild(size_t num)
|
||||
{
|
||||
llarp::LogDebug("manual rebuild ", num);
|
||||
while(num--)
|
||||
BuildOne();
|
||||
}
|
||||
|
|
|
@ -191,6 +191,10 @@ namespace llarp
|
|||
SendLRCM(void* 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);
|
||||
delete self;
|
||||
}
|
||||
|
|
|
@ -59,7 +59,14 @@ void
|
|||
llarp_router::PersistSessionUntil(const llarp::RouterID &remote,
|
||||
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
|
||||
|
@ -412,34 +419,37 @@ llarp_router::Tick()
|
|||
// llarp::LogDebug("tick router");
|
||||
auto now = llarp_time_now_ms();
|
||||
paths.ExpirePaths();
|
||||
if(inboundLinks.size() == 0)
|
||||
{
|
||||
auto itr = m_PersistingSessions.begin();
|
||||
while(itr != m_PersistingSessions.end())
|
||||
{
|
||||
auto itr = m_PersistingSessions.begin();
|
||||
while(itr != m_PersistingSessions.end())
|
||||
auto link = GetLinkWithSessionByPubkey(itr->first);
|
||||
if(now < itr->second)
|
||||
{
|
||||
auto link = GetLinkWithSessionByPubkey(itr->first);
|
||||
if(now <= itr->second)
|
||||
// persisting ended
|
||||
if(link)
|
||||
link->CloseSessionTo(itr->first);
|
||||
itr = m_PersistingSessions.erase(itr);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(link)
|
||||
{
|
||||
// persisting ended
|
||||
if(link)
|
||||
link->CloseSessionTo(itr->first);
|
||||
itr = m_PersistingSessions.erase(itr);
|
||||
llarp::LogDebug("keepalive to ", itr->first);
|
||||
link->KeepAliveSessionTo(itr->first);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(link)
|
||||
{
|
||||
link->KeepAliveSessionTo(itr->first);
|
||||
}
|
||||
else
|
||||
{
|
||||
TryEstablishTo(itr->first);
|
||||
}
|
||||
++itr;
|
||||
llarp::LogDebug("establish to ", itr->first);
|
||||
TryEstablishTo(itr->first);
|
||||
}
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(inboundLinks.size() == 0)
|
||||
{
|
||||
auto N = llarp_nodedb_num_loaded(nodedb);
|
||||
if(N > 3)
|
||||
{
|
||||
|
|
|
@ -98,8 +98,8 @@ namespace llarp
|
|||
{
|
||||
llarp::LogWarn("could not publish descriptors for endpoint ", Name(),
|
||||
" because we couldn't get any introductions");
|
||||
if(ShouldBuildMore())
|
||||
ManualRebuild(1);
|
||||
// if(ShouldBuildMore())
|
||||
ManualRebuild(1);
|
||||
return;
|
||||
}
|
||||
m_IntroSet.I.clear();
|
||||
|
|
|
@ -17,6 +17,12 @@ namespace llarp
|
|||
return now - started > lifetime;
|
||||
}
|
||||
|
||||
llarp_time_t
|
||||
TransitHop::ExpireTime() const
|
||||
{
|
||||
return started + lifetime;
|
||||
}
|
||||
|
||||
TransitHopInfo::TransitHopInfo(const TransitHopInfo& other)
|
||||
: txID(other.txID)
|
||||
, rxID(other.rxID)
|
||||
|
|
Loading…
Reference in New Issue