---
title: llarp/endpoint_base.hpp

---

# llarp/endpoint_base.hpp



## Namespaces

| Name           |
| -------------- |
| **[llarp](Namespaces/namespacellarp.md)** <br>[crypto.hpp] |
| **[llarp::quic](Namespaces/namespacellarp_1_1quic.md)**  |
| **[llarp::dns](Namespaces/namespacellarp_1_1dns.md)**  |

## Classes

|                | Name           |
| -------------- | -------------- |
| class | **[llarp::EndpointBase](Classes/classllarp_1_1EndpointBase.md)**  |
| struct | **[llarp::EndpointBase::SendStat](Classes/structllarp_1_1EndpointBase_1_1SendStat.md)**  |
| struct | **[llarp::EndpointBase::QUICMappingInfo](Classes/structllarp_1_1EndpointBase_1_1QUICMappingInfo.md)** <br>info about a quic mapping  |




## Source code

```cpp
#pragma once

#include "llarp/service/address.hpp"
#include "llarp/service/convotag.hpp"
#include "llarp/service/protocol_type.hpp"
#include "router_id.hpp"
#include "llarp/ev/ev.hpp"
#include "llarp/dns/srv_data.hpp"

#include <functional>
#include <memory>
#include <string>
#include <tuple>
#include <optional>
#include <unordered_set>
#include <set>
#include "oxenc/variant.h"

namespace llarp
{
  namespace quic
  {
    class TunnelManager;
  }

  namespace dns
  {
    class Server;
  }

  class EndpointBase
  {
    std::unordered_set<dns::SRVData> m_SRVRecords;

   public:
    virtual ~EndpointBase() = default;

    using AddressVariant_t = std::variant<service::Address, RouterID>;

    struct SendStat
    {
      uint64_t messagesSend;
      uint64_t messagesRecv;
      size_t numTotalConvos;
      Duration_t estimatedRTT;
      Duration_t lastSendAt;
      Duration_t lastRecvAt;
    };

    struct QUICMappingInfo
    {
      std::optional<dns::SRVData> srv;
      SockAddr localAddr;
      std::optional<std::string> remoteName;
      AddressVariant_t remoteAddr;
      uint16_t remotePort;
    };

    std::optional<QUICMappingInfo>
    GetQUICMappingInfoByID(int stream_id) const;

    void
    PutSRVRecord(dns::SRVData srv);

    virtual std::shared_ptr<dns::Server>
    DNS() const
    {
      return nullptr;
    };

    virtual void
    SRVRecordsChanged() = 0;

    bool
    DelSRVRecordIf(std::function<bool(const dns::SRVData&)> filter);

    std::set<dns::SRVData>
    SRVRecords() const;

    virtual std::optional<SendStat>
    GetStatFor(AddressVariant_t remote) const = 0;

    virtual std::unordered_set<AddressVariant_t>
    AllRemoteEndpoints() const = 0;

    virtual AddressVariant_t
    LocalAddress() const = 0;

    virtual quic::TunnelManager*
    GetQUICTunnel() = 0;

    virtual std::optional<AddressVariant_t>
    GetEndpointWithConvoTag(service::ConvoTag tag) const = 0;

    virtual std::optional<service::ConvoTag>
    GetBestConvoTagFor(AddressVariant_t addr) const = 0;

    virtual bool
    EnsurePathTo(
        AddressVariant_t addr,
        std::function<void(std::optional<service::ConvoTag>)> hook,
        llarp_time_t timeout) = 0;

    virtual void
    LookupNameAsync(
        std::string name, std::function<void(std::optional<AddressVariant_t>)> resultHandler) = 0;

    virtual const EventLoop_ptr&
    Loop() = 0;

    virtual bool
    SendToOrQueue(
        service::ConvoTag tag, const llarp_buffer_t& payload, service::ProtocolType t) = 0;

    virtual void
    LookupServiceAsync(
        std::string name,
        std::string service,
        std::function<void(std::vector<dns::SRVData>)> resultHandler) = 0;

    virtual void
    MarkAddressOutbound(AddressVariant_t remote) = 0;
  };

}  // namespace llarp
```


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

Updated on 2022-10-25 at 00:38:18 +0000
