Simplify connection limit constants

pull/1186/head
Stephen Shelton 4 years ago
parent 14e7789847
commit 5b520a4dff
No known key found for this signature in database
GPG Key ID: EE4BADACCE8B631C

@ -5,7 +5,7 @@ set(LIB_UTIL_SRC
config/definition.cpp
config/ini.cpp
config/key_manager.cpp
constants/limits.cpp
${CMAKE_CURRENT_BINARY_DIR}/constants/version.cpp
util/bencode.cpp
util/buffer.cpp
util/encode.cpp

@ -2,7 +2,6 @@
#include <config/ini.hpp>
#include <constants/defaults.hpp>
#include <constants/limits.hpp>
#include <net/net.hpp>
#include <router_contact.hpp>
#include <stdexcept>
@ -21,6 +20,14 @@
namespace llarp
{
// constants for config file default values
constexpr int DefaultMinConnectionsForRouter = 6;
constexpr int DefaultMaxConnectionsForRouter = 60;
constexpr int DefaultMinConnectionsForClient = 4;
constexpr int DefaultMaxConnectionsForClient = 6;
const char*
lokinetEnv(string_view suffix)
{
@ -110,18 +117,24 @@ namespace llarp
m_netId = std::move(arg);
});
conf.defineOption<int>("router", "min-connections", false, m_minConnectedRouters,
[this](int arg) {
if (arg < 1)
throw std::invalid_argument("min-connections must be >= 1");
// TODO: refactor to pass isRelay in
bool isRelay = false;
int minConnections = (isRelay ? DefaultMinConnectionsForRouter
: DefaultMinConnectionsForClient);
conf.defineOption<int>("router", "min-connections", false, minConnections,
[=](int arg) {
if (arg < minConnections)
throw std::invalid_argument(stringify("min-connections must be >= ", minConnections));
m_minConnectedRouters = arg;
});
conf.defineOption<int>("router", "max-connections", false, m_maxConnectedRouters,
[this](int arg) {
if (arg < 1)
throw std::invalid_argument("max-connections must be >= 1");
int maxConnections = (isRelay ? DefaultMaxConnectionsForRouter
: DefaultMaxConnectionsForClient);
conf.defineOption<int>("router", "max-connections", false, maxConnections,
[=](int arg) {
if (arg < maxConnections)
throw std::invalid_argument(stringify("max-connections must be >= ", maxConnections));
m_maxConnectedRouters = arg;
});
@ -582,7 +595,6 @@ namespace llarp
// TODO: pass these in
const std::string basepath = "";
bool isRouter = false;
// router
def.addSectionComment("router", "Configuration for routing activity.");
@ -609,15 +621,11 @@ namespace llarp
// TODO: why did Kee want this, and/or what does it really do? Something about logs?
def.addOptionComment("router", "nickname", "Router nickname. Kee wanted it.");
const auto limits = isRouter ? llarp::limits::snode : llarp::limits::client;
def.addOptionComment("router", "min-connections",
"Minimum number of routers lokinet will attempt to maintain connections to.");
def.addConfigValue("router", "min-connections", stringify(limits.DefaultMinRouters));
def.addOptionComment("router", "max-connections",
"Maximum number (hard limit) of routers lokinet will be connected to at any time.");
def.addConfigValue("router", "max-connections", stringify(limits.DefaultMaxRouters));
// logging
def.addSectionComment("logging", "logging settings");

@ -1,13 +0,0 @@
#include <constants/limits.hpp>
namespace llarp
{
namespace limits
{
/// snode limit parameters
const LimitParameters snode = {6, 60};
/// client limit parameters
const LimitParameters client = {4, 6};
} // namespace limits
} // namespace llarp

@ -1,26 +0,0 @@
#ifndef LLARP_CONSTANTS_LIMITS_HPP
#define LLARP_CONSTANTS_LIMITS_HPP
#include <cstddef>
namespace llarp
{
namespace limits
{
/// Limits are a struct that contains all hard and soft limit
/// parameters for a given mode of operation
struct LimitParameters
{
/// minimum routers needed to run
std::size_t DefaultMinRouters;
/// hard limit on router sessions (by pubkey)
std::size_t DefaultMaxRouters;
};
/// snode limit parameters
const extern LimitParameters snode;
/// client limit parameters
const extern LimitParameters client;
} // namespace limits
} // namespace llarp
#endif

@ -2,7 +2,6 @@
#include <router/router.hpp>
#include <config/config.hpp>
#include <constants/limits.hpp>
#include <constants/proto.hpp>
#include <crypto/crypto_libsodium.hpp>
#include <crypto/crypto.hpp>
@ -1046,13 +1045,6 @@ namespace llarp
EnsureNetConfigDefaultsSane(netConfig);
const auto limits = IsServiceNode() ? llarp::limits::snode : llarp::limits::client;
_outboundSessionMaker.minConnectedRouters =
std::max(_outboundSessionMaker.minConnectedRouters, limits.DefaultMinRouters);
_outboundSessionMaker.maxConnectedRouters =
std::max(_outboundSessionMaker.maxConnectedRouters, limits.DefaultMaxRouters);
if (IsServiceNode())
{
// initialize as service node

Loading…
Cancel
Save