peering

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2020 License: Apache-2.0 Imports: 22 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrPeeringSlotsFilled is returned when all available peering slots are filled.
	ErrPeeringSlotsFilled = errors.New("peering slots filled")
	// ErrNonMatchingMWM is returned when the MWM doesn't match this node's MWM.
	ErrNonMatchingMWM = errors.New("used MWM doesn't match")
	// ErrNonMatchingCooAddr is returned when the Coo address doesn't match this node's Coo address.
	ErrNonMatchingCooAddr = errors.New("used coo addr doesn't match")
	// ErrNonMatchingSrvSocketPort is returned when the server socket port doesn't match.
	ErrNonMatchingSrvSocketPort = errors.New("advertised server socket port doesn't match")
	// ErrUnknownPeerID is returned when an unknown peer tried to connect.
	ErrUnknownPeerID = errors.New("peer ID is not known")
	// ErrPeerAlreadyConnected is returned when a given peer is already connected.
	ErrPeerAlreadyConnected = errors.New("peer is already connected")
	// ErrPeerAlreadyInReconnectPool is returned when a given peer is already in the reconnect pool.
	ErrPeerAlreadyInReconnect = errors.New("peer is already in the reconnect pool")
	// ErrManagerIsShutdown is returned when the manager is shutdown.
	ErrManagerIsShutdown = errors.New("peering manager is shutdown")
)

Functions

This section is empty.

Types

type Events

type Events struct {
	// Fired when an autopeered peer was connected and handshaked.
	ConnectedAutopeeredPeer *events.Event
	// Fired when an IP lookup error occurs.
	IPLookupError *events.Event
	// Fired when the handshaking phase with a peer was successfully executed.
	PeerConnected *events.Event
	// Fired when a peer is disconnected and completely removed from the Manager.
	PeerDisconnected *events.Event
	// Fired when a peer is removed from the reconnect pool.
	PeerRemovedFromReconnectPool *events.Event
	// Fired when a peer is moved into the reconnect pool.
	PeerMovedIntoReconnectPool *events.Event
	// Fired when a peer is moved from connected to the reconnect pool.
	PeerMovedFromConnectedToReconnectPool *events.Event
	// Fired when the handshaking phase of an outgoing peer connection is initiated.
	PeerHandshakingOutgoing *events.Event
	// Fired when the handshaking phase of an incoming peer connection is initiated.
	PeerHandshakingIncoming *events.Event
	// Fired when the handshaking phase with an outbound autopeered peer is initiated.
	AutopeeredPeerHandshaking *events.Event
	// Fired when an autopeered peer was added as a static neighbor.
	AutopeeredPeerBecameStatic *events.Event
	// Fired when a reconnect is initiated over the entire reconnect pool.
	Reconnecting *events.Event
	// Fired when during the reconnect phase a peer is already connected.
	ReconnectRemovedAlreadyConnected *events.Event
	// Fired when the manager has been successfully shutdown.
	Shutdown *events.Event
	// Fired when internal errors occur.
	Error *events.Event
}

Events defines events fired regarding peering.

type Manager

type Manager struct {
	sync.RWMutex

	// Peering related events.
	Events Events
	// manager options.
	Opts Options
	// contains filtered or unexported fields
}

Manager manages a set of connected peers and those to which the node wants to create a connection to.

func NewManager

func NewManager(opts Options, peers ...*config.PeerConfig) *Manager

NewManager creates a new manager instance with the given Options and moves the given peers into the reconnect pool.

func (*Manager) Add

func (m *Manager) Add(addr string, preferIPv6 bool, alias string, autoPeer ...*autopeering.Peer) error

Add adds a new peer to the reconnect pool and immediately invokes a connection attempt. The peer is not added if it is already connected or the given address is invalid.

func (*Manager) AnySTINGPeerConnected

func (m *Manager) AnySTINGPeerConnected() bool

