limit connections in outbound session maker

pull/768/head
Jeff Becker 5 years ago
parent efa61f324f
commit a1fff96a1b
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -199,7 +199,7 @@ namespace libuv
conn_glue* self = static_cast< conn_glue* >(h->data);
h->data = nullptr;
delete self;
llarp::LogInfo("deleted");
llarp::LogDebug("deleted");
}
void
@ -217,7 +217,7 @@ namespace libuv
m_Conn.closed(&m_Conn);
}
m_Conn.impl = nullptr;
llarp::LogInfo("closed");
llarp::LogDebug("closed");
uv_close((uv_handle_t*)&m_Ticker, &FullClose);
}

@ -52,6 +52,9 @@ namespace llarp
virtual util::StatusObject
ExtractStatus() const = 0;
virtual bool
ShouldConnectTo(const RouterID &router) const = 0;
};
} // namespace llarp

@ -215,9 +215,25 @@ namespace llarp
itr->second = session;
}
if(ShouldConnectTo(router))
{
auto fn = std::bind(&OutboundSessionMaker::DoEstablish, this, router);
_logic->queue_func(fn);
}
}
auto fn = std::bind(&OutboundSessionMaker::DoEstablish, this, router);
_logic->queue_func(fn);
bool
OutboundSessionMaker::ShouldConnectTo(const RouterID &router) const
{
size_t numPending = 0;
{
util::Lock lock(&_mutex);
numPending += pendingSessions.size();
}
if(_linkManager->HasSessionTo(router))
return false;
return _linkManager->NumberOfConnectedRouters() + numPending
< maxConnectedRouters;
}
void

@ -52,11 +52,20 @@ namespace llarp
util::StatusObject
ExtractStatus() const override;
bool
ShouldConnectTo(const RouterID &router) const override
LOCKS_EXCLUDED(_mutex);
void
Init(ILinkManager *linkManager, I_RCLookupHandler *rcLookup,
std::shared_ptr< Logic > logic, llarp_nodedb *nodedb,
std::shared_ptr< llarp::thread::ThreadPool > threadpool);
/// always maintain this many connections to other routers
size_t minConnectedRouters = 4;
/// hard upperbound limit on the number of router to router connections
size_t maxConnectedRouters = 6;
private:
void
DoEstablish(const RouterID &router) LOCKS_EXCLUDED(_mutex);

@ -374,14 +374,16 @@ namespace llarp
m_OutboundPort = conf->iwp_links.outboundPort();
// Router config
_rc.SetNick(conf->router.nickname());
maxConnectedRouters = conf->router.maxConnectedRouters();
minConnectedRouters = conf->router.minConnectedRouters();
encryption_keyfile = conf->router.encryptionKeyfile();
our_rc_file = conf->router.ourRcFile();
transport_keyfile = conf->router.transportKeyfile();
addrInfo = conf->router.addrInfo();
publicOverride = conf->router.publicOverride();
ip4addr = conf->router.ip4addr();
_outboundSessionMaker.maxConnectedRouters =
conf->router.maxConnectedRouters();
_outboundSessionMaker.minConnectedRouters =
conf->router.minConnectedRouters();
encryption_keyfile = conf->router.encryptionKeyfile();
our_rc_file = conf->router.ourRcFile();
transport_keyfile = conf->router.transportKeyfile();
addrInfo = conf->router.addrInfo();
publicOverride = conf->router.publicOverride();
ip4addr = conf->router.ip4addr();
// Lokid Config
usingSNSeed = conf->lokid.usingSNSeed;
@ -656,16 +658,16 @@ namespace llarp
const size_t connected = NumberOfConnectedRouters();
const size_t N = nodedb()->num_loaded();
if(N < minRequiredRouters)
if(N < 4)
{
LogInfo("We need at least ", minRequiredRouters,
LogInfo("We need at least ", 4,
" service nodes to build paths but we have ", N, " in nodedb");
_rcLookupHandler.ExploreNetwork();
}
if(connected < minConnectedRouters)
if(connected < _outboundSessionMaker.minConnectedRouters)
{
size_t dlt = minConnectedRouters - connected;
size_t dlt = _outboundSessionMaker.minConnectedRouters - connected;
LogInfo("connecting to ", dlt, " random routers to keep alive");
_outboundSessionMaker.ConnectToRandomRouters(dlt, now);
}
@ -890,10 +892,10 @@ namespace llarp
const auto limits =
IsServiceNode() ? llarp::limits::snode : llarp::limits::client;
minConnectedRouters =
std::max(minConnectedRouters, limits.DefaultMinRouters);
maxConnectedRouters =
std::max(maxConnectedRouters, limits.DefaultMaxRouters);
_outboundSessionMaker.minConnectedRouters = std::max(
_outboundSessionMaker.minConnectedRouters, limits.DefaultMinRouters);
_outboundSessionMaker.maxConnectedRouters = std::max(
_outboundSessionMaker.maxConnectedRouters, limits.DefaultMaxRouters);
if(IsServiceNode())
{

@ -194,13 +194,6 @@ namespace llarp
Sign(Signature &sig, const llarp_buffer_t &buf) const override;
uint16_t m_OutboundPort = 0;
/// always maintain this many connections to other routers
size_t minConnectedRouters = 2;
/// hard upperbound limit on the number of router to router connections
size_t maxConnectedRouters = 2000;
size_t minRequiredRouters = 4;
/// how often do we resign our RC? milliseconds.
// TODO: make configurable
llarp_time_t rcRegenInterval = 60 * 60 * 1000;

Loading…
Cancel
Save