mirror of https://github.com/oxen-io/lokinet
don't use bootstrap nodes for first hops in paths
This commit is contained in:
parent
94f87c3371
commit
97b9c679b0
|
@ -34,15 +34,33 @@ namespace llarp
|
|||
|
||||
void
|
||||
ILinkLayer::ForEachSession(
|
||||
std::function< void(const ILinkSession*) > visit) const
|
||||
std::function< void(const ILinkSession*) > visit, bool randomize) const
|
||||
{
|
||||
Lock l(&m_AuthedLinksMutex);
|
||||
if(m_AuthedLinks.size() == 0)
|
||||
return;
|
||||
const size_t sz = randint() % m_AuthedLinks.size();
|
||||
auto itr = m_AuthedLinks.begin();
|
||||
auto begin = itr;
|
||||
if(randomize)
|
||||
{
|
||||
std::advance(itr, sz);
|
||||
begin = itr;
|
||||
}
|
||||
while(itr != m_AuthedLinks.end())
|
||||
{
|
||||
visit(itr->second.get());
|
||||
++itr;
|
||||
}
|
||||
if(randomize)
|
||||
{
|
||||
itr = m_AuthedLinks.begin();
|
||||
while(itr != begin)
|
||||
{
|
||||
visit(itr->second.get());
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
@ -67,7 +67,7 @@ namespace llarp
|
|||
HasSessionVia(const Addr& addr);
|
||||
|
||||
void
|
||||
ForEachSession(std::function< void(const ILinkSession*) > visit) const
|
||||
ForEachSession(std::function< void(const ILinkSession*) > visit, bool randomize=false) const
|
||||
LOCKS_EXCLUDED(m_AuthedLinksMutex);
|
||||
|
||||
void
|
||||
|
|
|
@ -207,11 +207,20 @@ namespace llarp
|
|||
RouterContact& cur, size_t hop, PathRole roles)
|
||||
{
|
||||
(void)roles;
|
||||
if(hop == 0)
|
||||
return router->NumberOfConnectedRouters()
|
||||
&& router->GetRandomConnectedRouter(cur);
|
||||
|
||||
size_t tries = 10;
|
||||
if(hop == 0)
|
||||
{
|
||||
if(router->NumberOfConnectedRouters() == 0)
|
||||
return false;
|
||||
bool got = false;
|
||||
router->ForEachPeer([&](const ILinkSession * s, bool ) {
|
||||
if(got || router->IsBootstrapNode(s->GetPubKey()))
|
||||
return;
|
||||
cur = s->GetRemoteRC();
|
||||
got = true;
|
||||
}, true);
|
||||
return got;
|
||||
}
|
||||
std::set< RouterID > exclude = {prev.pubkey};
|
||||
do
|
||||
{
|
||||
|
|
|
@ -115,6 +115,9 @@ namespace llarp
|
|||
virtual void
|
||||
Stop() = 0;
|
||||
|
||||
virtual bool
|
||||
IsBootstrapNode(RouterID r) const = 0;
|
||||
|
||||
virtual const byte_t *
|
||||
pubkey() const = 0;
|
||||
|
||||
|
@ -185,7 +188,7 @@ namespace llarp
|
|||
/// visit each connected link session
|
||||
virtual void
|
||||
ForEachPeer(
|
||||
std::function< void(const ILinkSession *, bool) > visit) const = 0;
|
||||
std::function< void(const ILinkSession *, bool) > visit, bool randomize) const = 0;
|
||||
};
|
||||
} // namespace llarp
|
||||
|
||||
|
|
|
@ -375,17 +375,17 @@ namespace llarp
|
|||
|
||||
void
|
||||
Router::ForEachPeer(
|
||||
std::function< void(const ILinkSession *, bool) > visit) const
|
||||
std::function< void(const ILinkSession *, bool) > visit, bool randomize) const
|
||||
{
|
||||
for(const auto &link : outboundLinks)
|
||||
{
|
||||
link->ForEachSession(
|
||||
[visit](const ILinkSession *peer) { visit(peer, true); });
|
||||
[visit](const ILinkSession *peer) { visit(peer, true); }, randomize);
|
||||
}
|
||||
for(const auto &link : inboundLinks)
|
||||
{
|
||||
link->ForEachSession(
|
||||
[visit](const ILinkSession *peer) { visit(peer, false); });
|
||||
[visit](const ILinkSession *peer) { visit(peer, false); }, randomize);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1044,6 +1044,17 @@ namespace llarp
|
|||
ep->LookupRouterAnon(remote);
|
||||
}
|
||||
|
||||
bool
|
||||
Router::IsBootstrapNode(RouterID r) const
|
||||
{
|
||||
for(const auto & rc : bootstrapRCList)
|
||||
{
|
||||
if(rc.pubkey == r)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
Router::Tick()
|
||||
{
|
||||
|
@ -1132,11 +1143,14 @@ namespace llarp
|
|||
else
|
||||
LogError("we have no bootstrap nodes specified");
|
||||
}
|
||||
if(connected < minConnectedRouters)
|
||||
else
|
||||
{
|
||||
size_t dlt = minConnectedRouters - connected;
|
||||
LogInfo("connecting to ", dlt, " random routers to keep alive");
|
||||
ConnectToRandomRouters(dlt);
|
||||
if(connected < minConnectedRouters)
|
||||
{
|
||||
size_t dlt = minConnectedRouters - connected;
|
||||
LogInfo("connecting to ", dlt, " random routers to keep alive");
|
||||
ConnectToRandomRouters(dlt);
|
||||
}
|
||||
}
|
||||
|
||||
if(!IsServiceNode())
|
||||
|
|
|
@ -452,11 +452,14 @@ namespace llarp
|
|||
|
||||
void
|
||||
ForEachPeer(
|
||||
std::function< void(const ILinkSession *, bool) > visit) const override;
|
||||
std::function< void(const ILinkSession *, bool) > visit, bool randomize=false) const override;
|
||||
|
||||
void
|
||||
ForEachPeer(std::function< void(ILinkSession *) > visit);
|
||||
|
||||
bool
|
||||
IsBootstrapNode(RouterID) const override;
|
||||
|
||||
/// check if newRc matches oldRC and update local rc for this remote contact
|
||||
/// if valid
|
||||
/// returns true on valid and updated
|
||||
|
|
|
@ -237,7 +237,7 @@ namespace llarp
|
|||
Response{{"ident", RouterID(session->GetPubKey()).ToString()},
|
||||
{"addr", session->GetRemoteEndpoint().ToString()},
|
||||
{"outbound", outbound}});
|
||||
});
|
||||
}, false);
|
||||
return resp;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue