whclient

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2017 License: MPL-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

whclient

-- import "github.com/taskcluster/webhooktunnel/whclient"

Package whclient 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 whclient.New().

Usage

var (
	// ErrRetryTimedOut is returned when Reconnect() time exceeds MaxElapsedTime.
	ErrRetryTimedOut = clientError{timeout: true, errString: "retry timed out"}

	// ErrBadToken is returned when a usable token can not be generated by the authorizer.
	ErrBadToken = clientError{errString: "bad auth token"}

	// ErrRetryFailed is returned when retry attempts fail.
	ErrRetryFailed = clientError{errString: "retry failed"}

	// ErrClientReconnecting is returned when the connection is reconnecting.
	// This is a temporary error.
	ErrClientReconnecting = clientError{errString: "client reconnecting", reconnect: true}

	// ErrClientClosed is returned from an Accept call when the client is closed.
	ErrClientClosed = clientError{errString: "client closed"}

	// ErrAuthorizerNotProvided is returned from New when an Authorizer is not provided.
	ErrAuthorizerNotProvided = clientError{errString: "authorizer function was not provided to client"}
)
func New
func New(config Config) (net.Listener, error)

New returns a new net.Listener instance using the provided Config object.

type Authorizer
type Authorizer func(id string) (string, error)

Authorizer is a function which accepts a string id and returns a signed JWT (JSON Web Token). If an error occurs, the return values must be ("", ErrorGenerated).

type Config
type Config struct {
	// ID is the worker-id of the client. This field must match the "tid" claim of the
	// JWT.
	ID string

	// ProxyAddr is the websocket address of the proxy to which the client should connect.
	ProxyAddr string

	// Logger is an optional field. This logger is passed to the session created by
	// the GetListener method. This defaults to `&util.NilLogger{}`.
	Logger util.Logger

	Authorize Authorizer

	// Retry contains the retry parameters to use in case of reconnects.
	// The default values are specified in RetryConfig.
	Retry RetryConfig
}

Config is used for creating a new client.

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

Documentation

Overview

Package whclient 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 whclient.New().

Index

Constants

This section is empty.

Variables

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

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

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

	// ErrClientReconnecting is returned when the connection is reconnecting.
	// This is a temporary error.
	ErrClientReconnecting = clientError{/* contains filtered or unexported fields */}

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

	// ErrAuthorizerNotProvided is returned from New when an Authorizer is not provided.
	ErrAuthorizerNotProvided = clientError{/* contains filtered or unexported fields */}
)

Functions

func New

func New(config Config) (net.Listener, error)

New returns a new net.Listener instance using the provided Config object.

Types

type Authorizer

type Authorizer func(id string) (string, error)

Authorizer is a function which accepts a string `id` and returns a signed JWT (JSON Web Token). If an error occurs, the return values must be ("", ErrorGenerated).

type Config

type Config struct {
	// ID is the worker-id of the client. This field must match the "tid" claim of the
	// JWT.
	ID string

	// ProxyAddr is the websocket address of the proxy to which the client should connect.
	ProxyAddr string

	// Logger is an optional field. This logger is passed to the session created by
	// the GetListener method. This defaults to `&util.NilLogger{}`.
	Logger util.Logger

	Authorize Authorizer

	// Retry contains the retry parameters to use in case of reconnects.
	// The default values are specified in RetryConfig.
	Retry RetryConfig

	// TLSConfig to use for authentication
	TLSConfig *tls.Config
}

Config is used for creating a new client.

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

Jump to

Keyboard shortcuts

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