2021-03-09 22:24:35 +00:00
|
|
|
#pragma once
|
2018-07-18 03:10:21 +00:00
|
|
|
|
2021-03-09 22:24:35 +00:00
|
|
|
#include <llarp/routing/message.hpp>
|
|
|
|
#include "intro_set.hpp"
|
|
|
|
#include <llarp/path/pathset.hpp>
|
2018-12-12 02:04:32 +00:00
|
|
|
|
2021-06-03 15:40:01 +00:00
|
|
|
#include <llarp/endpoint_base.hpp>
|
|
|
|
|
2018-07-18 03:10:21 +00:00
|
|
|
#include <set>
|
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
// forward declare
|
|
|
|
namespace path
|
|
|
|
{
|
|
|
|
struct Path;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace service
|
|
|
|
{
|
2018-08-04 02:59:32 +00:00
|
|
|
struct ILookupHolder;
|
|
|
|
|
2019-09-19 14:41:31 +00:00
|
|
|
constexpr size_t MaxConcurrentLookups = size_t(16);
|
2019-02-06 15:52:00 +00:00
|
|
|
|
2019-04-19 15:10:26 +00:00
|
|
|
struct IServiceLookup
|
2018-07-18 03:10:21 +00:00
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
IServiceLookup() = delete;
|
2019-07-30 23:42:13 +00:00
|
|
|
virtual ~IServiceLookup() = default;
|
2018-07-18 03:10:21 +00:00
|
|
|
|
2020-09-17 19:18:08 +00:00
|
|
|
/// handle lookup result for introsets
|
2018-07-18 03:10:21 +00:00
|
|
|
virtual bool
|
2020-09-17 19:18:08 +00:00
|
|
|
HandleIntrosetResponse(const std::set<EncryptedIntroSet>&)
|
2018-08-14 21:17:18 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2018-07-18 03:10:21 +00:00
|
|
|
|
2020-09-17 19:18:08 +00:00
|
|
|
/// handle lookup result for introsets
|
2022-10-20 22:23:14 +00:00
|
|
|
virtual bool
|
|
|
|
HandleNameResponse(std::optional<Address>)
|
2020-09-17 19:18:08 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
HandleTimeout()
|
|
|
|
{
|
|
|
|
HandleIntrosetResponse({});
|
|
|
|
}
|
|
|
|
|
2018-07-18 03:10:21 +00:00
|
|
|
/// determine if this request has timed out
|
|
|
|
bool
|
2021-03-27 18:54:09 +00:00
|
|
|
IsTimedOut(llarp_time_t now) const
|
2018-07-18 03:10:21 +00:00
|
|
|
{
|
2021-03-27 18:54:09 +00:00
|
|
|
return TimeLeft(now) == 0ms;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// return how long this request has left to be fufilled
|
|
|
|
llarp_time_t
|
|
|
|
TimeLeft(llarp_time_t now) const
|
|
|
|
{
|
|
|
|
if (now > (m_created + m_timeout))
|
|
|
|
return 0s;
|
|
|
|
return now - (m_created + m_timeout);
|
2018-07-18 03:10:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// build request message for service lookup
|
2020-04-07 18:38:56 +00:00
|
|
|
virtual std::shared_ptr<routing::IMessage>
|
2018-07-18 03:10:21 +00:00
|
|
|
BuildRequestMessage() = 0;
|
|
|
|
|
2019-04-22 17:38:29 +00:00
|
|
|
/// build a new request message and send it via a path
|
2020-02-20 19:32:51 +00:00
|
|
|
virtual bool
|
2019-04-23 14:28:59 +00:00
|
|
|
SendRequestViaPath(path::Path_ptr p, AbstractRouter* r);
|
2018-07-18 03:10:21 +00:00
|
|
|
|
2019-08-02 09:27:27 +00:00
|
|
|
ILookupHolder* m_parent;
|
2018-08-04 02:59:32 +00:00
|
|
|
uint64_t txid;
|
2018-08-14 21:17:18 +00:00
|
|
|
const std::string name;
|
2018-10-15 15:43:41 +00:00
|
|
|
RouterID endpoint;
|
2018-08-04 02:59:32 +00:00
|
|
|
|
2021-06-03 15:40:01 +00:00
|
|
|
/// return true if this lookup is for a remote address
|
2022-10-20 22:23:14 +00:00
|
|
|
virtual bool
|
|
|
|
IsFor(EndpointBase::AddressVariant_t) const
|
2021-06-03 15:40:01 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-02-11 17:14:43 +00:00
|
|
|
util::StatusObject
|
2019-04-19 15:10:26 +00:00
|
|
|
ExtractStatus() const
|
2019-02-08 19:43:25 +00:00
|
|
|
{
|
2019-04-22 18:35:19 +00:00
|
|
|
auto now = time_now_ms();
|
2021-03-05 17:31:52 +00:00
|
|
|
util::StatusObject obj{
|
|
|
|
{"txid", txid},
|
|
|
|
{"endpoint", endpoint.ToHex()},
|
|
|
|
{"name", name},
|
|
|
|
{"timedOut", IsTimedOut(now)},
|
|
|
|
{"createdAt", m_created.count()}};
|
2019-02-11 17:14:43 +00:00
|
|
|
return obj;
|
2019-02-08 19:43:25 +00:00
|
|
|
}
|
|
|
|
|
2018-08-04 02:59:32 +00:00
|
|
|
protected:
|
2021-03-27 18:54:09 +00:00
|
|
|
IServiceLookup(
|
|
|
|
ILookupHolder* parent, uint64_t tx, std::string name, llarp_time_t timeout = 10s);
|
2018-08-14 21:17:18 +00:00
|
|
|
|
2021-03-27 18:54:09 +00:00
|
|
|
const llarp_time_t m_created, m_timeout;
|
2018-07-18 03:10:21 +00:00
|
|
|
};
|
|
|
|
|
2018-08-04 02:59:32 +00:00
|
|
|
struct ILookupHolder
|
|
|
|
{
|
|
|
|
virtual void
|
|
|
|
PutLookup(IServiceLookup* l, uint64_t txid) = 0;
|
|
|
|
};
|
|
|
|
|
2018-07-18 03:10:21 +00:00
|
|
|
} // namespace service
|
|
|
|
} // namespace llarp
|