2018-07-11 13:20:14 +00:00
|
|
|
#ifndef LLARP_DHT_CONTEXT_HPP
|
|
|
|
#define LLARP_DHT_CONTEXT_HPP
|
|
|
|
|
|
|
|
#include <llarp/dht.h>
|
|
|
|
#include <llarp/router.h>
|
|
|
|
#include <llarp/dht/bucket.hpp>
|
|
|
|
#include <llarp/dht/key.hpp>
|
|
|
|
#include <llarp/dht/message.hpp>
|
|
|
|
#include <llarp/dht/node.hpp>
|
|
|
|
#include <llarp/dht/search_job.hpp>
|
2018-07-18 20:58:16 +00:00
|
|
|
#include <llarp/service/IntroSet.hpp>
|
2018-07-11 13:20:14 +00:00
|
|
|
|
|
|
|
#include <set>
|
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace dht
|
|
|
|
{
|
|
|
|
struct Context
|
|
|
|
{
|
|
|
|
Context();
|
|
|
|
~Context();
|
|
|
|
|
|
|
|
SearchJob*
|
|
|
|
FindPendingTX(const Key_t& owner, uint64_t txid);
|
|
|
|
|
|
|
|
void
|
|
|
|
RemovePendingLookup(const Key_t& owner, uint64_t txid);
|
|
|
|
|
2018-07-12 18:21:44 +00:00
|
|
|
void
|
|
|
|
LookupServiceDirect(const Key_t& target, const Key_t& whoasked,
|
|
|
|
uint64_t whoaskedTX, const Key_t& askpeer,
|
|
|
|
SearchJob::IntroSetHookFunc handler,
|
|
|
|
bool iterateive = false,
|
|
|
|
std::set< Key_t > excludes = {});
|
|
|
|
|
2018-07-11 13:20:14 +00:00
|
|
|
void
|
|
|
|
LookupRouter(const Key_t& target, const Key_t& whoasked,
|
|
|
|
uint64_t whoaskedTX, const Key_t& askpeer,
|
|
|
|
llarp_router_lookup_job* job = nullptr,
|
|
|
|
bool iterative = false, std::set< Key_t > excludes = {});
|
|
|
|
|
2018-07-17 04:37:50 +00:00
|
|
|
void
|
|
|
|
LookupIntroSet(const service::Address& addr, const Key_t& whoasked,
|
|
|
|
uint64_t whoaskedTX, const Key_t& askpeer,
|
|
|
|
bool interative = false, std::set< Key_t > excludes = {});
|
|
|
|
|
2018-07-18 03:10:21 +00:00
|
|
|
void
|
|
|
|
LookupTag(const service::Tag& tag, const Key_t& whoasked,
|
|
|
|
uint64_t whoaskedTX, const Key_t& askpeer,
|
|
|
|
bool iterative = false);
|
|
|
|
|
2018-07-11 13:20:14 +00:00
|
|
|
void
|
|
|
|
LookupRouterViaJob(llarp_router_lookup_job* job);
|
|
|
|
|
2018-07-18 20:58:16 +00:00
|
|
|
void
|
|
|
|
LookupTagForPath(const service::Tag& tag, uint64_t txid,
|
|
|
|
const llarp::PathID_t& path, const Key_t& askpeer);
|
|
|
|
|
|
|
|
std::set< service::IntroSet >
|
2018-07-18 22:50:05 +00:00
|
|
|
FindRandomIntroSetsWithTag(const service::Tag& tag, size_t max = 2);
|
2018-07-18 20:58:16 +00:00
|
|
|
|
2018-07-11 13:20:14 +00:00
|
|
|
void
|
|
|
|
LookupRouterRelayed(const Key_t& requester, uint64_t txid,
|
|
|
|
const Key_t& target, bool recursive,
|
|
|
|
std::vector< IMessage* >& replies);
|
|
|
|
|
|
|
|
bool
|
|
|
|
RelayRequestForPath(const llarp::PathID_t& localPath,
|
|
|
|
const IMessage* msg);
|
2018-07-18 22:50:16 +00:00
|
|
|
|
|
|
|
void
|
2018-07-19 04:58:39 +00:00
|
|
|
PropagateIntroSetTo(const Key_t& from, uint64_t fromTX,
|
|
|
|
const service::IntroSet& introset, const Key_t& peer,
|
2018-08-01 22:10:38 +00:00
|
|
|
uint64_t S, const std::set< Key_t >& exclude);
|
2018-07-11 13:20:14 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
Init(const Key_t& us, llarp_router* router);
|
|
|
|
|
2018-07-16 21:22:25 +00:00
|
|
|
const llarp::service::IntroSet*
|
|
|
|
GetIntroSetByServiceAddress(const llarp::service::Address& addr) const;
|
|
|
|
|
2018-07-11 13:20:14 +00:00
|
|
|
void
|
|
|
|
QueueRouterLookup(llarp_router_lookup_job* job);
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_cleaner_timer(void* user, uint64_t orig, uint64_t left);
|
|
|
|
|
|
|
|
static void
|
|
|
|
queue_router_lookup(void* user);
|
|
|
|
|
|
|
|
llarp_router* router = nullptr;
|
|
|
|
// for router contacts
|
|
|
|
Bucket< RCNode >* nodes = nullptr;
|
|
|
|
|
|
|
|
// for introduction sets
|
|
|
|
Bucket< ISNode >* services = nullptr;
|
|
|
|
bool allowTransit = false;
|
|
|
|
|
|
|
|
const Key_t&
|
|
|
|
OurKey() const
|
|
|
|
{
|
|
|
|
return ourKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void
|
|
|
|
ScheduleCleanupTimer();
|
|
|
|
|
|
|
|
void
|
|
|
|
CleanupTX();
|
|
|
|
|
|
|
|
uint64_t ids;
|
|
|
|
|
|
|
|
struct TXOwner
|
|
|
|
{
|
|
|
|
Key_t node;
|
|
|
|
uint64_t txid = 0;
|
|
|
|
|
|
|
|
bool
|
|
|
|
operator==(const TXOwner& other) const
|
|
|
|
{
|
|
|
|
return txid == other.txid && node == other.node;
|
|
|
|
}
|
|
|
|
bool
|
|
|
|
operator<(const TXOwner& other) const
|
|
|
|
{
|
|
|
|
return txid < other.txid || node < other.node;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TXOwnerHash
|
|
|
|
{
|
|
|
|
std::size_t
|
|
|
|
operator()(TXOwner const& o) const noexcept
|
|
|
|
{
|
|
|
|
std::size_t sz2;
|
|
|
|
memcpy(&sz2, &o.node[0], sizeof(std::size_t));
|
|
|
|
return o.txid ^ (sz2 << 1);
|
|
|
|
}
|
2018-07-17 04:37:50 +00:00
|
|
|
}; // namespace dht
|
2018-07-11 13:20:14 +00:00
|
|
|
|
|
|
|
std::unordered_map< TXOwner, SearchJob, TXOwnerHash > pendingTX;
|
|
|
|
Key_t ourKey;
|
2018-07-17 04:37:50 +00:00
|
|
|
}; // namespace llarp
|
|
|
|
} // namespace dht
|
2018-07-12 13:43:37 +00:00
|
|
|
} // namespace llarp
|
2018-07-11 13:20:14 +00:00
|
|
|
|
|
|
|
struct llarp_dht_context
|
|
|
|
{
|
|
|
|
llarp::dht::Context impl;
|
|
|
|
llarp_router* parent;
|
|
|
|
llarp_dht_context(llarp_router* router);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|