lokinet/llarp/service/endpoint.hpp

587 lines
16 KiB
C++
Raw Normal View History

#pragma once
#include <llarp/dht/messages/gotrouter.hpp>
#include <llarp/ev/ev.hpp>
#include <llarp/exit/session.hpp>
#include <llarp/net/ip_range_map.hpp>
#include <llarp/net/net.hpp>
#include <llarp/path/path.hpp>
#include <llarp/path/pathbuilder.hpp>
#include <llarp/util/compare_ptr.hpp>
2023-01-09 18:47:41 +01:00
// --- begin kitchen sink headers ----
#include <llarp/service/address.hpp>
#include <llarp/service/handler.hpp>
#include <llarp/service/identity.hpp>
#include <llarp/service/pendingbuffer.hpp>
#include <llarp/service/protocol.hpp>
#include <llarp/service/sendcontext.hpp>
#include <llarp/service/protocol_type.hpp>
#include <llarp/service/session.hpp>
#include <llarp/service/lookup.hpp>
#include <llarp/service/endpoint_types.hpp>
#include <llarp/endpoint_base.hpp>
#include <llarp/service/auth.hpp>
// ----- end kitchen sink headers -----
#include <optional>
2021-03-12 18:41:48 +01:00
#include <unordered_map>
2021-03-16 20:17:02 +01:00
#include <variant>
#include <oxenc/variant.h>
2020-05-28 13:07:32 +02:00
2021-09-23 20:01:04 +02:00
#include <llarp/vpn/egres_packet_router.hpp>
#include <llarp/dns/server.hpp>
2021-09-23 20:01:04 +02:00
2019-03-29 02:02:41 +01:00
// minimum time between introset shifts
2018-09-18 19:48:26 +02:00
#ifndef MIN_SHIFT_INTERVAL
2020-02-24 20:40:45 +01:00
#define MIN_SHIFT_INTERVAL 5s
2018-09-18 19:48:26 +02:00
#endif
2018-07-09 19:32:11 +02:00
namespace llarp
{
QUIC lokinet integration refactor Refactors how quic packets get handled: the actual tunnels now live in tunnel.hpp's TunnelManager which holds and manages all the quic<->tcp tunnelling. service::Endpoint now holds a TunnelManager rather than a quic::Server. We only need one quic server, but we need a separate quic client instance per outgoing quic tunnel, and TunnelManager handles all that glue now. Adds QUIC packet handling to get to the right tunnel code. This required multiplexing incoming quic packets, as follows: Adds a very small quic tunnel packet header of 4 bytes: [1, SPORT, ECN] for client->server packets, where SPORT is our source "port" (really: just a uint16_t unique quic instance identifier) or [2, DPORT, ECN] for server->client packets where the DPORT is the SPORT from above. (This also reworks ECN bits to get properly carried over lokinet.) We don't need a destination/source port for the server-side because there is only ever one quic server (and we know we're going to it when the first byte of the header is 1). Removes the config option for quic exposing ports; a full lokinet will simply accept anything incoming on quic and tunnel it to the requested port on the the local endpoint IP (this handler will come in a following commit). Replace ConvoTags with full addresses: we need to carry the port, as well, which the ConvoTag can't give us, so change those to more general SockAddrs from which we can extract both the ConvoTag *and* the port. Add a pending connection queue along with new quic-side handlers to call when a stream becomes available (TunnelManager uses this to wire up pending incoming conns with quic streams as streams open up). Completely get rid of tunnel_server/tunnel_client.cpp code; it is now moved to tunnel.hpp. Add listen()/forget() methods in TunnelManager for setting up quic listening sockets (for liblokinet usage). Add open()/close() methods in TunnelManager for spinning up new quic clients for outgoing quic connections.
2021-03-23 20:26:32 +01:00
namespace quic
{
class TunnelManager;
}
2018-07-09 19:32:11 +02:00
namespace service
{
struct AsyncKeyExchange;
struct Context;
struct EndpointState;
struct OutboundContext;
2020-02-24 20:40:45 +01:00
/// minimum interval for publishing introsets
inline constexpr auto IntrosetPublishInterval = path::intro_path_spread / 2;
2020-02-24 20:40:45 +01:00
/// how agressively should we retry publishing introset on failure
inline constexpr auto IntrosetPublishRetryCooldown = 1s;
2020-02-24 20:40:45 +01:00
/// how aggressively should we retry looking up introsets
inline constexpr auto IntrosetLookupCooldown = 250ms;
/// number of unique snodes we want to talk to do to ons lookups
inline constexpr size_t MIN_ENDPOINTS_FOR_LNS_LOOKUP = 2;
2021-03-26 14:16:43 +01:00
struct Endpoint : public path::Builder,
public ILookupHolder,
public IDataHandler,
public EndpointBase
2018-07-09 19:32:11 +02:00
{
Endpoint(AbstractRouter* r, Context* parent);
~Endpoint() override;
2018-07-09 19:32:11 +02:00
/// return true if we are ready to recv packets from the void.
/// really should be ReadyForInboundTraffic() but the diff is HUGE and we need to rewrite this
/// component anyways.
bool
IsReady() const;
2019-11-29 00:08:02 +01:00
void
QueueRecvData(RecvDataEvent ev) override;
/// return true if our introset has expired intros
bool
IntrosetIsStale() const;
/// construct parameters for notify hooks
virtual std::unordered_map<std::string, std::string>
NotifyParams() const;
virtual util::StatusObject
2019-04-19 17:10:26 +02:00
ExtractStatus() const;
2019-02-08 20:43:25 +01:00
void
SetHandler(IDataHandler* h);
2018-08-16 16:34:15 +02:00
virtual bool
Configure(const NetworkConfig& conf, const DnsConfig& dnsConf);
2018-07-09 19:32:11 +02:00
2019-07-31 01:42:13 +02:00
void
2019-04-23 18:13:22 +02:00
Tick(llarp_time_t now) override;
/// return true if we have a resolvable ip address
virtual bool
HasIfAddr() const
{
return false;
}
2020-08-21 17:07:37 +02:00
virtual std::string
GetIfName() const = 0;
2021-02-17 20:26:39 +01:00
std::optional<ConvoTag>
2021-03-26 15:18:39 +01:00
GetBestConvoTagFor(std::variant<Address, RouterID> addr) const override;
2021-02-17 20:26:39 +01:00
/// get our ifaddr if it is set
2019-06-11 18:44:05 +02:00
virtual huint128_t
GetIfAddr() const
{
2019-07-01 15:44:25 +02:00
return {0};
}
2021-04-14 17:07:06 +02:00
/// get the exit policy for our exit if we have one
/// override me
virtual std::optional<net::TrafficPolicy>
GetExitPolicy() const
{
return std::nullopt;
};
/// get the ip ranges we claim to own
/// override me
2021-04-14 21:40:57 +02:00
virtual std::set<IPRange>
2021-04-14 17:07:06 +02:00
GetOwnedRanges() const
{
return {};
};
virtual void
Thaw(){};
2019-07-31 01:42:13 +02:00
void
2019-05-07 19:46:38 +02:00
ResetInternalState() override;
/// loop (via router)
/// use when sending any data on a path
const EventLoop_ptr&
2021-03-26 15:18:39 +01:00
Loop() override;
AbstractRouter*
Router();
2018-07-23 01:14:29 +02:00
virtual bool
LoadKeyFile();
2018-08-16 16:34:15 +02:00
virtual bool
2018-07-09 19:32:11 +02:00
Start();
2019-07-31 01:42:13 +02:00
std::string
2019-03-25 02:54:37 +01:00
Name() const override;
2018-07-16 05:32:13 +02:00
AddressVariant_t
LocalAddress() const override;
std::optional<SendStat>
GetStatFor(AddressVariant_t remote) const override;
std::unordered_set<AddressVariant_t>
AllRemoteEndpoints() const override;
2018-07-18 05:10:21 +02:00
bool
2018-12-24 22:10:35 +01:00
ShouldPublishDescriptors(llarp_time_t now) const override;
2018-07-18 05:10:21 +02:00
void
SRVRecordsChanged() override;
2019-03-30 14:02:10 +01:00
void
HandlePathDied(path::Path_ptr p) override;
2019-03-30 14:02:10 +01:00
2021-09-23 20:01:04 +02:00
virtual vpn::EgresPacketRouter*
EgresPacketRouter()
{
return nullptr;
};
virtual vpn::NetworkInterface*
GetVPNInterface()
{
return nullptr;
}
2018-07-18 05:10:21 +02:00
bool
2020-01-27 22:30:41 +01:00
PublishIntroSet(const EncryptedIntroSet& i, AbstractRouter* r) override;
2018-07-18 05:10:21 +02:00
2018-09-18 16:48:06 +02:00
bool
PublishIntroSetVia(
const EncryptedIntroSet& i, AbstractRouter* r, path::Path_ptr p, uint64_t relayOrder);
2018-09-18 16:48:06 +02:00
bool
HandleGotIntroMessage(std::shared_ptr<const dht::GotIntroMessage> msg) override;
2018-08-10 23:34:11 +02:00
bool
HandleGotRouterMessage(std::shared_ptr<const dht::GotRouterMessage> msg) override;
2018-08-10 23:34:11 +02:00
bool
HandleGotNameMessage(std::shared_ptr<const dht::GotNameMessage> msg) override;
2018-07-12 20:21:44 +02:00
bool
HandleHiddenServiceFrame(path::Path_ptr p, const service::ProtocolFrame& msg);
2018-07-12 20:21:44 +02:00
2020-05-28 13:07:32 +02:00
void
SetEndpointAuth(std::shared_ptr<IAuthPolicy> policy);
/// sets how we authenticate with remote address
void
SetAuthInfoForEndpoint(Address remote, AuthInfo info);
virtual huint128_t ObtainIPForAddr(std::variant<Address, RouterID>) = 0;
/// get a key for ip address
virtual std::optional<std::variant<service::Address, RouterID>>
ObtainAddrForIP(huint128_t ip) const = 0;
2018-10-23 20:06:55 +02:00
2019-07-01 15:44:25 +02:00
// virtual bool
// HasServiceAddress(const AlignedBuffer< 32 >& addr) const = 0;
2018-08-10 05:51:38 +02:00
/// return true if we have a pending job to build to a hidden service but
/// it's not done yet
bool
HasPendingPathToService(const Address& remote) const;
2018-09-18 19:48:26 +02:00
bool
HandleDataMessage(
path::Path_ptr path, const PathID_t from, std::shared_ptr<ProtocolMessage> msg) override;
2018-08-09 21:02:17 +02:00
/// handle packet io from service node or hidden service to frontend
virtual bool
HandleInboundPacket(
const ConvoTag tag, const llarp_buffer_t& pkt, ProtocolType t, uint64_t seqno) = 0;
2019-07-01 15:44:25 +02:00
// virtual bool
// HandleWriteIPPacket(const llarp_buffer_t& pkt,
// std::function< huint128_t(void) > getFromIP) = 0;
2018-11-29 14:12:35 +01:00
bool
ProcessDataMessage(std::shared_ptr<ProtocolMessage> msg);
2018-09-18 19:48:26 +02:00
2018-08-10 23:34:11 +02:00
/// ensure that we know a router, looks up if it doesn't
void
EnsureRouterIsKnown(const RouterID& router);
/// lookup a router via closest path
bool
2019-05-03 15:15:03 +02:00
LookupRouterAnon(RouterID router, RouterLookupHandler handler);
void
LookupNameAsync(
std::string name,
2021-03-26 15:18:39 +01:00
std::function<void(std::optional<std::variant<Address, RouterID>>)> resultHandler)
override;
2021-04-12 13:39:07 +02:00
void
LookupServiceAsync(
std::string name,
std::string service,
std::function<void(std::vector<dns::SRVData>)> resultHandler) override;
2019-04-25 19:15:56 +02:00
/// called on event loop pump
virtual void
Pump(llarp_time_t now);
/// stop this endpoint
bool
Stop() override;
const Identity&
2018-11-21 15:30:14 +01:00
GetIdentity() const
2018-07-23 01:14:29 +02:00
{
return m_Identity;
2018-07-23 01:14:29 +02:00
}
2018-07-19 06:58:39 +02:00
void
MapExitRange(IPRange range, service::Address exit);
void
UnmapExitRange(IPRange range);
2018-08-04 04:59:32 +02:00
void
2018-12-24 22:10:35 +01:00
PutLookup(IServiceLookup* lookup, uint64_t txid) override;
2018-08-04 04:59:32 +02:00
void
HandlePathBuilt(path::Path_ptr path) override;
bool
HandleDataDrop(path::Path_ptr p, const PathID_t& dst, uint64_t s);
bool
CheckPathIsDead(path::Path_ptr p, llarp_time_t latency);
using PendingBufferQueue = std::deque<PendingBuffer>;
2018-08-22 17:52:10 +02:00
size_t
RemoveAllConvoTagsFor(service::Address remote);
2020-02-18 17:00:45 +01:00
bool
WantsOutboundSession(const Address&) const override;
/// this MUST be called if you want to call EnsurePathTo on the given address
2021-06-05 15:06:17 +02:00
void MarkAddressOutbound(AddressVariant_t) override;
2020-02-18 17:00:45 +01:00
bool
2020-05-17 19:44:00 +02:00
ShouldBundleRC() const override
{
return false;
}
2020-05-21 16:18:23 +02:00
void
BlacklistSNode(const RouterID snode) override;
/// maybe get an endpoint variant given its convo tag
std::optional<std::variant<Address, RouterID>>
2021-03-26 15:18:39 +01:00
GetEndpointWithConvoTag(ConvoTag t) const override;
2019-03-08 18:00:13 +01:00
bool
HasConvoTag(const ConvoTag& t) const override;
2019-03-08 15:36:24 +01:00
bool
ShouldBuildMore(llarp_time_t now) const override;
virtual llarp_time_t
PathAlignmentTimeout() const
{
constexpr auto DefaultPathAlignmentTimeout = 30s;
return DefaultPathAlignmentTimeout;
}
bool
EnsurePathTo(
std::variant<Address, RouterID> addr,
std::function<void(std::optional<ConvoTag>)> hook,
2021-03-26 15:18:39 +01:00
llarp_time_t timeout) override;
2018-07-12 20:21:44 +02:00
// passed a sendto context when we have a path established otherwise
// nullptr if the path was not made before the timeout
using PathEnsureHook = std::function<void(Address, OutboundContext*)>;
2018-07-12 20:21:44 +02:00
static constexpr auto DefaultPathEnsureTimeout = 2s;
2018-07-12 20:21:44 +02:00
/// return false if we have already called this function before for this
/// address
bool
EnsurePathToService(
const Address remote,
PathEnsureHook h,
llarp_time_t timeoutMS = DefaultPathEnsureTimeout);
2018-07-12 20:21:44 +02:00
using SNodeEnsureHook = std::function<void(const RouterID, exit::BaseSession_ptr, ConvoTag)>;
2018-11-29 14:12:35 +01:00
void
InformPathToService(const Address remote, OutboundContext* ctx);
2018-11-29 14:12:35 +01:00
/// ensure a path to a service node by public key
bool
2019-07-01 15:44:25 +02:00
EnsurePathToSNode(const RouterID remote, SNodeEnsureHook h);
2018-11-29 14:12:35 +01:00
/// return true if this endpoint is trying to lookup this router right now
bool
HasPendingRouterLookup(const RouterID remote) const;
2018-11-29 14:12:35 +01:00
bool
2019-07-01 15:44:25 +02:00
HasPathToSNode(const RouterID remote) const;
2018-11-29 14:12:35 +01:00
bool
HasFlowToService(const Address remote) const;
2018-08-09 21:02:17 +02:00
void
PutSenderFor(const ConvoTag& tag, const ServiceInfo& info, bool inbound) override;
bool
HasInboundConvo(const Address& addr) const override;
bool
HasOutboundConvo(const Address& addr) const override;
2018-08-09 21:02:17 +02:00
bool
GetCachedSessionKeyFor(const ConvoTag& remote, SharedSecret& secret) const override;
2018-08-09 21:02:17 +02:00
void
PutCachedSessionKeyFor(const ConvoTag& remote, const SharedSecret& secret) override;
2018-08-09 21:02:17 +02:00
bool
2018-12-24 22:10:35 +01:00
GetSenderFor(const ConvoTag& remote, ServiceInfo& si) const override;
2018-08-09 21:02:17 +02:00
void
2018-12-24 22:10:35 +01:00
PutIntroFor(const ConvoTag& remote, const Introduction& intro) override;
2018-08-09 21:02:17 +02:00
bool
2018-12-24 22:10:35 +01:00
GetIntroFor(const ConvoTag& remote, Introduction& intro) const override;
2018-08-09 21:02:17 +02:00
2019-03-08 17:00:45 +01:00
void
RemoveConvoTag(const ConvoTag& remote) override;
2019-09-19 22:28:12 +02:00
void
ConvoTagTX(const ConvoTag& remote) override;
void
ConvoTagRX(const ConvoTag& remote) override;
2019-09-19 22:28:12 +02:00
2019-02-21 17:45:33 +01:00
void
PutReplyIntroFor(const ConvoTag& remote, const Introduction& intro) override;
2019-02-21 17:45:33 +01:00
bool
GetReplyIntroFor(const ConvoTag& remote, Introduction& intro) const override;
2019-02-21 17:45:33 +01:00
2018-08-09 21:02:17 +02:00
bool
GetConvoTagsForService(const Address& si, std::set<ConvoTag>& tag) const override;
2018-08-09 21:02:17 +02:00
void
PutNewOutboundContext(const IntroSet& introset, llarp_time_t timeLeftToAlign);
std::optional<uint64_t>
2019-04-19 18:02:32 +02:00
GetSeqNoForConvo(const ConvoTag& tag);
/// count unique endpoints we are talking to
size_t
UniqueEndpoints() const;
bool
HasExit() const;
std::optional<std::vector<RouterContact>>
GetHopsForBuild() override;
std::optional<std::vector<RouterContact>>
GetHopsForBuildWithEndpoint(RouterID endpoint);
2019-05-10 18:19:33 +02:00
virtual void
PathBuildStarted(path::Path_ptr path) override;
2018-07-18 05:10:21 +02:00
virtual void
IntroSetPublishFail();
virtual void
IntroSetPublished();
2020-05-28 13:07:32 +02:00
void
2020-06-17 15:07:05 +02:00
AsyncProcessAuthMessage(
std::shared_ptr<ProtocolMessage> msg, std::function<void(AuthResult)> hook);
2020-05-28 13:07:32 +02:00
void
2021-01-01 19:55:31 +01:00
SendAuthResult(path::Path_ptr path, PathID_t replyPath, ConvoTag tag, AuthResult st);
2020-05-28 13:07:32 +02:00
uint64_t
GenTXID();
void
ResetConvoTag(ConvoTag tag, path::Path_ptr path, PathID_t from);
const std::set<RouterID>&
SnodeBlacklist() const;
// Looks up the ConvoTag and, if it exists, calls SendToOrQueue to send it to a remote client
// or a snode (or nothing, if the convo tag is unknown).
bool
2021-03-26 15:18:39 +01:00
SendToOrQueue(ConvoTag tag, const llarp_buffer_t& payload, ProtocolType t) override;
// Send a to (or queues for sending) to either an address or router id
bool
SendToOrQueue(
const std::variant<Address, RouterID>& addr,
const llarp_buffer_t& payload,
ProtocolType t);
// Sends to (or queues for sending) to a remote client
bool
SendToOrQueue(const Address& addr, const llarp_buffer_t& payload, ProtocolType t);
// Sends to (or queues for sending) to a router
bool
SendToOrQueue(const RouterID& addr, const llarp_buffer_t& payload, ProtocolType t);
2020-03-07 02:20:11 +01:00
std::optional<AuthInfo>
MaybeGetAuthInfoForEndpoint(service::Address addr);
QUIC lokinet integration refactor Refactors how quic packets get handled: the actual tunnels now live in tunnel.hpp's TunnelManager which holds and manages all the quic<->tcp tunnelling. service::Endpoint now holds a TunnelManager rather than a quic::Server. We only need one quic server, but we need a separate quic client instance per outgoing quic tunnel, and TunnelManager handles all that glue now. Adds QUIC packet handling to get to the right tunnel code. This required multiplexing incoming quic packets, as follows: Adds a very small quic tunnel packet header of 4 bytes: [1, SPORT, ECN] for client->server packets, where SPORT is our source "port" (really: just a uint16_t unique quic instance identifier) or [2, DPORT, ECN] for server->client packets where the DPORT is the SPORT from above. (This also reworks ECN bits to get properly carried over lokinet.) We don't need a destination/source port for the server-side because there is only ever one quic server (and we know we're going to it when the first byte of the header is 1). Removes the config option for quic exposing ports; a full lokinet will simply accept anything incoming on quic and tunnel it to the requested port on the the local endpoint IP (this handler will come in a following commit). Replace ConvoTags with full addresses: we need to carry the port, as well, which the ConvoTag can't give us, so change those to more general SockAddrs from which we can extract both the ConvoTag *and* the port. Add a pending connection queue along with new quic-side handlers to call when a stream becomes available (TunnelManager uses this to wire up pending incoming conns with quic streams as streams open up). Completely get rid of tunnel_server/tunnel_client.cpp code; it is now moved to tunnel.hpp. Add listen()/forget() methods in TunnelManager for setting up quic listening sockets (for liblokinet usage). Add open()/close() methods in TunnelManager for spinning up new quic clients for outgoing quic connections.
2021-03-23 20:26:32 +01:00
/// Returns a pointer to the quic::Tunnel object handling quic connections for this endpoint.
/// Returns nullptr if quic is not supported.
quic::TunnelManager*
GetQUICTunnel() override;
QUIC lokinet integration refactor Refactors how quic packets get handled: the actual tunnels now live in tunnel.hpp's TunnelManager which holds and manages all the quic<->tcp tunnelling. service::Endpoint now holds a TunnelManager rather than a quic::Server. We only need one quic server, but we need a separate quic client instance per outgoing quic tunnel, and TunnelManager handles all that glue now. Adds QUIC packet handling to get to the right tunnel code. This required multiplexing incoming quic packets, as follows: Adds a very small quic tunnel packet header of 4 bytes: [1, SPORT, ECN] for client->server packets, where SPORT is our source "port" (really: just a uint16_t unique quic instance identifier) or [2, DPORT, ECN] for server->client packets where the DPORT is the SPORT from above. (This also reworks ECN bits to get properly carried over lokinet.) We don't need a destination/source port for the server-side because there is only ever one quic server (and we know we're going to it when the first byte of the header is 1). Removes the config option for quic exposing ports; a full lokinet will simply accept anything incoming on quic and tunnel it to the requested port on the the local endpoint IP (this handler will come in a following commit). Replace ConvoTags with full addresses: we need to carry the port, as well, which the ConvoTag can't give us, so change those to more general SockAddrs from which we can extract both the ConvoTag *and* the port. Add a pending connection queue along with new quic-side handlers to call when a stream becomes available (TunnelManager uses this to wire up pending incoming conns with quic streams as streams open up). Completely get rid of tunnel_server/tunnel_client.cpp code; it is now moved to tunnel.hpp. Add listen()/forget() methods in TunnelManager for setting up quic listening sockets (for liblokinet usage). Add open()/close() methods in TunnelManager for spinning up new quic clients for outgoing quic connections.
2021-03-23 20:26:32 +01:00
2020-03-07 02:20:11 +01:00
protected:
/// parent context that owns this endpoint
Context* const context;
2019-06-11 18:44:05 +02:00
virtual bool
SupportsV6() const = 0;
void
RegenAndPublishIntroSet();
2018-07-18 05:10:21 +02:00
IServiceLookup*
GenerateLookupByTag(const Tag& tag);
void
PrefetchServicesByTag(const Tag& tag);
private:
void
HandleVerifyGotRouter(dht::GotRouterMessage_constptr msg, RouterID id, bool valid);
2018-08-10 23:34:11 +02:00
bool
OnLookup(
const service::Address& addr,
std::optional<IntroSet> i,
const RouterID& endpoint,
llarp_time_t timeLeft,
uint64_t relayOrder);
2018-08-10 23:34:11 +02:00
2018-08-09 21:02:17 +02:00
bool
2018-08-18 16:01:21 +02:00
DoNetworkIsolation(bool failed);
2018-08-09 21:02:17 +02:00
2018-08-16 16:34:15 +02:00
virtual bool
SetupNetworking()
{
// XXX: override me
return true;
}
2018-08-18 16:01:21 +02:00
virtual bool
IsolationFailed()
{
// XXX: override me
return false;
}
/// return true if we are ready to do outbound and inbound traffic
2022-10-25 02:39:05 +02:00
bool
ReadyForNetwork() const;
2022-10-25 02:39:05 +02:00
protected:
bool
ReadyToDoLookup(size_t num_paths) const;
path::Path::UniqueEndpointSet_t
GetUniqueEndpointsForLookup() const;
IDataHandler* m_DataHandler = nullptr;
2018-08-09 21:02:17 +02:00
Identity m_Identity;
net::IPRangeMap<service::Address> m_ExitMap;
bool m_PublishIntroSet = true;
2020-06-01 19:58:45 +02:00
std::unique_ptr<EndpointState> m_state;
2020-06-02 23:10:42 +02:00
std::shared_ptr<IAuthPolicy> m_AuthPolicy;
std::unordered_map<Address, AuthInfo> m_RemoteAuthInfos;
QUIC lokinet integration refactor Refactors how quic packets get handled: the actual tunnels now live in tunnel.hpp's TunnelManager which holds and manages all the quic<->tcp tunnelling. service::Endpoint now holds a TunnelManager rather than a quic::Server. We only need one quic server, but we need a separate quic client instance per outgoing quic tunnel, and TunnelManager handles all that glue now. Adds QUIC packet handling to get to the right tunnel code. This required multiplexing incoming quic packets, as follows: Adds a very small quic tunnel packet header of 4 bytes: [1, SPORT, ECN] for client->server packets, where SPORT is our source "port" (really: just a uint16_t unique quic instance identifier) or [2, DPORT, ECN] for server->client packets where the DPORT is the SPORT from above. (This also reworks ECN bits to get properly carried over lokinet.) We don't need a destination/source port for the server-side because there is only ever one quic server (and we know we're going to it when the first byte of the header is 1). Removes the config option for quic exposing ports; a full lokinet will simply accept anything incoming on quic and tunnel it to the requested port on the the local endpoint IP (this handler will come in a following commit). Replace ConvoTags with full addresses: we need to carry the port, as well, which the ConvoTag can't give us, so change those to more general SockAddrs from which we can extract both the ConvoTag *and* the port. Add a pending connection queue along with new quic-side handlers to call when a stream becomes available (TunnelManager uses this to wire up pending incoming conns with quic streams as streams open up). Completely get rid of tunnel_server/tunnel_client.cpp code; it is now moved to tunnel.hpp. Add listen()/forget() methods in TunnelManager for setting up quic listening sockets (for liblokinet usage). Add open()/close() methods in TunnelManager for spinning up new quic clients for outgoing quic connections.
2021-03-23 20:26:32 +01:00
std::unique_ptr<quic::TunnelManager> m_quic;
/// (lns name, optional exit range, optional auth info) for looking up on startup
std::unordered_map<std::string, std::pair<std::optional<IPRange>, std::optional<AuthInfo>>>
m_StartupLNSMappings;
RecvPacketQueue_t m_InboundTrafficQueue;
2021-01-01 19:55:31 +01:00
public:
SendMessageQueue_t m_SendQueue;
private:
llarp_time_t m_LastIntrosetRegenAttempt = 0s;
2021-01-01 19:55:31 +01:00
protected:
2019-11-29 00:08:02 +01:00
void
FlushRecvData();
friend struct EndpointUtil;
// clang-format off
const IntroSet& introSet() const;
IntroSet& introSet();
2019-05-07 10:29:47 +02:00
using ConvoMap = std::unordered_map<ConvoTag, Session>;
const ConvoMap& Sessions() const;
ConvoMap& Sessions();
// clang-format on
thread::Queue<RecvDataEvent> m_RecvQueue;
/// for rate limiting introset lookups
util::DecayingHashSet<Address> m_IntrosetLookupFilter;
2018-07-09 19:32:11 +02:00
};
using Endpoint_ptr = std::shared_ptr<Endpoint>;
2018-07-09 19:32:11 +02:00
} // namespace service
} // namespace llarp