2019-04-30 01:06:20 +00:00
|
|
|
#include <service/endpoint_util.hpp>
|
|
|
|
|
2019-07-15 09:15:51 +00:00
|
|
|
#include <exit/session.hpp>
|
2019-04-30 01:06:20 +00:00
|
|
|
#include <service/outbound_context.hpp>
|
2019-07-15 09:15:51 +00:00
|
|
|
#include <service/lookup.hpp>
|
2019-09-01 12:10:49 +00:00
|
|
|
#include <util/logging/logger.hpp>
|
2019-04-30 01:06:20 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace service
|
|
|
|
{
|
|
|
|
void
|
2019-07-15 09:15:51 +00:00
|
|
|
EndpointUtil::ExpireSNodeSessions(llarp_time_t now, SNodeSessions& sessions)
|
2019-04-30 01:06:20 +00:00
|
|
|
{
|
|
|
|
auto itr = sessions.begin();
|
|
|
|
while(itr != sessions.end())
|
|
|
|
{
|
2019-07-01 14:56:56 +00:00
|
|
|
if(itr->second.first->ShouldRemove() && itr->second.first->IsStopped())
|
2019-04-30 01:06:20 +00:00
|
|
|
{
|
|
|
|
itr = sessions.erase(itr);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// expunge next tick
|
2019-07-01 14:56:56 +00:00
|
|
|
if(itr->second.first->IsExpired(now))
|
2019-04-30 01:06:20 +00:00
|
|
|
{
|
2019-07-01 14:56:56 +00:00
|
|
|
itr->second.first->Stop();
|
2019-04-30 01:06:20 +00:00
|
|
|
}
|
2019-04-30 21:36:27 +00:00
|
|
|
else
|
|
|
|
{
|
2019-07-01 14:56:56 +00:00
|
|
|
itr->second.first->Tick(now);
|
2019-04-30 21:36:27 +00:00
|
|
|
}
|
2019-04-30 01:06:20 +00:00
|
|
|
|
|
|
|
++itr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-07-15 09:15:51 +00:00
|
|
|
EndpointUtil::ExpirePendingTx(llarp_time_t now, PendingLookups& lookups)
|
2019-04-30 01:06:20 +00:00
|
|
|
{
|
|
|
|
for(auto itr = lookups.begin(); itr != lookups.end();)
|
|
|
|
{
|
|
|
|
if(!itr->second->IsTimedOut(now))
|
|
|
|
{
|
|
|
|
++itr;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
std::unique_ptr< IServiceLookup > lookup = std::move(itr->second);
|
|
|
|
|
2019-05-05 14:15:48 +00:00
|
|
|
LogWarn(lookup->name, " timed out txid=", lookup->txid);
|
2019-04-30 01:06:20 +00:00
|
|
|
lookup->HandleResponse({});
|
|
|
|
itr = lookups.erase(itr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
EndpointUtil::ExpirePendingRouterLookups(llarp_time_t now,
|
2019-07-15 09:15:51 +00:00
|
|
|
PendingRouters& routers)
|
2019-04-30 01:06:20 +00:00
|
|
|
{
|
|
|
|
for(auto itr = routers.begin(); itr != routers.end();)
|
|
|
|
{
|
|
|
|
if(!itr->second.IsExpired(now))
|
|
|
|
{
|
|
|
|
++itr;
|
|
|
|
continue;
|
|
|
|
}
|
2019-05-05 14:15:48 +00:00
|
|
|
LogWarn("lookup for ", itr->first, " timed out");
|
2019-05-05 14:42:13 +00:00
|
|
|
itr->second.InformResult({});
|
2019-04-30 01:06:20 +00:00
|
|
|
itr = routers.erase(itr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-07-15 09:15:51 +00:00
|
|
|
EndpointUtil::DeregisterDeadSessions(llarp_time_t now, Sessions& sessions)
|
2019-04-30 01:06:20 +00:00
|
|
|
{
|
|
|
|
auto itr = sessions.begin();
|
|
|
|
while(itr != sessions.end())
|
|
|
|
{
|
|
|
|
if(itr->second->IsDone(now))
|
|
|
|
{
|
|
|
|
itr = sessions.erase(itr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++itr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-07-15 09:15:51 +00:00
|
|
|
EndpointUtil::TickRemoteSessions(llarp_time_t now, Sessions& remoteSessions,
|
|
|
|
Sessions& deadSessions)
|
2019-04-30 01:06:20 +00:00
|
|
|
{
|
|
|
|
auto itr = remoteSessions.begin();
|
|
|
|
while(itr != remoteSessions.end())
|
|
|
|
{
|
2019-04-30 16:49:34 +00:00
|
|
|
itr->second->Tick(now);
|
2019-04-30 15:09:42 +00:00
|
|
|
if(itr->second->Pump(now))
|
2019-04-30 01:06:20 +00:00
|
|
|
{
|
2019-09-19 20:28:12 +00:00
|
|
|
LogInfo("marking session as dead T=", itr->first);
|
2019-04-30 01:06:20 +00:00
|
|
|
itr->second->Stop();
|
|
|
|
deadSessions.emplace(std::move(*itr));
|
|
|
|
itr = remoteSessions.erase(itr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++itr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-07-15 09:15:51 +00:00
|
|
|
EndpointUtil::ExpireConvoSessions(llarp_time_t now, ConvoMap& sessions)
|
2019-04-30 01:06:20 +00:00
|
|
|
{
|
|
|
|
auto itr = sessions.begin();
|
|
|
|
while(itr != sessions.end())
|
|
|
|
{
|
|
|
|
if(itr->second.IsExpired(now))
|
2019-06-14 12:49:45 +00:00
|
|
|
{
|
2019-09-20 16:56:19 +00:00
|
|
|
LogInfo("Expire session T=", itr->first);
|
2019-04-30 01:06:20 +00:00
|
|
|
itr = sessions.erase(itr);
|
2019-06-14 12:49:45 +00:00
|
|
|
}
|
2019-04-30 01:06:20 +00:00
|
|
|
else
|
|
|
|
++itr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-07-15 09:15:51 +00:00
|
|
|
EndpointUtil::StopRemoteSessions(Sessions& remoteSessions)
|
2019-04-30 01:06:20 +00:00
|
|
|
{
|
|
|
|
for(auto& item : remoteSessions)
|
|
|
|
{
|
|
|
|
item.second->Stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-07-15 09:15:51 +00:00
|
|
|
EndpointUtil::StopSnodeSessions(SNodeSessions& sessions)
|
2019-04-30 01:06:20 +00:00
|
|
|
{
|
|
|
|
for(auto& item : sessions)
|
|
|
|
{
|
2019-07-01 14:56:56 +00:00
|
|
|
item.second.first->Stop();
|
2019-04-30 01:06:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
EndpointUtil::HasPathToService(const Address& addr,
|
2019-07-15 09:15:51 +00:00
|
|
|
const Sessions& remoteSessions)
|
2019-04-30 01:06:20 +00:00
|
|
|
{
|
|
|
|
auto range = remoteSessions.equal_range(addr);
|
|
|
|
auto itr = range.first;
|
|
|
|
while(itr != range.second)
|
|
|
|
{
|
|
|
|
if(itr->second->ReadyToSend())
|
|
|
|
return true;
|
|
|
|
++itr;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2019-05-07 08:29:47 +00:00
|
|
|
|
|
|
|
bool
|
2019-07-15 09:15:51 +00:00
|
|
|
EndpointUtil::GetConvoTagsForService(const ConvoMap& sessions,
|
2019-06-14 12:49:45 +00:00
|
|
|
const Address& info,
|
2019-05-07 08:29:47 +00:00
|
|
|
std::set< ConvoTag >& tags)
|
|
|
|
{
|
|
|
|
bool inserted = false;
|
|
|
|
auto itr = sessions.begin();
|
|
|
|
while(itr != sessions.end())
|
|
|
|
{
|
2019-06-14 12:49:45 +00:00
|
|
|
if(itr->second.remote.Addr() == info)
|
2019-05-07 08:29:47 +00:00
|
|
|
{
|
|
|
|
if(tags.insert(itr->first).second)
|
|
|
|
{
|
|
|
|
inserted = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++itr;
|
|
|
|
}
|
|
|
|
return inserted;
|
|
|
|
}
|
2019-04-30 01:06:20 +00:00
|
|
|
} // namespace service
|
|
|
|
} // namespace llarp
|