comms

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2023 License: BlueOak-1.0.0 Imports: 17 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 ConnectionStatus added in v0.5.0

type ConnectionStatus uint32

ConnectionStatus represents the current status of the websocket connection.

const (
	Disconnected ConnectionStatus = iota
	Connected
	InvalidCert
)

func (ConnectionStatus) String added in v0.6.0

func (cs ConnectionStatus) String() string

String gives a human readable string for each connection status.

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(ConnectionStatus)

	// 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