peermgmt

package
v0.2300.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2023 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterNodeHandler

func RegisterNodeHandler(h NodeHandler)

RegisterNodeHandler registers a node handler.

Types

type NodeHandler

type NodeHandler interface {
	// Protocols returns the ids of the protocols the node supports on the given chain.
	Protocols(n *node.Node, chainContext string) []core.ProtocolID

	// Topics returns the ids of the topics the node supports on the given chain.
	Topics(n *node.Node, chainContext string) []string
}

NodeHandler is an interface for a handler to return protocols and topics supported by a node.

type NodeHandlerBundle

type NodeHandlerBundle struct {
	ProtocolsFn func(n *node.Node, chainContext string) []core.ProtocolID
	TopicsFn    func(n *node.Node, chainContext string) []string
}

NodeHandlerBundle implements NodeHandler by calling any of the functions set on it, and returning default values if they are unset.

func (*NodeHandlerBundle) Protocols

func (b *NodeHandlerBundle) Protocols(n *node.Node, chainContext string) []core.ProtocolID

Protocols calls ProtocolsFn if set or returns an empty list of protocols.

func (*NodeHandlerBundle) Topics

func (b *NodeHandlerBundle) Topics(n *node.Node, chainContext string) []string

Topics calls TopicsFn if set or returns an empty list of topics.

type PeerManager

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

PeerManager tracks and manages peers that support registered protocols and topics.

Peer manager's main responsibility is to keep sufficient number of peers from the registry and from the discovery connected to the host for any protocol and topic. If the number of connected peers is too low, the manager will try to connect to known peers or try to find new ones.

func NewPeerManager

func NewPeerManager(
	h host.Host,
	g connmgr.ConnectionGater,
	ps *pubsub.PubSub,
	consensus consensus.Backend,
	chainContext string,
	cs *persistent.CommonStore,
	opts ...PeerManagerOption,
) *PeerManager

NewPeerManager creates a new peer manager.

func (*PeerManager) NumProtocolPeers

func (m *PeerManager) NumProtocolPeers(p core.ProtocolID) int

NumProtocolPeers returns the number of connected peers that support the given protocol.

func (*PeerManager) NumTopicPeers

func (m *PeerManager) NumTopicPeers(topic string) int

NumTopicPeers returns the number of connected peers that support the given topic.

func (*PeerManager) PeerRegistry

func (m *PeerManager) PeerRegistry() api.PeerRegistry

PeerRegistry implements api.PeerManager.

func (*PeerManager) PeerTagger

func (m *PeerManager) PeerTagger() api.PeerTagger

PeerTagger implements api.PeerManager.

func (*PeerManager) Protocols

func (m *PeerManager) Protocols() []core.ProtocolID

Protocols returns the ids of the registered protocols.

func (*PeerManager) RegisterProtocol

func (m *PeerManager) RegisterProtocol(p core.ProtocolID, min int, total int)

RegisterProtocol starts tracking and managing peers that support the given protocol. If the protocol is already registered, its values are updated.

func (*PeerManager) RegisterTopic

func (m *PeerManager) RegisterTopic(topic string, min int, total int)

RegisterTopic starts tracking and managing peers that support the given topic. If the topic is already registered, its values are updated.

func (*PeerManager) Start

func (m *PeerManager) Start()

Start starts the background services required for the peer manager to work.

func (*PeerManager) Stop

func (m *PeerManager) Stop()

Stop stops all background services. The method blocks until all services finish their work.

func (*PeerManager) Topics

func (m *PeerManager) Topics() []string

Topics returns the ids of the registered topics.

func (*PeerManager) UnregisterProtocol

func (m *PeerManager) UnregisterProtocol(p core.ProtocolID)

UnregisterProtocol stops managing peers that support the given protocol. If the protocol is not registered, this is a noop operation.

func (*PeerManager) UnregisterTopic

func (m *PeerManager) UnregisterTopic(topic string)

UnregisterTopic stops managing peers that support the given topic. If the topic is not registered, this is a noop operation.

type PeerManagerOption

type PeerManagerOption func(opts *PeerManagerOptions)

PeerManagerOption is a peer manager option setter.

func WithBootstrapDiscovery

func WithBootstrapDiscovery(seeds []discovery.Discovery) PeerManagerOption

WithBootstrapDiscovery configures bootstrap discovery.

type PeerManagerOptions

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

PeerManagerOptions are peer manager options.

Jump to

Keyboard shortcuts

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