---
title: llarp/service/lookup.hpp

---

# llarp/service/lookup.hpp



## Namespaces

| Name           |
| -------------- |
| **[llarp](Namespaces/namespacellarp.md)** <br>[crypto.hpp] |
| **[llarp::path](Namespaces/namespacellarp_1_1path.md)**  |
| **[llarp::service](Namespaces/namespacellarp_1_1service.md)**  |

## Classes

|                | Name           |
| -------------- | -------------- |
| struct | **[llarp::service::IServiceLookup](Classes/structllarp_1_1service_1_1IServiceLookup.md)**  |
| struct | **[llarp::service::ILookupHolder](Classes/structllarp_1_1service_1_1ILookupHolder.md)**  |




## Source code

```cpp
#pragma once

#include <llarp/routing/message.hpp>
#include "intro_set.hpp"
#include <llarp/path/pathset.hpp>

#include <llarp/endpoint_base.hpp>

#include <set>

namespace llarp
{
  // forward declare
  namespace path
  {
    struct Path;
  }

  namespace service
  {
    struct ILookupHolder;

    constexpr size_t MaxConcurrentLookups = size_t(16);

    struct IServiceLookup
    {
      IServiceLookup() = delete;
      virtual ~IServiceLookup() = default;

      virtual bool
      HandleIntrosetResponse(const std::set<EncryptedIntroSet>&)
      {
        return false;
      }

      virtual bool
      HandleNameResponse(std::optional<Address>)
      {
        return false;
      }

      virtual void
      HandleTimeout()
      {
        HandleIntrosetResponse({});
      }

      bool
      IsTimedOut(llarp_time_t now) const
      {
        return TimeLeft(now) == 0ms;
      }

      llarp_time_t
      TimeLeft(llarp_time_t now) const
      {
        if (now > (m_created + m_timeout))
          return 0s;
        return now - (m_created + m_timeout);
      }

      virtual std::shared_ptr<routing::IMessage>
      BuildRequestMessage() = 0;

      virtual bool
      SendRequestViaPath(path::Path_ptr p, AbstractRouter* r);

      ILookupHolder* m_parent;
      uint64_t txid;
      const std::string name;
      RouterID endpoint;

      virtual bool
      IsFor(EndpointBase::AddressVariant_t) const
      {
        return false;
      }

      util::StatusObject
      ExtractStatus() const
      {
        auto now = time_now_ms();
        util::StatusObject obj{
            {"txid", txid},
            {"endpoint", endpoint.ToHex()},
            {"name", name},
            {"timedOut", IsTimedOut(now)},
            {"createdAt", m_created.count()}};
        return obj;
      }

     protected:
      IServiceLookup(
          ILookupHolder* parent, uint64_t tx, std::string name, llarp_time_t timeout = 10s);

      const llarp_time_t m_created, m_timeout;
    };

    struct ILookupHolder
    {
      virtual void
      PutLookup(IServiceLookup* l, uint64_t txid) = 0;
    };

  }  // namespace service
}  // namespace llarp
```


-------------------------------

Updated on 2023-01-26 at 19:35:18 +0000
