Merge pull request #255 from neuroscr/master

downgrade DNS server failure to a warning, autodetection delay, and don't create config if explicitly and no options
pull/248/head^2
Ryan Tharp 6 years ago committed by GitHub
commit ff7dd54028
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -6,6 +6,7 @@
#include <getopt.h> #include <getopt.h>
#include <signal.h> #include <signal.h>
#include <wordexp.h>
#include <string> #include <string>
#include <iostream> #include <iostream>
@ -56,6 +57,22 @@ handle_signal_win32(DWORD fdwCtrlType)
} }
#endif #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 int
main(int argc, char *argv[]) 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) if(optind < argc)
{ {
@ -116,15 +133,33 @@ main(int argc, char *argv[])
fs::path fname = fs::path(argv[optind]); fs::path fname = fs::path(argv[optind]);
fs::path basedir = fname.parent_path(); fs::path basedir = fname.parent_path();
conffname = fname.string(); conffname = fname.string();
conffname = resolvePath(conffname);
std::error_code ec;
// llarp::LogDebug("Basedir: ", basedir);
if(basedir.string().empty()) if(basedir.string().empty())
{ {
if(!llarp_ensure_config(fname.string().c_str(), nullptr, overWrite, // relative path to config
asRouter))
return 1; // 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 else
{ {
std::error_code ec; // absolute path to config
if(!fs::create_directories(basedir, ec)) if(!fs::create_directories(basedir, ec))
{ {
if(ec) if(ec)
@ -134,9 +169,22 @@ main(int argc, char *argv[])
return 1; return 1;
} }
} }
if(!llarp_ensure_config(fname.string().c_str(), basedir.string().c_str(), if(genconfigOnly)
overWrite, asRouter)) {
return 1; // 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 else
@ -149,6 +197,8 @@ main(int argc, char *argv[])
#endif #endif
fs::path basepath = homedir / fs::path(".lokinet"); fs::path basepath = homedir / fs::path(".lokinet");
fs::path fpath = basepath / "lokinet.ini"; 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()); llarp::LogDebug("Find or create ", basepath.string());
std::error_code ec; 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(), if(!llarp_ensure_config(fpath.string().c_str(), basepath.string().c_str(),
overWrite, asRouter)) overWrite, asRouter))
return 1; return 1;
@ -176,6 +227,7 @@ main(int argc, char *argv[])
} }
// this is important, can downgrade from Info though // this is important, can downgrade from Info though
llarp::LogInfo("Running from: ", cpp17::filesystem::current_path());
llarp::LogInfo("Using config file: ", conffname); llarp::LogInfo("Using config file: ", conffname);
ctx = llarp_main_init(conffname.c_str(), multiThreaded); ctx = llarp_main_init(conffname.c_str(), multiThreaded);
int code = 1; int code = 1;

@ -476,8 +476,9 @@ namespace llarp
} }
if(!m_Resolver.Start(m_LocalResolverAddr, m_UpstreamResolvers)) if(!m_Resolver.Start(m_LocalResolverAddr, m_UpstreamResolvers))
{ {
llarp::LogError(Name(), " failed to start dns server"); // downgrade DNS server failure to a warning
return false; llarp::LogWarn(Name(), " failed to start dns server");
// return false;
} }
return true; return true;
} }

@ -196,7 +196,7 @@ namespace llarp
Router::OnSessionEstablished(llarp::RouterContact rc) Router::OnSessionEstablished(llarp::RouterContact rc)
{ {
async_verify_RC(rc, nullptr); 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, Router::Router(struct llarp_threadpool *_tp, struct llarp_ev_loop *_netloop,
@ -1407,11 +1407,13 @@ namespace llarp
{ {
// fallback defaults // fallback defaults
// To NeuroScr: why run findFree* here instead of in tun.cpp? // 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, static const std::unordered_map< std::string,
std::function< std::string(void) > > std::function< std::string(void) > >
netConfigDefaults = { netConfigDefaults = {
{"ifname", llarp::findFreeLokiTunIfName}, {"ifname", []() -> std::string { return "auto"; }},
{"ifaddr", llarp::findFreePrivateRange}, {"ifaddr", []() -> std::string { return "auto"; }},
{"local-dns", []() -> std::string { return "127.0.0.1:53"; }}, {"local-dns", []() -> std::string { return "127.0.0.1:53"; }},
{"upstream-dns", []() -> std::string { return "1.1.1.1:53"; }}}; {"upstream-dns", []() -> std::string { return "1.1.1.1:53"; }}};
// populate with fallback defaults if values not present // populate with fallback defaults if values not present
@ -1607,6 +1609,7 @@ namespace llarp
else if(StrEq(section, "connect") else if(StrEq(section, "connect")
|| (StrEq(section, "bootstrap") && StrEq(key, "add-node"))) || (StrEq(section, "bootstrap") && StrEq(key, "add-node")))
{ {
//llarp::LogDebug("connect section has ", key, "=", val);
self->bootstrapRCList.emplace_back(); self->bootstrapRCList.emplace_back();
auto &rc = self->bootstrapRCList.back(); auto &rc = self->bootstrapRCList.back();
if(!rc.Read(val)) if(!rc.Read(val))

Loading…
Cancel
Save