Help us shape the future of Go! Take the 2026 Go Developer Survey

network

package
v1.3.104 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: AGPL-3.0 Imports: 47 Imported by: 9

Documentation

Overview

Package network pkg/transport/network/addr_canonical.go c2-net-transport

Package network pkg/transport/network/bind.go c2-net-transport

The address resolver bind and listen loops shared by stcpr, squicr and swtr.

Package network pkg/transport/network/client.go c2-net-transport

Package network pkg/transport/network/client_resolved.go c2-net-transport

The address-resolver-backed carrier machinery (stcpr/sudph/quic), split out of client.go behind //go:build !tinygo. It imports pkg/.../addrresolver (net/http + packetfilter → quic-go) and operates raw UDP/TCP — none of which fit the TinyGo/browser target, where only dmsg (and stcp, AR-free) carriers exist. The TinyGo build gets makeResolvedClient as an unsupported-error stub in client_tinygo.go.

Package network pkg/transport/network/client_unified_quic.go c2-net-transport

sharedQUICMux multiplexes several QUIC-based application protocols onto ONE quic.Transport over the unified transport_port UDP socket, so a visor accepts skywire-QUIC ("squicr", ALPN skywire-quic-1) AND WebTransport ("swtr", ALPN "h3") on a SINGLE forwardable UDP port instead of one socket each. Without this, WebTransport bound its own ephemeral UDP port — reachable on a bare public IP but NOT through a single port-forward (the operator forwards transport_port, not WT's random port), so a NAT'd-but-forwarded public visor was unreachable over WT (the carrier a browser visor depends on).

quic-go permits only one listener per packet conn, so we run ONE ListenEarly whose tls.Config.GetConfigForClient picks the per-ALPN server config (its own cert + client-auth policy) from the ClientHello's offered ALPNs, and ONE accept loop that hands each connection to the handler registered for its negotiated ALPN. squicr needs mutual TLS (RequireAnyClientCert + a PK-bound cert); WT needs none (a browser can't present a client cert) — incompatible in a fixed tls.Config, but fine when GetConfigForClient returns a different config per ALPN. Inbound WT (QUIC) and squicr (QUIC) packets are indistinguishable at the udpDemux layer (both classify as protoQUIC); the ALPN split here is what lets them coexist on that one demux conn.

Package network pkg/transport/network/client_unified_tcp.go c2-net-transport

The unified transport port (TCP side): bind ONE master TCP listener and route the TCP transport types (stcpr raw + WS HTTP-upgrade) over it via a tcpDemux (cmux), so they share a single listening port instead of binding one each. See docs/design/transport-port-unification.md. Opt-in: only active when the visor configures transport_port (EnableUnifiedTCP is a no-op for port 0).

Package network pkg/transport/network/client_unified_udp.go c2-net-transport

The unified transport port (UDP side): bind ONE master UDP socket and route the UDP transport types (QUIC + sudph) over it via a udpDemux, so they share a single listening port instead of binding one each. See docs/design/transport-port-unification.md. Opt-in: only active when the visor configures transport_port (EnableUnifiedUDP is a no-op for port 0).

Package network pkg/transport/network/conn_details.go c2-net-transport

Package network pkg/transport/network/connection.go c2-net-transport

Package network pkg/transport/network/dmsg.go c2-net-transport

Package network pkg/transport/network/link_stats.go c2-net-transport

Package network pkg/transport/network/link_stats_linux.go c2-net-transport

Package network pkg/transport/network/listener.go c2-net-transport

Package network pkg/transport/network/network.go c2-net-transport

Package network pkg/transport/network/quic.go c2-net-transport transport. Mirrors the sudph/stcpr structure (AR-resolved, UDP-based) but rides quic-go instead of KCP: the connection is secured by the skywire-PK-bound TLS identity (quic_identity.go, option A), one QUIC stream carries one skywire transport, and the existing handshake + noise layers run over the stream exactly as for the other types.

QUIC gives reliable streams AND RFC 9221 unreliable datagrams over one connection — the stream half is wired here; the datagram half (which makes faithful-UDP wire-real) is the follow-on tp.WriteDatagram path.

