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

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

@ -215,9 +215,25 @@ namespace llarp
itr->second = session; 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); bool
_logic->queue_func(fn); 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 void

@ -52,11 +52,20 @@ namespace llarp
util::StatusObject util::StatusObject
ExtractStatus() const override; ExtractStatus() const override;
bool
ShouldConnectTo(const RouterID &router) const override
LOCKS_EXCLUDED(_mutex);
void void
Init(ILinkManager *linkManager, I_RCLookupHandler *rcLookup, Init(ILinkManager *linkManager, I_RCLookupHandler *rcLookup,
std::shared_ptr< Logic > logic, llarp_nodedb *nodedb, std::shared_ptr< Logic > logic, llarp_nodedb *nodedb,
std::shared_ptr< llarp::thread::ThreadPool > threadpool); 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: private:
void void
DoEstablish(const RouterID &router) LOCKS_EXCLUDED(_mutex); DoEstablish(const RouterID &router) LOCKS_EXCLUDED(_mutex);

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

@ -194,13 +194,6 @@ namespace llarp
Sign(Signature &sig, const llarp_buffer_t &buf) const override; Sign(Signature &sig, const llarp_buffer_t &buf) const override;
uint16_t m_OutboundPort = 0; 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. /// how often do we resign our RC? milliseconds.
// TODO: make configurable // TODO: make configurable
llarp_time_t rcRegenInterval = 60 * 60 * 1000; llarp_time_t rcRegenInterval = 60 * 60 * 1000;

Loading…
Cancel
Save