2021-03-19 14:09:06 +00:00
|
|
|
#pragma once
|
|
|
|
|
2023-10-24 13:18:03 +00:00
|
|
|
#include "address.hpp"
|
|
|
|
|
2023-10-19 21:59:57 +00:00
|
|
|
#include <llarp/router_id.hpp>
|
2023-10-24 13:18:03 +00:00
|
|
|
|
2023-10-19 21:59:57 +00:00
|
|
|
#include <oxenc/variant.h>
|
2023-10-24 13:18:03 +00:00
|
|
|
|
2021-03-19 14:09:06 +00:00
|
|
|
#include <functional>
|
|
|
|
#include <optional>
|
2023-10-24 13:18:03 +00:00
|
|
|
#include <string>
|
2021-03-19 14:09:06 +00:00
|
|
|
#include <unordered_map>
|
|
|
|
#include <unordered_set>
|
|
|
|
|
|
|
|
namespace llarp::service
|
|
|
|
{
|
|
|
|
/// tracks and manages consensus of lns names we fetch from the network
|
|
|
|
class LNSLookupTracker
|
|
|
|
{
|
2021-03-20 15:47:36 +00:00
|
|
|
public:
|
2021-03-20 19:18:04 +00:00
|
|
|
using Addr_t = std::variant<Address, RouterID>;
|
2021-03-20 15:47:36 +00:00
|
|
|
|
|
|
|
private:
|
2021-03-19 14:09:06 +00:00
|
|
|
struct LookupInfo
|
|
|
|
{
|
2021-03-20 15:47:36 +00:00
|
|
|
std::unordered_set<Addr_t> m_CurrentValues;
|
|
|
|
std::function<void(std::optional<Addr_t>)> m_HandleResult;
|
2021-03-19 14:09:06 +00:00
|
|
|
std::size_t m_ResultsGotten = 0;
|
|
|
|
std::size_t m_ResultsNeeded;
|
|
|
|
|
2021-03-20 15:47:36 +00:00
|
|
|
LookupInfo(std::size_t wantResults, std::function<void(std::optional<Addr_t>)> resultHandler)
|
2021-03-19 14:09:06 +00:00
|
|
|
: m_HandleResult{std::move(resultHandler)}, m_ResultsNeeded{wantResults}
|
|
|
|
{}
|
|
|
|
|
|
|
|
bool
|
2021-03-19 20:13:09 +00:00
|
|
|
IsDone() const;
|
|
|
|
|
|
|
|
void
|
2021-03-20 15:47:36 +00:00
|
|
|
HandleOneResult(std::optional<Addr_t> result);
|
2021-03-19 14:09:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
std::unordered_map<std::string, LookupInfo> m_PendingLookups;
|
|
|
|
|
|
|
|
public:
|
|
|
|
/// make a function that will handle consensus of an lns request
|
|
|
|
/// name is the name we are requesting
|
|
|
|
/// numPeers is the number of peers we asked
|
|
|
|
/// resultHandler is a function that we are wrapping that will handle the final result
|
2021-03-20 15:47:36 +00:00
|
|
|
std::function<void(std::optional<Addr_t>)>
|
2021-03-19 14:09:06 +00:00
|
|
|
MakeResultHandler(
|
|
|
|
std::string name,
|
|
|
|
std::size_t numPeers,
|
2021-03-20 15:47:36 +00:00
|
|
|
std::function<void(std::optional<Addr_t>)> resultHandler);
|
2021-03-19 14:09:06 +00:00
|
|
|
};
|
|
|
|
} // namespace llarp::service
|