transports

package
v1.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

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

View Source
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

func ForAddress(addr ma.Multiaddr) (string, error)

ForAddress reports which transport serves a multiaddr.

func Known

func Known() []string

Known returns every transport name the server accepts.

func LoadServerTLS

func LoadServerTLS(certFile, keyFile string) (*tls.Config, error)

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

func OnIP(listen []string, ip net.IP) ([]string, error)

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

func Options(names []string, with ...Option) ([]libp2p.Option, error)

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

func Validate(names, listen, external []string, secureWebSocket bool) error

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

func WebSocketClientTLS(c *tls.Config) Option

WebSocketClientTLS is the TLS configuration the WebSocket transport dials secure WebSocket with; unset, the system roots verify the server.

func WebSocketServerTLS

func WebSocketServerTLS(c *tls.Config) Option

WebSocketServerTLS is the TLS configuration the WebSocket transport listens for secure WebSocket (/tls/ws, /wss) with.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址