mirror of https://github.com/oxen-io/lokinet
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.
101 lines
2.6 KiB
C++
101 lines
2.6 KiB
C++
|
|
#include <llarp/dht/context.hpp>
|
|
#include <llarp/dht/messages/gotintro.hpp>
|
|
#include <llarp/messages/dht.hpp>
|
|
#include "router.hpp"
|
|
|
|
namespace llarp
|
|
{
|
|
namespace dht
|
|
{
|
|
GotIntroMessage::GotIntroMessage(uint64_t tx,
|
|
const llarp::service::IntroSet *i)
|
|
: IMessage({}), T(tx)
|
|
{
|
|
if(i)
|
|
{
|
|
I.push_back(*i);
|
|
}
|
|
}
|
|
|
|
GotIntroMessage::~GotIntroMessage()
|
|
{
|
|
}
|
|
|
|
bool
|
|
GotIntroMessage::HandleMessage(llarp_dht_context *ctx,
|
|
std::vector< IMessage * > &replies) const
|
|
{
|
|
auto &dht = ctx->impl;
|
|
auto crypto = &dht.router->crypto;
|
|
if(I.size() == 1)
|
|
{
|
|
const auto &introset = I.front();
|
|
if(!introset.VerifySignature(crypto))
|
|
{
|
|
llarp::LogWarn(
|
|
"Invalid introset signature while handling direct GotIntro from ",
|
|
From);
|
|
return false;
|
|
}
|
|
llarp::dht::Key_t addr;
|
|
if(!introset.A.CalculateAddress(addr))
|
|
{
|
|
llarp::LogWarn(
|
|
"failed to calculate hidden service address for direct GotIntro "
|
|
"message from ",
|
|
From);
|
|
return false;
|
|
}
|
|
// TODO: inform any pending tx
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool
|
|
RelayedGotIntroMessage::HandleMessage(
|
|
llarp_dht_context *ctx, std::vector< IMessage * > &replies) const
|
|
{
|
|
// TODO: implement me better?
|
|
auto pathset = ctx->impl.router->paths.GetLocalPathSet(pathID);
|
|
if(pathset)
|
|
{
|
|
return pathset->HandleGotIntroMessage(this);
|
|
}
|
|
llarp::LogWarn("No path for got intro message pathid=", pathID);
|
|
return false;
|
|
}
|
|
|
|
bool
|
|
GotIntroMessage::DecodeKey(llarp_buffer_t key, llarp_buffer_t *buf)
|
|
{
|
|
if(llarp_buffer_eq(key, "I"))
|
|
{
|
|
return BEncodeReadList(I, buf);
|
|
}
|
|
bool read = false;
|
|
if(!BEncodeMaybeReadDictInt("T", T, read, key, buf))
|
|
return false;
|
|
if(!BEncodeMaybeReadDictInt("V", version, read, key, buf))
|
|
return false;
|
|
return read;
|
|
}
|
|
|
|
bool
|
|
GotIntroMessage::BEncode(llarp_buffer_t *buf) const
|
|
{
|
|
if(!bencode_start_dict(buf))
|
|
return false;
|
|
if(!BEncodeWriteDictMsgType(buf, "A", "G"))
|
|
return false;
|
|
if(!BEncodeWriteDictList("I", I, buf))
|
|
return false;
|
|
if(!BEncodeWriteDictInt(buf, "T", T))
|
|
return false;
|
|
if(!BEncodeWriteDictInt(buf, "V", version))
|
|
return false;
|
|
return bencode_end(buf);
|
|
}
|
|
} // namespace dht
|
|
} // namespace llarp
|