You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lokinet/llarp/service/endpoint.cpp

125 lines
2.8 KiB
C++

#include <llarp/service/endpoint.hpp>
#include "router.hpp"
namespace llarp
{
namespace service
{
Endpoint::Endpoint(const std::string& name, llarp_router* r)
6 years ago
: llarp_pathbuilder_context(r, r->dht, 2), 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;
}
void
Endpoint::Tick()
{
if(ShouldPublishDescriptors())
{
6 years ago
if(!GetCurrentIntroductions(m_Introset.I))
{
6 years ago
llarp::LogWarn("could not publish descriptors for endpoint ", Name(),
" because we couldn't get any introductions");
return;
}
6 years ago
if(!m_Identity.SignIntroSet(m_Introset, &m_Router->crypto))
{
6 years ago
llarp::LogWarn("failed to sign introset for endpoint ", Name());
return;
}
6 years ago
if(PublishIntroSet(m_Router))
{
6 years ago
llarp::LogInfo("publishing introset for endpoint ", Name());
}
else
{
6 years ago
llarp::LogWarn("failed to publish intro set for endpoint ", Name());
}
}
}
6 years ago
std::string
Endpoint::Name() const
{
return m_Name + ":" + m_Identity.pub.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 ",
6 years ago
Name());
6 years ago
IntroSetPublishFail();
return false;
}
if(m_Identity.pub == introset.A)
{
llarp::LogInfo(
"got introset publish confirmation for hidden service endpoint ",
6 years ago
Name());
6 years ago
IntroSetPublished();
}
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()
{
}
6 years ago
Endpoint::OutboundContext::OutboundContext(Endpoint* parent)
: llarp_pathbuilder_context(parent->m_Router, parent->m_Router->dht, 2)
, m_Parent(parent)
{
}
Endpoint::OutboundContext::~OutboundContext()
{
}
bool
Endpoint::OutboundContext::HandleGotIntroMessage(
const llarp::dht::GotIntroMessage* msg)
{
// TODO: implement me
return false;
}
} // namespace service
6 years ago
} // namespace llarp