2019-01-22 01:14:02 +00:00
|
|
|
#include <dht/publishservicejob.hpp>
|
|
|
|
|
|
|
|
#include <dht/context.hpp>
|
|
|
|
#include <dht/messages/pubintro.hpp>
|
2020-02-29 03:59:24 +00:00
|
|
|
#include <dht/messages/gotintro.hpp>
|
2020-03-01 17:30:05 +00:00
|
|
|
#include <path/path_context.hpp>
|
|
|
|
#include <routing/dht_message.hpp>
|
|
|
|
#include <router/abstractrouter.hpp>
|
2019-01-22 01:14:02 +00:00
|
|
|
|
2020-03-01 17:30:05 +00:00
|
|
|
#include <utility>
|
2019-01-22 01:14:02 +00:00
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace dht
|
|
|
|
{
|
2020-02-20 15:36:29 +00:00
|
|
|
PublishServiceJob::PublishServiceJob(
|
2020-04-07 18:38:56 +00:00
|
|
|
const TXOwner& asker,
|
|
|
|
const service::EncryptedIntroSet& introset_,
|
|
|
|
AbstractContext* ctx,
|
|
|
|
uint64_t relayOrder_)
|
|
|
|
: TX<TXOwner, service::EncryptedIntroSet>(asker, asker, ctx)
|
2020-02-20 00:07:46 +00:00
|
|
|
, relayOrder(relayOrder_)
|
|
|
|
, introset(introset_)
|
2019-01-22 01:14:02 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
PublishServiceJob::Validate(const service::EncryptedIntroSet& value) const
|
2019-01-22 01:14:02 +00:00
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
if (value.derivedSigningKey != introset.derivedSigningKey)
|
2019-01-22 01:14:02 +00:00
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
llarp::LogWarn("publish introset acknowledgement acked a different service");
|
2019-01-22 01:14:02 +00:00
|
|
|
return false;
|
|
|
|
}
|
2020-01-27 21:30:41 +00:00
|
|
|
const llarp_time_t now = llarp::time_now_ms();
|
|
|
|
return value.Verify(now);
|
2019-01-22 01:14:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-04-07 18:38:56 +00:00
|
|
|
PublishServiceJob::Start(const TXOwner& peer)
|
2019-01-22 01:14:02 +00:00
|
|
|
{
|
2020-01-27 21:30:41 +00:00
|
|
|
parent->DHTSendTo(
|
2020-04-07 18:38:56 +00:00
|
|
|
peer.node.as_array(), new PublishIntroMessage(introset, peer.txid, false, relayOrder));
|
2019-01-22 01:14:02 +00:00
|
|
|
}
|
2020-02-29 03:59:24 +00:00
|
|
|
|
|
|
|
void
|
2020-03-01 15:48:43 +00:00
|
|
|
PublishServiceJob::SendReply()
|
2020-02-29 03:59:24 +00:00
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
parent->DHTSendTo(whoasked.node.as_array(), new GotIntroMessage({introset}, whoasked.txid));
|
2020-02-29 03:59:24 +00:00
|
|
|
}
|
|
|
|
|
2020-03-01 17:30:05 +00:00
|
|
|
LocalPublishServiceJob::LocalPublishServiceJob(
|
2020-04-07 18:38:56 +00:00
|
|
|
const TXOwner& peer,
|
|
|
|
const PathID_t& fromID,
|
|
|
|
uint64_t _txid,
|
|
|
|
const service::EncryptedIntroSet& introset,
|
|
|
|
AbstractContext* ctx,
|
2020-03-01 17:30:05 +00:00
|
|
|
uint64_t relayOrder)
|
2020-04-07 18:38:56 +00:00
|
|
|
: PublishServiceJob(peer, introset, ctx, relayOrder), localPath(fromID), txid(_txid)
|
2020-03-01 17:30:05 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LocalPublishServiceJob::SendReply()
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
auto path =
|
|
|
|
parent->GetRouter()->pathContext().GetByUpstream(parent->OurKey().as_array(), localPath);
|
|
|
|
if (!path)
|
2020-03-01 17:30:05 +00:00
|
|
|
{
|
|
|
|
llarp::LogWarn(
|
|
|
|
"did not send reply for relayed dht request, no such local path "
|
|
|
|
"for pathid=",
|
|
|
|
localPath);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
routing::DHTMessage msg;
|
2020-03-01 17:33:54 +00:00
|
|
|
msg.M.emplace_back(new GotIntroMessage({introset}, txid));
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!path->SendRoutingMessage(msg, parent->GetRouter()))
|
2020-03-01 17:30:05 +00:00
|
|
|
{
|
|
|
|
llarp::LogWarn(
|
|
|
|
"failed to send routing message when informing result of dht "
|
|
|
|
"request, pathid=",
|
|
|
|
localPath);
|
|
|
|
}
|
|
|
|
}
|
2019-01-22 01:14:02 +00:00
|
|
|
} // namespace dht
|
|
|
|
} // namespace llarp
|