package websocket

Import Path
	github.com/libp2p/go-libp2p/p2p/transport/websocket (on go.dev)

Dependency Relation
	imports 21 packages, and imported by one package

Involved Source Files addrs.go conn.go listener.go Package websocket implements a websocket based transport for go-libp2p.
Package-Level Type Names (total 4)
/* sort by: | */
Addr is an implementation of net.Addr for WebSocket. URL *url.URL // append a query ('?') even if RawQuery is empty // fragment for references, without '#' // host or host:port (see Hostname and Port methods) // do not emit empty host (authority) // encoded opaque data // path (relative paths may omit leading slash) // encoded fragment hint (see EscapedFragment method) // encoded path hint (see EscapedPath method) // encoded query values, without '?' URL.Scheme string // username and password information ( Addr) AppendBinary(b []byte) ([]byte, error) EscapedFragment returns the escaped form of u.Fragment. In general there are multiple possible escaped forms of any fragment. EscapedFragment returns u.RawFragment when it is a valid escaping of u.Fragment. Otherwise EscapedFragment ignores u.RawFragment and computes an escaped form on its own. The [URL.String] method uses EscapedFragment to construct its result. In general, code should call EscapedFragment instead of reading u.RawFragment directly. EscapedPath returns the escaped form of u.Path. In general there are multiple possible escaped forms of any path. EscapedPath returns u.RawPath when it is a valid escaping of u.Path. Otherwise EscapedPath ignores u.RawPath and computes an escaped form on its own. The [URL.String] and [URL.RequestURI] methods use EscapedPath to construct their results. In general, code should call EscapedPath instead of reading u.RawPath directly. Hostname returns u.Host, stripping any valid port number if present. If the result is enclosed in square brackets, as literal IPv6 addresses are, the square brackets are removed from the result. IsAbs reports whether the [URL] is absolute. Absolute means that it has a non-empty scheme. JoinPath returns a new [URL] with the provided path elements joined to any existing path and the resulting path cleaned of any ./ or ../ elements. Any sequences of multiple / characters will be reduced to a single /. ( Addr) MarshalBinary() (text []byte, err error) Network returns the network type for a WebSocket, "websocket". Parse parses a [URL] in the context of the receiver. The provided URL may be relative or absolute. Parse returns nil, err on parse failure, otherwise its return value is the same as [URL.ResolveReference]. Port returns the port part of u.Host, without the leading colon. If u.Host doesn't contain a valid numeric port, Port returns an empty string. Query parses RawQuery and returns the corresponding values. It silently discards malformed value pairs. To check errors use [ParseQuery]. Redacted is like [URL.String] but replaces any password with "xxxxx". Only the password in u.User is redacted. RequestURI returns the encoded path?query or opaque?query string that would be used in an HTTP request for u. ResolveReference resolves a URI reference to an absolute URI from an absolute base URI u, per RFC 3986 Section 5.2. The URI reference may be relative or absolute. ResolveReference always returns a new [URL] instance, even if the returned URL is identical to either the base or reference. If ref is an absolute URL, then ResolveReference ignores base and returns a copy of ref. String reassembles the [URL] into a valid URL string. The general form of the result is one of: scheme:opaque?query#fragment scheme://userinfo@host/path?query#fragment If u.Opaque is non-empty, String uses the first form; otherwise it uses the second form. Any non-ASCII characters in host are escaped. To obtain the path, String uses u.EscapedPath(). In the second form, the following rules apply: - if u.Scheme is empty, scheme: is omitted. - if u.User is nil, userinfo@ is omitted. - if u.Host is empty, host/ is omitted. - if u.Scheme and u.Host are empty and u.User is nil, the entire scheme://userinfo@host/ is omitted. - if u.Host is non-empty and u.Path begins with a /, the form host/path does not add its own /. - if u.RawQuery is empty, ?query is omitted. - if u.Fragment is empty, #fragment is omitted. ( Addr) UnmarshalBinary(text []byte) error Addr : encoding.BinaryAppender Addr : encoding.BinaryMarshaler Addr : encoding.BinaryUnmarshaler Addr : expvar.Var Addr : fmt.Stringer *Addr : net.Addr func NewAddr(host string) *Addr func NewAddrWithScheme(host string, isSecure bool) *Addr
Conn implements net.Conn interface for gorilla/websocket. Conn *ws.Conn DefaultMessageType int Scope network.ConnManagementScope Close closes the connection. subsequent and concurrent calls will return the same error value. This method is thread-safe. CloseHandler returns the current close handler EnableWriteCompression enables and disables write compression of subsequent text and binary messages. This function is a noop if compression was not negotiated with the peer. (*Conn) LocalAddr() net.Addr LocalMultiaddr implements manet.Conn. NetConn returns the underlying connection that is wrapped by c. Note that writing to or reading from this connection directly will corrupt the WebSocket connection. NextReader returns the next data message received from the peer. The returned messageType is either TextMessage or BinaryMessage. There can be at most one open reader on a connection. NextReader discards the previous message if the application has not already consumed it. Applications must break out of the application's read loop when this method returns a non-nil error value. Errors returned from this method are permanent. Once this method returns a non-nil error, all subsequent calls to this method return the same error. NextWriter returns a writer for the next message to send. The writer's Close method flushes the complete message to the network. There can be at most one open writer on a connection. NextWriter closes the previous writer if the application has not already done so. All message types (TextMessage, BinaryMessage, CloseMessage, PingMessage and PongMessage) are supported. PingHandler returns the current ping handler PongHandler returns the current pong handler (*Conn) Read(b []byte) (int, error) ReadJSON reads the next JSON-encoded message from the connection and stores it in the value pointed to by v. See the documentation for the encoding/json Unmarshal function for details about the conversion of JSON to a Go value. ReadMessage is a helper method for getting a reader using NextReader and reading from that reader to a buffer. (*Conn) RemoteAddr() net.Addr RemoteMultiaddr implements manet.Conn. SetCloseHandler sets the handler for close messages received from the peer. The code argument to h is the received close code or CloseNoStatusReceived if the close message is empty. The default close handler sends a close message back to the peer. The handler function is called from the NextReader, ReadMessage and message reader Read methods. The application must read the connection to process close messages as described in the section on Control Messages above. The connection read methods return a CloseError when a close message is received. Most applications should handle close messages as part of their normal error handling. Applications should only set a close handler when the application must perform some action before sending a close message back to the peer. SetCompressionLevel sets the flate compression level for subsequent text and binary messages. This function is a noop if compression was not negotiated with the peer. See the compress/flate package for a description of compression levels. (*Conn) SetDeadline(t time.Time) error SetPingHandler sets the handler for ping messages received from the peer. The appData argument to h is the PING message application data. The default ping handler sends a pong to the peer. The handler function is called from the NextReader, ReadMessage and message reader Read methods. The application must read the connection to process ping messages as described in the section on Control Messages above. SetPongHandler sets the handler for pong messages received from the peer. The appData argument to h is the PONG message application data. The default pong handler does nothing. The handler function is called from the NextReader, ReadMessage and message reader Read methods. The application must read the connection to process pong messages as described in the section on Control Messages above. (*Conn) SetReadDeadline(t time.Time) error SetReadLimit sets the maximum size in bytes for a message read from the peer. If a message exceeds the limit, the connection sends a close message to the peer and returns ErrReadLimit to the application. (*Conn) SetWriteDeadline(t time.Time) error Subprotocol returns the negotiated protocol for the connection. UnderlyingConn returns the internal net.Conn. This can be used to further modifications to connection specific flags. Deprecated: Use the NetConn method. (*Conn) Write(b []byte) (n int, err error) WriteControl writes a control message with the given deadline. The allowed message types are CloseMessage, PingMessage and PongMessage. WriteJSON writes the JSON encoding of v as a message. See the documentation for encoding/json Marshal for details about the conversion of Go values to JSON. WriteMessage is a helper method for getting a writer using NextWriter, writing the message and closing the writer. WritePreparedMessage writes prepared message into connection. *Conn : github.com/libp2p/go-libp2p/core/network.ConnMultiaddrs *Conn : github.com/miekg/dns.Writer *Conn : github.com/multiformats/go-multiaddr/net.Conn *Conn : github.com/pion/datachannel.ReadDeadliner *Conn : github.com/pion/datachannel.WriteDeadliner *Conn : github.com/pion/stun.Connection *Conn : github.com/pion/stun/v3.Connection *Conn : github.com/prometheus/common/expfmt.Closer *Conn : internal/bisect.Writer *Conn : io.Closer *Conn : io.ReadCloser *Conn : io.Reader *Conn : io.ReadWriteCloser *Conn : io.ReadWriter *Conn : io.WriteCloser *Conn : io.Writer *Conn : net.Conn
func WithHandshakeTimeout(timeout time.Duration) Option func WithTLSClientConfig(c *tls.Config) Option func WithTLSConfig(conf *tls.Config) Option func New(u transport.Upgrader, rcmgr network.ResourceManager, sharedTCP *tcpreuse.ConnMgr, opts ...Option) (*WebsocketTransport, error)
WebsocketTransport is the actual go-libp2p transport (*WebsocketTransport) CanDial(a ma.Multiaddr) bool 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. (*WebsocketTransport) Listen(a ma.Multiaddr) (transport.Listener, error) (*WebsocketTransport) Protocols() []int (*WebsocketTransport) Proxy() bool (*WebsocketTransport) Resolve(_ context.Context, maddr ma.Multiaddr) ([]ma.Multiaddr, error) *WebsocketTransport : github.com/libp2p/go-libp2p/core/transport.Resolver *WebsocketTransport : github.com/libp2p/go-libp2p/core/transport.Transport func New(u transport.Upgrader, rcmgr network.ResourceManager, sharedTCP *tcpreuse.ConnMgr, opts ...Option) (*WebsocketTransport, error)
Package-Level Functions (total 8)
NewAddr creates an Addr with `ws` scheme (insecure). Deprecated. Use NewAddrWithScheme.
NewAddrWithScheme creates a new Addr using the given host string. isSecure should be true for WSS connections and false for WS.
WithHandshakeTimeout sets a timeout for the websocket upgrade.
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.
WithTLSConfig sets a TLS configuration for the WebSocket listener.
Package-Level Variables (total 2)
GracefulCloseTimeout is the time to wait trying to gracefully close a connection before simply cutting it.
WsFmt is multiaddr formatter for WsProtocol