From 9b6008db1d3ea8cd1f52785b48aae72c34283af3 Mon Sep 17 00:00:00 2001 From: Ryan Tharp Date: Tue, 29 Jan 2019 03:17:21 -0800 Subject: [PATCH 1/4] downgrade DNS server failure to a warning --- llarp/handlers/tun.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/llarp/handlers/tun.cpp b/llarp/handlers/tun.cpp index c585a19e3..6a7ca7afa 100644 --- a/llarp/handlers/tun.cpp +++ b/llarp/handlers/tun.cpp @@ -476,8 +476,9 @@ namespace llarp } if(!m_Resolver.Start(m_LocalResolverAddr, m_UpstreamResolvers)) { - llarp::LogError(Name(), " failed to start dns server"); - return false; + // downgrade DNS server failure to a warning + llarp::LogWarn(Name(), " failed to start dns server"); + // return false; } return true; } From 2ac41a226f2c27f26f8985fe1b335b00697a61f2 Mon Sep 17 00:00:00 2001 From: Ryan Tharp Date: Tue, 29 Jan 2019 03:23:10 -0800 Subject: [PATCH 2/4] delay autodetection to ev --- llarp/router/router.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index 7ecfa628a..ec5910eca 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -1407,11 +1407,13 @@ namespace llarp { // fallback defaults // To NeuroScr: why run findFree* here instead of in tun.cpp? + // I think it should be in tun.cpp, better to closer to time of usage + // that way new tun may have grab a range we may have also grabbed here static const std::unordered_map< std::string, std::function< std::string(void) > > netConfigDefaults = { - {"ifname", llarp::findFreeLokiTunIfName}, - {"ifaddr", llarp::findFreePrivateRange}, + {"ifname", []() -> std::string { return "auto"; }}, + {"ifaddr", []() -> std::string { return "auto"; }}, {"local-dns", []() -> std::string { return "127.0.0.1:53"; }}, {"upstream-dns", []() -> std::string { return "1.1.1.1:53"; }}}; // populate with fallback defaults if values not present @@ -1607,6 +1609,7 @@ namespace llarp else if(StrEq(section, "connect") || (StrEq(section, "bootstrap") && StrEq(key, "add-node"))) { + //llarp::LogDebug("connect section has ", key, "=", val); self->bootstrapRCList.emplace_back(); auto &rc = self->bootstrapRCList.back(); if(!rc.Read(val)) From befcdc179e497b5ed61ca5621afd26b3263603e4 Mon Sep 17 00:00:00 2001 From: Ryan Tharp Date: Tue, 29 Jan 2019 03:23:40 -0800 Subject: [PATCH 3/4] address #251 and improve UX --- daemon/main.cpp | 68 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 8 deletions(-) diff --git a/daemon/main.cpp b/daemon/main.cpp index feb5f773a..b2dae2afa 100644 --- a/daemon/main.cpp +++ b/daemon/main.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -56,6 +57,22 @@ handle_signal_win32(DWORD fdwCtrlType) } #endif +/// resolve ~ and symlinks into actual paths (so we know the real path on disk, +/// to remove assumptions and confusion with permissions) +std::string +resolvePath(std::string conffname) +{ + wordexp_t exp_result; + wordexp(conffname.c_str(), &exp_result, 0); + char *resolvedPath = realpath(exp_result.we_wordv[0], NULL); + if(!resolvedPath) + { + llarp::LogWarn("Can't resolve path: ", exp_result.we_wordv[0]); + return ""; + } + return resolvedPath; +} + int main(int argc, char *argv[]) { @@ -108,7 +125,7 @@ main(int argc, char *argv[]) } } - std::string conffname; + std::string conffname; // suggestions: confFName? conf_fname? if(optind < argc) { @@ -116,15 +133,33 @@ main(int argc, char *argv[]) fs::path fname = fs::path(argv[optind]); fs::path basedir = fname.parent_path(); conffname = fname.string(); + conffname = resolvePath(conffname); + std::error_code ec; + + // llarp::LogDebug("Basedir: ", basedir); if(basedir.string().empty()) { - if(!llarp_ensure_config(fname.string().c_str(), nullptr, overWrite, - asRouter)) - return 1; + // relative path to config + + // does this file exist? + if(genconfigOnly) + { + if(!llarp_ensure_config(conffname.c_str(), nullptr, overWrite, + asRouter)) + return 1; + } + else + { + if(!fs::exists(fname, ec)) + { + llarp::LogError("Config file not found ", conffname); + return 1; + } + } } else { - std::error_code ec; + // absolute path to config if(!fs::create_directories(basedir, ec)) { if(ec) @@ -134,9 +169,22 @@ main(int argc, char *argv[]) return 1; } } - if(!llarp_ensure_config(fname.string().c_str(), basedir.string().c_str(), - overWrite, asRouter)) - return 1; + if(genconfigOnly) + { + // find or create file + if(!llarp_ensure_config(conffname.c_str(), basedir.string().c_str(), + overWrite, asRouter)) + return 1; + } + else + { + // does this file exist? + if(!fs::exists(conffname, ec)) + { + llarp::LogError("Config file not found ", conffname); + return 1; + } + } } } else @@ -149,6 +197,8 @@ main(int argc, char *argv[]) #endif fs::path basepath = homedir / fs::path(".lokinet"); fs::path fpath = basepath / "lokinet.ini"; + // I don't think this is necessary with this condition + // conffname = resolvePath(conffname); llarp::LogDebug("Find or create ", basepath.string()); std::error_code ec; @@ -164,6 +214,7 @@ main(int argc, char *argv[]) } } + // if using default INI file, we're create it even if you don't ask us too if(!llarp_ensure_config(fpath.string().c_str(), basepath.string().c_str(), overWrite, asRouter)) return 1; @@ -176,6 +227,7 @@ main(int argc, char *argv[]) } // this is important, can downgrade from Info though + llarp::LogInfo("Running from: ", cpp17::filesystem::current_path()); llarp::LogInfo("Using config file: ", conffname); ctx = llarp_main_init(conffname.c_str(), multiThreaded); int code = 1; From e94a7b88e75eb3a495164398652e2fa770794344 Mon Sep 17 00:00:00 2001 From: Ryan Tharp Date: Tue, 29 Jan 2019 03:49:02 -0800 Subject: [PATCH 4/4] fix typo in log message --- llarp/router/router.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index ec5910eca..4ebf82342 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -196,7 +196,7 @@ namespace llarp Router::OnSessionEstablished(llarp::RouterContact rc) { async_verify_RC(rc, nullptr); - llarp::LogInfo("session with ", rc.pubkey, "established"); + llarp::LogInfo("session with ", rc.pubkey, " established"); } Router::Router(struct llarp_threadpool *_tp, struct llarp_ev_loop *_netloop,