2021-03-09 22:24:35 +00:00
|
|
|
#pragma once
|
2018-12-12 02:15:08 +00:00
|
|
|
|
2021-03-09 22:24:35 +00:00
|
|
|
#include <llarp/dht/message.hpp>
|
|
|
|
#include <llarp/service/intro_set.hpp>
|
|
|
|
#include <llarp/util/copy_or_nullptr.hpp>
|
2018-12-12 02:15:08 +00:00
|
|
|
|
2018-07-20 04:50:28 +00:00
|
|
|
#include <vector>
|
2020-05-01 19:51:15 +00:00
|
|
|
#include <optional>
|
2018-07-11 13:20:14 +00:00
|
|
|
|
2023-08-29 14:26:59 +00:00
|
|
|
namespace llarp::dht
|
2018-07-11 13:20:14 +00:00
|
|
|
{
|
2023-08-29 14:26:59 +00:00
|
|
|
/// acknowledgement to PublishIntroMessage or reply to FindIntroMessage
|
|
|
|
struct GotIntroMessage : public AbstractDHTMessage
|
2018-07-11 13:20:14 +00:00
|
|
|
{
|
2023-08-29 14:26:59 +00:00
|
|
|
/// the found introsets
|
|
|
|
std::vector<service::EncryptedIntroSet> found;
|
|
|
|
/// txid
|
|
|
|
uint64_t txid = 0;
|
|
|
|
/// the key of a router closer in keyspace if iterative lookup
|
|
|
|
std::optional<Key_t> closer;
|
|
|
|
|
|
|
|
GotIntroMessage(const Key_t& from) : AbstractDHTMessage(from)
|
|
|
|
{}
|
|
|
|
|
|
|
|
GotIntroMessage(const GotIntroMessage& other)
|
|
|
|
: AbstractDHTMessage(other.From), found(other.found), txid(other.txid), closer(other.closer)
|
2018-07-11 13:20:14 +00:00
|
|
|
{
|
2023-08-29 14:26:59 +00:00
|
|
|
version = other.version;
|
|
|
|
}
|
2018-07-11 16:11:19 +00:00
|
|
|
|
2023-08-29 14:26:59 +00:00
|
|
|
/// for iterative reply
|
|
|
|
GotIntroMessage(const Key_t& from, const Key_t& _closer, uint64_t _txid)
|
|
|
|
: AbstractDHTMessage(from), txid(_txid), closer(_closer)
|
|
|
|
{}
|
2018-07-11 13:20:14 +00:00
|
|
|
|
2023-08-29 14:26:59 +00:00
|
|
|
/// for recursive reply
|
|
|
|
GotIntroMessage(std::vector<service::EncryptedIntroSet> results, uint64_t txid);
|
2019-05-03 13:15:03 +00:00
|
|
|
|
2023-08-29 14:26:59 +00:00
|
|
|
~GotIntroMessage() override = default;
|
2018-11-08 15:15:02 +00:00
|
|
|
|
2023-08-29 14:26:59 +00:00
|
|
|
void
|
|
|
|
bt_encode(oxenc::bt_dict_producer& btdp) const override;
|
2018-07-11 13:20:14 +00:00
|
|
|
|
2023-08-29 14:26:59 +00:00
|
|
|
bool
|
|
|
|
decode_key(const llarp_buffer_t& key, llarp_buffer_t* val) override;
|
2018-07-11 13:20:14 +00:00
|
|
|
|
2023-08-29 14:26:59 +00:00
|
|
|
bool
|
|
|
|
handle_message(
|
2023-09-13 15:57:29 +00:00
|
|
|
AbstractDHTMessageHandler& dht,
|
2023-08-31 16:28:02 +00:00
|
|
|
std::vector<std::unique_ptr<AbstractDHTMessage>>& replies) const override;
|
2023-08-29 14:26:59 +00:00
|
|
|
};
|
2018-07-11 13:20:14 +00:00
|
|
|
|
2023-08-29 14:26:59 +00:00
|
|
|
struct RelayedGotIntroMessage final : public GotIntroMessage
|
|
|
|
{
|
|
|
|
RelayedGotIntroMessage() : GotIntroMessage({})
|
|
|
|
{}
|
2018-07-12 13:43:37 +00:00
|
|
|
|
2023-08-29 14:26:59 +00:00
|
|
|
bool
|
|
|
|
handle_message(
|
2023-09-13 15:57:29 +00:00
|
|
|
AbstractDHTMessageHandler& dht,
|
2023-08-31 16:28:02 +00:00
|
|
|
std::vector<std::unique_ptr<AbstractDHTMessage>>& replies) const override;
|
2023-08-29 14:26:59 +00:00
|
|
|
};
|
2019-05-03 13:15:03 +00:00
|
|
|
|
2023-08-29 14:26:59 +00:00
|
|
|
using GotIntroMessage_constptr = std::shared_ptr<const GotIntroMessage>;
|
|
|
|
} // namespace llarp::dht
|