connection

package
v0.29.0-stable-cadence-4 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2022 License: AGPL-3.0 Imports: 22 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, 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 {
	connmgr.NullConnMgr // a null conn mgr provided by libp2p to allow implementing only the functions needed
	// contains filtered or unexported fields
}

ConnManager provides an implementation of Libp2p's ConnManager interface (https://godoc.org/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. This implementation updates networking metrics when a peer connection is added or removed

func NewConnManager

func NewConnManager(log zerolog.Logger, metrics module.NetworkMetrics) *ConnManager

func (*ConnManager) Connected

func (cm *ConnManager) Connected(n network.Network, con network.Conn)

Connected is called by libp2p when a connection opened

func (*ConnManager) Disconnected

func (cm *ConnManager) Disconnected(n network.Network, con network.Conn)

Disconnected is called by libp2p when a connection closed

func (*ConnManager) IsProtected

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

func (*ConnManager) ListenCloseNotifee

func (cm *ConnManager) ListenCloseNotifee(n network.Network, m multiaddr.Multiaddr)

called by libp2p when network stops listening on an addr * This is never called back by libp2p currently and may be a bug on their side

func (*ConnManager) ListenNotifee

func (cm *ConnManager) ListenNotifee(n network.Network, m multiaddr.Multiaddr)

ListenNotifee is called by libp2p when network starts listening on an addr

func (*ConnManager) Notifee

func (cm *ConnManager) Notifee() network.Notifiee

func (*ConnManager) Protect

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

func (*ConnManager) Unprotect

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

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 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) 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

Jump to

Keyboard shortcuts

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