connmgr

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//ErrDialNil is used to indicate that Dial cannot be nil in the configuration.
	ErrDialNil = errors.New("Config: Dial cannot be nil")
)

Functions

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until either UseLogger or SetLogWriter are called.

func UseLogger

func UseLogger(logger elalog.Logger)

UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using elalog.

Types

type Config

type Config struct {
	// Listeners defines a slice of listeners for which the connection
	// manager will take ownership of and accept connections.  When a
	// connection is accepted, the OnAccept handler will be invoked with the
	// connection.  Since the connection manager takes ownership of these
	// listeners, they will be closed when the connection manager is
	// stopped.
	//
	// This field will not have any effect if the OnAccept field is not
	// also specified.  It may be nil if the caller does not wish to listen
	// for incoming connections.
	Listeners []net.Listener

	// OnAccept is a callback that is fired when an inbound connection is
	// accepted.  It is the caller's responsibility to close the connection.
	// Failure to close the connection will result in the connection manager
	// believing the connection is still active and thus have undesirable
	// side effects such as still counting toward maximum connection limits.
	//
	// This field will not have any effect if the Listeners field is not
	// also specified since there couldn't possibly be any accepted
	// connections in that case.
	OnAccept func(net.Conn)

	// RetryDuration is the duration to wait before retrying connection
	// requests. Defaults to 5s.
	RetryDuration time.Duration

	// OnConnection is a callback that is fired when a new outbound
	// connection is established.
	OnConnection func(*ConnReq, net.Conn)

	// GetAddr get the network address of the given PID.
	GetAddr func(pid [33]byte) (na net.Addr, err error)

	// Dial connects to the address on the named network. It cannot be nil.
	Dial func(net.Addr) (net.Conn, error)
}

Config holds the configuration options related to the connection manager.

type ConnManager

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

ConnManager provides a manager to handle network connections.

func New

func New(cfg *Config) (*ConnManager, error)

New returns a new connection manager. Use Start to start connecting to the network.

func (*ConnManager) Connect

func (cm *ConnManager) Connect(pid [33]byte)

Connect assigns an id and dials a connection to the address of the connection request.

func (*ConnManager) Disconnect

func (cm *ConnManager) Disconnect(pid [33]byte)

Disconnect disconnects the connection corresponding to the given connection id. If permanent, the connection will be retried with an increasing backoff duration.

func (*ConnManager) Remove

func (cm *ConnManager) Remove(pid [33]byte)

Remove removes the connection corresponding to the given connection id from known connections.

NOTE: This method can also be used to cancel a lingering connection attempt that hasn't yet succeeded.

func (*ConnManager) Start

func (cm *ConnManager) Start()

Start launches the connection manager and begins connecting to the network.

func (*ConnManager) Stop

func (cm *ConnManager) Stop()

Stop gracefully shuts down the connection manager.

func (*ConnManager) Wait

func (cm *ConnManager) Wait()

Wait blocks until the connection manager halts gracefully.

type ConnReq

type ConnReq struct {
	PID  [33]byte // PID is the peer public key id from PeerAddr
	Addr net.Addr
	// contains filtered or unexported fields
}

ConnReq is the connection request to a network address. If permanent, the connection will be retried on disconnection.

func (*ConnReq) String

func (c *ConnReq) String() string

String returns a human-readable string for the connection request.

Jump to

Keyboard shortcuts

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