comms

package
v0.4.0-rc3 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2022 License: BlueOak-1.0.0 Imports: 16 Imported by: 1

Documentation

Index

Constants

View Source
const (

	// DefaultResponseTimeout is the default timeout for responses after a
	// request is successfully sent.
	DefaultResponseTimeout = 30 * time.Second
)

Variables

View Source
var ErrCertRequired = fmt.Errorf("certificate required")

ErrCertRequired is the error returned when a ws connection fails because no cert was provided.

View Source
var ErrInvalidCert = fmt.Errorf("invalid certificate")

ErrInvalidCert is the error returned when attempting to use an invalid cert to set up a ws connection.

Functions

This section is empty.

Types

type WsCfg

type WsCfg struct {
	// URL is the websocket endpoint URL.
	URL string

	// The maximum time in seconds to wait for a ping from the server. This
	// should be larger than the server's ping interval to allow for network
	// latency.
	PingWait time.Duration

	// The server's certificate.
	Cert []byte

	// ReconnectSync runs the needed reconnection synchronization after
	// a reconnect.
	ReconnectSync func()

	// ConnectEventFunc runs whenever connection status changes.
	//
	// NOTE: Disconnect event notifications may lag behind actual
	// disconnections.
	ConnectEventFunc func(bool)

	// Logger is the logger for the WsConn.
	Logger dex.Logger

	// NetDialContext specifies an optional dialer context to use.
	NetDialContext func(context.Context, string, string) (net.Conn, error)
}

WsCfg is the configuration struct for initializing a WsConn.

type WsConn

type WsConn interface {
	NextID() uint64
	IsDown() bool
	Send(msg *msgjson.Message) error
	Request(msg *msgjson.Message, respHandler func(*msgjson.Message)) error
	RequestWithTimeout(msg *msgjson.Message, respHandler func(*msgjson.Message), expireTime time.Duration, expire func()) error
	Connect(ctx context.Context) (*sync.WaitGroup, error)
	MessageSource() <-chan *msgjson.Message
}

WsConn is an interface for a websocket client.

func NewWsConn

func NewWsConn(cfg *WsCfg) (WsConn, error)

NewWsConn creates a client websocket connection.

Jump to

Keyboard shortcuts

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