2019-01-22 01:14:02 +00:00
|
|
|
#ifndef LLARP_DHT_CONTEXT
|
|
|
|
#define LLARP_DHT_CONTEXT
|
2018-07-11 13:20:14 +00:00
|
|
|
|
2018-12-12 00:48:54 +00:00
|
|
|
#include <dht/bucket.hpp>
|
2019-01-13 22:39:10 +00:00
|
|
|
#include <dht/dht.h>
|
2018-12-12 00:48:54 +00:00
|
|
|
#include <dht/key.hpp>
|
|
|
|
#include <dht/message.hpp>
|
|
|
|
#include <dht/messages/findintro.hpp>
|
|
|
|
#include <dht/node.hpp>
|
2019-01-22 01:14:02 +00:00
|
|
|
#include <dht/tx.hpp>
|
|
|
|
#include <dht/txholder.hpp>
|
2019-01-19 18:16:40 +00:00
|
|
|
#include <dht/txowner.hpp>
|
2019-04-22 18:35:19 +00:00
|
|
|
#include <service/intro_set.hpp>
|
2019-01-10 19:41:51 +00:00
|
|
|
#include <util/time.hpp>
|
2019-02-08 19:43:25 +00:00
|
|
|
#include <util/status.hpp>
|
2018-07-11 13:20:14 +00:00
|
|
|
|
2019-02-22 15:08:00 +00:00
|
|
|
#include <memory>
|
2018-07-11 13:20:14 +00:00
|
|
|
#include <set>
|
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
2019-01-29 02:16:31 +00:00
|
|
|
struct AbstractRouter;
|
2018-12-10 16:26:46 +00:00
|
|
|
|
2018-07-11 13:20:14 +00:00
|
|
|
namespace dht
|
|
|
|
{
|
2020-03-02 16:54:11 +00:00
|
|
|
/// number of routers to publish to
|
|
|
|
static constexpr size_t IntroSetRelayRedundancy = 2;
|
|
|
|
|
|
|
|
/// number of dht locations handled per relay
|
|
|
|
static constexpr size_t IntroSetRequestsPerRelay = 2;
|
|
|
|
|
|
|
|
static constexpr size_t IntroSetStorageRedundancy =
|
|
|
|
(IntroSetRelayRedundancy * IntroSetRequestsPerRelay);
|
|
|
|
|
2019-04-19 15:10:26 +00:00
|
|
|
struct AbstractContext
|
2019-01-24 01:31:02 +00:00
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
using PendingIntrosetLookups = TXHolder<TXOwner, service::EncryptedIntroSet, TXOwner::Hash>;
|
|
|
|
using PendingRouterLookups = TXHolder<RouterID, RouterContact, RouterID::Hash>;
|
|
|
|
using PendingExploreLookups = TXHolder<RouterID, RouterID, RouterID::Hash>;
|
2019-02-22 15:08:00 +00:00
|
|
|
|
2019-01-24 01:31:02 +00:00
|
|
|
virtual ~AbstractContext() = 0;
|
|
|
|
|
|
|
|
virtual bool
|
|
|
|
LookupRouter(const RouterID& target, RouterLookupHandler result) = 0;
|
|
|
|
|
2019-04-12 15:29:48 +00:00
|
|
|
virtual void
|
2020-04-07 18:38:56 +00:00
|
|
|
LookupRouterRecursive(
|
|
|
|
const RouterID& target,
|
|
|
|
const Key_t& whoasked,
|
|
|
|
uint64_t whoaskedTX,
|
|
|
|
const Key_t& askpeer,
|
|
|
|
RouterLookupHandler result = nullptr) = 0;
|
2019-04-12 15:29:48 +00:00
|
|
|
|
2020-02-20 18:18:05 +00:00
|
|
|
/// Ask a Service Node to perform an Introset lookup for us
|
2019-01-24 01:31:02 +00:00
|
|
|
virtual void
|
2020-04-07 18:38:56 +00:00
|
|
|
LookupIntroSetRelayed(
|
|
|
|
const Key_t& target,
|
|
|
|
const Key_t& whoasked,
|
|
|
|
uint64_t whoaskedTX,
|
|
|
|
const Key_t& askpeer,
|
|
|
|
uint64_t relayOrder,
|
|
|
|
service::EncryptedIntroSetLookupHandler result =
|
|
|
|
service::EncryptedIntroSetLookupHandler()) = 0;
|
2019-01-24 01:31:02 +00:00
|
|
|
|
2020-02-20 18:18:05 +00:00
|
|
|
/// Directly as a Service Node for an Introset
|
2019-01-24 01:31:02 +00:00
|
|
|
virtual void
|
2020-04-07 18:38:56 +00:00
|
|
|
LookupIntroSetDirect(
|
|
|
|
const Key_t& target,
|
|
|
|
const Key_t& whoasked,
|
|
|
|
uint64_t whoaskedTX,
|
|
|
|
const Key_t& askpeer,
|
|
|
|
service::EncryptedIntroSetLookupHandler result =
|
|
|
|
service::EncryptedIntroSetLookupHandler()) = 0;
|
2019-01-24 01:31:02 +00:00
|
|
|
|
2019-02-22 15:08:00 +00:00
|
|
|
virtual bool
|
|
|
|
HasRouterLookup(const RouterID& target) const = 0;
|
2018-09-14 13:43:42 +00:00
|
|
|
|
2018-08-30 18:48:43 +00:00
|
|
|
/// issue dht lookup for router via askpeer and send reply to local path
|
2019-02-22 15:08:00 +00:00
|
|
|
virtual void
|
2020-04-07 18:38:56 +00:00
|
|
|
LookupRouterForPath(
|
|
|
|
const RouterID& target, uint64_t txid, const PathID_t& path, const Key_t& askpeer) = 0;
|
2018-08-30 18:48:43 +00:00
|
|
|
|
2019-02-22 15:08:00 +00:00
|
|
|
virtual void
|
2020-04-07 18:38:56 +00:00
|
|
|
LookupIntroSetForPath(
|
|
|
|
const Key_t& addr,
|
|
|
|
uint64_t txid,
|
|
|
|
const PathID_t& path,
|
|
|
|
const Key_t& askpeer,
|
|
|
|
uint64_t relayOrder) = 0;
|
2018-08-10 21:34:11 +00:00
|
|
|
|
2019-02-22 15:08:00 +00:00
|
|
|
virtual void
|
|
|
|
DHTSendTo(const RouterID& peer, IMessage* msg, bool keepalive = true) = 0;
|
2018-08-02 01:41:40 +00:00
|
|
|
|
2018-08-29 20:40:26 +00:00
|
|
|
/// get routers closest to target excluding requester
|
2019-02-22 15:08:00 +00:00
|
|
|
virtual bool
|
2018-09-02 18:25:42 +00:00
|
|
|
HandleExploritoryRouterLookup(
|
2020-04-07 18:38:56 +00:00
|
|
|
const Key_t& requester,
|
|
|
|
uint64_t txid,
|
|
|
|
const RouterID& target,
|
|
|
|
std::vector<std::unique_ptr<IMessage>>& reply) = 0;
|
2018-07-18 20:58:16 +00:00
|
|
|
|
2018-08-29 20:40:26 +00:00
|
|
|
/// handle rc lookup from requester for target
|
2019-02-22 15:08:00 +00:00
|
|
|
virtual void
|
|
|
|
LookupRouterRelayed(
|
2020-04-07 18:38:56 +00:00
|
|
|
const Key_t& requester,
|
|
|
|
uint64_t txid,
|
|
|
|
const Key_t& target,
|
2019-02-22 15:08:00 +00:00
|
|
|
bool recursive,
|
2020-04-07 18:38:56 +00:00
|
|
|
std::vector<std::unique_ptr<IMessage>>& replies) = 0;
|
2018-07-11 13:20:14 +00:00
|
|
|
|
2019-02-22 15:08:00 +00:00
|
|
|
virtual bool
|
2019-04-22 17:38:29 +00:00
|
|
|
RelayRequestForPath(const PathID_t& localPath, const IMessage& msg) = 0;
|
2018-07-18 22:50:16 +00:00
|
|
|
|
2020-03-01 17:30:05 +00:00
|
|
|
/// send introset to peer from source with S counter and excluding peers
|
|
|
|
virtual void
|
2020-04-07 18:38:56 +00:00
|
|
|
PropagateLocalIntroSet(
|
|
|
|
const PathID_t& path,
|
|
|
|
uint64_t sourceTX,
|
|
|
|
const service::EncryptedIntroSet& introset,
|
|
|
|
const Key_t& peer,
|
|
|
|
uint64_t relayOrder) = 0;
|
2020-03-01 17:30:05 +00:00
|
|
|
|
2018-08-29 20:40:26 +00:00
|
|
|
/// send introset to peer from source with S counter and excluding peers
|
2019-02-22 15:08:00 +00:00
|
|
|
virtual void
|
2020-04-07 18:38:56 +00:00
|
|
|
PropagateIntroSetTo(
|
|
|
|
const Key_t& source,
|
|
|
|
uint64_t sourceTX,
|
|
|
|
const service::EncryptedIntroSet& introset,
|
|
|
|
const Key_t& peer,
|
|
|
|
uint64_t relayOrder) = 0;
|
2018-07-11 13:20:14 +00:00
|
|
|
|
2019-02-22 15:08:00 +00:00
|
|
|
virtual void
|
2020-02-27 16:37:23 +00:00
|
|
|
Init(const Key_t& us, AbstractRouter* router) = 0;
|
2018-07-11 13:20:14 +00:00
|
|
|
|
2020-05-01 19:51:15 +00:00
|
|
|
virtual std::optional<llarp::service::EncryptedIntroSet>
|
2020-01-27 21:30:41 +00:00
|
|
|
GetIntroSetByLocation(const Key_t& location) const = 0;
|
2018-07-16 21:22:25 +00:00
|
|
|
|
2019-02-22 15:08:00 +00:00
|
|
|
virtual llarp_time_t
|
|
|
|
Now() const = 0;
|
2018-08-27 13:44:16 +00:00
|
|
|
|
2019-02-22 15:08:00 +00:00
|
|
|
virtual void
|
|
|
|
ExploreNetworkVia(const Key_t& peer) = 0;
|
2018-07-11 13:20:14 +00:00
|
|
|
|
2019-02-22 15:08:00 +00:00
|
|
|
virtual llarp::AbstractRouter*
|
|
|
|
GetRouter() const = 0;
|
2019-01-24 01:31:02 +00:00
|
|
|
|
2019-03-27 12:36:27 +00:00
|
|
|
virtual bool
|
|
|
|
GetRCFromNodeDB(const Key_t& k, llarp::RouterContact& rc) const = 0;
|
|
|
|
|
2019-02-22 15:08:00 +00:00
|
|
|
virtual const Key_t&
|
|
|
|
OurKey() const = 0;
|
2018-07-11 13:20:14 +00:00
|
|
|
|
2019-02-22 15:08:00 +00:00
|
|
|
virtual PendingIntrosetLookups&
|
|
|
|
pendingIntrosetLookups() = 0;
|
2019-01-24 01:31:02 +00:00
|
|
|
|
2019-02-22 15:08:00 +00:00
|
|
|
virtual const PendingIntrosetLookups&
|
|
|
|
pendingIntrosetLookups() const = 0;
|
2018-08-29 20:40:26 +00:00
|
|
|
|
2019-02-22 15:08:00 +00:00
|
|
|
virtual PendingRouterLookups&
|
|
|
|
pendingRouterLookups() = 0;
|
2018-08-29 20:40:26 +00:00
|
|
|
|
2019-02-22 15:08:00 +00:00
|
|
|
virtual const PendingRouterLookups&
|
|
|
|
pendingRouterLookups() const = 0;
|
2018-08-29 20:40:26 +00:00
|
|
|
|
2019-02-22 15:08:00 +00:00
|
|
|
virtual PendingExploreLookups&
|
|
|
|
pendingExploreLookups() = 0;
|
2018-10-29 16:48:36 +00:00
|
|
|
|
2019-02-22 15:08:00 +00:00
|
|
|
virtual const PendingExploreLookups&
|
|
|
|
pendingExploreLookups() const = 0;
|
2018-11-28 15:27:36 +00:00
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
virtual Bucket<ISNode>*
|
2019-02-22 15:08:00 +00:00
|
|
|
services() = 0;
|
2018-08-29 20:40:26 +00:00
|
|
|
|
2019-02-22 15:08:00 +00:00
|
|
|
virtual bool&
|
|
|
|
AllowTransit() = 0;
|
|
|
|
virtual const bool&
|
|
|
|
AllowTransit() const = 0;
|
2018-08-29 20:40:26 +00:00
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
virtual Bucket<RCNode>*
|
2019-02-22 15:08:00 +00:00
|
|
|
Nodes() const = 0;
|
2019-04-19 15:10:26 +00:00
|
|
|
|
2019-06-26 21:39:29 +00:00
|
|
|
virtual void
|
|
|
|
PutRCNodeAsync(const RCNode& val) = 0;
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
DelRCNodeAsync(const Key_t& val) = 0;
|
|
|
|
|
2019-04-19 15:10:26 +00:00
|
|
|
virtual util::StatusObject
|
|
|
|
ExtractStatus() const = 0;
|
2019-07-19 17:21:20 +00:00
|
|
|
|
|
|
|
virtual void
|
|
|
|
StoreRC(const RouterContact rc) const = 0;
|
2019-02-22 15:08:00 +00:00
|
|
|
};
|
2018-07-11 13:20:14 +00:00
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
std::unique_ptr<AbstractContext>
|
2019-02-22 15:08:00 +00:00
|
|
|
makeContext();
|
|
|
|
} // namespace dht
|
2018-07-12 13:43:37 +00:00
|
|
|
} // namespace llarp
|
2018-07-11 13:20:14 +00:00
|
|
|
|
|
|
|
struct llarp_dht_context
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
std::unique_ptr<llarp::dht::AbstractContext> impl;
|
2019-02-11 19:45:42 +00:00
|
|
|
llarp::AbstractRouter* parent;
|
|
|
|
llarp_dht_context(llarp::AbstractRouter* router);
|
2018-07-11 13:20:14 +00:00
|
|
|
};
|
|
|
|
|
2018-08-27 13:44:16 +00:00
|
|
|
#endif
|