transport

package
v0.2024.4 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var WriteTimeoutError = errors.New("write timed out waiting for connection")

Functions

This section is empty.

Types

type Connection

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

Connection represents a connection to another system, and implements Transport, keeping a ConnectionState for handling reconnects, etc...

func NewConnection

func NewConnection(conf ConnectionConfig, bo backoff.BackOff, dial func() error, rwc io.ReadWriteCloser) *Connection

func (*Connection) Close

func (c *Connection) Close() error

func (*Connection) Connect

func (c *Connection) Connect(ctx context.Context) error

func (*Connection) Read

func (c *Connection) Read(p []byte) (n int, err error)

func (*Connection) WaitForStateChange

func (c *Connection) WaitForStateChange(ctx context.Context, sourceState State) (state State, changed bool)

func (*Connection) Write

func (c *Connection) Write(p []byte) (n int, err error)

type ConnectionConfig

type ConnectionConfig struct {
	// Timeout is the dial timeout when attempting connection, defaults to 15s
	Timeout jsontypes.Duration
	// ReadTimeout is the timeout used when attempting to read, defaults to 0
	ReadTimeout jsontypes.Duration
	// WriteTimeout is the timeout used when attempting to write, defaults to 15s
	WriteTimeout jsontypes.Duration
}

type ConnectionState

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

ConnectionState stores a State and provides methods for subscribing to changes to the state

func NewConnectionState

func NewConnectionState() *ConnectionState

NewConnectionState creates a new ConnectionState

func (*ConnectionState) WaitForStateChange

func (c *ConnectionState) WaitForStateChange(ctx context.Context, sourceState State) (state State, changed bool)

WaitForStateChange waits until the State changes from sourceState or ctx expires. Changed is true returned in former case and false in latter.

type Ssh

type Ssh struct {
	*Connection
	// contains filtered or unexported fields
}

func NewSsh

func NewSsh(conf SshConfig) *Ssh

NewSsh creates a new Ssh transport with the given config

type SshConfig

type SshConfig struct {
	ConnectionConfig
	// Ip is the IP address or hostname of the endpoint
	Ip string
	// Port is the port number to connect to, defaults to 22
	Port int

	Username string
	Password string

	IgnoreHostKey bool
}

SshConfig is used to configure an Ssh transport

type State

type State int
const (
	Idle State = iota
	Connected
	Disconnected
)

type Tcp

type Tcp struct {
	*Connection
	// contains filtered or unexported fields
}

Tcp implements Transport, back by a tcp connection. Reconnecting is handled automatically, with an exponential backoff for retries.

func NewTcp

func NewTcp(conf TcpConfig, logger *zap.Logger) *Tcp

NewTcp creates a new Tcp transport with the given config

type TcpConfig

type TcpConfig struct {
	ConnectionConfig
	// Ip is the IP address or hostname of the endpoint
	Ip string
	// Port is the port number to connect to
	Port int
}

TcpConfig is used to configure a Tcp transport

type Transport

type Transport interface {
	io.ReadWriteCloser

	Connect(ctx context.Context) error
	WaitForStateChange(ctx context.Context, sourceState State) (state State, changed bool)
}

Transport presents a way to communicate with another system over arbitrary protocols such as those built on TCP for an example usage, see cmd/tools/tcp-conn-test

Jump to

Keyboard shortcuts

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