limit outbound connections

pull/598/head
Jeff Becker 5 years ago
parent 1d852a1e83
commit b68f539de6
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -155,7 +155,8 @@ namespace llarp
BaseSession::ResetInternalState()
{
auto sendExitClose = [&](const llarp::path::Path_ptr p) {
if(p->SupportsAnyRoles(llarp::path::ePathRoleExit | llarp::path::ePathRoleSVC))
if(p->SupportsAnyRoles(llarp::path::ePathRoleExit
| llarp::path::ePathRoleSVC))
{
llarp::LogInfo(p->Name(), " closing exit path");
llarp::routing::CloseExitMessage msg;

@ -5,6 +5,8 @@
namespace llarp
{
static constexpr size_t MaxSessionsPerKey = 16;
ILinkLayer::ILinkLayer(const SecretKey& routerEncSecret, GetRCFunc getrc,
LinkMessageHandler handler, SignBufferFunc signbuf,
SessionEstablishedHandler establishedSession,
@ -152,7 +154,6 @@ namespace llarp
bool
ILinkLayer::MapAddr(const RouterID& pk, ILinkSession* s)
{
static constexpr size_t MaxSessionsPerKey = 16;
Lock l_authed(&m_AuthedLinksMutex);
Lock l_pending(&m_PendingMutex);
llarp::Addr addr = s->GetRemoteEndpoint();
@ -220,10 +221,20 @@ namespace llarp
bool
ILinkLayer::TryEstablishTo(RouterContact rc)
{
{
Lock l(&m_AuthedLinksMutex);
if(m_AuthedLinks.count(rc.pubkey) >= MaxSessionsPerKey)
return false;
}
llarp::AddressInfo to;
if(!PickAddress(rc, to))
return false;
llarp::Addr addr(to);
{
Lock l(&m_PendingMutex);
if(m_Pending.count(addr) >= MaxSessionsPerKey)
return false;
}
std::shared_ptr< ILinkSession > s = NewOutboundSession(rc, to);
if(PutSession(s))
{

@ -185,7 +185,7 @@ namespace llarp
Builder::ResetInternalState()
{
buildIntervalLimit = MIN_PATH_BUILD_INTERVAL;
lastBuild = 0;
lastBuild = 0;
}
void

@ -358,8 +358,7 @@ namespace llarp
if(nodedb()->Get(remote, remoteRC))
{
// try connecting directly as the rc is loaded from disk
TryConnectAsync(remoteRC, 10);
return true;
return TryConnectAsync(remoteRC, 10);
}
// we don't have the RC locally so do a dht lookup
@ -1796,9 +1795,8 @@ namespace llarp
}
return want > 0;
});
if(wanted != want)
LogInfo("connecting to ", abs(want - wanted), " out of ", wanted,
" random routers");
LogInfo("connecting to ", abs(want - wanted), " out of ", wanted,
" random routers");
}
bool

@ -189,7 +189,7 @@ namespace llarp
bool
Session::TimedOut(llarp_time_t now) const
{
if(state == eInitial)
if(state == eInitial || state == eLinkEstablished)
return false;
if(sendq.size() >= MaxSendQueueSize)
{

Loading…
Cancel
Save