Documentation ¶
Index ¶
Constants ¶
View Source
const ( WsServerHandshakeAuthHeaderName string = "Authorization" WsServerHandshakeChallengeHeaderName string = "Challenge" )
Variables ¶
View Source
var ( ErrNoActiveConnection = errors.New("no active connection") ErrWrapperShutdown = errors.New("wrapper shutting down") )
Functions ¶
This section is empty.
Types ¶
type ConnectionAcceptor ¶
type ConnectionInitiator ¶
type ConnectionInitiator interface { NewAuthHeader(url *url.URL) []byte ChallengeResponse(challenge []byte) ([]byte, error) }
The handshake works as follows:
Client (Initiator) Server (Acceptor) NewAuthHeader() -------auth header--------> StartHandshake() <-------challenge---------- ChallengeResponse() ---------response---------> FinalizeHandshake()
type HTTPRequestHandler ¶
type HTTPServerConfig ¶
type HttpServer ¶
type HttpServer interface { job.ServiceCtx // Not thread-safe. Should be done once before calling Start(). SetHTTPRequestHandler(handler HTTPRequestHandler) }
func NewHttpServer ¶
func NewHttpServer(config *HTTPServerConfig, lggr logger.Logger) HttpServer
type WSConnectionWrapper ¶
type WSConnectionWrapper interface { // Update underlying connection object. Return a channel that gets an error on connection close. // Cannot be called after Close(). Restart(newConn *websocket.Conn) <-chan error Write(ctx context.Context, msgType int, data []byte) error ReadChannel() <-chan ReadItem Close() }
WSConnectionWrapper is a websocket connection abstraction that supports re-connects. I/O is separated from connection management:
- component doing writes can use the thread-safe Write() method
- component doing reads can listen on the ReadChannel()
- component managing connections can listen to connection-closed channels and call Restart() to swap the underlying connection object
The Wrapper can be used by a server expecting long-lived connections from a given client, as well as a client maintaining such long-lived connection with a given server. This fits the Gateway very well as servers accept connections only from a fixed set of nodes and conversely, nodes only connect to a fixed set of servers (Gateways).
The concept of "pumps" is borrowed from https://github.com/smartcontractkit/wsrpc All methods are thread-safe.
func NewWSConnectionWrapper ¶
func NewWSConnectionWrapper() WSConnectionWrapper
type WebSocketClient ¶
type WebSocketClient interface {
Connect(ctx context.Context, url *url.URL) (*websocket.Conn, error)
}
func NewWebSocketClient ¶
func NewWebSocketClient(config WebSocketClientConfig, initiator ConnectionInitiator, lggr logger.Logger) WebSocketClient
type WebSocketClientConfig ¶
type WebSocketClientConfig struct {
HandshakeTimeoutMillis uint32
}
type WebSocketServer ¶
type WebSocketServer interface { job.ServiceCtx }
func NewWebSocketServer ¶
func NewWebSocketServer(config *WebSocketServerConfig, acceptor ConnectionAcceptor, lggr logger.Logger) WebSocketServer
type WebSocketServerConfig ¶
type WebSocketServerConfig struct { HTTPServerConfig HandshakeTimeoutMillis uint32 }
Source Files ¶
Click to show internal directories.
Click to hide internal directories.