2021-03-26 13:16:43 +00:00
|
|
|
#pragma once
|
|
|
|
|
2023-10-24 13:18:03 +00:00
|
|
|
#include "router_id.hpp"
|
|
|
|
|
|
|
|
#include <llarp/dns/srv_data.hpp>
|
|
|
|
#include <llarp/ev/ev.hpp>
|
2023-10-19 11:49:46 +00:00
|
|
|
#include <llarp/link/tunnel.hpp>
|
2023-10-24 13:18:03 +00:00
|
|
|
#include <llarp/service/address.hpp>
|
|
|
|
#include <llarp/service/convotag.hpp>
|
|
|
|
#include <llarp/service/protocol_type.hpp>
|
|
|
|
|
|
|
|
#include <oxenc/variant.h>
|
2023-10-19 21:59:57 +00:00
|
|
|
#include <quic.hpp>
|
2023-10-24 13:18:03 +00:00
|
|
|
|
2021-03-26 13:16:43 +00:00
|
|
|
#include <functional>
|
|
|
|
#include <memory>
|
2023-10-24 13:18:03 +00:00
|
|
|
#include <optional>
|
|
|
|
#include <set>
|
2021-03-26 13:16:43 +00:00
|
|
|
#include <string>
|
2021-03-29 16:31:55 +00:00
|
|
|
#include <tuple>
|
2021-04-06 12:25:46 +00:00
|
|
|
#include <unordered_set>
|
2021-03-26 13:16:43 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
2022-04-07 20:44:23 +00:00
|
|
|
namespace dns
|
|
|
|
{
|
|
|
|
class Server;
|
|
|
|
}
|
|
|
|
|
2023-10-24 13:18:03 +00:00
|
|
|
// TODO: add forward declaration of TunnelManager
|
|
|
|
// namespace link
|
|
|
|
// {
|
|
|
|
// class TunneLManager;
|
|
|
|
// }
|
|
|
|
|
2021-03-26 13:16:43 +00:00
|
|
|
class EndpointBase
|
|
|
|
{
|
2021-04-06 12:25:46 +00:00
|
|
|
std::unordered_set<dns::SRVData> m_SRVRecords;
|
|
|
|
|
2021-03-26 13:16:43 +00:00
|
|
|
public:
|
|
|
|
virtual ~EndpointBase() = default;
|
|
|
|
|
|
|
|
using AddressVariant_t = std::variant<service::Address, RouterID>;
|
|
|
|
|
2021-04-02 15:10:37 +00:00
|
|
|
struct SendStat
|
|
|
|
{
|
|
|
|
/// how many routing messages we sent to them
|
|
|
|
uint64_t messagesSend;
|
|
|
|
/// how many routing messages we got from them
|
|
|
|
uint64_t messagesRecv;
|
|
|
|
/// how many convos have we had to this guy total?
|
|
|
|
size_t numTotalConvos;
|
|
|
|
/// current estimated rtt
|
|
|
|
Duration_t estimatedRTT;
|
|
|
|
/// last time point when we sent a message to them
|
|
|
|
Duration_t lastSendAt;
|
|
|
|
/// last time point when we got a message from them
|
|
|
|
Duration_t lastRecvAt;
|
|
|
|
};
|
|
|
|
|
2021-04-06 12:25:46 +00:00
|
|
|
/// info about a quic mapping
|
|
|
|
struct QUICMappingInfo
|
|
|
|
{
|
|
|
|
/// srv data if it was provided
|
|
|
|
std::optional<dns::SRVData> srv;
|
|
|
|
/// address we are bound on
|
|
|
|
SockAddr localAddr;
|
|
|
|
/// the remote's lns name if we have one
|
|
|
|
std::optional<std::string> remoteName;
|
|
|
|
/// the remote's address
|
|
|
|
AddressVariant_t remoteAddr;
|
|
|
|
/// the remote's port we are connecting to
|
|
|
|
uint16_t remotePort;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// maybe get quic mapping info given its stream id
|
|
|
|
/// returns std::nullopt if we have no stream given that id
|
|
|
|
std::optional<QUICMappingInfo>
|
|
|
|
GetQUICMappingInfoByID(int stream_id) const;
|
|
|
|
|
|
|
|
/// add an srv record to this endpoint's descriptor
|
|
|
|
void
|
|
|
|
PutSRVRecord(dns::SRVData srv);
|
|
|
|
|
2022-04-07 20:44:23 +00:00
|
|
|
/// get dns serverr if we have on on this endpoint
|
|
|
|
virtual std::shared_ptr<dns::Server>
|
|
|
|
DNS() const
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
};
|
|
|
|
|
2021-04-06 12:25:46 +00:00
|
|
|
/// called when srv data changes in some way
|
|
|
|
virtual void
|
|
|
|
SRVRecordsChanged() = 0;
|
|
|
|
|
|
|
|
/// remove srv records from this endpoint that match a filter
|
|
|
|
/// for each srv record call it with filter, remove if filter returns true
|
|
|
|
/// return if we removed any srv records
|
|
|
|
bool
|
|
|
|
DelSRVRecordIf(std::function<bool(const dns::SRVData&)> filter);
|
|
|
|
|
|
|
|
/// get copy of all srv records
|
|
|
|
std::set<dns::SRVData>
|
|
|
|
SRVRecords() const;
|
|
|
|
|
|
|
|
/// get statistics about how much traffic we sent and recv'd to a remote endpoint
|
|
|
|
virtual std::optional<SendStat>
|
|
|
|
GetStatFor(AddressVariant_t remote) const = 0;
|
|
|
|
|
|
|
|
/// list all remote endpoint addresses we have that are mapped
|
|
|
|
virtual std::unordered_set<AddressVariant_t>
|
|
|
|
AllRemoteEndpoints() const = 0;
|
2021-04-02 15:10:37 +00:00
|
|
|
|
|
|
|
/// get our local address
|
|
|
|
virtual AddressVariant_t
|
2021-03-27 18:54:09 +00:00
|
|
|
LocalAddress() const = 0;
|
|
|
|
|
2023-10-19 11:49:46 +00:00
|
|
|
virtual link::TunnelManager*
|
2021-03-26 20:45:19 +00:00
|
|
|
GetQUICTunnel() = 0;
|
|
|
|
|
2021-03-26 13:16:43 +00:00
|
|
|
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
|
2023-10-21 03:30:10 +00:00
|
|
|
lookup_name(std::string name, std::function<void(std::string, bool)> func) = 0;
|
2021-03-26 13:16:43 +00:00
|
|
|
|
|
|
|
virtual const EventLoop_ptr&
|
|
|
|
Loop() = 0;
|
|
|
|
|
|
|
|
virtual bool
|
2023-10-12 20:37:45 +00:00
|
|
|
send_to(service::ConvoTag tag, std::string payload) = 0;
|
2021-04-12 11:39:07 +00:00
|
|
|
|
|
|
|
/// lookup srv records async
|
|
|
|
virtual void
|
|
|
|
LookupServiceAsync(
|
|
|
|
std::string name,
|
|
|
|
std::string service,
|
|
|
|
std::function<void(std::vector<dns::SRVData>)> resultHandler) = 0;
|
2021-06-05 13:06:17 +00:00
|
|
|
|
|
|
|
virtual void
|
2023-10-10 20:49:53 +00:00
|
|
|
MarkAddressOutbound(service::Address remote) = 0;
|
2021-03-26 13:16:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace llarp
|