Package network pkg/transport/network/quic_identity.go c2-net-transport pkg/skyquic, which holds the skywire-PK-bound QUIC TLS identity (#2607, option A). The implementation moved to its own package so dmsg-over-QUIC can reuse it without an import cycle (pkg/transport/network imports pkg/dmsg/dmsg).

Package network pkg/transport/network/sockets.go c2-net-transport

Package network pkg/transport/network/stcp.go c2-net-transport

Package network pkg/transport/network/stcpr.go c2-net-transport

Package network pkg/transport/network/stun_client.go c2-net-transport

Package network pkg/transport/network/sudph.go c2-net-transport

Package network pkg/transport/network/tcp_liveness.go c2-net-transport

Package network pkg/transport/network/tcp_notsent.go c2-net-transport

Package network pkg/transport/network/tcp_notsent_linux.go c2-net-transport

Package network pkg/transport/network/tcp_tune_native.go c2-net-transport

Package network pkg/transport/network/tcp_usertimeout_linux.go c2-net-transport

Package network pkg/transport/network/tcpdemux.go c2-net-transport

tcpDemux multiplexes ONE TCP listener across the TCP transport types — WS (an HTTP/1.1 WebSocket upgrade) and stcpr (a raw skywire handshake) — so a visor can listen for both on a single transport_port instead of binding a port each. See docs/design/transport-port-unification.md.

It is a thin wrapper around the vendored soheilhy/cmux: cmux peeks each accepted connection's first bytes (replaying them to the matched protocol) and routes HTTP/1 to the WS listener, everything else to the stcpr listener. cmux is the established connection-mux library, so unlike the UDP side this needs no custom classifier. The TCP analog of udpDemux.

A visor running the in-process dmsg server on its own key takes a third branch here, so the server shares the visor's transport port rather than binding one of its own. That branch is only installed when something will consume it: an unconsumed cmux listener queues its matched connections and then blocks their goroutines.

Package network pkg/transport/network/udpdemux.go c2-net-transport

udpDemux multiplexes ONE UDP socket across the UDP-based transport protocols (QUIC, sudph/KCP, WebRTC/ICE), so a visor can listen for all of them on a single `transport_port` instead of one port per type. See docs/design/transport-port-unification.md.

Each inbound datagram is classified by its wire signature (classifyUDP) and routed to a per-protocol virtual net.PacketConn (demuxConn). The protocols' own stacks — quic-go's Transport, xtaci/kcp-go, pion's ICE UDP-mux — each take a net.PacketConn, so they consume a demuxConn unchanged. Classification is applied to the FIRST datagram from a remote address; the result is then PINNED per source (srcProto) so short-header QUIC and subsequent KCP packets — which carry no distinguishing prefix — follow the same route.

This component is intentionally standalone + unit-tested before being wired into the transport managers; getting the classifier wrong would misroute live traffic, so it is validated in isolation first.

Package network pkg/transport/network/webrtc.go c2-net-transport

WEBRTC is a first-class skywire transport type: a direct visor-to-visor link over a WebRTC DataChannel (DTLS+SCTP, NAT-traversed via ICE). Unlike WS/WT (which dial a single listening endpoint), WebRTC is genuinely peer-to-peer — the payload rides a direct encrypted pipe between the two leaves, no relay.

WebRTC needs a signaling side-channel to exchange the SDP offer/answer and ICE candidates BEFORE the direct pipe exists. dmsg is that channel: the dialing visor opens a dmsg stream to the peer's signaling port (webrtcSignalPort) and the two run the offer/answer/ICE handshake over it (signalConn — 4-byte length-prefixed JSON, the SAME wire format the browser carrier uses, so a native pion visor and a browser visor interoperate). Once the DataChannel opens it is adapted to a net.Conn and flows through the SAME genericClient initTransport (Noise + yamux) path as every other carrier.

The carrier is build-tagged: webrtc_native.go (pion) on native; the browser (TinyGo/js) dials the browser-native RTCPeerConnection. Both can dial AND accept (WebRTC is symmetric), unlike WS/WT where a browser can only dial.

Package network pkg/transport/network/webrtc_capability_native.go c2-net-transport

Package network pkg/transport/network/webrtc_native.go c2-net-transport

Native WebRTC carrier via pion: dial (offerer) and accept (answerer) a direct DataChannel, negotiated over a dmsg signaling stream, adapted to a net.Conn. The browser carrier (TinyGo/js) speaks the SAME signaling wire format against the browser-native RTCPeerConnection, so a native pion visor and a browser visor interoperate.

Package network pkg/transport/network/ws.go c2-net-transport

WS is a first-class skywire transport type: a direct visor-to-visor link over a WebSocket, with the peer's wss:// endpoint resolved from a PK table (like stcp, but over WebSocket instead of raw TCP). It is distinct from the dmsg WebSocket carrier, which reaches a dmsg server rather than a peer visor.

A browser visor can DIAL this transport (the browser's WebSocket API) but cannot accept it (no listening socket) — so server-visors run the WS listener (ws_native.go) while the dial side is build-tagged: coder/websocket on native, the browser-native WebSocket under TinyGo/js (ws_tinygo.go). The accepted / dialed WebSocket is adapted to a net.Conn and flows through the SAME genericClient initTransport (Noise + yamux) path as every other carrier.

Package network pkg/transport/network/ws_attached.go c2-net-transport

Package network pkg/transport/network/ws_native.go c2-net-transport

Native WS-transport carrier: dial via coder/websocket, and accept by running a WebSocket HTTP server fronted as a net.Listener so the shared acceptTransports loop can drain it. A browser visor has neither (it can't run a server, and coder/websocket pulls net/http) — see ws_tinygo.go.

Package network pkg/transport/network/wt.go c2-net-transport

WT is a first-class skywire transport type: a direct visor-to-visor link over WebTransport (HTTP/3 over QUIC), with the peer's https:// endpoint and pinned cert hash resolved from a table (like WS, but over WebTransport instead of a WebSocket). It is distinct from the dmsg WebTransport carrier, which reaches a dmsg server rather than a peer visor.

The server presents a short-lived self-signed cert pinned by SHA-256 — no CA, no domain (the dmsg WT cert-hash model). A browser visor can DIAL this transport (the browser's WebTransport API + serverCertificateHashes) but cannot accept it (no listening socket) — so server-visors run the WT listener (wt_native.go) while the dial side is build-tagged: webtransport-go on native, the browser-native WebTransport under TinyGo/js (wt_browser.go). The dialed / accepted bidirectional stream is adapted to a net.Conn and flows through the SAME genericClient initTransport (Noise + yamux) path as every other carrier.

Package network pkg/transport/network/wt_native.go c2-net-transport

Native WT-transport carrier: dial via webtransport-go (pinning the server's self-signed cert by SHA-256, the browser serverCertificateHashes model), and accept by running a WebTransport (HTTP/3 over QUIC) server fronted as a net.Listener so the shared acceptTransports loop can drain it. A browser visor has neither (it can't run a server, and webtransport-go pulls quic-go) — see wt_tinygo.go.

Index

Constants

View Source
const DefaultTCPNotSentLowat = 128 << 10

DefaultTCPNotSentLowat is how many unsent bytes a TCP transport lets the kernel hold (TCP_NOTSENT_LOWAT, tcp(7)). The rest waits in the transport's own write queue, so a small write is not stuck behind seconds of bulk data.

Variables

View Source
var (
	// ErrUnknownTransportType is returned when transport type is unknown.
	ErrUnknownTransportType = errors.New("unknown transport type")

	// ErrTimeout indicates a timeout.
	ErrTimeout = errors.New("timeout")

	// ErrAlreadyListening is returned when transport is already listening.
	ErrAlreadyListening = errors.New("already listening")

	// ErrNotListening is returned when transport is not listening.
	ErrNotListening = errors.New("not listening")

	// ErrPortOccupied is returned when port is occupied.
	ErrPortOccupied = errors.New("port is already occupied")
)
View Source
var ErrServeDialOnly = errors.New("transport network is dial-only on this build (serving unsupported)")

ErrServeDialOnly is the sentinel a network client's Start returns (wrapped) when the build is dial-only and cannot serve (no listening socket). The transport manager checks errors.Is(err, ErrServeDialOnly) to log this expected condition at Debug rather than ERROR/Fatal — a browser/embedded WT client dials peers but never accepts, which is by design, not a failure.

View Source
var ErrStcpEntryNotFound = errors.New("entry not found in PK table")

ErrStcpEntryNotFound is returned when requested PK is not found in the local PK table

View Source
var ErrWSEntryNotFound = errors.New("ws: entry not found in PK table")

ErrWSEntryNotFound is returned when the requested PK has no WS URL in the table.

View Source
var ErrWTEntryNotFound = errors.New("wt: entry not found in table")

ErrWTEntryNotFound is returned when the requested PK has no WT entry in the table.

View Source
var ErrWebRTCNoDmsg = errors.New("webrtc: no dmsg client for signaling")

ErrWebRTCNoDmsg is returned when the WebRTC client has no dmsg client to signal over (signaling rides dmsg).

View Source
var ErrWebRTCUnavailable = errors.New("webrtc: no peer connection available in this runtime")

ErrWebRTCUnavailable is the sentinel MakeClient returns when the runtime has no way to construct a peer connection (see WebRTCAvailable). It is expected, not a failure: the transport manager simply leaves WEBRTC out of its known networks, and every caller that picks candidate transport types from the manager stops offering it.

Functions

func EncryptConn

func EncryptConn(config noise.Config, conn net.Conn) (net.Conn, error)

EncryptConn encrypts given connection

func SetTCPNotSentLowat

func SetTCPNotSentLowat(n int)

SetTCPNotSentLowat sets the limit for TCP transports opened from now on. 0 leaves the kernel's default, which holds as much as the send buffer.

func WebRTCAvailable

func WebRTCAvailable() bool

WebRTCAvailable reports whether this runtime can construct a peer connection. Native builds carry pion, which always can.

Types

type Client

type Client interface {
	// Dial remote visor, that is listening on the given skywire port
	Dial(ctx context.Context, remote cipher.PubKey, port uint16) (Transport, error)
	// Start initializes the client and prepares it for listening. It is required
	// to be called to start accepting transports
	Start() error
	// Listen on the given skywire port. This can be called multiple times
	// for different ports for the same client. It requires Start to be called
	// to start accepting transports
	Listen(port uint16) (Listener, error)
	// LocalAddr returns the actual network address under which this client listens to
	// new transports
	LocalAddr() (net.Addr, error)
	// PK returns public key of the visor running this client
	PK() cipher.PubKey
	// SK returns secret key of the visor running this client
	SK() cipher.SecKey
	// Close the client, stop accepting transports. Connections returned by the
	// client should be closed manually
	Close() error
	// Type returns skywire network type in which this client operates
	Type() types.Type
}

Client provides access to skywire network It allows dialing remote visors using their public keys, as well as listening to incoming transports from other visors

type ClientFactory

type ClientFactory struct {
	PK         cipher.PubKey
	SK         cipher.SecKey
	ListenAddr string
	PKTable    stcp.PKTable
	// WSTable maps a peer PK to its direct WebSocket (wss://) URL for the WS
	// transport type. Reuses stcp.PKTable (PK→URL); empty/absent disables WS.
	WSTable stcp.PKTable
	// WTTable maps a peer PK to its direct WebTransport endpoint + pinned cert
	// hash for the WT transport type. A nil/absent table disables WT dialing.
	WTTable WTTable
	// QUICTable statically pins a peer PK → UDP address ("host:port") for the QUIC
	// transport type (the QUIC analog of PKTable/stcp). Consulted before the
	// address resolver; nil/absent = AR-only.
	QUICTable stcp.PKTable
	// ICEURLs are the STUN/TURN URLs used for ICE by the WEBRTC transport type
	// (skywire's own STUN, reused from sudph). Empty = host candidates only.
	ICEURLs []string
	// ARClient is the address-resolver client (addrresolver.APIClient). Typed as
	// `any` so this file doesn't import addrresolver — which pulls net/http +
	// packetfilter (→ quic-go), none of which compile on the TinyGo target. Only
	// the AR-resolved carriers (stcpr/sudph/quic, all //go:build !tinygo) consume
	// it, via a type-assert in makeResolvedClient (client_resolved.go). The visor
	// passes a real addrresolver.APIClient; a nil/absent one is fine for a
	// dmsg-only (e.g. browser) client.
	ARClient any
	EB       tcpDialAnnouncer
	DmsgC    *dmsg.Client
	MLogger  *logging.MasterLogger
	// OnExternalSTCPR is called when an incoming STCPR connection is detected
	// from an external (non-LAN) IP address. This validates that the visor is
	// reachable from the internet.
	OnExternalSTCPR func()

	// Sockets opens the OS sockets of the carriers. Nil means the host's own.
	Sockets Sockets

	// ShareTCPWithDmsgServer asks the TCP cmux for a dmsg branch, so a visor
	// running the in-process dmsg server on its own key serves it on the same
	// TCP port as stcpr and WS instead of binding a second one. Set it before
	// EnableUnifiedTCP / EnableDefaultTCPDemux; the branch is not installed
	// afterwards, because an unconsumed cmux branch stalls its connections.
	ShareTCPWithDmsgServer bool
	// contains filtered or unexported fields
}

ClientFactory is used to create Client instances and holds dependencies for different clients

func (*ClientFactory) CloseUnifiedTCP

func (f *ClientFactory) CloseUnifiedTCP() error

CloseUnifiedTCP closes the master TCP listener + cmux demux, if enabled.

func (*ClientFactory) CloseUnifiedUDP

func (f *ClientFactory) CloseUnifiedUDP() error

CloseUnifiedUDP closes the shared QUIC mux (its listener + transport), then the master UDP socket + demux, if enabled.

func (*ClientFactory) DmsgSharedListener

func (f *ClientFactory) DmsgSharedListener() net.Listener

DmsgSharedListener returns the TCP cmux branch the co-resident dmsg server serves on, or nil when the port is not shared with it (ShareTCPWithDmsgServer was false, or no demux is bound). Its Addr is the master listener's, so a server that advertises what its listener resolves to advertises the shared transport port.

func (*ClientFactory) EnableDefaultTCPDemux

func (f *ClientFactory) EnableDefaultTCPDemux(stcprPort int) error

EnableDefaultTCPDemux binds the DEFAULT TCP cmux (stcpr + WS) on the stcpr port — the phase-2 behavior so EVERY visor accepts WebSocket on its stcpr TCP socket without any config, with no port change (the cmux peeks: HTTP/WS-upgrade → WS, else the raw skywire handshake → stcpr; existing stcpr peers are unaffected). stcprPort 0 binds a random port (exactly as a per-type stcpr listener would). Unlike EnableUnifiedTCP this is NOT gated on transport_port, and stcpr always rides it (the cmux IS the stcpr listener — no break-out).

func (*ClientFactory) EnableUnifiedTCP

func (f *ClientFactory) EnableUnifiedTCP(port int) error

EnableUnifiedTCP binds the master TCP listener on port and prepares the cmux demux. Call once, before MakeClient. port 0 is a no-op (per-type binding stays). stcpr accepts over the raw virtual listener and the WS HTTP server runs over the HTTP virtual listener (see makeResolvedClient / MakeClient). The master listener lifecycle is owned here — close it with CloseUnifiedTCP.

func (*ClientFactory) EnableUnifiedUDP

func (f *ClientFactory) EnableUnifiedUDP(port int) error

EnableUnifiedUDP binds the master UDP socket on port and prepares the demux. Call once, before MakeClient. port 0 is a no-op (per-type binding stays). The quic/sudph clients created afterwards listen over the demux's per-protocol virtual conn (see makeResolvedClient). The master socket lifecycle is owned here — close it with CloseUnifiedUDP.

func (*ClientFactory) MakeClient

func (f *ClientFactory) MakeClient(netType types.Type, port int) (Client, error)

MakeClient creates a new client of specified type

func (*ClientFactory) SetDmsgQUICServer added in v1.3.99

func (f *ClientFactory) SetDmsgQUICServer(srv any) (net.Addr, error)

SetDmsgQUICServer registers the dmsg ALPN on the shared QUIC socket and hands its connections to srv, so a dmsg server folded into this visor serves dmsg-over-QUIC on the transport port. Without it that port belongs to squicr and WT alone, and a dmsg client's QUIC dial is refused at the handshake. srv is typed `any`, as SetDmsgWSHandler's handler is. Returns the socket's local address, or nil when unified UDP is not enabled.

func (*ClientFactory) SetDmsgWSHandler

func (f *ClientFactory) SetDmsgWSHandler(h any)

SetDmsgWSHandler routes the dmsg-over-WebSocket path on the shared transport port to h (an http.Handler), so a dmsg server folded into this visor keeps a WS front. Typed `any` to keep net/http out of this file's import graph, as ARClient is. Called once the co-resident server is up; the WS client reads it per request, so ordering does not matter.

func (*ClientFactory) SetDmsgWTServer added in v1.3.99

func (f *ClientFactory) SetDmsgWTServer(srv any, advertise func(addr net.Addr, certHash, nextCertHash [32]byte)) (bool, error)

SetDmsgWTServer serves a folded dmsg server's WebTransport front on the shared QUIC socket, at dmsg.WTPath beside the visor's own WT transport — the way a browser reaches a dmsg server without a TLS certificate from a CA. srv is typed `any`, as SetDmsgQUICServer's is. advertise is called with the socket's local address and the current and next certificate hashes a client pins, now and again whenever the certificate rotates. Reports false when unified UDP is not enabled, so there is nothing to serve on.

type ConnDetailer

type ConnDetailer interface {
	ConnDetails() ConnDetails
}

ConnDetailer is optionally implemented by a network.Transport to expose its curated ConnDetails. pkg/transport.ManagedTransport consumes it via a type assertion, so transports/mocks that do not implement it simply report no details.

type ConnDetails

type ConnDetails struct {
	// RemoteAddr is the underlying raw remote network address
	// ("host:port"): the direct TCP peer for stcp/stcpr, the
	// hole-punched UDP endpoint for sudph, the QUIC peer for squicr,
	// the selected ICE candidate for webrtc. Empty for dmsg — an
	// empty RemoteAddr is itself the signal "relayed, not direct".
	RemoteAddr string `json:"remote_addr,omitempty"`
	// LocalAddr is the underlying raw local network address, when the
	// carrier exposes one.
	LocalAddr string `json:"local_addr,omitempty"`
	// ARBackedType is true for the address-resolver-backed carriers
	// (stcpr/sudph/squicr): their endpoint was discovered via the
	// address resolver (a static PK-table dial is the rare exception).
	// Direct carriers (stcp) and relayed dmsg leave it false.
	ARBackedType bool `json:"ar_backed_type,omitempty"`
	// DmsgServerPK is the hex public key of the dmsg.Server this
	// (dmsg) transport relays its frames through. dmsg-only field; it
	// is a public key, never a secret. Empty for every other type.
	DmsgServerPK string `json:"dmsg_server_pk,omitempty"`
	// TLSCertSHA256 is the hex SHA-256 fingerprint of the remote
	// peer's TLS certificate (the skywire-PK-bound QUIC identity).
	// squicr-only. Empty for every other type.
	TLSCertSHA256 string `json:"tls_cert_sha256,omitempty"`
	// ALPN is the negotiated TLS application protocol (e.g.
	// "skywire-quic-1"). squicr-only.
	ALPN string `json:"alpn,omitempty"`
	// Link holds live RTT, congestion and loss counters from the carrier's
	// own stack (TCP_INFO, quic-go, KCP, SCTP).
	Link *LinkStats `json:"link,omitempty"`
}

ConnDetails is a curated, secrets-free snapshot of the low-level connection metadata that is meaningful for a given transport kind. It is surfaced through pkg/transport.ManagedTransport.ConnDetails and, from there, onto the visor's TransportSummary so `skywire cli visor state` / `skywire cli tp` can show what a transport actually rides on (the direct IP:port, the relaying dmsg server, the TLS identity, …) without leaking any secret key.

Every field is optional (omitempty): each transport type populates only what it can expose cleanly. A field left empty is a deliberate "not applicable / not available for this kind" — e.g. dmsg leaves RemoteAddr empty (it relays through a server, there is no direct IP) and instead fills DmsgServerPK.

type DatagramConn

type DatagramConn interface {
	WriteDatagram(b []byte) error
	ReadDatagram(ctx context.Context) ([]byte, error)
}

DatagramConn is implemented by transport connections that carry unreliable datagrams natively over the wire (currently QUIC, RFC 9221). When a transport's underlying conn supports it, the router sends faithful-UDP DatagramPackets over this channel instead of the reliable stream — realizing genuine UDP semantics (no head-of-line blocking, loss tolerance). Reliable-only transports (TCP/KCP/dmsg) don't implement it, and the router transparently falls back to the reliable stream.

type Dialer

type Dialer interface {
	Dial(ctx context.Context, remote cipher.PubKey, port uint16) (net.Conn, error)
	// Probe checks whether a remote visor is reachable on the given port
	// by performing a lightweight dial and immediately closing. Returns
	// true if the dial handshake succeeded. Implementations that don't
	// support probing should return true (optimistic).
	Probe(ctx context.Context, remote cipher.PubKey, port uint16) bool
	Type() string
}

Dialer is an entity that can be dialed and asked for its type.

type LinkLoss

type LinkLoss struct {
	PacketsSent uint64  `json:"packets_sent"`
	PacketsLost uint64  `json:"packets_lost"`
	BytesLost   uint64  `json:"bytes_lost"`
	Pct         float64 `json:"pct"`
}

LinkLoss counts this side's sends only, because loss is detected by the sender. For TCP, lost means retransmitted.

type LinkStats

type LinkStats struct {
	SRTTMs    float64 `json:"srtt_ms,omitempty"`
	MinRTTMs  float64 `json:"min_rtt_ms,omitempty"`
	RTOMs     float64 `json:"rto_ms,omitempty"`
	CwndBytes uint64  `json:"cwnd_bytes,omitempty"`
	// UnsentBytes is data queued in the kernel and not yet sent (TCP).
	UnsentBytes uint64 `json:"unsent_bytes,omitempty"`
	// Loss is nil when the carrier does not count losses (KCP, SCTP).
	Loss *LinkLoss `json:"loss,omitempty"`
}

LinkStats is a snapshot of the carrier's own RTT, congestion and loss state, read from the transport stack below skywire when requested.

type Listener

type Listener interface {
	net.Listener
	PK() cipher.PubKey
	Port() uint16
	Network() types.Type
	AcceptTransport() (Transport, error)
}

Listener represents a skywire network listener. It wraps net.Listener with other skywire-specific data Listener implements net.Listener

func NewListener

func NewListener(lAddr dmsg.Addr, freePort func(), network types.Type) Listener

NewListener returns a new Listener.

type MockDialer

type MockDialer struct {
	mock.Mock
}

MockDialer is an autogenerated mock type for the Dialer type

func NewMockDialer

func NewMockDialer(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockDialer

NewMockDialer creates a new instance of MockDialer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockDialer) Dial

func (_m *MockDialer) Dial(ctx context.Context, remote cipher.PubKey, port uint16) (net.Conn, error)

Dial provides a mock function with given fields: ctx, remote, port

func (*MockDialer) Probe

func (_m *MockDialer) Probe(ctx context.Context, remote cipher.PubKey, port uint16) bool

Probe provides a mock function with given fields: ctx, remote, port

func (*MockDialer) Type

func (_m *MockDialer) Type() string

Type provides a mock function with no fields

type OSSockets added in v1.3.101

type OSSockets struct{}

OSSockets is Sockets on the host's own network stack.

func (OSSockets) DialContext added in v1.3.101

func (OSSockets) DialContext(ctx context.Context, network, addr string) (net.Conn, error)

DialContext implements Sockets.

func (OSSockets) Listen added in v1.3.101

func (OSSockets) Listen(network, addr string) (net.Listener, error)

Listen implements Sockets.

func (OSSockets) ListenPacket added in v1.3.101

func (OSSockets) ListenPacket(network, addr string) (net.PacketConn, error)

ListenPacket implements Sockets.

type PushReader added in v1.3.100

type PushReader interface {
	// SetNotify sets fn to run whenever data may be ready or the conn ended.
	SetNotify(fn func())
	// ReadPlain reads what is ready into buf, decrypts it and passes the
	// plaintext to emit. It returns 0 with no error when nothing was ready.
	ReadPlain(buf []byte, emit func([]byte)) (int, error)
}

PushReader takes a transport's decrypted stream as it arrives.

func PushReaderOf added in v1.3.100

func PushReaderOf(tp Transport) (PushReader, bool)

PushReaderOf moves tp's reads to a PushReader if its conn supports one. tp must not be read once it returns true.

type PushSource added in v1.3.100

type PushSource interface {
	// SetReadNotify sets fn to run whenever data may be ready or the conn
	// ended. fn must not block.
	SetReadNotify(fn func())
	// TryRead returns ready data, 0 with no error when there is none, and the
	// conn's error once it has ended.
	TryRead(b []byte) (int, error)
}

PushSource is a conn whose data can be taken as it arrives, without a goroutine blocked in Read. A KCP session is one.

type Rebinder

type Rebinder interface {
	Rebind()
}

Rebinder is a network client that can re-register with the address resolver at once, as after a move to another network.

type STCPConfig

type STCPConfig = spec.STCPConfig

STCPConfig is the wire-format type for Skywire-TCP configuration. Aliased from pkg/transport/network/spec so existing callers writing `network.STCPConfig{...}` keep compiling, while the canonical (WASM-clean) definition lives in the spec leaf package.

type Sockets added in v1.3.101

type Sockets interface {
	Listen(network, addr string) (net.Listener, error)
	ListenPacket(network, addr string) (net.PacketConn, error)
	DialContext(ctx context.Context, network, addr string) (net.Conn, error)
}

Sockets opens the OS sockets the carriers listen and dial on. A browser visor, which has none, gets them from a host bridge (pkg/hostbridge).

type StunDetails

type StunDetails struct {
	PublicIP *stun.Host
	NATType  stun.NATType
}

StunDetails represents the visors public network details.

func GetStunDetails

func GetStunDetails(stunServers []string, log *logging.Logger) *StunDetails

GetStunDetails provides STUN details

type Transport

type Transport interface {
	net.Conn
	// LocalPK returns local public key of transport
	LocalPK() cipher.PubKey

	// RemotePK returns remote public key of transport
	RemotePK() cipher.PubKey

	// LocalPort returns local skywire port of transport
	// This is not underlying OS port, but port within skywire network
	LocalPort() uint16

	// RemotePort returns remote skywire port of transport
	// This is not underlying OS port, but port within skywire network
	RemotePort() uint16

	// LocalRawAddr returns local raw network address (not skywire address)
	LocalRawAddr() net.Addr

	// RemoteRawAddr returns remote raw network address (not skywire address)
	RemoteRawAddr() net.Addr

	// Network returns network of transport
	Network() types.Type
}

Transport represents a network connection between two visors in skywire network This transport wraps raw network connection and is ready to use for sending data. It also provides skywire-specific methods on top of net.Conn

func DoHandshake

func DoHandshake(rawConn net.Conn, hs handshake.Handshake, netType types.Type, log *logging.Logger) (Transport, error)

DoHandshake performs given handshake over given raw connection and wraps connection in network.Transport. Uses the default handshake.Timeout (10s).

func DoHandshakeWithTimeout

func DoHandshakeWithTimeout(rawConn net.Conn, hs handshake.Handshake, netType types.Type, timeout time.Duration, log *logging.Logger) (Transport, error)

DoHandshakeWithTimeout is the same as DoHandshake but lets the caller pick a per-call handshake deadline. Useful for public-facing listeners (e.g. the address-resolver's SUDPH accept loop) that need a tighter timeout than the 10-second default to resist scanner / broken-client accumulation.

type WTEntry

type WTEntry struct {
	URL      string
	CertHash string
	// CertHashNext is the hash the peer will serve after its next rotation;
	// pinned alongside CertHash. Empty when the peer does not advertise one.
	CertHashNext string
}

WTEntry is a peer's WebTransport dial target: the https:// endpoint URL and the lowercase SHA-256 hex of the server's self-signed cert (pinned exactly as a browser pins it via serverCertificateHashes).

type WTTable

type WTTable interface {
	Entry(pk cipher.PubKey) (WTEntry, bool)
	SetEntry(pk cipher.PubKey, e WTEntry)
}

WTTable maps a peer PK to its WebTransport dial target (URL + pinned cert hash). It is the WT analog of stcp.PKTable, which carries only a bare address. SetEntry allows entries to be added at runtime (e.g. learned from a peer or a JS hook), mirroring stcp.PKTable.SetAddr.

func NewWTTable

func NewWTTable(entries map[cipher.PubKey]WTEntry) WTTable

NewWTTable returns an in-memory WTTable seeded with the given entries (may be nil for an empty, runtime-populated table).

Directories

Path Synopsis
Package addrresolver pkg/transport/network/addrresolver/client.go c2-net-transport
Package addrresolver pkg/transport/network/addrresolver/client.go c2-net-transport
Package handshake pkg/transport/network/handshake/handshake.go c2-net-transport
Package handshake pkg/transport/network/handshake/handshake.go c2-net-transport
Package packetfilter pkg/transport/network/packetfilter/address-filter.go c2-net-transport
Package packetfilter pkg/transport/network/packetfilter/address-filter.go c2-net-transport
Package porter pkg/transport/network/porter/porter.go c2-net-transport
Package porter pkg/transport/network/porter/porter.go c2-net-transport
Package spec pkg/transport/network/spec/spec.go c2-net-transport Currently holds STCPConfig (the visor-side Skywire-TCP configuration stanza) — a pure-data type that pkg/visor/visorconfig.V1 embeds.
Package spec pkg/transport/network/spec/spec.go c2-net-transport Currently holds STCPConfig (the visor-side Skywire-TCP configuration stanza) — a pure-data type that pkg/visor/visorconfig.V1 embeds.
Package stcp pkg/transport/network/stcp/pktable.go c2-net-transport
Package stcp pkg/transport/network/stcp/pktable.go c2-net-transport

Jump to

Keyboard shortcuts

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