The wsport project provides a robust implementation of a WebSocket-based transport for the go-libp2p ecosystem doc.go1-2 It bridges the gap between traditional web protocols and peer-to-peer networking by allowing libp2p nodes to communicate over standard WebSocket (ws://) and Secure WebSocket (wss://) connections.
The project is split into two primary areas:
transport.Transport interface, enabling libp2p hosts to use WebSockets for dialing and listening.cmd/ directory that demonstrate practical applications, such as DHT bootstrapping, circuit relays, and proxying.wsport functions as a transport layer that upgrades standard network connections into libp2p-compatible streams. It supports various multiaddr formats, including the x-parity-ws and x-parity-wss protocols for handling WebSockets with custom paths websocket.go50-56
The following diagram illustrates how standard web components map to the internal WebsocketTransport entities.
Sources: websocket.go18-41 websocket.go72-78 websocket.go81-87
The heart of the library is the WebsocketTransport struct websocket.go81-87 It implements the transport.Transport interface from go-libp2p, providing the necessary logic to:
CanDial websocket.go108-110Dial websocket.go156-167Listen websocket.go211-217For a deep dive into the transport implementation and multiaddr matching, see Core Library (wsport package).
The transport stack moves from raw TCP through WebSocket upgrades into the libp2p upgrader.
Sources: websocket.go169-179 websocket.go181-200
The cmd/ sub-module contains several tools that leverage wsport for various network tasks. These tools share common patterns for identity management and host construction.
pid_seed and peerid handle persistent peer identities.dial and reconnect manage active and self-healing peer connections.circuit_relay_hop and bootstrap provide the backbone for p2p networks.http and proxy demonstrate high-level protocols like file sharing and SOCKS5 proxying over libp2p.For details on building and using these tools, see Getting Started and Command-Line Tools (cmd/ sub-module).
RELAY, PID_SEED).wsport integrates with libp2p.Sources: go.mod1-15 cmd/go.mod1-16 websocket.go1-16