Documentation ¶
Index ¶
- Constants
- Variables
- func DefaultLibp2pBackoffConnectorFactory() p2p.ConnectorFactory
- type ConnGater
- func (c *ConnGater) InterceptAccept(cm network.ConnMultiaddrs) bool
- func (c *ConnGater) InterceptAddrDial(_ peer.ID, ma multiaddr.Multiaddr) bool
- func (c *ConnGater) InterceptPeerDial(p peer.ID) bool
- func (c *ConnGater) InterceptSecured(dir network.Direction, p peer.ID, addr network.ConnMultiaddrs) bool
- func (c *ConnGater) InterceptUpgraded(network.Conn) (allow bool, reason control.DisconnectReason)
- func (c *ConnGater) SetDisallowListOracle(oracle p2p.DisallowListOracle)
- type ConnGaterOption
- type ConnManager
- func (cm *ConnManager) CheckLimit(l connmgr.GetConnLimiter) error
- func (cm *ConnManager) Close() error
- func (cm *ConnManager) GetTagInfo(p peer.ID) *connmgr.TagInfo
- func (cm *ConnManager) IsProtected(id peer.ID, tag string) bool
- func (cm *ConnManager) Notifee() network.Notifiee
- func (cm *ConnManager) Protect(id peer.ID, tag string)
- func (cm *ConnManager) TagPeer(id peer.ID, s string, i int)
- func (cm *ConnManager) TrimOpenConns(ctx context.Context)
- func (cm *ConnManager) Unprotect(id peer.ID, tag string) bool
- func (cm *ConnManager) UntagPeer(p peer.ID, tag string)
- func (cm *ConnManager) UpsertTag(p peer.ID, tag string, upsert func(int) int)
- type ConnectorHost
- func (c *ConnectorHost) ClosePeer(id peer.ID) error
- func (c *ConnectorHost) Connections() []network.Conn
- func (c *ConnectorHost) ID() peer.ID
- func (c *ConnectorHost) IsConnectedTo(peerID peer.ID) bool
- func (c *ConnectorHost) IsProtected(id peer.ID) bool
- func (c *ConnectorHost) PeerInfo(id peer.ID) peer.AddrInfo
- type PeerManager
- type PeerUpdater
- type PeerUpdaterConfig
Constants ¶
const ( // PruningEnabled is a boolean flag to enable pruning of connections to peers that are not part of // the explicit update list. // If set to true, the connector will prune connections to peers that are not part of the explicit update list. PruningEnabled = true // PruningDisabled is a boolean flag to disable pruning of connections to peers that are not part of // the explicit update list. // If set to false, the connector will not prune connections to peers that are not part of the explicit update list. PruningDisabled = false )
Variables ¶
var DefaultPeerUpdateInterval = time.Second
DefaultPeerUpdateInterval is default duration for which the peer manager waits in between attempts to update peer connections. We set it to 1 second to be aligned with the heartbeat intervals of libp2p, alsp, and gossipsub.
Functions ¶
func DefaultLibp2pBackoffConnectorFactory ¶ added in v0.31.0
func DefaultLibp2pBackoffConnectorFactory() p2p.ConnectorFactory
DefaultLibp2pBackoffConnectorFactory is a factory function to create a new BackoffConnector. It uses the default values for the backoff connector. (https://github.com/libp2p/go-libp2p-pubsub/blob/master/discovery.go#L34)
Types ¶
type ConnGater ¶
ConnGater is the implementation of the libp2p connmgr.ConnectionGater interface It provides node allowlisting by libp2p peer.ID which is derived from the node public networking key
func NewConnGater ¶
func NewConnGater(log zerolog.Logger, identityProvider module.IdentityProvider, opts ...ConnGaterOption) *ConnGater
func (*ConnGater) InterceptAccept ¶
func (c *ConnGater) InterceptAccept(cm network.ConnMultiaddrs) bool
InterceptAccept is not used. Currently, allowlisting is only implemented by Peer IDs and not multi-addresses
func (*ConnGater) InterceptAddrDial ¶
InterceptAddrDial is not used. Currently, allowlisting is only implemented by Peer IDs and not multi-addresses
func (*ConnGater) InterceptPeerDial ¶
InterceptPeerDial - a callback which allows or disallows outbound connection
func (*ConnGater) InterceptSecured ¶
func (c *ConnGater) InterceptSecured(dir network.Direction, p peer.ID, addr network.ConnMultiaddrs) bool
InterceptSecured a callback executed after the libp2p security handshake. It tests whether to accept or reject an inbound connection based on its peer id.
func (*ConnGater) InterceptUpgraded ¶
InterceptUpgraded decision to continue or drop the connection should have been made before this call
func (*ConnGater) SetDisallowListOracle ¶ added in v0.32.0
func (c *ConnGater) SetDisallowListOracle(oracle p2p.DisallowListOracle)
SetDisallowListOracle sets the disallow list oracle for the connection gater. If one is set, the oracle is consulted upon every incoming or outgoing connection attempt, and the connection is only allowed if the remote peer is not on the disallow list. In Flow blockchain, it is not optional to dismiss the disallow list oracle, and if one is not set the connection gater will panic. Also, it follows a dependency injection pattern and does not allow to set the disallow list oracle more than once, any subsequent calls to this method will result in a panic. Args:
oracle: the disallow list oracle to set.
Returns:
none
Panics:
if the disallow list oracle is already set.
type ConnGaterOption ¶
type ConnGaterOption func(*ConnGater)
ConnGaterOption allow the connection gater to be configured with a list of PeerFilter funcs for a specific conn gater callback. In the current implementation of the ConnGater the following callbacks can be configured with peer filters. * InterceptPeerDial - peer filters can be configured with WithOnInterceptPeerDialFilters which will allow or disallow outbound connections. * InterceptSecured - peer filters can be configured with WithOnInterceptSecuredFilters which will allow or disallow inbound connections after libP2P security handshake.
func WithOnInterceptPeerDialFilters ¶
func WithOnInterceptPeerDialFilters(filters []p2p.PeerFilter) ConnGaterOption
WithOnInterceptPeerDialFilters sets peer filters for outbound connections.
func WithOnInterceptSecuredFilters ¶
func WithOnInterceptSecuredFilters(filters []p2p.PeerFilter) ConnGaterOption
WithOnInterceptSecuredFilters sets peer filters for inbound secured connections.
type ConnManager ¶
type ConnManager struct {
// contains filtered or unexported fields
}
ConnManager provides an implementation of Libp2p's ConnManager interface (https://pkg.go.dev/github.com/libp2p/go-libp2p/core/connmgr#ConnManager) It is called back by libp2p when certain events occur such as opening/closing a stream, opening/closing connection etc. Current implementation primarily acts as a wrapper around libp2p's BasicConnMgr (https://pkg.go.dev/github.com/libp2p/go-libp2p/p2p/net/connmgr#BasicConnMgr). However, we override the notifiee callback to add additional functionality so that it provides metrics and logging instrumentation for Flow.
func NewConnManager ¶
func NewConnManager(logger zerolog.Logger, metric module.LibP2PConnectionMetrics, cfg *netconf.ConnectionManager) (*ConnManager, error)
NewConnManager creates a new connection manager. It errors if creating the basic connection manager of libp2p fails. The error is not benign, and we should crash the node if it happens. It is a malpractice to start the node without connection manager.
func (*ConnManager) CheckLimit ¶ added in v0.33.14
func (cm *ConnManager) CheckLimit(l connmgr.GetConnLimiter) error
func (*ConnManager) Close ¶ added in v0.30.0
func (cm *ConnManager) Close() error
func (*ConnManager) GetTagInfo ¶ added in v0.30.0
func (cm *ConnManager) GetTagInfo(p peer.ID) *connmgr.TagInfo
func (*ConnManager) IsProtected ¶
func (cm *ConnManager) IsProtected(id peer.ID, tag string) bool
func (*ConnManager) Notifee ¶
func (cm *ConnManager) Notifee() network.Notifiee
func (*ConnManager) TagPeer ¶ added in v0.30.0
func (cm *ConnManager) TagPeer(id peer.ID, s string, i int)
func (*ConnManager) TrimOpenConns ¶ added in v0.30.0
func (cm *ConnManager) TrimOpenConns(ctx context.Context)
type ConnectorHost ¶ added in v0.31.0
type ConnectorHost struct {
// contains filtered or unexported fields
}
ConnectorHost is a wrapper around the libp2p host.Host interface to provide the required functionality for the Connector interface.
func NewConnectorHost ¶ added in v0.31.0
func NewConnectorHost(h host.Host) *ConnectorHost
func (*ConnectorHost) ClosePeer ¶ added in v0.31.0
func (c *ConnectorHost) ClosePeer(id peer.ID) error
ClosePeer closes the connection to the given peer.ID. Args:
id: peer.ID for which the connection is to be closed
Returns:
error if there is any error while closing the connection to the given peer.ID. All errors are benign.
func (*ConnectorHost) Connections ¶ added in v0.31.0
func (c *ConnectorHost) Connections() []network.Conn
Connections returns all the connections of the underlying host.
func (*ConnectorHost) ID ¶ added in v0.31.0
func (c *ConnectorHost) ID() peer.ID
ID returns the peer.ID of the underlying host. Returns:
peer.ID of the underlying host.
ID returns the peer.ID of the underlying host.
func (*ConnectorHost) IsConnectedTo ¶ added in v0.32.0
func (c *ConnectorHost) IsConnectedTo(peerID peer.ID) bool
IsConnectedTo returns true if the given peer.ID is connected to the underlying host. Args:
peerID: peer.ID for which the connection status is requested
Returns:
true if the given peer.ID is connected to the underlying host.
func (*ConnectorHost) IsProtected ¶ added in v0.31.0
func (c *ConnectorHost) IsProtected(id peer.ID) bool
IsProtected returns true if the given peer.ID is protected from pruning. Args:
id: peer.ID for which the protection status is requested
Returns:
true if the given peer.ID is protected from pruning
type PeerManager ¶
PeerManager adds and removes connections to peers periodically and on request
func NewPeerManager ¶
func NewPeerManager(logger zerolog.Logger, updateInterval time.Duration, connector p2p.PeerUpdater) *PeerManager
NewPeerManager creates a new peer manager which calls the peersProvider callback to get a list of peers to connect to and it uses the connector to actually connect or disconnect from peers.
func (*PeerManager) ForceUpdatePeers ¶
func (pm *PeerManager) ForceUpdatePeers(ctx context.Context)
ForceUpdatePeers initiates an update to the peer connections of this node immediately
func (*PeerManager) OnRateLimitedPeer ¶ added in v0.30.0
func (pm *PeerManager) OnRateLimitedPeer(pid peer.ID, role, msgType, topic, reason string)
OnRateLimitedPeer rate limiter distributor consumer func that will be called when a peer is rate limited, the rate limited peer is disconnected immediately after being rate limited.
func (*PeerManager) RequestPeerUpdate ¶
func (pm *PeerManager) RequestPeerUpdate()
RequestPeerUpdate requests an update to the peer connections of this node. If a peer update has already been requested (either as a periodic request or an on-demand request) and is outstanding, then this call is a no-op.
func (*PeerManager) SetPeersProvider ¶
func (pm *PeerManager) SetPeersProvider(peersProvider p2p.PeersProvider)
SetPeersProvider sets the peers provider SetPeersProvider may be called at most once
type PeerUpdater ¶ added in v0.32.0
type PeerUpdater struct {
// contains filtered or unexported fields
}
PeerUpdater is a connector that connects to a list of peers and disconnects from any other connection that the libp2p node might have.
func NewPeerUpdater ¶ added in v0.32.0
func NewPeerUpdater(cfg *PeerUpdaterConfig) (*PeerUpdater, error)
NewPeerUpdater creates a new libp2p based connector Args:
- cfg: configuration for the connector
Returns:
- *PeerUpdater: a new libp2p based connector
- error: an error if there is any error while creating the connector. The errors are irrecoverable and unexpected.
func (*PeerUpdater) UpdatePeers ¶ added in v0.32.0
func (l *PeerUpdater) UpdatePeers(ctx context.Context, peerIDs peer.IDSlice)
UpdatePeers is the implementation of the Connector.UpdatePeers function. It connects to all of the ids and disconnects from any other connection that the libp2p node might have.
type PeerUpdaterConfig ¶ added in v0.32.0
type PeerUpdaterConfig struct { // PruneConnections is a boolean flag to enable pruning of connections to peers that are not part of the explicit update list. PruneConnections bool // Logger is the logger to be used by the connector Logger zerolog.Logger // Host is the libp2p host to be used by the connector. Host p2p.ConnectorHost // ConnectorFactory is a factory function to create a new connector. Connector p2p.Connector }
PeerUpdaterConfig is the configuration for the libp2p based connector.