add path latency minimum checker

add min-latency option to hidden service config
pull/15/head
Jeff Becker 6 years ago
parent c0afc97d41
commit 3af51cbe55
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -224,6 +224,7 @@ namespace llarp
struct Path : public IHopHandler, public llarp::routing::IMessageHandler
{
typedef std::function< void(Path*) > BuildResultHookFunc;
typedef std::function< bool(Path*, llarp_time_t) > CheckForDeadFunc;
typedef std::function< bool(Path*, const PathID_t&, uint64_t) >
DropHandlerFunc;
typedef std::vector< PathHopConfig > HopList;
@ -254,6 +255,12 @@ namespace llarp
m_DropHandler = func;
}
void
SetDeadChecker(CheckForDeadFunc func)
{
m_CheckForDead = func;
}
llarp_time_t
ExpireTime() const
{
@ -329,6 +336,7 @@ namespace llarp
BuildResultHookFunc m_BuiltHook;
DataHandlerFunc m_DataHandler;
DropHandlerFunc m_DropHandler;
CheckForDeadFunc m_CheckForDead;
llarp_time_t m_LastLatencyTestTime = 0;
uint64_t m_LastLatencyTestID = 0;
};

@ -146,6 +146,9 @@ namespace llarp
bool
HandleDataDrop(path::Path* p, const PathID_t& dst, uint64_t s);
bool
CheckPathIsDead(path::Path* p, llarp_time_t latency);
typedef std::queue< PendingBuffer > PendingBufferQueue;
/// context needed to initiate an outbound hidden service session
@ -359,6 +362,7 @@ namespace llarp
uint64_t m_CurrentPublishTX = 0;
llarp_time_t m_LastPublish = 0;
llarp_time_t m_LastPublishAttempt = 0;
llarp_time_t m_MinPathLatency = 5000;
/// our introset
service::IntroSet m_IntroSet;
/// pending remote service lookups by id

@ -27,7 +27,7 @@ namespace llarp
Context::Explore(size_t N)
{
// ask N random peers for new routers
llarp::LogInfo("Exploring network");
llarp::LogInfo("Exploring network via ", N, " peers");
std::set< Key_t > peers;
if(nodes->GetManyRandom(peers, N))

@ -385,6 +385,7 @@ namespace llarp
{
if(Expired(now))
return;
if(now < m_LastLatencyTestTime)
return;
auto dlt = now - m_LastLatencyTestTime;
@ -396,6 +397,14 @@ namespace llarp
m_LastLatencyTestTime = now;
SendRoutingMessage(&latency, r);
}
// check to see if this path is dead
if(m_CheckForDead)
{
if(m_CheckForDead(this, dlt))
status = ePathTimeout;
}
else if(dlt >= 5000)
status = ePathTimeout;
}
bool

@ -439,7 +439,8 @@ llarp_router::Tick()
{
llarp::LogInfo(
"We need at least 4 service nodes to build paths but we have ", N);
dht->impl.Explore(1);
auto explore = std::max(NumberOfConnectedRouters(), 1UL);
dht->impl.Explore(explore);
}
hiddenServiceContext.Tick();
}

@ -43,6 +43,12 @@ namespace llarp
m_NetNS = v;
m_OnInit.push_back(std::bind(&Endpoint::IsolateNetwork, this));
}
if(k == "min-latency")
{
auto val = atoi(v.c_str());
if(val > 0)
m_MinPathLatency = val;
}
return true;
}
@ -648,6 +654,9 @@ namespace llarp
p->SetDropHandler(std::bind(&Endpoint::HandleDataDrop, this,
std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3));
p->SetDeadChecker(std::bind(&Endpoint::CheckPathIsDead, this,
std::placeholders::_1,
std::placeholders::_2));
RegenAndPublishIntroSet(llarp_time_now_ms());
}
@ -703,6 +712,15 @@ namespace llarp
p->SetDropHandler(std::bind(
&Endpoint::OutboundContext::HandleDataDrop, this,
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
p->SetDeadChecker(std::bind(&Endpoint::CheckPathIsDead, m_Parent,
std::placeholders::_1,
std::placeholders::_2));
}
bool
Endpoint::CheckPathIsDead(path::Path*, llarp_time_t latency)
{
return latency >= m_MinPathLatency;
}
bool

Loading…
Cancel
Save