Use fs::path over std::string for files

pull/1186/head
Stephen Shelton 4 years ago
parent 7ce256d846
commit 7ea8d62640
No known key found for this signature in database
GPG Key ID: EE4BADACCE8B631C

@ -90,7 +90,14 @@ namespace llarp
AssignmentAcceptor(m_nickname));
conf.defineOption<std::string>("router", "data-dir", false, GetDefaultDataDir(),
AssignmentAcceptor(m_dataDir));
[this](std::string arg) {
fs::path dir = arg;
if (not fs::exists(dir))
throw std::runtime_error(stringify(
"Specified [router]:data-dir ", arg, " does not exist"));
m_dataDir = std::move(dir);
});
conf.defineOption<std::string>("router", "public-address", false, "",
[this](std::string arg) {
@ -249,9 +256,13 @@ namespace llarp
conf.addUndeclaredHandler("connect", [this](string_view section,
string_view name,
string_view value) {
(void)section;
(void)name;
routers.emplace_back(value);
fs::path file = str(value);
if (not fs::exists(file))
throw std::runtime_error(stringify(
"Specified bootstrap file ", value,
"specified in [",section,"]:",name," does not exist"));
routers.emplace_back(std::move(file));
return true;
});
}

@ -39,7 +39,7 @@ namespace llarp
std::string m_netId;
std::string m_nickname;
std::string m_dataDir;
fs::path m_dataDir;
bool m_blockBogons;
@ -59,7 +59,7 @@ namespace llarp
struct NetworkConfig
{
nonstd::optional< bool > m_enableProfiling;
std::string m_routerProfilesFile = "profiles.dat";
std::string m_routerProfilesFile;
std::string m_strictConnect;
FreehandOptions m_options;
@ -105,7 +105,7 @@ namespace llarp
struct ConnectConfig
{
std::vector<std::string> routers;
std::vector<fs::path> routers;
void
defineConfigOptions(ConfigDefinition& conf, const ConfigGenParameters& params);

@ -395,9 +395,9 @@ namespace llarp
conf->router.m_maxConnectedRouters;
_outboundSessionMaker.minConnectedRouters =
conf->router.m_minConnectedRouters;
encryption_keyfile = conf->router.m_dataDir + "/encryption.key";
our_rc_file = conf->router.m_dataDir + "/rc.signed";
transport_keyfile = conf->router.m_dataDir + "/transport.key";
encryption_keyfile = conf->router.m_dataDir / "encryption.key";
our_rc_file = conf->router.m_dataDir / "rc.signed";
transport_keyfile = conf->router.m_dataDir / "transport.key";
addrInfo = conf->router.m_addrInfo;
publicOverride = conf->router.m_publicOverride;
ip4addr = conf->router.m_ip4addr;
@ -451,17 +451,16 @@ namespace llarp
llarp::LogError("invalid key for strict-connect: ", val);
}
llarp::LogWarn("Bootstrap routers list size: ", conf->bootstrap.routers.size());
std::vector<std::string> configRouters = conf->connect.routers;
configRouters.insert(
configRouters.end(), conf->bootstrap.routers.begin(), conf->bootstrap.routers.end());
std::vector<fs::path> configRouters = conf->connect.routers;
configRouters.insert(configRouters.end(), conf->bootstrap.routers.begin(),
conf->bootstrap.routers.end());
BootstrapList b_list;
for (const auto& router : configRouters)
{
bool isListFile = false;
{
std::ifstream inf(router, std::ios::binary);
if (inf.is_open())
std::ifstream inf(router.c_str(), std::ios::binary);
if(inf.is_open())
{
const char ch = inf.get();
isListFile = ch == 'l';
@ -517,7 +516,7 @@ namespace llarp
if (!usingSNSeed)
{
ident_keyfile = conf->router.m_dataDir + "/identity.key";
ident_keyfile = conf->router.m_dataDir / "identity.key";
}
// create inbound links, if we are a service node

Loading…
Cancel
Save