lokinet/llarp/dht/publishservicejob.cpp
2020-03-01 11:48:43 -04:00

53 lines
1.4 KiB
C++

#include <dht/publishservicejob.hpp>
#include <dht/context.hpp>
#include <dht/messages/pubintro.hpp>
#include <dht/messages/gotintro.hpp>
#include <utility>
namespace llarp
{
namespace dht
{
PublishServiceJob::PublishServiceJob(
const TXOwner &asker, const service::EncryptedIntroSet &introset_,
AbstractContext *ctx, bool relayed_, uint64_t relayOrder_)
: TX< Key_t, service::EncryptedIntroSet >(
asker, Key_t{introset_.derivedSigningKey}, ctx)
, relayed(relayed_)
, relayOrder(relayOrder_)
, introset(introset_)
{
}
bool
PublishServiceJob::Validate(const service::EncryptedIntroSet &value) const
{
if(value.derivedSigningKey != introset.derivedSigningKey)
{
llarp::LogWarn(
"publish introset acknowledgement acked a different service");
return false;
}
const llarp_time_t now = llarp::time_now_ms();
return value.Verify(now);
}
void
PublishServiceJob::Start(const TXOwner &peer)
{
parent->DHTSendTo(
peer.node.as_array(),
new PublishIntroMessage(introset, peer.txid, relayed, relayOrder));
}
void
PublishServiceJob::SendReply()
{
parent->DHTSendTo(whoasked.node.as_array(),
new GotIntroMessage({introset}, whoasked.txid));
}
} // namespace dht
} // namespace llarp