peermanager

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2023 License: MIT Imports: 29 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoPeersAvailable = errors.New("no suitable peers found")

ErrNoPeersAvailable is emitted when no suitable peers are found for some protocol

Functions

func AddrInfoToPeerData added in v0.9.0

func AddrInfoToPeerData(origin wps.Origin, peerID peer.ID, host host.Host, pubsubTopics ...string) *service.PeerData

Types

type ConnectionGater

type ConnectionGater struct {
	sync.Mutex
	// contains filtered or unexported fields
}

ConnectionGater is the implementation of the connection gater used to limit the number of connections per IP address

func NewConnectionGater

func NewConnectionGater(logger *zap.Logger) *ConnectionGater

NewConnectionGater creates a new instance of ConnectionGater

func (*ConnectionGater) InterceptAccept

func (c *ConnectionGater) InterceptAccept(n network.ConnMultiaddrs) (allow bool)

InterceptAccept is called as soon as a transport listener receives an inbound connection request, before any upgrade takes place. Transports who accept already secure and/or multiplexed connections (e.g. possibly QUIC) MUST call this method regardless, for correctness/consistency.

func (*ConnectionGater) InterceptAddrDial

func (c *ConnectionGater) InterceptAddrDial(pid peer.ID, m multiaddr.Multiaddr) (allow bool)

InterceptAddrDial is called on an imminent outbound dial to a peer on a particular address. Blocking connections at this stage is typical for address filtering.

func (*ConnectionGater) InterceptPeerDial

func (c *ConnectionGater) InterceptPeerDial(_ peer.ID) (allow bool)

InterceptPeerDial is called on an imminent outbound peer dial request, prior to the addresses of that peer being available/resolved. Blocking connections at this stage is typical for blacklisting scenarios.

func (*ConnectionGater) InterceptSecured

func (c *ConnectionGater) InterceptSecured(_ network.Direction, _ peer.ID, _ network.ConnMultiaddrs) (allow bool)

InterceptSecured is called for both inbound and outbound connections, after a security handshake has taken place and we've authenticated the peer

func (*ConnectionGater) InterceptUpgraded

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

InterceptUpgraded is called for inbound and outbound connections, after libp2p has finished upgrading the connection entirely to a secure, multiplexed channel.

func (*ConnectionGater) NotifyDisconnect

func (c *ConnectionGater) NotifyDisconnect(addr multiaddr.Multiaddr)

NotifyDisconnect is called when a connection disconnects.

type NodeTopicDetails added in v0.8.1

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

NodeTopicDetails stores pubSubTopic related data like topicHandle for the node.

type PeerConnectionStrategy

type PeerConnectionStrategy struct {
	*service.CommonDiscoveryService
	// contains filtered or unexported fields
}

PeerConnectionStrategy is a utility to connect to peers, but only if we have not recently tried connecting to them already

func NewPeerConnectionStrategy

func NewPeerConnectionStrategy(pm *PeerManager,
	dialTimeout time.Duration, logger *zap.Logger) (*PeerConnectionStrategy, error)

NewPeerConnectionStrategy creates a utility to connect to peers, but only if we have not recently tried connecting to them already.

dialTimeout is how long we attempt to connect to a peer before giving up minPeers is the minimum number of peers that the node should have

func (*PeerConnectionStrategy) SetHost

func (c *PeerConnectionStrategy) SetHost(h host.Host)

SetHost sets the host to be able to mount or consume a protocol

func (*PeerConnectionStrategy) Start

Start attempts to connect to the peers passed in by peerCh. Will not connect to peers if they are within the backoff period.

func (*PeerConnectionStrategy) Stop

func (c *PeerConnectionStrategy) Stop()

Stop terminates the peer-connector

func (*PeerConnectionStrategy) Subscribe

func (c *PeerConnectionStrategy) Subscribe(ctx context.Context, ch <-chan service.PeerData)

Subscribe receives channels on which discovered peers should be pushed

type PeerManager

type PeerManager struct {
	InRelayPeersTarget  int
	OutRelayPeersTarget int
	// contains filtered or unexported fields
}

PeerManager applies various controls and manage connections towards peers.

func NewPeerManager

func NewPeerManager(maxConnections int, maxPeers int, logger *zap.Logger) *PeerManager

NewPeerManager creates a new peerManager instance.

func (*PeerManager) AddDiscoveredPeer

func (pm *PeerManager) AddDiscoveredPeer(p service.PeerData, connectNow bool)

AddDiscoveredPeer to add dynamically discovered peers. Note that these peers will not be set in service-slots.

func (*PeerManager) AddPeer

func (pm *PeerManager) AddPeer(address ma.Multiaddr, origin wps.Origin, pubsubTopics []string, protocols ...protocol.ID) (*service.PeerData, error)

AddPeer adds peer to the peerStore and also to service slots

func (*PeerManager) Connect added in v0.9.0

func (pm *PeerManager) Connect(pData *service.PeerData)

Connect establishes a connection to a

func (*PeerManager) DiscoverAndConnectToPeers added in v0.9.0

func (pm *PeerManager) DiscoverAndConnectToPeers(ctx context.Context, cluster uint16,
	shard uint16, serviceProtocol protocol.ID, maxCount int) error

