snetproxy

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2018 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package snetproxy implements transparent logic for reconnecting to the dispatcher.

This is done via two types: ProxyConn, a wrapper around snet.Conn that supports transparent reconnects, and ProxyNetwork, a wrapper around snet.Network that provides some helper functions for initializing ProxyConns (e.g., creating callbacks and checking that addresses stay the same). Callers can opt to use the helper ProxyNetwork, or manage reconnection logic themselves by using ProxyConn directly.

Index

Constants

View Source
const (
	ErrDispatcherDead            = "dispatcher dead"
	ErrLocalAddressChanged       = "local address changed on reconnect"
	ErrBindAddressChanged        = "bind address changed on reconnect"
	ErrReconnecterTimeoutExpired = "Timeout expired"
	ErrReconnecterStopped        = "Stop method was called"
	ErrClosed                    = "closed"
)

Variables

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 IOOperation

type IOOperation interface {
	// Runs the I/O operation on conn
	Do(conn snet.Conn) 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 ProxyConn

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

func NewProxyConn

func NewProxyConn(conn snet.Conn, reconnecter Reconnecter) *ProxyConn

func (*ProxyConn) BindAddr

func (conn *ProxyConn) BindAddr() net.Addr

func (*ProxyConn) Close

func (conn *ProxyConn) Close() error

func (*ProxyConn) DoIO

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

func (*ProxyConn) LocalAddr

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

func (*ProxyConn) Read

func (conn *ProxyConn) Read(b []byte) (int, error)

func (*ProxyConn) ReadFrom

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

func (*ProxyConn) ReadFromSCION

func (conn *ProxyConn) ReadFromSCION(b []byte) (int, *snet.Addr, error)

func (*ProxyConn) Reconnect

func (conn *ProxyConn) Reconnect() (snet.Conn, error)

Reconnect is only used for testing purposes and should never be called.

func (*ProxyConn) RemoteAddr

func (conn *ProxyConn) RemoteAddr() net.Addr

func (*ProxyConn) SVC

func (conn *ProxyConn) SVC() addr.HostSVC

func (*ProxyConn) SetDeadline

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

func (*ProxyConn) SetReadDeadline

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

func (*ProxyConn) SetWriteDeadline

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

func (*ProxyConn) Write

func (conn *ProxyConn) Write(b []byte) (int, error)

func (*ProxyConn) WriteTo

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

func (*ProxyConn) WriteToSCION

func (conn *ProxyConn) WriteToSCION(b []byte, address *snet.Addr) (int, error)

type ProxyNetwork

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

ProxyNetwork is a wrapper network that creates conns with transparent reconnection capabilities. Connections created by ProxyNetwork 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 proxy connection constructors directly.

func NewProxyNetwork

func NewProxyNetwork(network snet.Network) *ProxyNetwork

NewProxyNetwork adds transparent reconnection capabilities to the connections created by an snet network.

func (*ProxyNetwork) DialSCIONWithBindSVC

func (pn *ProxyNetwork) DialSCIONWithBindSVC(network string,
	laddr, raddr, baddr *snet.Addr, svc addr.HostSVC, timeout time.Duration) (snet.Conn, error)

func (*ProxyNetwork) ListenSCIONWithBindSVC

func (pn *ProxyNetwork) ListenSCIONWithBindSVC(network string,
	laddr, baddr *snet.Addr, svc addr.HostSVC, timeout time.Duration) (snet.Conn, error)

type ReadFromOperation

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

func (*ReadFromOperation) Do

func (op *ReadFromOperation) Do(conn snet.Conn) error

type ReadFromSCIONOperation

type ReadFromSCIONOperation struct {
	ReadFromOperation
}

func (*ReadFromSCIONOperation) Do

func (op *ReadFromSCIONOperation) Do(conn snet.Conn) error

type ReadOperation

type ReadOperation struct {
	BaseOperation
}

func (*ReadOperation) Do

func (op *ReadOperation) Do(conn snet.Conn) error

func (*ReadOperation) IsWrite

func (_ *ReadOperation) IsWrite() bool

type Reconnecter

type Reconnecter interface {
	Reconnect(timeout time.Duration) (snet.Conn, 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) (snet.Conn, 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

func (r *TickingReconnecter) Reconnect(timeout time.Duration) (snet.Conn, error)

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) Do

func (op *WriteOperation) Do(conn snet.Conn) error

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 snet.Conn) error

type WriteToSCIONOperation

type WriteToSCIONOperation struct {
	WriteToOperation
}

func (*WriteToSCIONOperation) Do

func (op *WriteToSCIONOperation) Do(conn snet.Conn) error

Jump to

Keyboard shortcuts

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