rafttransport

package
v0.0.0-...-b0bff92 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2021 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AddrTimeout is how long we'll wait for a good address to be
	// sent before timing out in the Addr call - this is better than
	// hanging indefinitely.
	AddrTimeout = 1 * time.Minute
)

Variables

View Source
var (
	// ErrAddressTimeout is used as the death reason when this transport dies because no good API address has been sent.
	ErrAddressTimeout = errors.New("timed out waiting for API address")
)

Functions

func DialConn

func DialConn(ctx context.Context, addr string, tlsConfig *tls.Config) (net.Conn, error)

DialConn dials a TLS connection to the API server with the given address, using the given TLS configuration. This will be used for requesting the raft endpoint, upgrading to a raw connection for inter-node raft communications.

TODO: this function needs to be made proxy-aware.

func Manifold

func Manifold(config ManifoldConfig) dependency.Manifold

Manifold returns a dependency.Manifold that will run an apiserver-based raft transport worker.

func NewWorker

func NewWorker(config Config) (worker.Worker, error)

NewWorker returns a new apiserver-based raft transport worker, with the given configuration. The worker itself implements raft.Transport.

func NewWorkerShim

func NewWorkerShim(config Config) (worker.Worker, error)

NewWorkerShim calls straight through to NewWorker. This exists only to adapt to the signature of ManifoldConfig.NewWorker.

Types

type Config

type Config struct {
	// APIInfo contains the information, excluding addresses,
	// required to connect to an API server.
	APIInfo *api.Info

	// Authenticator is the HTTP request authenticator to use for
	// the raft endpoint.
	Authenticator httpcontext.Authenticator

	// DialConn is the function to use for dialing connections to
	// other API servers.
	DialConn DialConnFunc

	// Hub is the central hub to which the worker will subscribe
	// for notification of local address changes.
	Hub *pubsub.StructuredHub

	// Mux is the API server HTTP mux into which the handler will
	// be installed.
	Mux *apiserverhttp.Mux

	// Path is the path of the raft HTTP endpoint.
	Path string

	// LocalID is the raft.ServerID of the agent running this worker.
	LocalID raft.ServerID

	// Timeout, if non-zero, is the timeout to apply to transport
	// operations. See raft.NetworkTransportConfig.Timeout for more
	// details.
	Timeout time.Duration

	// TLSConfig is the TLS configuration to use for making
	// connections to API servers.
	TLSConfig *tls.Config

	// Clock is used for timing out the Addr getter - if the
	// peergrouper isn't publishing good API addresses in a timely
	// fashion it's better to fail and log than to hang indefinitely.
	Clock clock.Clock
}

Config is the configuration required for running an apiserver-based raft transport worker.

func (Config) Validate

func (config Config) Validate() error

Validate validates the raft worker configuration.

type DialConnFunc

type DialConnFunc func(ctx context.Context, addr string, tlsConfig *tls.Config) (net.Conn, error)

DialConnFunc is type of function used by the transport for dialing a TLS connection to another API server. The worker will send an HTTP request over the connection to upgrade it.

type Dialer

type Dialer struct {
	// APIInfo is used for authentication.
	APIInfo *api.Info

	// DialRaw returns a connection to the HTTP server
	// that is serving the raft endpoint.
	DialRaw func(raft.ServerAddress, time.Duration) (net.Conn, error)

	// Path is the path of the raft HTTP endpoint.
	Path string
}

Dialer is a type that can be used for dialling a connection connecting to a raft endpoint using the configured path, and upgrading to a raft connection.

func (*Dialer) Dial

func (d *Dialer) Dial(addr raft.ServerAddress, timeout time.Duration) (net.Conn, error)

Dial dials a new raft network connection to the controller agent with the tag identified by the given address.

Based on code from https://github.com/CanonicalLtd/raft-http.

type Handler

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

Handler is an http.Handler suitable for serving an endpoint that upgrades to raft transport connections.

func NewHandler

func NewHandler(
	connections chan<- net.Conn,
	abort <-chan struct{},
) *Handler

NewHandler returns a new Handler that sends connections to the given connections channel, and stops accepting connections after the abort channel is closed.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP is part of the http.Handler interface.

ServeHTTP checks for "raft" upgrade requests, and hijacks those connections for use as a raw connection for raft communications.

Based on code from https://github.com/CanonicalLtd/raft-http.

type ManifoldConfig

type ManifoldConfig struct {
	ClockName         string
	AgentName         string
	AuthenticatorName string
	HubName           string
	MuxName           string

	DialConn  DialConnFunc
	NewWorker func(Config) (worker.Worker, error)

	// Path is the path of the raft HTTP endpoint.
	Path string
}

ManifoldConfig holds the information necessary to run an apiserver-based raft transport worker in a dependency.Engine.

func (ManifoldConfig) Validate

func (config ManifoldConfig) Validate() error

Validate validates the manifold configuration.

type Worker

type Worker struct {
	raft.Transport
	// contains filtered or unexported fields
}

Worker is a worker that manages a raft.Transport.

func (*Worker) Kill

func (w *Worker) Kill()

Kill is part of the worker.Worker interface.

func (*Worker) Wait

func (w *Worker) Wait() error

Wait is part of the worker.Worker interface.

Jump to

Keyboard shortcuts

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