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
- Variables
- type AtomicBool
- type BaseOperation
- type IOOperation
- type ProxyConn
- func (conn *ProxyConn) BindAddr() net.Addr
- func (conn *ProxyConn) Close() error
- func (conn *ProxyConn) DoIO(op IOOperation) error
- func (conn *ProxyConn) LocalAddr() net.Addr
- func (conn *ProxyConn) Read(b []byte) (int, error)
- func (conn *ProxyConn) ReadFrom(b []byte) (int, net.Addr, error)
- func (conn *ProxyConn) ReadFromSCION(b []byte) (int, *snet.Addr, error)
- func (conn *ProxyConn) Reconnect() (snet.Conn, error)
- func (conn *ProxyConn) RemoteAddr() net.Addr
- func (conn *ProxyConn) SVC() addr.HostSVC
- func (conn *ProxyConn) SetDeadline(deadline time.Time) error
- func (conn *ProxyConn) SetReadDeadline(deadline time.Time) error
- func (conn *ProxyConn) SetWriteDeadline(deadline time.Time) error
- func (conn *ProxyConn) Write(b []byte) (int, error)
- func (conn *ProxyConn) WriteTo(b []byte, address net.Addr) (int, error)
- func (conn *ProxyConn) WriteToSCION(b []byte, address *snet.Addr) (int, error)
- type ProxyNetwork
- type ReadFromOperation
- type ReadFromSCIONOperation
- type ReadOperation
- type Reconnecter
- type State
- type TickingReconnecter
- type WriteOperation
- type WriteToOperation
- type WriteToSCIONOperation
Constants ¶
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 ¶
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) DoIO ¶
func (conn *ProxyConn) DoIO(op IOOperation) error
func (*ProxyConn) ReadFromSCION ¶
func (*ProxyConn) Reconnect ¶
Reconnect is only used for testing purposes and should never be called.
func (*ProxyConn) RemoteAddr ¶
func (*ProxyConn) SetReadDeadline ¶
func (*ProxyConn) SetWriteDeadline ¶
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 ¶
type ReadFromOperation ¶
type ReadFromOperation struct { ReadOperation // contains filtered or unexported fields }
type ReadFromSCIONOperation ¶
type ReadFromSCIONOperation struct {
ReadFromOperation
}
type ReadOperation ¶
type ReadOperation struct {
BaseOperation
}
func (*ReadOperation) IsWrite ¶
func (_ *ReadOperation) IsWrite() bool
type Reconnecter ¶
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.
type TickingReconnecter ¶
type TickingReconnecter struct {
// contains filtered or unexported fields
}
func NewTickingReconnecter ¶
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 }
type WriteToSCIONOperation ¶
type WriteToSCIONOperation struct {
WriteToOperation
}