1
1
Fork 0
mirror of https://github.com/oxen-io/lokinet synced 2023-12-14 06:53:00 +01:00

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

This commit is contained in:
Ryan Tharp 2019-01-16 13:12:24 -08:00
parent dc1bd9acb4
commit c24751f3c1
3 changed files with 28 additions and 1 deletions

View file

@ -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)

View file

@ -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;
}

View file

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