websocket

package
v0.36.5 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2024 License: MIT, Apache-2.0, MIT Imports: 18 Imported by: 58

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

View Source
var GracefulCloseTimeout = 100 * time.Millisecond

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

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.

func (*Conn) Close

func (c *Conn) Close() error

Close closes the connection. Only the first call to Close will receive the close error, subsequent and concurrent calls will return nil. This method is thread-safe.

func (*Conn) LocalAddr

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

func (*Conn) Read

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

func (*Conn) RemoteAddr

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

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 (*WebsocketTransport) CanDial

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

func (*WebsocketTransport) Dial

func (*WebsocketTransport) Listen

func (*WebsocketTransport) Protocols

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

func (*WebsocketTransport) Proxy

func (t *WebsocketTransport) Proxy() bool

func (*WebsocketTransport) Resolve added in v0.23.0

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

Jump to

Keyboard shortcuts

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