1
1
Fork 0
mirror of https://github.com/oxen-io/lokinet synced 2023-12-14 06:53:00 +01:00
lokinet/llarp/service/lookup.hpp

86 lines
1.9 KiB
C++
Raw Normal View History

2018-07-18 05:10:21 +02:00
#ifndef LLARP_SERVICE_LOOKUP_HPP
#define LLARP_SERVICE_LOOKUP_HPP
2018-12-12 03:04:32 +01:00
#include <routing/message.hpp>
#include <service/intro_set.hpp>
#include <path/pathset.hpp>
2018-12-12 03:04:32 +01:00
2018-07-18 05:10:21 +02:00
#include <set>
namespace llarp
{
// forward declare
namespace path
{
struct Path;
}
namespace service
{
2018-08-04 04:59:32 +02:00
struct ILookupHolder;
constexpr size_t MaxConcurrentLookups = size_t(16);
2019-04-19 17:10:26 +02:00
struct IServiceLookup
2018-07-18 05:10:21 +02:00
{
2019-07-31 01:42:13 +02:00
IServiceLookup() = delete;
virtual ~IServiceLookup() = default;
2018-07-18 05:10:21 +02:00
/// handle lookup result
virtual bool
2020-01-27 22:30:41 +01:00
HandleResponse(const std::set< EncryptedIntroSet >&)
2018-08-14 23:17:18 +02:00
{
return false;
}
2018-07-18 05:10:21 +02:00
/// determine if this request has timed out
bool
2020-01-10 16:45:25 +01:00
IsTimedOut(llarp_time_t now, llarp_time_t timeout = 20000) const
2018-07-18 05:10:21 +02:00
{
if(now <= m_created)
return false;
return now - m_created > timeout;
}
/// build request message for service lookup
virtual std::shared_ptr< routing::IMessage >
2018-07-18 05:10:21 +02:00
BuildRequestMessage() = 0;
/// build a new request message and send it via a path
2018-07-18 05:10:21 +02:00
bool
SendRequestViaPath(path::Path_ptr p, AbstractRouter* r);
2018-07-18 05:10:21 +02:00
2019-08-02 11:27:27 +02:00
ILookupHolder* m_parent;
2018-08-04 04:59:32 +02:00
uint64_t txid;
2018-08-14 23:17:18 +02:00
const std::string name;
2018-10-15 17:43:41 +02:00
RouterID endpoint;
2018-08-04 04:59:32 +02:00
2019-02-11 18:14:43 +01:00
util::StatusObject
2019-04-19 17:10:26 +02:00
ExtractStatus() const
2019-02-08 20:43:25 +01:00
{
auto now = time_now_ms();
2019-02-11 18:14:43 +01:00
util::StatusObject obj{{"txid", txid},
{"endpoint", endpoint.ToHex()},
{"name", name},
{"timedOut", IsTimedOut(now)},
{"createdAt", m_created}};
return obj;
2019-02-08 20:43:25 +01:00
}
2018-08-04 04:59:32 +02:00
protected:
2019-07-31 01:42:13 +02:00
IServiceLookup(ILookupHolder* parent, uint64_t tx, std::string name);
2018-08-14 23:17:18 +02:00
2018-07-18 05:10:21 +02:00
llarp_time_t m_created;
};
2018-08-04 04:59:32 +02:00
struct ILookupHolder
{
virtual void
PutLookup(IServiceLookup* l, uint64_t txid) = 0;
};
2018-07-18 05:10:21 +02:00
} // namespace service
} // namespace llarp
#endif