Skip to content
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Discourse posts GoDoc Coverage Status Build Status

A libp2p transport implementation using WebSockets

go-ws-transport is an implementation of the libp2p transport interface that streams data over WebSockets, which are themselves layered over TCP/IP. It is included by default in the main go-libp2p "entry point" module.

Table of Contents


go-ws-transport is included as a dependency of go-libp2p, which is the most common libp2p entry point. If you depend on go-libp2p, there is generally no need to explicitly depend on this module.

go-ws-transport is a standard Go module which can be installed with:

> go get

This repo is gomod-compatible, and users of go 1.11 and later with modules enabled will automatically pull the latest tagged release by referencing this package. Upgrades to future releases can be managed using go get, or by editing your go.mod file as described by the gomod documentation.


WebSockets are one of the default transports enabled when constructing a standard libp2p Host, along with TCP.

Calling libp2p.New to construct a libp2p Host will enable the WebSocket transport, unless you override the default transports by passing in Options to libp2p.New.

To explicitly enable the WebSocket transport while constructing a host, use the libp2p.Transport option, passing in the ws.New constructor function:

import (

    libp2p ""
    ws ""

ctx := context.Background()

// WebSockets only:
h, err := libp2p.New(ctx,

The example above will replace the default transports with a single WebSocket transport. To add multiple tranports, use ChainOptions:

// WebSockets and QUIC:
h, err := libp2p.New(ctx,
        libp2p.Transport(quic.NewTransport)) // see


The WebSocket transport supports multiaddrs that contain a ws component, which is encapsulated within (or layered onto) another valid TCP multiaddr.


addr description
/ip4/ IPv4:, TCP port 1234
/ip6/::1/tcp/1234/ws IPv6 loopback, TCP port 1234
/dns4/ DNS over IPv4, hostname, TCP port 80

Notice that the /ws multiaddr component contextualizes an existing TCP/IP multiaddr and does not require any additional addressing information.

Security and Multiplexing

While the WebSocket spec defines a wss URI scheme for encrypted WebSocket connections, support for wss URIs relies on TLS, which wraps the WebSocket connection in a similar manner to TLS-protected HTTP traffic.

As libp2p does not integrate with the TLS Certificate Authority infrastructure by design, security for WebSockets is provided by a transport upgrader. The transport upgrader negotiates transport security for each connection according to the protocols supported by each party.

The transport upgrader also negotiates a stream multiplexing protocol to allow many bidirectional streams to coexist on a single WebSocket connection.


Feel free to join in. All welcome. Open an issue!

This repository falls under the libp2p Code of Conduct.

Want to hack on libp2p?



The last gx published version of this module was: 2.0.27: QmaSWc4ox6SZQF6DHZvDuM9sP1syNajkKuPXmKR1t5BAz5

You can’t perform that action at this time.