|
|
|
@ -33,19 +33,58 @@ namespace llarp
|
|
|
|
|
bool
|
|
|
|
|
Context::AddEndpoint(const Config::section_t &conf)
|
|
|
|
|
{
|
|
|
|
|
auto itr = m_Endpoints.find(conf.first);
|
|
|
|
|
if(itr != m_Endpoints.end())
|
|
|
|
|
{
|
|
|
|
|
llarp::LogError("cannot add hidden service with duplicate name: ",
|
|
|
|
|
conf.first);
|
|
|
|
|
return false;
|
|
|
|
|
auto itr = m_Endpoints.find(conf.first);
|
|
|
|
|
if(itr != m_Endpoints.end())
|
|
|
|
|
{
|
|
|
|
|
llarp::LogError("cannot add hidden service with duplicate name: ",
|
|
|
|
|
conf.first);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// extract type
|
|
|
|
|
std::string endpointType = "tun";
|
|
|
|
|
for(const auto &option : conf.second)
|
|
|
|
|
{
|
|
|
|
|
if(option.first == "type")
|
|
|
|
|
endpointType = option.second;
|
|
|
|
|
}
|
|
|
|
|
std::unique_ptr< llarp::service::Endpoint > service;
|
|
|
|
|
|
|
|
|
|
static std::map< std::string,
|
|
|
|
|
std::function< llarp::service::Endpoint *(
|
|
|
|
|
const std::string &, llarp_router *) > >
|
|
|
|
|
endpointConstructors = {
|
|
|
|
|
{"tun",
|
|
|
|
|
[](const std::string &nick,
|
|
|
|
|
llarp_router *r) -> llarp::service::Endpoint * {
|
|
|
|
|
return new llarp::handlers::TunEndpoint(nick, r);
|
|
|
|
|
}},
|
|
|
|
|
{"null",
|
|
|
|
|
[](const std::string &nick,
|
|
|
|
|
llarp_router *r) -> llarp::service::Endpoint * {
|
|
|
|
|
return new llarp::service::Endpoint(nick, r);
|
|
|
|
|
}}};
|
|
|
|
|
|
|
|
|
|
std::unique_ptr< llarp::service::Endpoint > service(
|
|
|
|
|
new llarp::handlers::TunEndpoint(conf.first, m_Router));
|
|
|
|
|
{
|
|
|
|
|
// detect type
|
|
|
|
|
auto itr = endpointConstructors.find(endpointType);
|
|
|
|
|
if(itr == endpointConstructors.end())
|
|
|
|
|
{
|
|
|
|
|
llarp::LogError("no such endpoint type: ", endpointType);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// construct
|
|
|
|
|
service = std::unique_ptr< llarp::service::Endpoint >(
|
|
|
|
|
itr->second(conf.first, m_Router));
|
|
|
|
|
}
|
|
|
|
|
// configure
|
|
|
|
|
for(const auto &option : conf.second)
|
|
|
|
|
{
|
|
|
|
|
auto &k = option.first;
|
|
|
|
|
if(k == "type")
|
|
|
|
|
continue;
|
|
|
|
|
auto &v = option.second;
|
|
|
|
|
if(!service->SetOption(k, v))
|
|
|
|
|
{
|
|
|
|
@ -54,6 +93,7 @@ namespace llarp
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// start
|
|
|
|
|
if(service->Start())
|
|
|
|
|
{
|
|
|
|
|
llarp::LogInfo("added hidden service endpoint ", service->Name());
|
|
|
|
|