From aaeb035033c4912a02c164ed8c94b4ad7c7018e2 Mon Sep 17 00:00:00 2001 From: Ryan Tharp Date: Thu, 20 Sep 2018 12:35:29 +0000 Subject: [PATCH] getRange() and getFirstTun() refactor start --- include/llarp/service/context.hpp | 9 +++++++++ llarp/service/context.cpp | 29 ++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/include/llarp/service/context.hpp b/include/llarp/service/context.hpp index 752438125..6d6cf2512 100644 --- a/include/llarp/service/context.hpp +++ b/include/llarp/service/context.hpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace llarp { @@ -18,6 +19,14 @@ namespace llarp void Tick(); + /// DRY refactor + llarp::handlers::TunEndpoint * + getFirstTun(); + + /// punch a hole to get ip range from first tun endpoint + llarp_tun_io * + getRange(); + /// punch a hole open for DNS to add mappings bool MapAddress(const llarp::service::Address &addr, uint32_t ip); diff --git a/llarp/service/context.cpp b/llarp/service/context.cpp index 33981c788..ceb46bfc2 100644 --- a/llarp/service/context.cpp +++ b/llarp/service/context.cpp @@ -29,7 +29,34 @@ namespace llarp ++itr; } } - + + llarp::handlers::TunEndpoint * + Context::getFirstTun() + { + if (!m_Endpoints.size()) + { + llarp::LogError("No endpoints found"); + return nullptr; + } + auto firstEndpoint = m_Endpoints.begin(); + auto *uniqueEndpoint = &firstEndpoint->second; + llarp::service::Endpoint *endpointer = uniqueEndpoint->get(); + llarp::handlers::TunEndpoint *tunEndpoint = dynamic_cast(endpointer); + return tunEndpoint; + } + + llarp_tun_io * + Context::getRange() + { + llarp::handlers::TunEndpoint *tunEndpoint = this->getFirstTun(); + if (!tunEndpoint) + { + llarp::LogError("No tunnel endpoint found"); + return nullptr; + } + return &tunEndpoint->tunif; + } + bool Context::MapAddress(const llarp::service::Address &addr, uint32_t ip) {