2018-07-18 03:10:21 +00:00
|
|
|
#ifndef LLARP_SERVICE_LOOKUP_HPP
|
|
|
|
#define LLARP_SERVICE_LOOKUP_HPP
|
|
|
|
|
2018-12-12 02:04:32 +00:00
|
|
|
#include <routing/message.hpp>
|
2018-12-12 02:15:08 +00:00
|
|
|
#include <service/IntroSet.hpp>
|
2018-12-12 02:04:32 +00:00
|
|
|
|
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-02-06 15:52:00 +00:00
|
|
|
constexpr size_t MaxConcurrentLookups = size_t(4);
|
|
|
|
|
2019-02-08 19:43:25 +00:00
|
|
|
struct IServiceLookup : public util::IStateful
|
2018-07-18 03:10:21 +00:00
|
|
|
{
|
2018-08-14 21:17:18 +00:00
|
|
|
IServiceLookup() = delete;
|
2018-07-18 03:10:21 +00:00
|
|
|
virtual ~IServiceLookup(){};
|
|
|
|
|
|
|
|
/// handle lookup result
|
|
|
|
virtual bool
|
2018-11-07 15:30:22 +00:00
|
|
|
HandleResponse(__attribute__((unused))
|
|
|
|
const std::set< IntroSet >& results)
|
2018-08-14 21:17:18 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2018-07-18 03:10:21 +00:00
|
|
|
|
|
|
|
/// determine if this request has timed out
|
|
|
|
bool
|
2019-02-06 15:05:25 +00:00
|
|
|
IsTimedOut(llarp_time_t now, llarp_time_t timeout = 15000) const
|
2018-07-18 03:10:21 +00:00
|
|
|
{
|
|
|
|
if(now <= m_created)
|
|
|
|
return false;
|
|
|
|
return now - m_created > timeout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// build request message for service lookup
|
|
|
|
virtual llarp::routing::IMessage*
|
|
|
|
BuildRequestMessage() = 0;
|
|
|
|
|
|
|
|
/// build a new requset message and send it via a path
|
|
|
|
bool
|
2019-02-11 19:45:42 +00:00
|
|
|
SendRequestViaPath(llarp::path::Path* p, AbstractRouter* r);
|
2018-07-18 03:10:21 +00:00
|
|
|
|
2018-08-04 02:59:32 +00:00
|
|
|
ILookupHolder* parent;
|
|
|
|
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
|
|
|
|
2019-02-11 17:14:43 +00:00
|
|
|
util::StatusObject
|
|
|
|
ExtractStatus() const override
|
2019-02-08 19:43:25 +00:00
|
|
|
{
|
|
|
|
auto now = llarp::time_now_ms();
|
2019-02-11 17:14:43 +00:00
|
|
|
util::StatusObject obj{{"txid", txid},
|
|
|
|
{"endpoint", endpoint.ToHex()},
|
|
|
|
{"name", name},
|
|
|
|
{"timedOut", IsTimedOut(now)},
|
|
|
|
{"createdAt", m_created}};
|
|
|
|
return obj;
|
2019-02-08 19:43:25 +00:00
|
|
|
}
|
|
|
|
|
2018-08-04 02:59:32 +00:00
|
|
|
protected:
|
2018-08-14 21:17:18 +00:00
|
|
|
IServiceLookup(ILookupHolder* parent, uint64_t tx,
|
|
|
|
const std::string& name);
|
|
|
|
|
2018-07-18 03:10:21 +00:00
|
|
|
llarp_time_t m_created;
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
|
2018-09-02 18:25:42 +00:00
|
|
|
#endif
|