DiscoverAndConnectToPeers discovers peers using discoveryv5 and connects to the peers. It discovers peers till maxCount peers are found for the cluster,shard and protocol or the context passed expires.

func (*PeerManager) FilterPeersByProto added in v0.9.0

func (pm *PeerManager) FilterPeersByProto(specificPeers peer.IDSlice, proto ...protocol.ID) (peer.IDSlice, error)

FilterPeersByProto filters list of peers that support specified protocols. If specificPeers is nil, all peers in the host's peerStore are considered for filtering.

func (*PeerManager) GroupPeersByDirection

func (pm *PeerManager) GroupPeersByDirection(specificPeers ...peer.ID) (inPeers peer.IDSlice, outPeers peer.IDSlice, err error)

GroupPeersByDirection returns all the connected peers in peer store grouped by Inbound or outBound direction

func (*PeerManager) RegisterWakuProtocol added in v0.9.0

func (pm *PeerManager) RegisterWakuProtocol(proto protocol.ID, bitField uint8)

RegisterWakuProtocol to be used by Waku protocols that could be used for peer discovery Which means protoocl should be as defined in waku2 ENR key in https://rfc.vac.dev/spec/31/.

func (*PeerManager) RemovePeer

func (pm *PeerManager) RemovePeer(peerID peer.ID)

RemovePeer deletes peer from the peerStore after disconnecting it. It also removes the peer from serviceSlot.

func (*PeerManager) SelectPeer

func (pm *PeerManager) SelectPeer(criteria PeerSelectionCriteria) (peer.ID, error)

SelectPeer selects a peer based on selectionType specified. Context is required only in case of selectionType set to LowestRTT

func (*PeerManager) SelectPeerByContentTopics added in v0.9.0

func (pm *PeerManager) SelectPeerByContentTopics(proto protocol.ID, contentTopics []string, specificPeers ...peer.ID) (peer.ID, error)

SelectPeerByContentTopic is used to return a random peer that supports a given protocol for given contentTopic. If a list of specific peers is passed, the peer will be chosen from that list assuming it supports the chosen protocol and contentTopic, otherwise it will chose a peer from the service slot. If a peer cannot be found in the service slot, a peer will be selected from node peerstore

func (*PeerManager) SelectPeerWithLowestRTT added in v0.9.0

func (pm *PeerManager) SelectPeerWithLowestRTT(criteria PeerSelectionCriteria) (peer.ID, error)

SelectPeerWithLowestRTT will select a peer that supports a specific protocol with the lowest reply time If a list of specific peers is passed, the peer will be chosen from that list assuming it supports the chosen protocol, otherwise it will chose a peer from the node peerstore TO OPTIMIZE: As of now the peer with lowest RTT is identified when select is called, this should be optimized to maintain the RTT as part of peer-scoring and just select based on that.

func (*PeerManager) SelectRandomPeer added in v0.9.0

func (pm *PeerManager) SelectRandomPeer(criteria PeerSelectionCriteria) (peer.ID, error)

SelectRandomPeer is used to return a random peer that supports a given protocol. If a list of specific peers is passed, the peer will be chosen from that list assuming it supports the chosen protocol, otherwise it will chose a peer from the service slot. If a peer cannot be found in the service slot, a peer will be selected from node peerstore if pubSubTopic is specified, peer is selected from list that support the pubSubTopic

func (*PeerManager) SetDiscv5 added in v0.9.0

func (pm *PeerManager) SetDiscv5(discv5 *discv5.DiscoveryV5)

SetDiscv5 sets the discoveryv5 service to be used for peer discovery.

func (*PeerManager) SetHost

func (pm *PeerManager) SetHost(host host.Host)

SetHost sets the host to be used in order to access the peerStore.

func (*PeerManager) SetPeerConnector

func (pm *PeerManager) SetPeerConnector(pc *PeerConnectionStrategy)

SetPeerConnector sets the peer connector to be used for establishing relay connections.

func (*PeerManager) Start

func (pm *PeerManager) Start(ctx context.Context)

Start starts the processing to be done by peer manager.

func (*PeerManager) SubscribeToRelayEvtBus added in v0.8.1

func (pm *PeerManager) SubscribeToRelayEvtBus(bus event.Bus) error

type PeerSelection added in v0.9.0

type PeerSelection int

PeerSelection provides various options based on which Peer is selected from a list of peers.

const (
	Automatic PeerSelection = iota
	LowestRTT
)

type PeerSelectionCriteria added in v0.9.0

type PeerSelectionCriteria struct {
	SelectionType PeerSelection
	Proto         protocol.ID
	PubsubTopics  []string
	SpecificPeers peer.IDSlice
	Ctx           context.Context
}

PeerSelectionCriteria is the selection Criteria that is used by PeerManager to select peers.

type ServiceSlots

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

ServiceSlots is for storing service slots for a given protocol topic

func NewServiceSlot

func NewServiceSlot() *ServiceSlots

NewServiceSlot is a constructor for ServiceSlot

type WakuProtoInfo added in v0.9.0

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

WakuProtoInfo holds protocol specific info To be used at a later stage to set various config such as criteria for peer management specific to each Waku protocols This should make peer-manager agnostic to protocol

Jump to

Keyboard shortcuts

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