transport

package
v0.0.0-...-abdb4f7 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package transport provides a websocket, rawsocket, and local transport implementation. The local transport is for in-process connection of a client to a router. Each transport implements the wamp.Peer interface, that connect Send and Recv methods to a particular transport.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AcceptRawSocket

func AcceptRawSocket(conn net.Conn, logger stdlog.StdLog, recvLimit, outQueueSize int) (wamp.Peer, error)

AcceptRawSocket handles the client handshake and returns a rawSocketPeer.

If recvLimit is > 0, then the client will not receive messages with size larger than the nearest power of 2 greater than or equal to recvLimit. If recvLimit is <= 0, then the default of 16M is used.

func ConnectRawSocketPeer

func ConnectRawSocketPeer(network, address string, serialization serialize.Serialization, logger stdlog.StdLog, recvLimit int) (wamp.Peer, error)

ConnectRawSocketPeer calls ConnectRawSocketPeerContext without a context.

func ConnectRawSocketPeerContext

func ConnectRawSocketPeerContext(ctx context.Context, network, address string, serialization serialize.Serialization, logger stdlog.StdLog, recvLimit int) (wamp.Peer, error)

ConnectRawSocketPeerContext creates a new rawSocketPeer with the specified config, and connects it to the WAMP router at the specified address. The network and address parameters are documented here: https://golang.org/pkg/net/#Dial

The provided Context must be non-nil. If the context expires before the connection is complete, an error is returned. Once successfully connected, any expiration of the context will not affect the connection.

If recvLimit is > 0, then the client will not receive messages with size larger than the nearest power of 2 greater than or equal to recvLimit. If recvLimit is <= 0, then the default of 16M is used.

func ConnectTlsRawSocketPeer

func ConnectTlsRawSocketPeer(network, address string, serialization serialize.Serialization, tlsConfig *tls.Config, logger stdlog.StdLog, recvLimit int) (wamp.Peer, error)

ConnectTlsRawSocketPeer calls ConnectTlsRawSocketPeerContext without a Dial context.

func ConnectTlsRawSocketPeerContext

func ConnectTlsRawSocketPeerContext(ctx context.Context, network, address string, serialization serialize.Serialization, tlsConfig *tls.Config, logger stdlog.StdLog, recvLimit int) (wamp.Peer, error)

ConnectTlsRawSocketPeerContext creates a new rawSocketPeer with the specified config, and connects it, using TLS, to the WAMP router at the specified address. The network, address, and tlscfg parameters are documented here: https://golang.org/pkg/crypto/tls/#Dial

The provided Context must be non-nil. If the context expires before the connection is complete, an error is returned. Once successfully connected, any expiration of the context will not affect the connection.

If recvLimit is > 0, then the client will not receive messages with size larger than the nearest power of 2 greater than or equal to recvLimit. If recvLimit is <= 0, then the default of 16M is used.

func ConnectWebsocketPeer

func ConnectWebsocketPeer(
	routerURL string,
	serialization serialize.Serialization,
	tlsConfig *tls.Config,
	dial DialFunc,
	logger stdlog.StdLog,
	wsCfg *WebsocketConfig) (wamp.Peer, error)

ConnectWebsocketPeer calls ConnectWebsocketPeerContext without a Dial context.

func ConnectWebsocketPeerContext

func ConnectWebsocketPeerContext(ctx context.Context, routerURL string, serialization serialize.Serialization, tlsConfig *tls.Config, dial DialFunc, logger stdlog.StdLog, wsCfg *WebsocketConfig) (wamp.Peer, error)

ConnectWebsocketPeerContext creates a new websocket client with the specified config, connects the client to the websocket server at the specified URL, and returns the connected websocket peer.

The provided Context must be non-nil. If the context expires before the connection is complete, an error is returned. Once successfully connected, any expiration of the context will not affect the connection.

func IsLocal

func IsLocal(p wamp.Peer) bool

IsLocal returns true is the wamp.Peer is a localPeer. These do not need authentication since they are part of the same process.

func LinkedPeers

func LinkedPeers() (wamp.Peer, wamp.Peer)

LinkedPeers creates two connected peers. Messages sent to one peer appear in the Recv of the other. This is used for connecting client sessions to the router.

func NewWebsocketPeer

func NewWebsocketPeer(conn *websocket.Conn, serializer serialize.Serializer, payloadType int, logger stdlog.StdLog, keepAlive time.Duration, outQueueSize int) wamp.Peer

NewWebsocketPeer creates a websocket peer from an existing websocket connection. This is used by clients connecting to the WAMP router, and by servers to handle connections from clients.

A non-zero keepAlive value configures a websocket "ping/pong" heartbeat, sending websocket "pings" every keepAlive interval. If a "pong" response is not received after 2 intervals have elapsed then the websocket is closed.

Types

type DialFunc

type DialFunc func(network, addr string) (net.Conn, error)

type WebsocketConfig

type WebsocketConfig struct {
	// Request per message write compression, if allowed by server.
	EnableCompression bool `json:"enable_compression"`

	// If provided when configuring websocket client, cookies from server are
	// put in here.  This allows cookies to be stored and then sent back to the
	// server in subsequent websocket connections.  Cookies may be used to
	// identify returning clients, and can be used to authenticate clients.
	Jar http.CookieJar

	// ProxyURL is an optional URL of the proxy to use for websocket requests.
	// If not defined, the proxy defined by the environment is used if defined.
	ProxyURL string

	// Deprecated server config options.
	// See: https://godoc.org/github.com/goldwindev/nexus/router#WebsocketServer
	EnableTrackingCookie bool `json:"enable_tracking_cookie"`
	EnableRequestCapture bool `json:"enable_request_capture"`

	// KeepAlive configures a websocket "ping/pong" heartbeat when set to a
	// non-zero value.  KeepAlive is the interval between websocket "pings".
	// If a "pong" response is not received after 2 intervals have elapsed then
	// the websocket connection is closed.
	KeepAlive time.Duration
}

WebsocketConfig is used to configure client websocket settings.

type WebsocketError

type WebsocketError struct {
	Err      error
	Response *http.Response
}

WebsocketError is returned on failure to connect to a websocket, and contains the http response if one is available.

func (*WebsocketError) Error

func (e *WebsocketError) Error() string

Error returns a string describing the failure to connect to a websocket.

Directories

Path Synopsis
Package serialize provides a Serializer interface with implementations that encode and decode message data in various ways.
Package serialize provides a Serializer interface with implementations that encode and decode message data in various ways.

Jump to

Keyboard shortcuts

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