From e3bfe76f9857381bbae26e83ef8e594e92aecacd Mon Sep 17 00:00:00 2001 From: jeff Date: Thu, 27 Aug 2020 07:12:56 -0400 Subject: [PATCH] add exit auth token awareness to config --- llarp/config/config.cpp | 20 ++++++++++++++++++++ llarp/config/config.hpp | 1 + llarp/service/endpoint.cpp | 5 +++++ 3 files changed, 26 insertions(+) diff --git a/llarp/config/config.cpp b/llarp/config/config.cpp index 0f5c8a191..fe258904a 100644 --- a/llarp/config/config.cpp +++ b/llarp/config/config.cpp @@ -212,6 +212,26 @@ namespace llarp m_Paths = arg; }); + conf.defineOption("network", "exit-auth", false, "", [this](std::string arg) { + if (arg.empty()) + return; + service::Address exit; + service::AuthInfo auth; + const auto pos = arg.find(":"); + if (pos == std::string::npos) + { + throw std::invalid_argument( + "[network]:exit-auth invalid format, expects exit-address.loki:auth-code-goes-here"); + } + const auto exit_str = arg.substr(0, pos); + auth.token = arg.substr(pos + 1); + if (not exit.FromString(exit_str)) + { + throw std::invalid_argument("[network]:exit-auth invalid exit address"); + } + m_ExitAuths.emplace(exit, auth); + }); + conf.defineOption("network", "exit-node", false, "", [this](std::string arg) { if (arg.empty()) return; diff --git a/llarp/config/config.hpp b/llarp/config/config.hpp index 99e54df81..ae22cdd69 100644 --- a/llarp/config/config.hpp +++ b/llarp/config/config.hpp @@ -85,6 +85,7 @@ namespace llarp bool m_AllowExit = false; std::set m_snodeBlacklist; net::IPRangeMap m_ExitMap; + std::unordered_map m_ExitAuths; std::unordered_map m_mapAddrs; service::AuthType m_AuthType = service::AuthType::eAuthTypeNone; diff --git a/llarp/service/endpoint.cpp b/llarp/service/endpoint.cpp index 555de0348..9442e79af 100644 --- a/llarp/service/endpoint.cpp +++ b/llarp/service/endpoint.cpp @@ -54,6 +54,11 @@ namespace llarp conf.m_ExitMap.ForEachEntry( [&](const IPRange& range, const service::Address& addr) { MapExitRange(range, addr); }); + for (auto [exit, auth] : conf.m_ExitAuths) + { + SetAuthInfoForEndpoint(exit, auth); + } + return m_state->Configure(conf); }