Jeff approved workaround to read Keyfile early so Name() can be correct during set up/configuration

pull/230/head
Ryan Tharp 5 years ago
parent dc1bd9acb4
commit c24751f3c1

@ -261,10 +261,13 @@ namespace llarp
}
// extract type
std::string endpointType = "tun";
std::string keyfile = "";
for(const auto &option : conf.second)
{
if(option.first == "type")
endpointType = option.second;
if(option.first == "keyfile")
keyfile = option.second;
}
std::unique_ptr< llarp::service::Endpoint > service;
@ -294,6 +297,14 @@ namespace llarp
// construct
service.reset(itr->second(conf.first, m_Router));
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");
}
}
// configure
for(const auto &option : conf.second)

@ -486,18 +486,28 @@ namespace llarp
}
bool
Endpoint::Start()
Endpoint::LoadKeyFile()
{
auto crypto = &m_Router->crypto;
if(m_Keyfile.size())
{
if(!m_Identity.EnsureKeys(m_Keyfile, crypto))
{
llarp::LogWarn("Can't ensure keyfile [", m_Keyfile, "]");
return false;
}
}
else
{
m_Identity.RegenerateKeys(crypto);
}
return true;
}
bool
Endpoint::Start()
{
this->LoadKeyFile();
if(!m_DataHandler)
{
m_DataHandler = this;
@ -508,7 +518,10 @@ namespace llarp
if(m_OnInit.front()())
m_OnInit.pop_front();
else
{
llarp::LogWarn("Can't call init of network isolation");
return false;
}
}
return true;
}

@ -72,6 +72,9 @@ namespace llarp
return m_Router;
}
virtual bool
LoadKeyFile();
virtual bool
Start();

Loading…
Cancel
Save