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

---

# llarp/service/address.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::Address](Classes/structllarp_1_1service_1_1Address.md)** <br>Snapp [Address]().  |
| struct | **[std::hash< llarp::service::Address >](Classes/structstd_1_1hash_3_01llarp_1_1service_1_1Address_01_4.md)**  |




## Source code

```cpp
#pragma once

#include <llarp/dht/key.hpp>
#include <llarp/router_id.hpp>
#include <llarp/util/aligned.hpp>

#include <functional>
#include <numeric>
#include <string>
#include <string_view>
#include <variant>
#include <set>

namespace llarp
{
  namespace service
  {
    struct [[deprecated("replaced by llarp::layers::flow::FlowAddr")]] Address
        : public AlignedBuffer<32>
    {
      std::string subdomain;

      static const std::set<std::string> AllowedTLDs;

      static bool PermitTLD(const char* tld);

      std::string ToString(const char* tld = ".loki") const;

      bool FromString(std::string_view str, const char* tld = ".loki");

      Address() = default;

      explicit Address(const std::string& str) : AlignedBuffer<32>()
      {
        if (not FromString(str))
          throw std::runtime_error("invalid address");
      }

      explicit Address(const Data& buf) : AlignedBuffer<32>(buf)
      {}

      Address(const Address& other)
          : AlignedBuffer<32>(other.as_array()), subdomain(other.subdomain)
      {}

      explicit Address(const AlignedBuffer<32>& other) : AlignedBuffer<32>(other)
      {}

      bool operator<(const Address& other) const
      {
        return as_array() < other.as_array();
      }

      bool operator==(const Address& other) const
      {
        return as_array() == other.as_array();
      }

      bool operator!=(const Address& other) const
      {
        return as_array() != other.as_array();
      }

      Address& operator=(const Address& other) = default;
      Address& operator=(Address& other) = default;

      dht::Key_t ToKey() const;
    };

    std::optional<std::variant<Address, RouterID>>
    ParseAddress(std::string_view lokinet_addr)
        [[deprecated("replaced by llarp::layers::flow::FlowAddr")]];

  }  // namespace service

  template <>
  constexpr inline bool IsToStringFormattable<service::Address> = true;
}  // namespace llarp

namespace std
{
  template <>
  struct hash<llarp::service::Address>
  {
    size_t
    operator()(const llarp::service::Address& addr) const
    {
      return std::accumulate(addr.begin(), addr.end(), 0, std::bit_xor{});
    }
  };
}  // namespace std
```


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

Updated on 2023-04-27 at 04:17:18 +0000
