mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-17 15:25:35 +00:00
752879d712
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.
54 lines
1.2 KiB
C++
54 lines
1.2 KiB
C++
#include "address.hpp"
|
|
#include <cstring>
|
|
#include <iostream>
|
|
|
|
namespace llarp::quic
|
|
{
|
|
using namespace std::literals;
|
|
|
|
Address::Address(const SockAddr& addr) : saddr{*addr.operator const sockaddr_in6*()}
|
|
{}
|
|
|
|
Address&
|
|
Address::operator=(const Address& other)
|
|
{
|
|
std::memmove(&saddr, &other.saddr, sizeof(saddr));
|
|
a.addrlen = other.a.addrlen;
|
|
return *this;
|
|
}
|
|
|
|
Address::operator service::ConvoTag() const
|
|
{
|
|
service::ConvoTag tag{};
|
|
tag.FromV6(saddr);
|
|
return tag;
|
|
}
|
|
|
|
std::string
|
|
Address::to_string() const
|
|
{
|
|
if (a.addrlen != sizeof(sockaddr_in6))
|
|
return "(unknown-addr)";
|
|
std::string result;
|
|
result.resize(8 + INET6_ADDRSTRLEN);
|
|
result[0] = '[';
|
|
inet_ntop(AF_INET6, &saddr.sin6_addr, &result[1], INET6_ADDRSTRLEN);
|
|
result.resize(result.find(char{0}));
|
|
result += "]:";
|
|
result += std::to_string(ToHost(nuint16_t{saddr.sin6_port}).h);
|
|
return result;
|
|
}
|
|
|
|
std::ostream&
|
|
operator<<(std::ostream& o, const Address& a)
|
|
{
|
|
return o << a.to_string();
|
|
}
|
|
std::ostream&
|
|
operator<<(std::ostream& o, const Path& p)
|
|
{
|
|
return o << p.local << "<-" << p.remote;
|
|
}
|
|
|
|
} // namespace llarp::quic
|