Demystify LinksConfig

pull/1186/head
Stephen Shelton 4 years ago
parent cd1e7713de
commit 2e47262350
No known key found for this signature in database
GPG Key ID: EE4BADACCE8B631C

@ -142,24 +142,23 @@ namespace llarp
class LinksConfig
{
public:
static constexpr int Interface = 0;
static constexpr int AddressFamily = 1;
static constexpr int Port = 2;
static constexpr int Options = 3;
using ServerOptions = std::unordered_set<std::string>;
using LinkInfo = std::tuple<std::string, int, uint16_t, ServerOptions>;
using Links = std::vector<LinkInfo>;
struct LinkInfo
{
std::string interface;
int addressFamily;
uint16_t port;
std::unordered_set<std::string> serverOptions;
};
public:
LinkInfo m_OutboundLink;
Links m_InboundLinks;
std::vector<LinkInfo> m_InboundLinks;
public:
// clang-format off
const LinkInfo& outboundLink() const { return m_OutboundLink; }
const Links& inboundLinks() const { return m_InboundLinks; }
const std::vector<LinkInfo>& inboundLinks() const { return m_InboundLinks; }
// clang-format on
void

@ -397,7 +397,7 @@ namespace llarp
}
// IWP config
m_OutboundPort = std::get<LinksConfig::Port>(conf->links.outboundLink());
m_OutboundPort = conf->links.outboundLink().port;
// Router config
_rc.SetNick(conf->router.nickname());
_outboundSessionMaker.maxConnectedRouters = conf->router.maxConnectedRouters();
@ -531,12 +531,12 @@ namespace llarp
}
// create inbound links, if we are a service node
for (const auto& serverConfig : conf->links.inboundLinks())
for(const LinksConfig::LinkInfo &serverConfig : conf->links.inboundLinks())
{
// get default factory
auto inboundLinkFactory = LinkFactory::Obtain(_defaultLinkType, true);
// for each option if provided ...
for (const auto& opt : std::get<LinksConfig::Options>(serverConfig))
for(const auto &opt : serverConfig.serverOptions)
{
// try interpreting it as a link type
const auto linktype = LinkFactory::TypeFromName(opt);
@ -563,11 +563,10 @@ namespace llarp
util::memFn(&AbstractRouter::SessionClosed, this),
util::memFn(&AbstractRouter::PumpLL, this));
const auto& key = std::get<LinksConfig::Interface>(serverConfig);
int af = std::get<LinksConfig::AddressFamily>(serverConfig);
uint16_t port = std::get<LinksConfig::Port>(serverConfig);
llarp::LogWarn("tun: ", key, " -- af: ", af, " -- port: ", port);
if (!server->Configure(netloop(), key, af, port))
const std::string& key = serverConfig.interface;
int af = serverConfig.addressFamily;
uint16_t port = serverConfig.port;
if(!server->Configure(netloop(), key, af, port))
{
LogError("failed to bind inbound link on ", key, " port ", port);
return false;

@ -96,10 +96,12 @@ ifaddr=10.101.0.1/16
}
{
using kv = LinksConfig::Links::value_type;
ASSERT_THAT(config.links.inboundLinks(),
UnorderedElementsAre(kv("eth0", AF_INET, 5501, {})));
const auto& links = config.links.inboundLinks();
ASSERT_EQ(links.size(), 1);
ASSERT_EQ(links[0].interface, "eth0");
ASSERT_EQ(links[0].addressFamily, AF_INET);
ASSERT_EQ(links[0].port, 5501);
ASSERT_TRUE(links[0].serverOptions.empty());
}
ASSERT_THAT(config.bootstrap.routers,

Loading…
Cancel
Save