Documentation
¶
Overview ¶
Package transports maps the transport names an operator writes in the config to the go-libp2p transports the host runs, and checks that a set of listen and external addresses is one those transports can serve.
UDX is the transport the mobile clients speak and the default. The rest are go-libp2p's own: TCP, QUIC, WebSocket and WebTransport. TCP and WebSocket run Noise and yamux over the connection; QUIC and WebTransport bring their own encryption and stream multiplexing, so the yamux keepalive and write timeout do not apply to them (quic-go keeps a connection alive on its own 15-second period).
Index ¶
- Constants
- func ForAddress(addr ma.Multiaddr) (string, error)
- func Known() []string
- func LoadServerTLS(certFile, keyFile string) (*tls.Config, error)
- func OnIP(listen []string, ip net.IP) ([]string, error)
- func Options(names []string, with ...Option) ([]libp2p.Option, error)
- func Validate(names, listen, external []string, secureWebSocket bool) error
- type Option
Constants ¶
const ( UDX = "udx" TCP = "tcp" QUIC = "quic-v1" WebSocket = "websocket" WebTransport = "webtransport" // WebRTCDirect is recognised so that it can be refused by name. // go-libp2p's WebRTC transport runs pion/dtls/v2, which carries // GO-2026-4479 (AES-GCM nonce reuse) with no upstream fix; the server // links it but, while this transport stays off, never reaches it. WebRTCDirect = "webrtc-direct" )
Transport names, as written in server.transports.
Variables ¶
This section is empty.
Functions ¶
func ForAddress ¶
ForAddress reports which transport serves a multiaddr.
func LoadServerTLS ¶
LoadServerTLS loads a certificate and key for listening on secure WebSocket, and reloads them when the certificate file changes, so a renewal (certbot, an ACME client) takes effect without a restart. A renewal that cannot be loaded leaves the previous certificate serving and is retried on later handshakes.
func OnIP ¶
OnIP returns each listen address as reached on ip: the address a peer outside the host dials for it. Listen addresses of the other IP family, and those bound to loopback, are left out, since nothing outside the host reaches them; so are DNS addresses, which already name the host.
func Options ¶
Options returns one libp2p transport option per name. The names must already have passed Validate.
With both TCP and WebSocket enabled, the two share their TCP listeners, so they may listen on one port: go-libp2p tells the connections apart by their first bytes. go-libp2p means to make this its default.
func Validate ¶
Validate checks a transport list against the addresses the host will listen on and advertise. secureWebSocket says whether the server holds a certificate to listen for secure WebSocket with.
Every listen address needs its transport enabled, or the host fails to start; every external address needs its transport enabled, or the server advertises an address it cannot answer on. Relay addresses are skipped: circuit relay is configured separately.
Two listeners must not claim the same port. UDX holds its own UDP socket, while QUIC and WebTransport share one through go-libp2p's quicreuse; with SO_REUSEPORT on both, the kernel would split one port's datagrams between two transports that cannot read each other's. TCP and WebSocket share a listener (see Options), and TCP and UDP may share a number.
Types ¶
type Option ¶
type Option func(*settings)
Option adjusts the transports Options builds.
func WebSocketClientTLS ¶
WebSocketClientTLS is the TLS configuration the WebSocket transport dials secure WebSocket with; unset, the system roots verify the server.
func WebSocketServerTLS ¶
WebSocketServerTLS is the TLS configuration the WebSocket transport listens for secure WebSocket (/tls/ws, /wss) with.