lokinet/llarp/dht/messages/gotintro.hpp
Jason Rhinelander ac1486d0be Replace absl::optional with optional-lite
Step 1 of removing abseil from lokinet.

For the most part this is a drop-in replacement, but there are also a
few changes here to the JSONRPC layer that were needed to work around
current gcc 10 dev snapshot:

- JSONRPC returns a json now instead of an optional<json>.  It doesn't
  make any sense to have a json rpc call that just closes the connection
  with returning anything.  Invoked functions can return a null (default
  constructed) result now if they don't have anything to return (such a
  null value won't be added as "result").
2020-02-19 18:21:25 -04:00

76 lines
2.0 KiB
C++

#ifndef LLARP_DHT_MESSAGES_GOT_INTRO_HPP
#define LLARP_DHT_MESSAGES_GOT_INTRO_HPP
#include <dht/message.hpp>
#include <service/intro_set.hpp>
#include <util/copy_or_nullptr.hpp>
#include <vector>
#include <nonstd/optional.hpp>
namespace llarp
{
namespace dht
{
/// acknowledgement to PublishIntroMessage or reply to FindIntroMessage
struct GotIntroMessage : public IMessage
{
/// the found introsets
std::vector< service::EncryptedIntroSet > found;
/// txid
uint64_t txid = 0;
/// the key of a router closer in keyspace if iterative lookup
nonstd::optional< Key_t > closer;
GotIntroMessage(const Key_t& from) : IMessage(from)
{
}
GotIntroMessage(const GotIntroMessage& other)
: IMessage(other.From)
, found(other.found)
, txid(other.txid)
, closer(other.closer)
{
version = other.version;
}
/// for iterative reply
GotIntroMessage(const Key_t& from, const Key_t& _closer, uint64_t _txid)
: IMessage(from), txid(_txid), closer(_closer)
{
}
/// for recursive reply
GotIntroMessage(std::vector< service::EncryptedIntroSet > results,
uint64_t txid);
~GotIntroMessage() override = default;
bool
BEncode(llarp_buffer_t* buf) const override;
bool
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* val) override;
bool
HandleMessage(llarp_dht_context* ctx,
std::vector< IMessage::Ptr_t >& replies) const override;
};
struct RelayedGotIntroMessage final : public GotIntroMessage
{
RelayedGotIntroMessage() : GotIntroMessage({})
{
}
bool
HandleMessage(llarp_dht_context* ctx,
std::vector< IMessage::Ptr_t >& replies) const override;
};
using GotIntroMessage_constptr = std::shared_ptr< const GotIntroMessage >;
} // namespace dht
} // namespace llarp
#endif