package websocket

import "github.com/libp2p/go-libp2p/p2p/transport/websocket"

Package websocket implements a websocket based transport for go-libp2p.

Index

Variables

var GracefulCloseTimeout = 100 * time.Millisecond

GracefulCloseTimeout is the time to wait trying to gracefully close a connection before simply cutting it.

var WsFmt = mafmt.And(mafmt.TCP, mafmt.Base(ma.P_WS))

WsFmt is multiaddr formatter for WsProtocol

Functions

func ConvertWebsocketMultiaddrToNetAddr

func ConvertWebsocketMultiaddrToNetAddr(maddr ma.Multiaddr) (net.Addr, error)

func ParseWebsocketNetAddr

func ParseWebsocketNetAddr(a net.Addr) (ma.Multiaddr, error)

Types

type Addr

type Addr struct {
	*url.URL
}

Addr is an implementation of net.Addr for WebSocket.

func NewAddr

func NewAddr(host string) *Addr

NewAddr creates an Addr with `ws` scheme (insecure).

Deprecated. Use NewAddrWithScheme.

func NewAddrWithScheme

func NewAddrWithScheme(host string, isSecure bool) *Addr

NewAddrWithScheme creates a new Addr using the given host string. isSecure should be true for WSS connections and false for WS.

func (*Addr) Network

func (addr *Addr) Network() string

Network returns the network type for a WebSocket, "websocket".

type Conn

type Conn struct {
	*ws.Conn

	DefaultMessageType int
	// contains filtered or unexported fields
}

Conn implements net.Conn interface for gorilla/websocket.

func NewConn

func NewConn(raw *ws.Conn, secure bool) *Conn

NewConn creates a Conn given a regular gorilla/websocket Conn.

Deprecated: There's no reason to use this method externally. It'll be unexported in a future release.

func (*Conn) Close

func (c *Conn) Close() error

Close closes the connection. subsequent and concurrent calls will return the same error value. This method is thread-safe.

func (*Conn) LocalAddr

func (c *Conn) LocalAddr() net.Addr

func (*Conn) LocalMultiaddr

func (c *Conn) LocalMultiaddr() ma.Multiaddr

LocalMultiaddr implements manet.Conn.

func (*Conn) Read

func (c *Conn) Read(b []byte) (int, error)

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() net.Addr

func (*Conn) RemoteMultiaddr

func (c *Conn) RemoteMultiaddr() ma.Multiaddr

RemoteMultiaddr implements manet.Conn.

func (*Conn) Scope

func (c *Conn) Scope() network.ConnManagementScope

func (*Conn) SetDeadline

func (c *Conn) SetDeadline(t time.Time) error

func (*Conn) SetReadDeadline

func (c *Conn) SetReadDeadline(t time.Time) error

func (*Conn) SetWriteDeadline

func (c *Conn) SetWriteDeadline(t time.Time) error

func (*Conn) Write

func (c *Conn) Write(b []byte) (n int, err error)

type Option

type Option func(*WebsocketTransport) error

func WithTLSClientConfig

func WithTLSClientConfig(c *tls.Config) Option

WithTLSClientConfig sets a TLS client configuration on the WebSocket Dialer. Only relevant for non-browser usages.

Some useful use cases include setting InsecureSkipVerify to `true`, or setting user-defined trusted CA certificates.

func WithTLSConfig

func WithTLSConfig(conf *tls.Config) Option

WithTLSConfig sets a TLS configuration for the WebSocket listener.

type WebsocketTransport

type WebsocketTransport struct {
	// contains filtered or unexported fields
}

WebsocketTransport is the actual go-libp2p transport

func New

func (*WebsocketTransport) CanDial

func (t *WebsocketTransport) CanDial(a ma.Multiaddr) bool

func (*WebsocketTransport) Dial

Dial will dial the given multiaddr and expect the given peer. If an HTTPS_PROXY env is set, it will use that for the dial out.

func (*WebsocketTransport) Listen

func (*WebsocketTransport) Protocols

func (t *WebsocketTransport) Protocols() []int

func (*WebsocketTransport) Proxy

func (t *WebsocketTransport) Proxy() bool

func (*WebsocketTransport) Resolve

func (t *WebsocketTransport) Resolve(_ context.Context, maddr ma.Multiaddr) ([]ma.Multiaddr, error)

Source Files

addrs.go conn.go listener.go websocket.go

Version
v0.41.1 (latest)
Published
Mar 24, 2025
Platform
linux/amd64
Imports
21 packages
Last checked
3 weeks ago

Tools for package owners.