mirror of https://github.com/oxen-io/lokinet
publish hidden service descriptors and acknoledge publish
parent
980db97145
commit
bae4f746be
@ -0,0 +1,23 @@
|
||||
#ifndef LLARP_SERVICE_CONFIG_HPP
|
||||
#define LLARP_SERVICE_CONFIG_HPP
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace service
|
||||
{
|
||||
struct Config
|
||||
{
|
||||
typedef std::list< std::pair< std::string, std::string > >
|
||||
section_values_t;
|
||||
typedef std::pair< std::string, section_values_t > section_t;
|
||||
|
||||
std::list< section_t > services;
|
||||
|
||||
bool
|
||||
Load(const std::string& fname);
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
@ -0,0 +1,30 @@
|
||||
#ifndef LLARP_SERVICE_CONTEXT_HPP
|
||||
#define LLARP_SERVICE_CONTEXT_HPP
|
||||
#include <llarp/router.h>
|
||||
#include <llarp/service/config.hpp>
|
||||
#include <llarp/service/endpoint.hpp>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace service
|
||||
{
|
||||
/// holds all the hidden service endpoints we own
|
||||
struct Context
|
||||
{
|
||||
Context(llarp_router *r);
|
||||
~Context();
|
||||
|
||||
void
|
||||
Tick();
|
||||
|
||||
bool
|
||||
AddEndpoint(const Config::section_t &conf);
|
||||
|
||||
private:
|
||||
llarp_router *m_Router;
|
||||
std::unordered_map< std::string, Endpoint * > m_Endpoints;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
@ -0,0 +1,64 @@
|
||||
#include <llarp/service/context.hpp>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace service
|
||||
{
|
||||
Context::Context(llarp_router *r) : m_Router(r)
|
||||
{
|
||||
}
|
||||
|
||||
Context::~Context()
|
||||
{
|
||||
auto itr = m_Endpoints.begin();
|
||||
while(itr != m_Endpoints.end())
|
||||
{
|
||||
delete itr->second;
|
||||
itr = m_Endpoints.erase(itr);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Context::Tick()
|
||||
{
|
||||
auto itr = m_Endpoints.begin();
|
||||
while(itr != m_Endpoints.end())
|
||||
{
|
||||
itr->second->Tick();
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
|
||||
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 service = new llarp::service::Endpoint(conf.first, m_Router);
|
||||
for(const auto &option : conf.second)
|
||||
{
|
||||
auto &k = option.first;
|
||||
auto &v = option.second;
|
||||
if(!service->SetOption(k, v))
|
||||
{
|
||||
delete service;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(service->Start())
|
||||
{
|
||||
llarp::LogInfo("added hidden service endpoint ", conf.first);
|
||||
m_Endpoints.emplace(conf.first, service);
|
||||
return true;
|
||||
}
|
||||
llarp::LogError("failed to start hidden service endpoint ", conf.first);
|
||||
delete service;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,101 @@
|
||||
#include <llarp/service/endpoint.hpp>
|
||||
#include "router.hpp"
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace service
|
||||
{
|
||||
Endpoint::Endpoint(const std::string& name, llarp_router* r)
|
||||
: llarp_pathbuilder_context(r, r->dht), m_Router(r), m_Name(name)
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
Endpoint::SetOption(const std::string& k, const std::string& v)
|
||||
{
|
||||
if(k == "keyfile")
|
||||
{
|
||||
m_Keyfile = v;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
Endpoint::Tick()
|
||||
{
|
||||
if(ShouldPublishDescriptors())
|
||||
{
|
||||
llarp::LogDebug("publish descriptor for endpoint ", m_Name);
|
||||
IntroSet introset;
|
||||
if(!GetCurrentIntroductions(introset.I))
|
||||
{
|
||||
llarp::LogWarn("could not publish descriptors for endpoint ", m_Name,
|
||||
" because we couldn't get any introductions");
|
||||
return;
|
||||
}
|
||||
if(!m_Identity.SignIntroSet(introset, &m_Router->crypto))
|
||||
{
|
||||
llarp::LogWarn("failed to sign introset for endpoint ", m_Name);
|
||||
return;
|
||||
}
|
||||
if(PublishIntroSet(introset, m_Router))
|
||||
{
|
||||
llarp::LogInfo("publishing introset for endpoint ", m_Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
llarp::LogWarn("failed to publish intro set for endpoint ", m_Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
Endpoint::HandleGotIntroMessage(const llarp::dht::GotIntroMessage* msg)
|
||||
{
|
||||
auto crypto = &m_Router->crypto;
|
||||
for(const auto& introset : msg->I)
|
||||
{
|
||||
if(!introset.VerifySignature(crypto))
|
||||
{
|
||||
llarp::LogWarn(
|
||||
"invalid signature in got intro message for service endpoint ",
|
||||
m_Name);
|
||||
return false;
|
||||
}
|
||||
if(m_Identity.pub == introset.A)
|
||||
{
|
||||
llarp::LogInfo(
|
||||
"got introset publish confirmation for hidden service endpoint ",
|
||||
m_Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
/// TODO: implement lookup response
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
Endpoint::Start()
|
||||
{
|
||||
auto crypto = &m_Router->crypto;
|
||||
if(m_Keyfile.size())
|
||||
{
|
||||
if(!m_Identity.EnsureKeys(m_Keyfile, crypto))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Identity.RegenerateKeys(crypto);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Endpoint::~Endpoint()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue