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

---

# llarp/service/intro.hpp



## Namespaces

| Name           |
| -------------- |
| **[llarp](Namespaces/namespacellarp.md)** <br>[crypto.hpp] |
| **[llarp::service](Namespaces/namespacellarp_1_1service.md)**  |
| **[std](Namespaces/namespacestd.md)** <br>STL namespace.  |

## Classes

|                | Name           |
| -------------- | -------------- |
| struct | **[llarp::service::Introduction](Classes/structllarp_1_1service_1_1Introduction.md)**  |
| struct | **[llarp::service::CompareIntroTimestamp](Classes/structllarp_1_1service_1_1CompareIntroTimestamp.md)** <br>comparator for introset timestamp  |
| struct | **[std::hash< llarp::service::Introduction >](Classes/structstd_1_1hash_3_01llarp_1_1service_1_1Introduction_01_4.md)**  |




## Source code

```cpp
#pragma once

#include <llarp/crypto/types.hpp>
#include <llarp/path/path_types.hpp>
#include <llarp/util/bencode.hpp>
#include <llarp/util/status.hpp>

#include <iostream>

namespace llarp
{
  namespace service
  {
    struct Introduction
    {
      RouterID router;
      PathID_t pathID;
      llarp_time_t latency = 0s;
      llarp_time_t expiresAt = 0s;
      uint64_t version = llarp::constants::proto_version;

      util::StatusObject
      ExtractStatus() const;

      bool
      IsExpired(llarp_time_t now) const
      {
        return now >= expiresAt;
      }

      bool
      ExpiresSoon(llarp_time_t now, llarp_time_t dlt = 30s) const
      {
        return IsExpired(now + dlt);
      }

      std::string
      ToString() const;

      bool
      BEncode(llarp_buffer_t* buf) const;

      bool
      BDecode(llarp_buffer_t* buf)
      {
        return bencode_decode_dict(*this, buf);
      }

      bool
      DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf);

      void
      Clear();

      bool
      operator<(const Introduction& other) const
      {
        return std::tie(expiresAt, pathID, router, version, latency)
            < std::tie(other.expiresAt, other.pathID, other.router, other.version, other.latency);
      }

      bool
      operator==(const Introduction& other) const
      {
        return pathID == other.pathID && router == other.router;
      }

      bool
      operator!=(const Introduction& other) const
      {
        return pathID != other.pathID || router != other.router;
      }
    };

    struct CompareIntroTimestamp
    {
      bool
      operator()(const Introduction& left, const Introduction& right) const
      {
        return left.expiresAt > right.expiresAt;
      }
    };
  }  // namespace service
}  // namespace llarp

template <>
constexpr inline bool llarp::IsToStringFormattable<llarp::service::Introduction> = true;

namespace std
{
  template <>
  struct hash<llarp::service::Introduction>
  {
    size_t
    operator()(const llarp::service::Introduction& i) const
    {
      return std::hash<llarp::PubKey>{}(i.router) ^ std::hash<llarp::PathID_t>{}(i.pathID);
    }
  };
}  // namespace std
```


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

Updated on 2022-11-17 at 22:27:42 +0000
