Documentation ¶
Index ¶
- Variables
- type Events
- type Manager
- func (m *Manager) Add(addr string, preferIPv6 bool, alias string, autoPeer ...*autopeering.Peer) error
- func (m *Manager) AnySTINGPeerConnected() bool
- func (m *Manager) Blacklist(ip string)
- func (m *Manager) BlacklistRemove(ip string)
- func (m *Manager) Blacklisted(ip string) bool
- func (m *Manager) ConnectedAndSyncedPeerCount() (uint8, uint8)
- func (m *Manager) ConnectedPeerCount() int
- func (m *Manager) ForAll(f PeerConsumerFunc)
- func (m *Manager) ForAllConnected(f PeerConsumerFunc)
- func (m *Manager) IsStaticallyPeered(ips []string, port uint16) bool
- func (m *Manager) Listen() error
- func (m *Manager) PeerCount() int
- func (m *Manager) PeerInfos() []*peer.Info
- func (m *Manager) Reconnect()
- func (m *Manager) Remove(id string) error
- func (m *Manager) SetupEventHandlers(p *peer.Peer)
- func (m *Manager) Shutdown()
- func (m *Manager) SlotsFilled() bool
- func (m *Manager) Whitelist(ips []string, port uint16, autopeeringPeer ...*autopeering.Peer)
- func (m *Manager) WhitelistRemove(id string)
- func (m *Manager) Whitelisted(id string) (*autopeering.Peer, bool)
- type Options
- type PeerConsumerFunc
Constants ¶
This section is empty.
Variables ¶
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 ¶ added in v0.4.1
AnySTINGPeerConnected returns true if any of the connected, handshaked peers supports the STING protocol.
func (*Manager) BlacklistRemove ¶
BlacklistRemove removes the blacklist entry for the given IP address.
func (*Manager) Blacklisted ¶
Blacklisted tells whether the given IP address is blacklisted.
func (*Manager) ConnectedAndSyncedPeerCount ¶ added in v0.5.0
ConnectedPeerCount returns the current count of connected peers. it has a cooldown time to not update too frequently.
func (*Manager) ConnectedPeerCount ¶
ConnectedPeerCount returns the current count of connected peers.
func (*Manager) ForAll ¶ added in v0.4.1
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 ¶
IsStaticallyPeered tells if the peer is already statically peered. all possible IDs for the given IP addresses/port combination are checked.
func (*Manager) PeerCount ¶
PeerCount returns the current count of connected and in the reconnect pool residing peers.
func (*Manager) PeerInfos ¶
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 ¶
Remove tries to remove and close any open connections for peers which are identifiable through the given ID.
func (*Manager) SetupEventHandlers ¶
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 ¶
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 ¶
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 ¶
PeerConsumerFunc is a function which consumes a peer. If it returns false, it signals that no further calls should be made to the function.