connection

package
v0.30.6 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2023 License: AGPL-3.0 Imports: 24 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ConnectionPruningEnabled  = true
	ConnectionPruningDisabled = false
)

Variables

View Source
var DefaultPeerUpdateInterval = 10 * time.Minute

DefaultPeerUpdateInterval is default duration for which the peer manager waits in between attempts to update peer connections

Functions

func IsUnconvertibleIdentitiesError

func IsUnconvertibleIdentitiesError(err error) bool

IsUnconvertibleIdentitiesError returns whether the given error is an UnconvertibleIdentitiesError error

func NewUnconvertableIdentitiesError

func NewUnconvertableIdentitiesError(errs map[flow.Identifier]error) error

Types

type ConnGater

type ConnGater struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

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

func (c *ConnGater) InterceptAddrDial(_ peer.ID, ma multiaddr.Multiaddr) bool

InterceptAddrDial is not used. Currently, allowlisting is only implemented by Peer IDs and not multi-addresses

func (*ConnGater) InterceptPeerDial

func (c *ConnGater) InterceptPeerDial(p peer.ID) bool

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

func (c *ConnGater) InterceptUpgraded(network.Conn) (allow bool, reason control.DisconnectReason)

InterceptUpgraded decision to continue or drop the connection should have been made before this call

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 *ManagerConfig) (*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) 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) Protect

func (cm *ConnManager) Protect(id peer.ID, tag string)

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)

func (*ConnManager) Unprotect

func (cm *ConnManager) Unprotect(id peer.ID, tag string) bool

func (*ConnManager) UntagPeer added in v0.30.0

func (cm *ConnManager) UntagPeer(p peer.ID, tag string)

func (*ConnManager) UpsertTag added in v0.30.0

func (cm *ConnManager) UpsertTag(p peer.ID, tag string, upsert func(int) int)

type Libp2pConnector

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

Libp2pConnector is a libp2p based Connector implementation to connect and disconnect from peers

func NewLibp2pConnector

func NewLibp2pConnector(log zerolog.Logger, host host.Host, pruning bool) (*Libp2pConnector, error)

func (*Libp2pConnector) UpdatePeers

func (l *Libp2pConnector) 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 ManagerConfig added in v0.30.0

type ManagerConfig struct {
	// HighWatermark and LowWatermark govern the number of connections are maintained by the ConnManager.
	// When the peer count exceeds the HighWatermark, as many peers will be pruned (and
	// their connections terminated) until LowWatermark peers remain. In other words, whenever the
	// peer count is x > HighWatermark, the ConnManager will prune x - LowWatermark peers.
	// The pruning algorithm is as follows:
	// 1. The ConnManager will not prune any peers that have been connected for less than GracePeriod.
	// 2. The ConnManager will not prune any peers that are protected.
	// 3. The ConnManager will sort the peers based on their number of streams and direction of connections, and
	// prunes the peers with the least number of streams. If there are ties, the peer with the incoming connection
	// will be pruned. If both peers have incoming connections, and there are still ties, one of the peers will be
	// pruned at random.
	// Algorithm implementation is in https://github.com/libp2p/go-libp2p/blob/master/p2p/net/connmgr/connmgr.go#L262-L318
	HighWatermark int // naming from libp2p
	LowWatermark  int // naming from libp2p

	// SilencePeriod is the time to wait before start pruning connections.
	SilencePeriod time.Duration // naming from libp2p
	// GracePeriod is the time to wait before pruning a new connection.
	GracePeriod time.Duration // naming from libp2p
}

func DefaultConnManagerConfig added in v0.30.0

func DefaultConnManagerConfig() *ManagerConfig

DefaultConnManagerConfig returns the default configuration for the connection manager.

type PeerManager

type PeerManager struct {
	component.Component
	// contains filtered or unexported fields
}

PeerManager adds and removes connections to peers periodically and on request

func NewPeerManager

func NewPeerManager(logger zerolog.Logger, updateInterval time.Duration, connector p2p.Connector) *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 UnconvertibleIdentitiesError

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

UnconvertibleIdentitiesError is an error which reports all the flow.Identifiers that could not be converted to peer.AddrInfo

func (UnconvertibleIdentitiesError) Error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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