Remove ability to have multiple endpoints/snodes from config

pull/1246/head
Stephen Shelton 4 years ago committed by Jeff Becker
parent b7451b7632
commit dd9ab0f1d5
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -361,69 +361,49 @@ namespace llarp
{
(void)params;
static constexpr bool ReachableDefault = true;
static constexpr bool ReachableDefault = false;
static constexpr int HopsDefault = 4;
static constexpr int PathsDefault = 6;
static constexpr bool BundleRCDefault = false;
static constexpr int MinLatencyDefault = 5000;
if (m_name.empty())
throw std::runtime_error("Cannot create EndpointConfig with empty name");
const std::string section = m_name + "-snapp";
conf.defineOption<std::string>(section, "keyfile", false, "", [this](std::string arg) {
// TODO: validate as valid .loki / .snode address
m_keyfile = arg;
});
// TODO: m_endpointType -- this is used downstream, but was it ever supported in config file?
conf.defineOption<std::string>(
"endpoint", "keyfile", false, "", [this](std::string arg) { m_keyfile = arg; });
conf.defineOption<bool>(
section, "reachable", false, ReachableDefault, AssignmentAcceptor(m_reachable));
"endpoint", "reachable", false, ReachableDefault, AssignmentAcceptor(m_reachable));
conf.defineOption<int>(section, "hops", false, HopsDefault, [this](int arg) {
conf.defineOption<int>("endpoint", "hops", false, HopsDefault, [this](int arg) {
if (arg < 1 or arg > 8)
throw std::invalid_argument("[snapp]:hops must be >= 1 and <= 8");
throw std::invalid_argument("[endpoint]:hops must be >= 1 and <= 8");
});
conf.defineOption<int>(section, "paths", false, PathsDefault, [this](int arg) {
conf.defineOption<int>("endpoint", "paths", false, PathsDefault, [this](int arg) {
if (arg < 1 or arg > 8)
throw std::invalid_argument("[snapp]:paths must be >= 1 and <= 8");
throw std::invalid_argument("[endpoint]:paths must be >= 1 and <= 8");
});
conf.defineOption<std::string>(section, "exit-node", false, "", [this](std::string arg) {
#ifdef LOKINET_EXITS
conf.defineOption<std::string>("endpoint", "exit-node", false, "", [this](std::string arg) {
// TODO: validate as valid .loki / .snode address
// probably not .snode...?
m_exitNode = arg;
});
#endif
conf.defineOption<std::string>(section, "local-dns", false, "", [this](std::string arg) {
// TODO: validate as IP address
m_localDNS = arg;
});
conf.defineOption<std::string>(section, "upstream-dns", false, "", [this](std::string arg) {
// TODO: validate as IP address
m_upstreamDNS = arg;
});
conf.defineOption<std::string>(section, "mapaddr", false, "", [this](std::string arg) {
conf.defineOption<std::string>("endpoint", "mapaddr", false, "", [this](std::string arg) {
// TODO: parse / validate as loki_addr : IP addr pair
m_mapAddr = arg;
});
conf.defineOption<bool>(
section, "bundle-rc", false, BundleRCDefault, AssignmentAcceptor(m_bundleRC));
conf.defineOption<std::string>(section, "blacklist-snode", true, "", [this](std::string arg) {
RouterID id;
if (not id.FromString(arg))
throw std::invalid_argument(stringify("Invalide RouterID: ", arg));
conf.defineOption<std::string>(
"endpoint", "blacklist-snode", false, true, "", [this](std::string arg) {
RouterID id;
if (not id.FromString(arg))
throw std::invalid_argument(stringify("Invalide RouterID: ", arg));
auto itr = m_snodeBlacklist.emplace(std::move(id));
if (itr.second)
throw std::invalid_argument(stringify("Duplicate blacklist-snode: ", arg));
});
auto itr = m_snodeBlacklist.emplace(std::move(id));
if (itr.second)
throw std::invalid_argument(stringify("Duplicate blacklist-snode: ", arg));
});
}
bool
@ -445,30 +425,6 @@ namespace llarp
return false;
}
// first pass: find any "foo-snapp" sections and configure them as config options
// this will cause the ConfigDefinition to handle them as values are fed to it during
// the second pass below
parser.IterAll([&](std::string_view section, const SectionValues_t& values) {
(void)values;
const static string_view suffix = "-snapp";
if (section.size() > suffix.size())
{
string_view snappName = section.substr(0, section.size() - suffix.size());
string_view ending = section.substr(snappName.size());
if (ending == suffix)
{
EndpointConfig snappConf;
snappConf.m_name = str(snappName);
snappConf.defineConfigOptions(conf, params);
snapps[str(snappName)] = std::move(snappConf);
}
}
});
// second pass: feed all k:v pairs to ConfigDefinition for processing
parser.IterAll([&](std::string_view section, const SectionValues_t& values) {
for (const auto& pair : values)
{
@ -526,6 +482,7 @@ namespace llarp
lokid.defineConfigOptions(conf, params);
bootstrap.defineConfigOptions(conf, params);
logging.defineConfigOptions(conf, params);
endpoint.defineConfigOptions(conf, params);
}
void
@ -795,13 +752,13 @@ namespace llarp
// snapp
def.addSectionComments(
"example-snapp",
"endpoint",
{
"Snapp settings",
});
def.addOptionComments(
"example-snapp",
"endpoint",
"keyfile",
{
"The private key to persist address with. If not specified the address will be",
@ -810,60 +767,44 @@ namespace llarp
// TODO: is this redundant with / should be merged with basic client config?
def.addOptionComments(
"example-snapp",
"endpoint",
"reachable",
{
"Determines whether we will publish our snapp's introset to the DHT.",
});
// TODO: merge with client conf?
def.addOptionComments(
"example-snapp",
"endpoint",
"hops",
{
"Number of hops in a path. Min 1, max 8.",
});
// TODO: is this actually different than client's paths min/max config?
def.addOptionComments(
"example-snapp",
"endpoint",
"paths",
{
"Number of paths to maintain at any given time.",
});
def.addOptionComments(
"example-snapp",
"endpoint",
"blacklist-snode",
{
"Adds a `.snode` address to the blacklist.",
});
#ifdef LOKINET_EXITS
def.addOptionComments(
"example-snapp",
"endpoint",
"exit-node",
{
"Specify a `.snode` or `.loki` address to use as an exit broker.",
});
// TODO: merge with client conf?
def.addOptionComments(
"example-snapp",
"local-dns",
{
"Address to bind local DNS resolver to. Ex: `127.3.2.1:53`. Iif port is omitted, port",
});
def.addOptionComments(
"example-snapp",
"upstream-dns",
{
"Address to forward non-lokinet related queries to. If not set, lokinet DNS will reply",
"with `srvfail`.",
});
#endif
def.addOptionComments(
"example-snapp",
"endpoint",
"mapaddr",
{
"Permanently map a `.loki` address to an IP owned by the snapp. Example:",

@ -153,17 +153,15 @@ namespace llarp
struct EndpointConfig
{
std::string m_name;
std::string m_keyfile;
std::string m_endpointType;
bool m_reachable;
int m_hops;
int m_paths;
bool m_bundleRC;
std::set<RouterID> m_snodeBlacklist;
#ifdef LOKINET_EXITS
std::string m_exitNode;
std::string m_localDNS;
std::string m_upstreamDNS;
#endif
std::string m_mapAddr;
// TODO:
@ -186,7 +184,7 @@ namespace llarp
LokidConfig lokid;
BootstrapConfig bootstrap;
LoggingConfig logging;
std::unordered_map<std::string, EndpointConfig> snapps;
EndpointConfig endpoint;
// Initialize config definition
void

@ -10,8 +10,8 @@ namespace llarp
struct NullEndpoint final : public llarp::service::Endpoint,
public std::enable_shared_from_this<NullEndpoint>
{
NullEndpoint(const EndpointConfig& conf, AbstractRouter* r, llarp::service::Context* parent)
: llarp::service::Endpoint(conf, r, parent)
NullEndpoint(AbstractRouter* r, llarp::service::Context* parent)
: llarp::service::Endpoint(r, parent)
{
}

@ -49,11 +49,10 @@ namespace llarp
}
}
TunEndpoint::TunEndpoint(
const EndpointConfig& conf, AbstractRouter* r, service::Context* parent, bool lazyVPN)
: service::Endpoint(conf, r, parent)
, m_UserToNetworkPktQueue(conf.m_name + "_sendq", r->netloop(), r->netloop())
, m_NetworkToUserPktQueue(conf.m_name + "_recvq", r->netloop(), r->netloop())
TunEndpoint::TunEndpoint(AbstractRouter* r, service::Context* parent, bool lazyVPN)
: service::Endpoint(r, parent)
, m_UserToNetworkPktQueue("endpoint_sendq", r->netloop(), r->netloop())
, m_NetworkToUserPktQueue("endpoint_recvq", r->netloop(), r->netloop())
, m_Resolver(std::make_shared<dns::Proxy>(
r->netloop(), r->logic(), r->netloop(), r->logic(), this))
{

@ -21,7 +21,6 @@ namespace llarp
public std::enable_shared_from_this<TunEndpoint>
{
TunEndpoint(
const EndpointConfig& conf,
AbstractRouter* r,
llarp::service::Context* parent,
bool lazyVPN = false);

@ -575,24 +575,7 @@ namespace llarp
enableRPCServer = conf->api.m_enableRPCServer;
rpcBindAddr = conf->api.m_rpcBindAddr;
// create endpoint
// TODO: ensure that preconditions are met, e.g. net ifname/ifaddr/etc is sane
if (conf->snapps.size() > 1)
{
// TODO: refactor config to only allow one
throw std::runtime_error("Only one endpoint allowed (including SNApps");
}
else if (conf->snapps.size() == 1)
{
const auto itr = conf->snapps.begin();
const EndpointConfig& endpointConfig = itr->second;
hiddenServiceContext().AddEndpoint(endpointConfig, networkConfig);
}
else
{
// TODO: service context had logic that if keyfile was empty, reachable is false
hiddenServiceContext().AddEndpoint({}, networkConfig);
}
hiddenServiceContext().AddEndpoint(conf->endpoint);
// Logging config
LogContext::Instance().Initialize(

@ -13,25 +13,25 @@ namespace llarp
{
namespace
{
using EndpointConstructor = std::function<service::Endpoint_ptr(
const EndpointConfig&, AbstractRouter*, service::Context*)>;
using EndpointConstructor =
std::function<service::Endpoint_ptr(AbstractRouter*, service::Context*)>;
using EndpointConstructors = std::map<std::string, EndpointConstructor>;
static EndpointConstructors endpointConstructors = {
{"tun",
[](const EndpointConfig& conf, AbstractRouter* r, service::Context* c) {
return std::make_shared<handlers::TunEndpoint>(conf, r, c, false);
[](AbstractRouter* r, service::Context* c) {
return std::make_shared<handlers::TunEndpoint>(r, c, false);
}},
{"android",
[](const EndpointConfig& conf, AbstractRouter* r, service::Context* c) {
return std::make_shared<handlers::TunEndpoint>(conf, r, c, true);
[](AbstractRouter* r, service::Context* c) {
return std::make_shared<handlers::TunEndpoint>(r, c, true);
}},
{"ios",
[](const EndpointConfig& conf, AbstractRouter* r, service::Context* c) {
return std::make_shared<handlers::TunEndpoint>(conf, r, c, true);
[](AbstractRouter* r, service::Context* c) {
return std::make_shared<handlers::TunEndpoint>(r, c, true);
}},
{"null", [](const EndpointConfig& conf, AbstractRouter* r, service::Context* c) {
return std::make_shared<handlers::NullEndpoint>(conf, r, c);
{"null", [](AbstractRouter* r, service::Context* c) {
return std::make_shared<handlers::NullEndpoint>(r, c);
}}};
} // namespace
@ -172,30 +172,25 @@ namespace llarp
}
void
Context::AddEndpoint(
const EndpointConfig& conf, const NetworkConfig& networkConfig, bool autostart)
Context::AddEndpoint(const EndpointConfig& conf, bool autostart)
{
if (m_Endpoints.find(conf.m_name) != m_Endpoints.end())
throw std::invalid_argument(stringify("Snapp ", conf.m_name, " already exists"));
// TODO: refactor Context to only contain one endpoint
constexpr auto endpointName = "endpoint";
// use specified type, fall back to default
std::string endpointType = conf.m_name;
if (endpointType.empty())
endpointType = DefaultEndpointType();
if (m_Endpoints.find(endpointName) != m_Endpoints.end())
throw std::invalid_argument("service::Context only supports one endpoint now");
// TODO: make endpoint type configurable [again]
std::string endpointType = DefaultEndpointType();
// use factory to create endpoint
const auto itr = endpointConstructors.find(endpointType);
const auto itr = endpointConstructors.find(DefaultEndpointType());
if (itr == endpointConstructors.end())
throw std::invalid_argument(stringify("Endpoint type ", endpointType, " does not exist"));
auto service = itr->second(conf, m_Router, this);
auto service = itr->second(m_Router, this);
if (not service)
throw std::runtime_error(stringify(
"Failed to create endpoint service for ",
conf.m_name,
"(type: ",
conf.m_endpointType,
")"));
throw std::runtime_error(stringify("Failed to construct endpoint of type ", endpointType));
// pass conf to service
service->Configure(conf);
@ -203,21 +198,13 @@ namespace llarp
// autostart if requested
if (autostart)
{
// start
if (service->Start())
{
LogInfo("autostarting hidden service endpoint ", service->Name());
m_Endpoints.emplace(conf.m_name, service);
}
else
{
throw std::runtime_error(
stringify("failed to start hidden service endpoint ", conf.m_name));
}
throw std::runtime_error("failed to start hidden service endpoint");
}
LogInfo("added hidden service endpoint ", service->Name());
m_Endpoints.emplace(conf.m_name, service);
m_Endpoints.emplace(endpointName, service);
}
} // namespace service
} // namespace llarp

@ -13,6 +13,8 @@ namespace llarp
namespace service
{
/// holds all the hidden service endpoints we own
/// TODO: this should be refactored (removed entirely...?) now that lokinet
/// only supports one endpoint per instance
struct Context
{
explicit Context(AbstractRouter* r);
@ -37,8 +39,7 @@ namespace llarp
/// add endpoint via config
void
AddEndpoint(
const EndpointConfig& conf, const NetworkConfig& networkConfig, bool autostart = false);
AddEndpoint(const EndpointConfig& conf, bool autostart = false);
/// inject endpoint instance
void

@ -33,12 +33,12 @@ namespace llarp
{
namespace service
{
Endpoint::Endpoint(const EndpointConfig& conf, AbstractRouter* r, Context* parent)
Endpoint::Endpoint(AbstractRouter* r, Context* parent)
: path::Builder(r, 3, path::default_len), context(parent), m_RecvQueue(128)
{
m_state = std::make_unique<EndpointState>();
m_state->m_Router = r;
m_state->m_Name = conf.m_name;
m_state->m_Name = "endpoint";
m_RecvQueue.enable();
}
@ -635,12 +635,6 @@ namespace llarp
[](const exit::BaseSession_ptr& ptr) -> RouterID { return ptr->Endpoint(); });
}
bool
Endpoint::ShouldBundleRC() const
{
return m_state->m_BundleRC;
}
void
Endpoint::PutNewOutboundContext(const service::IntroSet& introset)
{

@ -69,7 +69,7 @@ namespace llarp
{
static const size_t MAX_OUTBOUND_CONTEXT_COUNT = 4;
Endpoint(const EndpointConfig& conf, AbstractRouter* r, Context* parent);
Endpoint(AbstractRouter* r, Context* parent);
~Endpoint() override;
/// return true if we are ready to recv packets from the void
@ -256,7 +256,10 @@ namespace llarp
MarkAddressOutbound(const Address&) override;
bool
ShouldBundleRC() const override;
ShouldBundleRC() const
{
return false;
}
/// return true if we have a convotag as an exit session
/// or as a hidden service session

@ -14,7 +14,6 @@ namespace llarp
EndpointState::Configure(const EndpointConfig& conf)
{
m_Keyfile = conf.m_keyfile;
m_BundleRC = conf.m_bundleRC;
m_SnodeBlacklist = conf.m_snodeBlacklist;
// TODO:

@ -52,7 +52,6 @@ namespace llarp
std::string m_Keyfile;
std::string m_Name;
std::string m_NetNS;
bool m_BundleRC = false;
util::Mutex m_SendQueueMutex; // protects m_SendQueue
std::deque<SendEvent_t> m_SendQueue GUARDED_BY(m_SendQueueMutex);

Loading…
Cancel
Save