reconnect

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package reconnect implements transparent logic for reconnecting to the dispatcher.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDispatcherDead = serrors.New("dispatcher dead")
	// FIXME(scrye): Change this s.t. it's serrors.IsTimeout compatible.
	ErrReconnecterTimeoutExpired = serrors.New("timeout expired")
	ErrReconnecterStopped        = serrors.New("stop method was called")
	ErrClosed                    = serrors.New("closed")
)
View Source
var (
	DefaultTickerInterval = time.Second
)

Use a var here to allow tests to inject shorter intervals for fast testing.

Functions

This section is empty.

Types

type AtomicBool

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

func (*AtomicBool) IsFalse

func (f *AtomicBool) IsFalse() bool

func (*AtomicBool) IsTrue

func (f *AtomicBool) IsTrue() bool

func (*AtomicBool) Set

func (f *AtomicBool) Set(v bool)

type BaseOperation

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

type DispatcherService

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

DispatcherService is a dispatcher wrapper that creates conns with transparent reconnection capabilities. Connections created by DispatcherService also validate that dispatcher registrations do not change addresses.

Callers interested in providing their own reconnection callbacks and validating the new connection themselves should use the connection constructors directly.

func NewDispatcherService

func NewDispatcherService(dispatcher reliable.Dispatcher) *DispatcherService

NewDispatcherService adds transparent reconnection capabilities to dispatcher connections.

func (*DispatcherService) Register

func (pn *DispatcherService) Register(ctx context.Context, ia addr.IA, public *net.UDPAddr,
	svc addr.HostSVC) (net.PacketConn, uint16, error)

type IOOperation

type IOOperation interface {
	// Runs the I/O operation on conn
	Do(conn net.PacketConn) error
	// IsWrite returns true for types implementing write operations
	IsWrite() bool
}

IOOperation provides an abstraction around any Conn reads and writes. Types that implement this interface contain the Read/Write arguments and return values as fields, thus allowing the reconnection loop to run any I/O function without caring what it is.

type PacketConn

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

func NewPacketConn

func NewPacketConn(dispConn net.PacketConn, reconnecter Reconnecter) *PacketConn

func (*PacketConn) Close

func (conn *PacketConn) Close() error

func (*PacketConn) DoIO

func (conn *PacketConn) DoIO(op IOOperation) error

func (*PacketConn) LocalAddr

func (conn *PacketConn) LocalAddr() net.Addr

func (*PacketConn) ReadFrom

func (conn *PacketConn) ReadFrom(b []byte) (int, net.Addr, error)

func (*PacketConn) Reconnect

func (conn *PacketConn) Reconnect() (net.PacketConn, error)

Reconnect is only used internally and should never be called from outside the package.

func (*PacketConn) SetDeadline

func (conn *PacketConn) SetDeadline(deadline time.Time) error

func (*PacketConn) SetReadDeadline

func (conn *PacketConn) SetReadDeadline(deadline time.Time) error

func (*PacketConn) SetWriteDeadline

func (conn *PacketConn) SetWriteDeadline(deadline time.Time) error

func (*PacketConn) WriteTo

func (conn *PacketConn) WriteTo(b []byte, address net.Addr) (int, error)

type ReadFromOperation

type ReadFromOperation struct {
	ReadOperation
	// contains filtered or unexported fields
}

func (*ReadFromOperation) Do

func (op *ReadFromOperation) Do(conn net.PacketConn) error

type ReadOperation

type ReadOperation struct {
	BaseOperation
}

func (*ReadOperation) IsWrite

func (_ *ReadOperation) IsWrite() bool

type Reconnecter

type Reconnecter interface {
	Reconnect(ctx context.Context) (net.PacketConn, uint16, error)
	Stop()
}

type State

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

A State objects encodes an up or down state in a way that can be used directly in selects. Note that not all methods are safe for concurrent use (see their documentation for more information).

func NewState

func NewState() *State

NewState returns a new state. The state is initially set to up.

func (*State) SetDown

func (s *State) SetDown()

SetDown sets the state to down.

It is not safe to call SetDown concurrently with other methods.

func (*State) SetUp

func (s *State) SetUp()

SetUp sets the state to up.

It is safe to call SetUp concurrently with Up.

func (*State) Up

func (s *State) Up() <-chan struct{}

Up yields a channel that will be closed once SetUp() is called.

It is safe to call SetUp concurrently with Up.

type TickingReconnecter

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

func NewTickingReconnecter

func NewTickingReconnecter(
	f func(timeout time.Duration) (net.PacketConn, uint16, error)) *TickingReconnecter

NewTickingReconnecter creates a new dispatcher reconnecter. Calling Reconnect in turn calls f periodically to obtain a new connection to the dispatcher,

func (*TickingReconnecter) Reconnect

Reconnect repeatedly attempts to reestablish a connection to the dispatcher, subject to timeout. Attempts that receive dispatcher connection errors are followed by reattempts. Critical errors (e.g., port mismatches) return immediately.

func (*TickingReconnecter) Stop

func (r *TickingReconnecter) Stop()

Stop shuts down the reconnection attempt (if any), and waits for the reconnecting goroutine to finish.

It is safe to call Stop while Reconnect is running.

type WriteOperation

type WriteOperation struct {
	BaseOperation
}

func (*WriteOperation) IsWrite

func (_ *WriteOperation) IsWrite() bool

type WriteToOperation

type WriteToOperation struct {
	WriteOperation
	// contains filtered or unexported fields
}

func (*WriteToOperation) Do

func (op *WriteToOperation) Do(conn net.PacketConn) error

Directories

Path Synopsis
internal
Package mock_reconnect is a generated GoMock package.
Package mock_reconnect is a generated GoMock package.

Jump to

Keyboard shortcuts

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