client

package
v44.23.4 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2022 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package client wraps a wsmux client session in a net.Listener interface. It attempts to reconnect to the proxy in case of a connection failure. It can be configured by setting the appropriate parameters in the Config object passed to client.New().

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrRetryTimedOut is returned when Reconnect() time exceeds MaxElapsedTime.
	ErrRetryTimedOut = Error{/* contains filtered or unexported fields */}

	// ErrBadToken is returned when a usable token can not be generated by the authorizer.
	ErrBadToken = Error{/* contains filtered or unexported fields */}

	// ErrRetryFailed is returned when retry attempts fail.
	ErrRetryFailed = Error{/* contains filtered or unexported fields */}

	// ErrClientReconnecting is returned when the connection is reconnecting.
	// This is a temporary error, and callers should retry the operation after
	// a delay.
	ErrClientReconnecting = Error{/* contains filtered or unexported fields */}

	// ErrClientClosed is returned from an Accept call when the client is closed.
	ErrClientClosed = Error{/* contains filtered or unexported fields */}

	// ErrAuthFailed is returned when authentication with the proxy fails
	ErrAuthFailed = Error{/* contains filtered or unexported fields */}
)

Functions

This section is empty.

Types

type Client

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

Client is used to connect to a websocktunnel instance and serve content over the tunnel. Client implements net.Listener.

func New

func New(configurer Configurer) (*Client, error)

New creates a new Client instance.

func (*Client) Accept

func (c *Client) Accept() (net.Conn, error)

Accept is used to accept multiplexed streams from the tunnel as a net.Conn implementer.

This is a net.Listener interface method.

func (*Client) Addr

func (c *Client) Addr() net.Addr

Addr returns the net.Addr of the underlying wsmux session

This is a net.Listener method. Its return value in this case is not especially useful.

func (*Client) Close

func (c *Client) Close() error

Close connection to the tunnel.

This is a net.Listener method.

func (*Client) URL

func (c *Client) URL() string

URL returns the url at which the websocktunnel server serves the client's endpoints. Users should use this value to create URLs (by appending) for viewers to access the client.

type Config

type Config struct {
	// The client ID to register
	ID string

	// The address of the websocktunnel server (https:// or wss://)
	TunnelAddr string

	// The JWT to authenticate to the websocktunnel server.  This should be
	// a "fresh" token for each call to the Configurer.
	Token string

	// Configuration for retrying connections to the server
	Retry RetryConfig

	// A Logger for logging status updates; default is no logging
	Logger util.Logger
}

Config contains the configuration for a Client. This is generated by a Configurer.

type Configurer

type Configurer func() (Config, error)

Configurer is a function which can generate a Config object to be used by the client. This is called whenever a reconnection is made, and should return a Config with a "fresh" token at that time.

type Error

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

Error represents an error from the client package. It implements net.Error, and in particular the err.Temporary() function is useful for distinguishing temporary, retryable errors from permanent errors.

func (Error) Error

func (c Error) Error() string

func (Error) Temporary

func (c Error) Temporary() bool

func (Error) Timeout

func (c Error) Timeout() bool

type RetryConfig

type RetryConfig struct {
	// InitialDelay is the delay after which the first reconnect
	// attempt takes place.
	// Default = 500 * time.Millisecond
	InitialDelay time.Duration

	// MaxDelay is the maximum possible delay between two consecutive
	// reconnect attempts.
	// Default = 60 * time.Second
	MaxDelay time.Duration

	// MaxElapsedTime is the time after which reconnect will time out
	// Default = 3 * time.Minute
	MaxElapsedTime time.Duration

	// Multplier is the rate at which the delay will increase
	// Default = 1.5
	Multiplier float64

	// RandomizationFactor is the extent to which the delay values will be randomized
	// Default = 0.5
	RandomizationFactor float64
}

RetryConfig contains exponential backoff parameters for retrying connections. In most cases, the default values are good enough.

Jump to

Keyboard shortcuts

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