llarp/net/address_info.hpp

Namespaces

Name
llarp
[crypto.hpp]
std
STL namespace.

Classes

Name
struct llarp::AddressInfo
struct std::hash< llarp::AddressInfo >

Source code

#pragma once

#include <llarp/crypto/types.hpp>
#include <llarp/net/net_int.hpp>
#include <llarp/util/bencode.hpp>
#include <llarp/util/mem.h>

#include <string>
#include <vector>

#include <oxenc/variant.h>

namespace llarp
{
  struct SockAddr;

  struct AddressInfo
  {
    uint16_t rank;
    std::string dialect;
    llarp::PubKey pubkey;
    net::ipv6addr_t ip{};
    uint16_t port;
    uint64_t version = llarp::constants::proto_version;

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

    bool
    BEncode(llarp_buffer_t* buf) const;

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

    void
    fromSockAddr(const SockAddr& address);

    net::ipaddr_t
    IP() const;

    inline net::ipv4addr_t
    IPv4() const
    {
      auto ip = IP();
      if (auto* ptr = std::get_if<net::ipv4addr_t>(&ip))
        return *ptr;
      throw std::runtime_error{"no ipv4 address found in address info"};
    }

    std::string
    ToString() const;
  };

  bool
  operator==(const AddressInfo& lhs, const AddressInfo& rhs);

  bool
  operator<(const AddressInfo& lhs, const AddressInfo& rhs);

  template <>
  constexpr inline bool IsToStringFormattable<AddressInfo> = true;

}  // namespace llarp

namespace std
{
  template <>
  struct hash<llarp::AddressInfo>
  {
    size_t
    operator()(const llarp::AddressInfo& addr) const
    {
      return std::hash<llarp::PubKey>{}(addr.pubkey);
    }
  };
}  // namespace std

Updated on 2026-01-10 at 22:49:45 +0000