You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lokinet/llarp/service/lookup.hpp

73 lines
1.5 KiB
C++

6 years ago
#ifndef LLARP_SERVICE_LOOKUP_HPP
#define LLARP_SERVICE_LOOKUP_HPP
#include <routing/message.hpp>
#include <service/IntroSet.hpp>
6 years ago
#include <set>
namespace llarp
{
// forward declare
namespace path
{
struct Path;
}
namespace service
{
struct ILookupHolder;
6 years ago
struct IServiceLookup
{
IServiceLookup() = delete;
6 years ago
virtual ~IServiceLookup(){};
/// handle lookup result
virtual bool
HandleResponse(__attribute__((unused))
const std::set< IntroSet >& results)
{
return false;
}
6 years ago
/// determine if this request has timed out
bool
IsTimedOut(llarp_time_t now, llarp_time_t timeout = 15000) const
6 years ago
{
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
SendRequestViaPath(llarp::path::Path* p, llarp::Router* r);
6 years ago
ILookupHolder* parent;
uint64_t txid;
const std::string name;
RouterID endpoint;
protected:
IServiceLookup(ILookupHolder* parent, uint64_t tx,
const std::string& name);
6 years ago
llarp_time_t m_created;
};
struct ILookupHolder
{
virtual void
PutLookup(IServiceLookup* l, uint64_t txid) = 0;
};
6 years ago
} // namespace service
} // namespace llarp
#endif