AnySTINGPeerConnected returns true if any of the connected, handshaked peers supports the STING protocol.

func (*Manager) Blacklist

func (m *Manager) Blacklist(ip string)

Blacklist blacklists the given IP from connecting.

func (*Manager) BlacklistRemove

func (m *Manager) BlacklistRemove(ip string)

BlacklistRemove removes the blacklist entry for the given IP address.

func (*Manager) Blacklisted

func (m *Manager) Blacklisted(ip string) bool

Blacklisted tells whether the given IP address is blacklisted.

func (*Manager) ConnectedAndSyncedPeerCount

func (m *Manager) ConnectedAndSyncedPeerCount() (uint8, uint8)

ConnectedPeerCount returns the current count of connected peers. it has a cooldown time to not update too frequently.

func (*Manager) ConnectedPeerCount

func (m *Manager) ConnectedPeerCount() int

ConnectedPeerCount returns the current count of connected peers.

func (*Manager) ForAll

func (m *Manager) ForAll(f PeerConsumerFunc)

ForAll executes the given function for each peer until abort is returned from within the consumer function.

func (*Manager) ForAllConnected

func (m *Manager) ForAllConnected(f PeerConsumerFunc)

ForAllConnected executes the given function for each currently connected peer until abort is returned from within the consumer function. The consumer function is only called on peers who are handshaked.

func (*Manager) IsStaticallyPeered

func (m *Manager) IsStaticallyPeered(ips []string, port uint16) bool

IsStaticallyPeered tells if the peer is already statically peered. all possible IDs for the given IP addresses/port combination are checked.

func (*Manager) Listen

func (m *Manager) Listen() error

Listen starts the peering server to listen for incoming connections.

func (*Manager) PeerCount

func (m *Manager) PeerCount() int

PeerCount returns the current count of connected and in the reconnect pool residing peers.

func (*Manager) PeerInfos

func (m *Manager) PeerInfos() []*peer.Info

PeerInfos returns snapshots of the currently connected and in the reconnect pool residing peers.

func (*Manager) Reconnect

func (m *Manager) Reconnect()

Reconnect instructs the manager to initiate connections to all peers residing in the reconnect pool.

func (*Manager) Remove

func (m *Manager) Remove(id string) error

Remove tries to remove and close any open connections for peers which are identifiable through the given ID.

func (*Manager) SetupEventHandlers

func (m *Manager) SetupEventHandlers(p *peer.Peer)

SetupEventHandlers inits the event handlers for handshaking, the underlying connection and errors.

func (*Manager) Shutdown

func (m *Manager) Shutdown()

Shutdown shuts down the peering server and disconnect all connected peers.

func (*Manager) SlotsFilled

func (m *Manager) SlotsFilled() bool

SlotsFilled checks whether all available peer slots are filled.

func (*Manager) Whitelist

func (m *Manager) Whitelist(ips []string, port uint16, autopeeringPeer ...*autopeering.Peer)

Whitelist whitelists all possible IDs for the given IP addresses/port combination (also removes any excess blacklist entry). Optionally takes in autopeering metadata which is passed further to the peer once its connected.

func (*Manager) WhitelistRemove

func (m *Manager) WhitelistRemove(id string)

WhitelistRemove removes the whitelist entry for the given IP address.

func (*Manager) Whitelisted

func (m *Manager) Whitelisted(id string) (*autopeering.Peer, bool)

Whitelisted tells whether the given ID is whitelisted.

type Options

type Options struct {
	ValidHandshake handshake.Handshake
	// The max amount of connected peers.
	MaxConnected int
	// Whether to allow connections from any peer.
	AcceptAnyPeer bool
	// Inbound connection bind address.
	BindAddress string
}

Options defines options for the Manager.

type PeerConsumerFunc

type PeerConsumerFunc func(p *peer.Peer) bool

PeerConsumerFunc is a function which consumes a peer. If it returns false, it signals that no further calls should be made to the function.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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