From c4c9197586963983f1e1f7fad123d6fdc859e565 Mon Sep 17 00:00:00 2001 From: Ryan Tharp Date: Thu, 17 Jan 2019 13:15:40 -0800 Subject: [PATCH 1/3] address Michael's code review (remove std::make_pair) and add note --- llarp/router/router.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index f9fefae6a..3d6e5c554 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -1182,10 +1182,10 @@ namespace llarp if(hiddenServiceContext.hasEndpoints()) { llarp::LogInfo("Auto mode detected and we have endpoints"); - netConfig.emplace(std::make_pair("enabled", "false")); + netConfig.emplace("enabled", "false"); return false; } - netConfig.emplace(std::make_pair("enabled", "true")); + netConfig.emplace("enabled", "true"); } // ev.cpp llarp_ev_add_tun now handles this /* @@ -1388,6 +1388,7 @@ namespace llarp Router::CreateDefaultHiddenService() { // fallback defaults + // To NeuroScr: why run findFree* here instead of in tun.cpp? static const std::unordered_map< std::string, std::function< std::string(void) > > netConfigDefaults = { From 332336060ceca56e06edcec9f62647c43c92f62c Mon Sep 17 00:00:00 2001 From: Ryan Tharp Date: Thu, 17 Jan 2019 18:28:30 -0800 Subject: [PATCH 2/3] Always have a key early (even if no key file set) so you don't regen keys twice --- llarp/service/context.cpp | 9 ++++++--- llarp/service/endpoint.cpp | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/llarp/service/context.cpp b/llarp/service/context.cpp index ba7dc3f00..243346ec9 100644 --- a/llarp/service/context.cpp +++ b/llarp/service/context.cpp @@ -298,14 +298,17 @@ namespace llarp // construct service.reset(itr->second(conf.first, m_Router)); + + // if ephemeral, then we need to regen key + // if privkey file, then set it and load it if(keyfile != "") { - llarp::LogInfo("Found keyfile, prestarting endpoint"); service->SetOption("keyfile", keyfile); // load keyfile, so we have the correct name for logging - service->LoadKeyFile(); // only start endpoint not tun - llarp::LogInfo("Endpoint prestarted"); } + llarp::LogInfo("Establishing endpoint identity"); + service->LoadKeyFile(); // only start endpoint not tun + // now Name() will be correct } // configure for(const auto &option : conf.second) diff --git a/llarp/service/endpoint.cpp b/llarp/service/endpoint.cpp index 2470555d4..496e6e237 100644 --- a/llarp/service/endpoint.cpp +++ b/llarp/service/endpoint.cpp @@ -507,7 +507,8 @@ namespace llarp bool Endpoint::Start() { - this->LoadKeyFile(); + // how can I tell if a m_Identity isn't loaded? + //this->LoadKeyFile(); if(!m_DataHandler) { m_DataHandler = this; From 947d702b3b87e508bc2f4a6bdd978b76527f774e Mon Sep 17 00:00:00 2001 From: Ryan Tharp Date: Thu, 17 Jan 2019 18:33:55 -0800 Subject: [PATCH 3/3] refactor out strcpy --- llarp/ev/ev.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/llarp/ev/ev.cpp b/llarp/ev/ev.cpp index ccc9831c0..dc20eb910 100644 --- a/llarp/ev/ev.cpp +++ b/llarp/ev/ev.cpp @@ -151,7 +151,6 @@ llarp_ev_add_tun(struct llarp_ev_loop *loop, struct llarp_tun_io *tun) if(strcmp(tun->ifaddr, "") == 0 || strcmp(tun->ifaddr, "auto")) { std::string ifaddr = llarp::findFreePrivateRange(); - std::string addr; auto pos = ifaddr.find("/"); if(pos == std::string::npos) { @@ -171,13 +170,14 @@ llarp_ev_add_tun(struct llarp_ev_loop *loop, struct llarp_tun_io *tun) return false; } tun->netmask = num; - addr = ifaddr.substr(0, pos); - strcpy(tun->ifaddr, addr.c_str()); + const std::string addr = ifaddr.substr(0, pos); + std::copy_n(addr.begin(), std::min(sizeof(tun->ifaddr), addr.size()), tun->ifaddr); llarp::LogInfo("IfAddr autodetect: ", tun->ifaddr, "/", tun->netmask); } if(strcmp(tun->ifname, "") == 0 || strcmp(tun->ifname, "auto")) { - strcpy(tun->ifname, llarp::findFreeLokiTunIfName().c_str()); + std::string ifname = llarp::findFreeLokiTunIfName(); + std::copy_n(ifname.begin(), std::min(sizeof(tun->ifname), ifname.size()), tun->ifname); llarp::LogInfo("IfName autodetect: ", tun->ifname); } llarp::LogDebug("Tun Interface will use the following settings:");