make outbound session if we do not have

currently creating an outbound session will cancel if we have any session
at all with the relay.  instead, only cancel if we have an outbound session
to that relay.  this is useful for reachability testing.
pull/1659/head
Thomas Winget 3 years ago
parent 37ab78b654
commit d68d39a450

@ -35,6 +35,12 @@ namespace llarp
virtual bool
HasSessionTo(const RouterID& remote) const = 0;
// it is fine to have both an inbound and outbound session with
// another relay, and is useful for network testing. This test
// is more specific for use with "should we connect outbound?"
virtual bool
HasOutboundSessionTo(const RouterID& remote) const = 0;
/// return true if the session with this pubkey is a client
/// return false if the session with this pubkey is a router
/// return std::nullopt we have no session with this pubkey

@ -60,6 +60,17 @@ namespace llarp
return GetLinkWithSessionTo(remote) != nullptr;
}
bool
LinkManager::HasOutboundSessionTo(const RouterID& remote) const
{
for (const auto& link : outboundLinks)
{
if (link->HasSessionTo(remote))
return true;
}
return false;
}
std::optional<bool>
LinkManager::SessionIsClient(RouterID remote) const
{
@ -69,11 +80,8 @@ namespace llarp
if (session)
return not session->IsRelay();
}
for (const auto& link : outboundLinks)
{
if (link->HasSessionTo(remote))
return false;
}
if (HasOutboundSessionTo(remote))
return false;
return std::nullopt;
}

@ -33,6 +33,9 @@ namespace llarp
bool
HasSessionTo(const RouterID& remote) const override;
bool
HasOutboundSessionTo(const RouterID& remote) const override;
std::optional<bool>
SessionIsClient(RouterID remote) const override;

@ -247,7 +247,7 @@ namespace llarp
if (pendingSessions.find(router) == pendingSessions.end())
numPending += pendingSessions.size();
}
if (_linkManager->HasSessionTo(router))
if (_linkManager->HasOutboundSessionTo(router))
return false;
if (_router->IsServiceNode())
return true;

Loading…
Cancel
Save