websocket_path

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2024 License: MIT Imports: 20 Imported by: 0

README

go-libp2p-websocket-path

libp2p websocket transport with path

Transport:

libp2p.Transport(path_websocket.New)

Connect:

addr, err := websocket_path.NewMultiaddr("/dns4/your.ipfs.server.io/tcp/443/tls/ws+path/(/ipfs/ws)/p2p/12D3KooXXXXXXXXXX")
info, err := peer.AddrInfoFromP2pAddr(addr)
lite.Bootstrap([]peer.AddrInfo{*info})

License

MIT License

Documentation

Index

Constants

View Source
const (
	P_WS_PATH = 0x3001dd
)

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 NewMultiaddr

func NewMultiaddr(address string) (multiaddr.Multiaddr, error)

func ParseWebsocketNetAddr

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

Types

type Addr added in v0.1.0

type Addr struct {
	*url.URL
}

Addr is an implementation of net.Addr for WebSocket.

func NewLocalAddrWithScheme added in v0.1.0

func NewLocalAddrWithScheme(host string, isSecure bool) Addr

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

func (Addr) Network added in v0.1.0

func (a Addr) Network() string

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

type Conn added in v0.1.0

type Conn struct {
	*ws.Conn

	DefaultMessageType int
	// contains filtered or unexported fields
}

func NewConnWithAddr added in v0.1.0

func NewConnWithAddr(raw *ws.Conn, secure bool, remoteAddr Addr) *Conn

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

func (*Conn) Close added in v0.1.0

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 added in v0.1.0

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

func (*Conn) Read added in v0.1.0

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

func (*Conn) RemoteAddr added in v0.1.0

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

func (*Conn) SetDeadline added in v0.1.0

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

func (*Conn) SetReadDeadline added in v0.1.0

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

func (*Conn) SetWriteDeadline added in v0.1.0

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

func (*Conn) Write added in v0.1.0

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

func (t *WebsocketTransport) Resolve(ctx 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