Merge remote-tracking branch 'origin/master' into debian/buster

This commit is contained in:
Jason Rhinelander 2020-10-02 18:05:29 -03:00
commit bee6a3ed6c
8 changed files with 102 additions and 46 deletions

View File

@ -36,7 +36,6 @@ namespace llarp
constexpr int DefaultWorkerThreads = 1; constexpr int DefaultWorkerThreads = 1;
constexpr int DefaultNetThreads = 1; constexpr int DefaultNetThreads = 1;
constexpr bool DefaultBlockBogons = true; constexpr bool DefaultBlockBogons = true;
constexpr bool DefaultEnablePeerStats = true;
conf.defineOption<int>("router", "job-queue-size", false, DefaultJobQueueSize, [this](int arg) { conf.defineOption<int>("router", "job-queue-size", false, DefaultJobQueueSize, [this](int arg) {
if (arg < 1024) if (arg < 1024)
@ -81,12 +80,29 @@ namespace llarp
m_dataDir = std::move(arg); m_dataDir = std::move(arg);
}); });
conf.defineOption<std::string>("router", "public-address", false, "", [this](std::string arg) { conf.defineOption<std::string>("router", "public-ip", false, "", [this](std::string arg) {
if (not arg.empty()) if (not arg.empty())
{ {
llarp::LogInfo("public ip ", arg, " size ", arg.size()); llarp::LogInfo("public ip ", arg, " size ", arg.size());
if (arg.size() > 16) if (arg.size() > 15)
throw std::invalid_argument(stringify("Not a valid IPv4 addr: ", arg));
m_publicAddress.setAddress(arg);
}
});
conf.defineOption<std::string>("router", "public-address", false, "", [this](std::string arg) {
if (not arg.empty())
{
llarp::LogWarn(
"*** WARNING: The config option [router]:public-address=",
arg,
" is deprecated, use public-ip=",
arg,
" instead.");
if (arg.size() > 15)
throw std::invalid_argument(stringify("Not a valid IPv4 addr: ", arg)); throw std::invalid_argument(stringify("Not a valid IPv4 addr: ", arg));
m_publicAddress.setAddress(arg); m_publicAddress.setAddress(arg);
@ -134,7 +150,7 @@ namespace llarp
"router", "router",
"enable-peer-stats", "enable-peer-stats",
false, false,
DefaultEnablePeerStats, params.isRelay,
AssignmentAcceptor(m_enablePeerStats)); AssignmentAcceptor(m_enablePeerStats));
m_isRelay = params.isRelay; m_isRelay = params.isRelay;
} }
@ -448,13 +464,10 @@ namespace llarp
void void
ApiConfig::defineConfigOptions(ConfigDefinition& conf, const ConfigGenParameters& params) ApiConfig::defineConfigOptions(ConfigDefinition& conf, const ConfigGenParameters& params)
{ {
(void)params;
constexpr bool DefaultRPCEnabled = true;
constexpr auto DefaultRPCBindAddr = "tcp://127.0.0.1:1190"; constexpr auto DefaultRPCBindAddr = "tcp://127.0.0.1:1190";
conf.defineOption<bool>( conf.defineOption<bool>(
"api", "enabled", false, DefaultRPCEnabled, AssignmentAcceptor(m_enableRPCServer)); "api", "enabled", false, not params.isRelay, AssignmentAcceptor(m_enableRPCServer));
conf.defineOption<std::string>( conf.defineOption<std::string>(
"api", "bind", false, DefaultRPCBindAddr, [this](std::string arg) { "api", "bind", false, DefaultRPCBindAddr, [this](std::string arg) {
@ -478,7 +491,6 @@ namespace llarp
{ {
(void)params; (void)params;
constexpr bool DefaultWhitelistRouters = false;
constexpr auto DefaultLokidRPCAddr = "tcp://127.0.0.1:22023"; constexpr auto DefaultLokidRPCAddr = "tcp://127.0.0.1:22023";
conf.defineOption<std::string>( conf.defineOption<std::string>(
@ -491,7 +503,7 @@ namespace llarp
}); });
conf.defineOption<bool>( conf.defineOption<bool>(
"lokid", "enabled", false, DefaultWhitelistRouters, AssignmentAcceptor(whitelistRouters)); "lokid", "enabled", false, params.isRelay, AssignmentAcceptor(whitelistRouters));
conf.defineOption<std::string>("lokid", "jsonrpc", false, "", [](std::string arg) { conf.defineOption<std::string>("lokid", "jsonrpc", false, "", [](std::string arg) {
if (arg.empty()) if (arg.empty())
@ -769,6 +781,23 @@ namespace llarp
"Maximum number (hard limit) of routers lokinet will be connected to at any time.", "Maximum number (hard limit) of routers lokinet will be connected to at any time.",
}); });
def.addOptionComments(
"router",
"public-ip",
{
"For complex network configurations where the detected IP is incorrect or non-public",
"this setting specifies the public IP at which this router is reachable. When",
"provided the public-port option must also be specified.",
});
def.addOptionComments(
"router",
"public-port",
{
"When specifying public-ip=, this specifies the public UDP port at which this lokinet",
"router is reachable. Required when public-ip is used.",
});
// logging // logging
def.addSectionComments( def.addSectionComments(
"logging", "logging",

View File

@ -18,7 +18,7 @@ namespace llarp
if (m_initialized) if (m_initialized)
return false; return false;
fs::path root = config.router.m_dataDir; const fs::path root = config.router.m_dataDir;
// utility function to assign a path, using the specified config parameter if present and // utility function to assign a path, using the specified config parameter if present and
// falling back to root / defaultName if not // falling back to root / defaultName if not
@ -31,7 +31,7 @@ namespace llarp
{ {
fs::path file(option); fs::path file(option);
if (not file.is_absolute()) if (not file.is_absolute())
throw std::runtime_error(stringify("override for ", defaultName, " cannot be relative")); file = root / file;
return file; return file;
} }

View File

@ -66,7 +66,8 @@ namespace llarp
, m_lokidRpcClient(std::make_shared<rpc::LokidRpcClient>(m_lmq, this)) , m_lokidRpcClient(std::make_shared<rpc::LokidRpcClient>(m_lmq, this))
{ {
m_keyManager = std::make_shared<KeyManager>(); m_keyManager = std::make_shared<KeyManager>();
// for lokid, so we don't close the connection when syncing the whitelist
m_lmq->MAX_MSG_SIZE = -1;
_stopping.store(false); _stopping.store(false);
_running.store(false); _running.store(false);
_lastTick = llarp::time_now_ms(); _lastTick = llarp::time_now_ms();
@ -567,8 +568,22 @@ namespace llarp
whitelistRouters, whitelistRouters,
m_isServiceNode); m_isServiceNode);
std::vector<LinksConfig::LinkInfo> inboundLinks = conf.links.m_InboundLinks;
if (inboundLinks.empty() and m_isServiceNode)
{
const auto& publicAddr = conf.router.m_publicAddress;
if (publicAddr.isEmpty() or not publicAddr.hasPort())
{
throw std::runtime_error(
"service node enabled but could not find a public IP to bind to; you need to set the "
"public-ip= and public-port= options");
}
inboundLinks.push_back(LinksConfig::LinkInfo{"0.0.0.0", AF_INET, *publicAddr.getPort()});
}
// create inbound links, if we are a service node // create inbound links, if we are a service node
for (const LinksConfig::LinkInfo& serverConfig : conf.links.m_InboundLinks) for (const LinksConfig::LinkInfo& serverConfig : inboundLinks)
{ {
auto server = iwp::NewInboundLink( auto server = iwp::NewInboundLink(
m_keyManager, m_keyManager,
@ -593,11 +608,6 @@ namespace llarp
_linkManager.AddLink(std::move(server), true); _linkManager.AddLink(std::move(server), true);
} }
if (conf.links.m_InboundLinks.empty() and m_isServiceNode)
{
throw std::runtime_error("service node enabled but have no inbound links");
}
// Network config // Network config
if (conf.network.m_enableProfiling.has_value() and not*conf.network.m_enableProfiling) if (conf.network.m_enableProfiling.has_value() and not*conf.network.m_enableProfiling)
{ {
@ -1118,6 +1128,7 @@ namespace llarp
StopLinks(); StopLinks();
nodedb()->AsyncFlushToDisk(); nodedb()->AsyncFlushToDisk();
_logic->call_later(200ms, std::bind(&Router::AfterStopLinks, this)); _logic->call_later(200ms, std::bind(&Router::AfterStopLinks, this));
m_lmq.reset();
} }
void void

View File

@ -235,7 +235,7 @@ namespace llarp
try try
{ {
std::string_view buf_view(reinterpret_cast<char*>(buf->cur), buf->sz); std::string_view buf_view(reinterpret_cast<char*>(buf->cur), buf->size_left());
lokimq::bt_list_consumer btlist(buf_view); lokimq::bt_list_consumer btlist(buf_view);
uint64_t outer_version = btlist.consume_integer<uint64_t>(); uint64_t outer_version = btlist.consume_integer<uint64_t>();
@ -266,7 +266,6 @@ namespace llarp
bool bool
RouterContact::DecodeVersion_0(llarp_buffer_t* buf) RouterContact::DecodeVersion_0(llarp_buffer_t* buf)
{ {
signed_bt_dict = std::string(reinterpret_cast<char*>(buf->cur), buf->sz);
return bencode_decode_dict(*this, buf); return bencode_decode_dict(*this, buf);
} }

View File

@ -67,8 +67,9 @@ namespace llarp
void void
LokidRpcClient::UpdateServiceNodeList() LokidRpcClient::UpdateServiceNodeList()
{ {
nlohmann::json request; nlohmann::json request, fields;
request["pubkey_ed25519"] = true; fields["pubkey_ed25519"] = true;
request["fields"] = fields;
request["active_only"] = true; request["active_only"] = true;
if (not m_CurrentBlockHash.empty()) if (not m_CurrentBlockHash.empty())
request["poll_block_hash"] = m_CurrentBlockHash; request["poll_block_hash"] = m_CurrentBlockHash;
@ -100,7 +101,7 @@ namespace llarp
void void
LokidRpcClient::Connected() LokidRpcClient::Connected()
{ {
constexpr auto PingInterval = 1min; constexpr auto PingInterval = 30s;
constexpr auto NodeListUpdateInterval = 30s; constexpr auto NodeListUpdateInterval = 30s;
auto makePingRequest = [self = shared_from_this()]() { auto makePingRequest = [self = shared_from_this()]() {
@ -113,7 +114,6 @@ namespace llarp
}, },
payload.dump()); payload.dump());
}; };
makePingRequest();
m_lokiMQ->add_timer(makePingRequest, PingInterval); m_lokiMQ->add_timer(makePingRequest, PingInterval);
m_lokiMQ->add_timer( m_lokiMQ->add_timer(
[self = shared_from_this()]() { self->UpdateServiceNodeList(); }, NodeListUpdateInterval); [self = shared_from_this()]() { self->UpdateServiceNodeList(); }, NodeListUpdateInterval);

View File

@ -62,7 +62,9 @@ Build requirements:
* C++ 17 capable C++ compiler * C++ 17 capable C++ compiler
* libuv >= 1.27.0 * libuv >= 1.27.0
* libsodium >= 1.0.18 * libsodium >= 1.0.18
* gcovr (if generating test coverage with gcc) * libunbound
* libzmq
* sqlite3
### Linux ### Linux
@ -73,7 +75,7 @@ build:
$ cd loki-network $ cd loki-network
$ mkdir build $ mkdir build
$ cd build $ cd build
$ cmake .. $ cmake .. -DBUILD_STATIC_DEPS=ON -DBUILD_SHARED_LIBS=OFF -DSTATIC_LINK=ON
$ make -j$(nproc) $ make -j$(nproc)
install: install:
@ -89,7 +91,7 @@ build:
$ cd loki-network $ cd loki-network
$ mkdir build $ mkdir build
$ cd build $ cd build
$ cmake .. $ cmake .. -DBUILD_STATIC_DEPS=ON -DBUILD_SHARED_LIBS=OFF -DSTATIC_LINK=ON
$ make -j$(nproc) $ make -j$(nproc)
install: install:
@ -115,7 +117,7 @@ building:
$ cd loki-network $ cd loki-network
$ mkdir build-windows $ mkdir build-windows
$ cd build-windows $ cd build-windows
$ cmake -DNATIVE_BUILD=OFF -DCMAKE_BUILD_TYPE=Release -DBUILD_PACKAGE=ON -DCMAKE_TOOLCHAIN_FILE='../contrib/cross/mingw64.cmake' -DWITH_TESTS=OFF -DCMAKE_CROSSCOMPILING=ON .. $ cmake -DBUILD_STATIC_DEPS=ON -DNATIVE_BUILD=OFF -DCMAKE_BUILD_TYPE=Release -DBUILD_PACKAGE=ON -DCMAKE_TOOLCHAIN_FILE='../contrib/cross/mingw64.cmake' -DWITH_TESTS=OFF -DCMAKE_CROSSCOMPILING=ON ..
$ cpack -D CPACK_MONOLITHIC_INSTALL=1 -G NSIS .. $ cpack -D CPACK_MONOLITHIC_INSTALL=1 -G NSIS ..
### Solaris 2.10+ ### Solaris 2.10+
@ -146,7 +148,7 @@ install:
build: build:
$ pkg install cmake git curl libuv libsodium pkgconf $ pkg install cmake git curl libuv libsodium pkgconf libunbound
$ git clone --recursive https://github.com/loki-project/loki-network $ git clone --recursive https://github.com/loki-project/loki-network
$ cd loki-network $ cd loki-network
$ mkdir build $ mkdir build

View File

@ -71,15 +71,20 @@ Requerimientos de compilación:
* gcovr (para generar la covertura de prueba en gcc) * gcovr (para generar la covertura de prueba en gcc)
* libuv >= 1.27.0 * libuv >= 1.27.0
* libsodium >= 1.0.18 * libsodium >= 1.0.18
* libcurl * libunbound
* libzmq
* sqlite3
### Linux ### Linux
compilando: compilando:
$ sudo apt install build-essential cmake git libcap-dev curl libuv1-dev libsodium-dev $ sudo apt install build-essential cmake git libcap-dev curl libuv1-dev libsodium-dev pkg-config
$ git clone https://github.com/loki-project/loki-network $ git clone --recursive https://github.com/loki-project/loki-network
$ cd loki-network $ cd loki-network
$ mkdir build
$ cd build
$ cmake .. -DBUILD_STATIC_DEPS=ON -DBUILD_SHARED_LIBS=OFF -DSTATIC_LINK=ON
$ make $ make
instalando: instalando:
@ -100,6 +105,9 @@ compilando:
$ git clone https://github.com/loki-project/loki-network $ git clone https://github.com/loki-project/loki-network
$ cd loki-network $ cd loki-network
$ mkdir build
$ cd build
$ cmake ..
$ make -j8 $ make -j8
instalando: instalando:
@ -159,9 +167,12 @@ PENDIENTE: agregar instrucciones para pkgsrc
compilando: compilando:
# pkg_add curl cmake git (opcional: ninja ccache) # pkg_add curl cmake git (opcional: ninja ccache)
$ git clone https://github.com/loki-project/loki-network $ git clone --recursive https://github.com/loki-project/loki-network
$ cd loki-network $ cd loki-network
$ gmake -j8 $ mkdir build
$ cd build
$ cmake .. -DBUILD_STATIC_DEPS=ON -DBUILD_SHARED_LIBS=OFF -DSTATIC_LINK=ON
$ make
instalando (root): instalando (root):
@ -172,9 +183,12 @@ instalando (root):
compilando: compilando:
$ pkg install cmake git curl libuv-1.27.0 libsodium $ pkg install cmake git curl libuv-1.27.0 libsodium
$ git clone https://github.com/loki-project/loki-network $ git clone --recursive https://github.com/loki-project/loki-network
$ cd loki-network $ cd loki-network
$ gmake -j8 $ mkdir build
$ cd build
$ cmake .. -DBUILD_STATIC_DEPS=ON -DBUILD_SHARED_LIBS=OFF -DSTATIC_LINK=ON
$ make
instalando (root): instalando (root):

View File

@ -19,6 +19,7 @@ make_context()
conf.bootstrap.skipBootstrap = true; conf.bootstrap.skipBootstrap = true;
conf.api.m_enableRPCServer = false; conf.api.m_enableRPCServer = false;
conf.router.m_enablePeerStats = true; conf.router.m_enablePeerStats = true;
conf.lokid.whitelistRouters = false;
conf.router.m_publicAddress = llarp::IpAddress("1.1.1.1"); conf.router.m_publicAddress = llarp::IpAddress("1.1.1.1");
// make a fake inbound link // make a fake inbound link
conf.links.m_InboundLinks.emplace_back(); conf.links.m_InboundLinks.emplace_back();