premptively build path to selected intro's router every time we don't have it if we get an introset update, on the outbound context

pull/18/head
Jeff Becker 6 years ago
parent 10d463e51a
commit 36c927fc79
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -34,6 +34,12 @@ namespace llarp
void
BuildOne();
void
Build(const std::vector< RouterContact >& hops);
bool
SelectHops(llarp_nodedb* db, std::vector< RouterContact >& hops);
void
ManualRebuild(size_t N);

@ -271,6 +271,9 @@ namespace llarp
void
UpdateIntroSet();
bool
BuildOneAlignedTo(const RouterID& remote);
void
HandlePathBuilt(path::Path* path);

@ -198,31 +198,44 @@ namespace llarp
void
Builder::BuildOne()
{
// select hops
std::vector< RouterContact > hops;
if(SelectHops(router->nodedb, hops))
Build(hops);
}
bool
Builder::SelectHops(llarp_nodedb* nodedb,
std::vector< RouterContact >& hops)
{
hops.resize(numHops);
size_t idx = 0;
while(idx < numHops)
{
if(idx == 0)
{
if(!SelectHop(router->nodedb, hops[0], hops[0], 0))
if(!SelectHop(nodedb, hops[0], hops[0], 0))
{
llarp::LogError("failed to select first hop");
return;
return false;
}
}
else
{
if(!SelectHop(router->nodedb, hops[idx - 1], hops[idx], idx))
if(!SelectHop(nodedb, hops[idx - 1], hops[idx], idx))
{
/// TODO: handle this failure properly
llarp::LogWarn("Failed to select hop ", idx);
return;
return false;
}
}
++idx;
}
return true;
}
void
Builder::Build(const std::vector< RouterContact >& hops)
{
lastBuild = llarp_time_now_ms();
// async generate keys
AsyncPathKeyExchangeContext< Builder >* ctx =

@ -922,6 +922,8 @@ namespace llarp
{
currentIntroSet = *i;
ShiftIntroduction();
if(GetPathByRouter(remoteIntro.router) == nullptr)
BuildOneAlignedTo(remoteIntro.router);
}
updatingIntroSet = false;
return true;
@ -1049,6 +1051,41 @@ namespace llarp
return true;
}
bool
Endpoint::OutboundContext::BuildOneAlignedTo(const RouterID& remote)
{
llarp::LogInfo(Name(), " building path to ", remote);
auto nodedb = m_Endpoint->Router()->nodedb;
std::vector< RouterContact > hops;
hops.resize(numHops);
for(size_t hop = 0; hop < numHops; ++hop)
{
if(hop == 0)
{
// first hop
if(router->NumberOfConnectedRouters())
{
if(!router->GetRandomConnectedRouter(hops[0]))
return false;
}
else if(!llarp_nodedb_select_random_hop(nodedb, hops[0], hops[0], 0))
return false;
}
else if(hop == numHops - 1)
{
// last hop
if(!llarp_nodedb_get_rc(nodedb, remote, hops[hop]))
return false;
}
// middle hop
else if(!llarp_nodedb_select_random_hop(nodedb, hops[hop - 1],
hops[hop], hop))
return false;
}
Build(hops);
return true;
}
bool
Endpoint::OutboundContext::MarkCurrentIntroBad(llarp_time_t now)
{

Loading…
Cancel
Save