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; 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; } diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index 7ecfa628a..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, @@ -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))