Documentation ¶
Index ¶
- Variables
- func DefaultObservedAddr(r *http.Request) (netip.AddrPort, error)
- func DefaultSelfAddrs(ctx context.Context, socket *Socket) []netip.AddrPort
- func DefaultServeFunc(ctx context.Context, dc, ac *Conn)
- type AddrSpace
- type Chooser
- type Client
- type ClientConfig
- type Conn
- type Meta
- type Relayer
- type Server
- type ServerConfig
- type Socket
Constants ¶
This section is empty.
Variables ¶
var ( ErrHijackFailed = errors.New("failed hijacking http conn") ErrBadHandshake = errors.New("bad http handshake") ErrProtocol = errors.New("rdv protocol error") ErrUpgrade = errors.New("rdv http upgrade error") ErrNotChosen = errors.New("no rdv conn chosen") ErrServerClosed = errors.New("rdv server closed") ErrPrivilegedPort = errors.New("bad addr: expected port >=1024") ErrInvalidAddr = errors.New("bad addr: invalid addr") ErrDontUse = errors.New("bad addr: not helpful for connectivity") )
Functions ¶
func DefaultSelfAddrs ¶
TODO: Ipv4-mapped v6-addrs
func DefaultServeFunc ¶ added in v0.0.5
Handler which simply relays data without timeouts or taps.
Types ¶
type AddrSpace ¶ added in v0.0.3
type AddrSpace uint32
An IP address space is derived from an IP address. These are used for connectivity in rdv, and thus don't include multicast etc. order to differentiate between meaningful addrs.
const ( // Denotes invalid spaces. SpaceInvalid AddrSpace = 0 // Public IPv4 addrs, extremely common and useful for remote connectivity when available. SpacePublic4 AddrSpace = 1 << iota // Public IPv6 addrs, very common and very useful for both local and remote connectivity. SpacePublic6 // Private IPv4 addrs are very common and useful for local connectivity. SpacePrivate4 // ULA ipv6 addrs are not common (although link-local are). SpacePrivate6 // Link-local ipv4 addrs are not common in most setups. SpaceLink4 // Link-local ipv6 addrs are not recommended with rdv due to zones. SpaceLink6 // Loopback addresses are mostly useful for testing. SpaceLoopback )
const ( // No spaces won't match any spaces NoSpaces AddrSpace = 1 << 31 // Public IPs only PublicSpaces AddrSpace = SpacePublic4 | SpacePublic6 // Sensible defaults for most users, includes private and public spaces DefaultSpaces AddrSpace = SpacePublic4 | SpacePublic6 | SpacePrivate4 | SpacePrivate6 // All IP spaces AllSpaces AddrSpace = ^NoSpaces )
func FromNetAddr ¶ added in v0.0.3
Get AddrPort and AddrSpace from a TCP net.Addr
func GetAddrSpace ¶ added in v0.0.3
type Chooser ¶
Chooser is called once a direct connection is started. All conns on lobby are ready to go The chan is closed when either: - The parents timeout is reached - The parents context is canceled - The picker calls the cancel function (optional) The picker must drain the lobby channel. The picker must return all conns. Chosen may be nil
func RelayPenalty ¶
A chooser which gives the relay some penalty How long the dialer waits for a p2p connection, before falling back on using the relay. If zero, the relay is used as soon as available, but p2p can still be faster. A larger value increases the chances of p2p, at the cost of delaying the connection. If exceeding ConnTimeout, the relay will not be used.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶ added in v0.0.3
func NewClient(cfg *ClientConfig) *Client
type ClientConfig ¶ added in v0.0.3
type ClientConfig struct { // TLS config to use with the rdv server. TlsConfig *tls.Config // Strategy for choosing the conn to use. If nil, defaults to RelayPenalty(time.Second) DialChooser Chooser // Can be used to allow only a certain set of spaces, such as public IPs only. Defaults to // DefaultSpaces which optimal for both local and global peering. AddrSpaces AddrSpace // Defaults to using all available interface addresses. The list is automatically filtered by // AddrSpaces. This is called on each Dial or Accept, so it should be quick (ideally < 100ms). // Can be overridden if port mapping protocols are needed. SelfAddrFunc func(ctx context.Context, socket *Socket) []netip.AddrPort // Logger, by default slog.Default() Logger *slog.Logger }
type Relayer ¶
type Relayer struct {
DialTap, AcceptTap io.Writer
// At least this much inactivity is allowed on both peers before terminating the connection.
// Recommended at least 30s to account for network conditions and
// application level heartbeats. Zero means no timeout.
// As relays may serve a lot of traffic, activity is checked at an interval.
IdleTimeout time.Duration
}
A relayer handles a pair of rdv conns. The zero-value can be used.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func NewServer ¶
func NewServer(cfg *ServerConfig) *Server
type ServerConfig ¶
type ServerConfig struct { // Amount of time that on peer can wait in the lobby for its partner. Zero means no timeout. LobbyTimeout time.Duration // Function to serve a relay connection between dialer and server. // The provided context is canceled when the server is closed. // The function is responsible for closing conns. // Used to customize monitoring, rate limiting, idle timeouts relating to relay // connections. Defaults to `DefaultServeFunc`. ServeFunc func(ctx context.Context, dc, ac *Conn) // Determines the remote addr:port from the client request, and adds it to the set of // candidate addrs sent to the other peer. If nil, `req.RemoteAddr` is used. // If your server is behind a load balancer, reverse proxy or similar, you may need to extract // the address using forwarding headers. To disable this feature, return an error. // See the server setup guide for details. ObservedAddrFunc func(req *http.Request) (netip.AddrPort, error) // Logging function. Logger *slog.Logger }
type Socket ¶
type Socket struct { // A dual-stack (ipv4/6) TCP listener. // // TODO: Should this be refactored into two single-stack listeners, in order to support // non dual-stack systems? And if so, can the ports be different? See also NAT64. net.Listener /// Dialers for ipv4 and ipv6. D4, D6 *net.Dialer /// Port number for the socket, both stacks. Port uint16 // TLS config for https. // // TODO: Higher level protocols should be one layer above sockets? TlsConfig *tls.Config }
An SO_REUSEPORT TCP socket suitable for NAT traversal/hole punching, over both ipv4 and ipv6. Usually, higher level abstractions should be used.