lokinet/llarp/dht/messages/gotintro.hpp

66 lines
1.8 KiB
C++
Raw Normal View History

#pragma once
2018-12-12 02:15:08 +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>
#include <optional>
2023-08-29 14:26:59 +00:00
namespace llarp::dht
{
2023-08-29 14:26:59 +00:00
/// acknowledgement to PublishIntroMessage or reply to FindIntroMessage
struct GotIntroMessage : public AbstractDHTMessage
{
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)
{
2023-08-29 14:26:59 +00:00
version = other.version;
}
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)
{}
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;
2023-08-29 14:26:59 +00:00
bool
decode_key(const llarp_buffer_t& key, llarp_buffer_t* val) override;
2023-08-29 14:26:59 +00:00
bool
handle_message(
AbstractDHTMessageHandler& dht,
std::vector<std::unique_ptr<AbstractDHTMessage>>& replies) const override;
2023-08-29 14:26:59 +00:00
};
2023-08-29 14:26:59 +00:00
struct RelayedGotIntroMessage final : public GotIntroMessage
{
RelayedGotIntroMessage() : GotIntroMessage({})
{}
2023-08-29 14:26:59 +00:00
bool
handle_message(
AbstractDHTMessageHandler& dht,
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