latency

package
v1.3.3-0...-f31c912 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2024 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Monitor

type Monitor struct {
	// contains filtered or unexported fields
}

Monitor periodically pings both legs of a proxied connection and records the round trip times so that they may be emitted to consumers.

func NewMonitor

func NewMonitor(cfg MonitorConfig) (*Monitor, error)

NewMonitor creates an unstarted Monitor with the provided configuration. To begin sampling connection latencies Monitor.Run must be called.

func (*Monitor) GetStats

func (m *Monitor) GetStats() Statistics

GetStats returns a copy of the last known latency measurements.

func (*Monitor) Run

func (m *Monitor) Run(ctx context.Context)

Run periodically records round trip times. It should not be called more than once.

type MonitorConfig

type MonitorConfig struct {
	// ClientPinger measure the round trip time for client half of the connection.
	ClientPinger Pinger
	// ServerPinger measure the round trip time for server half of the connection.
	ServerPinger Pinger
	// Reporter periodically emits statistics to consumers.
	Reporter Reporter
	// Clock used to measure time.
	Clock clockwork.Clock
	// InitialPingInterval an optional duration to use for the first PingInterval.
	InitialPingInterval time.Duration
	// PingInterval is the frequency at which both legs of the connection are pinged for
	// latency calculations.
	PingInterval time.Duration
	// InitialReportInterval an optional duration to use for the first ReportInterval.
	InitialReportInterval time.Duration
	// ReportInterval is the frequency at which the latency information is reported.
	ReportInterval time.Duration
}

MonitorConfig provides required dependencies for the Monitor.

func (*MonitorConfig) CheckAndSetDefaults

func (c *MonitorConfig) CheckAndSetDefaults() error

CheckAndSetDefaults ensures required fields are provided and sets default values for any omitted optional fields.

type Pinger

type Pinger interface {
	Ping(ctx context.Context) error
}

Pinger abstracts the mechanism used to measure the round trip time of a connection. All "ping" messages should be responded to before returning from [Pinger.Ping].

type Reporter

type Reporter interface {
	Report(ctx context.Context, statistics Statistics) error
}

Reporter is an abstraction over how to provide the latency statistics to the consumer. Used by the Monitor to provide periodic latency updates.

type ReporterFunc

type ReporterFunc func(ctx context.Context, stats Statistics) error

ReporterFunc type is an adapter to allow the use of ordinary functions as a Reporter. If f is a function with the appropriate signature, Reporter(f) is a Reporter that calls f.

func (ReporterFunc) Report

func (f ReporterFunc) Report(ctx context.Context, stats Statistics) error

Report calls f(ctx, stats).

type SSHClient

type SSHClient interface {
	SendRequest(ctx context.Context, name string, wantReply bool, payload []byte) (bool, []byte, error)
}

SSHClient is the subset of the [ssh.Client] required by the SSHPinger.

type SSHPinger

type SSHPinger struct {
	// contains filtered or unexported fields
}

SSHPinger is a Pinger implementation that measures the latency of an SSH connection. To calculate round trip time, a keepalive@openssh.com request is sent.

func NewSSHPinger

func NewSSHPinger(clt SSHClient) (*SSHPinger, error)

NewSSHPinger creates a new SSHPinger with the provided configuration.

func (*SSHPinger) Ping

func (s *SSHPinger) Ping(ctx context.Context) error

Ping sends a keepalive@openssh.com request via the provided SSHClient.

type Statistics

type Statistics struct {
	// Client measures the round trip time between the client and the Proxy.
	Client int64
	// Server measures the round trip time the Proxy and the target host.
	Server int64
}

Statistics contain latency measurements for both legs of a proxied connection.

type WebSocket

type WebSocket interface {
	WriteControl(messageType int, data []byte, deadline time.Time) error
	PongHandler() func(appData string) error
	SetPongHandler(h func(appData string) error)
}

WebSocket is the subset of [websocket.Conn] required by the WebSocketPinger.

type WebSocketPinger

type WebSocketPinger struct {
	// contains filtered or unexported fields
}

WebSocketPinger is a Pinger implementation that measures the latency of a websocket connection.

func NewWebsocketPinger

func NewWebsocketPinger(clock clockwork.Clock, ws WebSocket) (*WebSocketPinger, error)

NewWebsocketPinger creates a WebSocketPinger with the provided configuration.

func (*WebSocketPinger) Ping

func (s *WebSocketPinger) Ping(ctx context.Context) error

Ping writes a ping control message and waits for the corresponding pong control message to be received before returning. The random identifier in the ping message is expected to be returned in the pong payload so that we can determine the true round trip time for a ping/pong message pair.

Jump to

Keyboard shortcuts

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