p2pnode

package
v0.30.3 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2023 License: AGPL-3.0 Imports: 28 Imported by: 0

Documentation

Overview

Package p2pnode encapsulates the libp2p library

Index

Constants

View Source
const (
	// MaxConnectAttempt is the maximum number of attempts to be made to connect to a remote node for 1-1 direct communication
	MaxConnectAttempt = 3

	// DefaultMaxPubSubMsgSize defines the maximum message size in publish and multicast modes
	DefaultMaxPubSubMsgSize = 5 * mb // 5 mb

)

Variables

This section is empty.

Functions

func NewGossipSubAdapter added in v0.29.0

func NewGossipSubAdapter(ctx context.Context, logger zerolog.Logger, h host.Host, cfg p2p.PubSubAdapterConfig) (p2p.PubSubAdapter, error)

Types

type GossipSubAdapter added in v0.29.0

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

GossipSubAdapter is a wrapper around the libp2p GossipSub implementation that implements the PubSubAdapter interface for the Flow network.

func (*GossipSubAdapter) GetTopics added in v0.29.0

func (g *GossipSubAdapter) GetTopics() []string

func (*GossipSubAdapter) Join added in v0.29.0

func (g *GossipSubAdapter) Join(topic string) (p2p.Topic, error)

func (*GossipSubAdapter) ListPeers added in v0.29.0

func (g *GossipSubAdapter) ListPeers(topic string) []peer.ID

func (*GossipSubAdapter) RegisterTopicValidator added in v0.29.0

func (g *GossipSubAdapter) RegisterTopicValidator(topic string, topicValidator p2p.TopicValidatorFunc) error

func (*GossipSubAdapter) UnregisterTopicValidator added in v0.29.0

func (g *GossipSubAdapter) UnregisterTopicValidator(topic string) error

type GossipSubAdapterConfig added in v0.29.0

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

GossipSubAdapterConfig is a wrapper around libp2p pubsub options that implements the PubSubAdapterConfig interface for the Flow network.

func NewGossipSubAdapterConfig added in v0.29.0

func NewGossipSubAdapterConfig(base *p2p.BasePubSubAdapterConfig) *GossipSubAdapterConfig

func (*GossipSubAdapterConfig) Build added in v0.29.0

func (g *GossipSubAdapterConfig) Build() []pubsub.Option

func (*GossipSubAdapterConfig) PubSubTracer added in v0.30.0

func (g *GossipSubAdapterConfig) PubSubTracer() p2p.PubSubTracer

func (*GossipSubAdapterConfig) RPCInspectors added in v0.30.0

func (g *GossipSubAdapterConfig) RPCInspectors() []p2p.GossipSubRPCInspector

func (*GossipSubAdapterConfig) ScoreTracer added in v0.30.0

func (g *GossipSubAdapterConfig) ScoreTracer() p2p.PeerScoreTracer

func (*GossipSubAdapterConfig) WithAppSpecificRpcInspectors added in v0.30.0

func (g *GossipSubAdapterConfig) WithAppSpecificRpcInspectors(inspectors ...p2p.GossipSubRPCInspector)

func (*GossipSubAdapterConfig) WithMessageIdFunction added in v0.29.0

func (g *GossipSubAdapterConfig) WithMessageIdFunction(f func([]byte) string)

func (*GossipSubAdapterConfig) WithRoutingDiscovery added in v0.29.0

func (g *GossipSubAdapterConfig) WithRoutingDiscovery(routing routing.ContentRouting)

func (*GossipSubAdapterConfig) WithScoreOption added in v0.29.0

func (g *GossipSubAdapterConfig) WithScoreOption(option p2p.ScoreOptionBuilder)

func (*GossipSubAdapterConfig) WithScoreTracer added in v0.30.0

func (g *GossipSubAdapterConfig) WithScoreTracer(tracer p2p.PeerScoreTracer)

func (*GossipSubAdapterConfig) WithSubscriptionFilter added in v0.29.0

func (g *GossipSubAdapterConfig) WithSubscriptionFilter(filter p2p.SubscriptionFilter)

func (*GossipSubAdapterConfig) WithTracer added in v0.30.0

func (g *GossipSubAdapterConfig) WithTracer(tracer p2p.PubSubTracer)

type GossipSubControlMessageMetrics added in v0.29.0

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

GossipSubControlMessageMetrics is a metrics and observability wrapper component for the incoming RPCs to a GossipSub router. It records metrics on the number of control messages received in each RPC.

func NewGossipSubControlMessageMetrics added in v0.29.0

func NewGossipSubControlMessageMetrics(metrics module.GossipSubRouterMetrics, logger zerolog.Logger) *GossipSubControlMessageMetrics

func (*GossipSubControlMessageMetrics) ObserveRPC added in v0.29.0

func (o *GossipSubControlMessageMetrics) ObserveRPC(from peer.ID, rpc *pubsub.RPC)

ObserveRPC is invoked to record metrics on incoming RPC messages.

type GossipSubTopic added in v0.29.0

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

GossipSubTopic is a wrapper around libp2p pubsub topics that implements the PubSubTopic interface for the Flow network.

func NewGossipSubTopic added in v0.29.0

func NewGossipSubTopic(topic *pubsub.Topic) *GossipSubTopic

func (*GossipSubTopic) Close added in v0.29.0

func (g *GossipSubTopic) Close() error

func (*GossipSubTopic) Publish added in v0.29.0

func (g *GossipSubTopic) Publish(ctx context.Context, bytes []byte) error

func (*GossipSubTopic) String added in v0.29.0

func (g *GossipSubTopic) String() string

func (*GossipSubTopic) Subscribe added in v0.29.0

func (g *GossipSubTopic) Subscribe() (p2p.Subscription, error)

type Node

type Node struct {
	component.Component
	sync.RWMutex
	// contains filtered or unexported fields
}

Node is a wrapper around the LibP2P host.

func NewNode

func NewNode(
	logger zerolog.Logger,
	host host.Host,
	pCache p2p.ProtocolPeerCache,
	peerManager p2p.PeerManager,
) *Node

NewNode creates a new libp2p node and sets its parameters.

func (*Node) AddPeer

func (n *Node) AddPeer(ctx context.Context, peerInfo peer.AddrInfo) error

AddPeer adds a peer to this node by adding it to this node's peerstore and connecting to it. All errors returned from this function can be considered benign.

func (*Node) CreateStream

func (n *Node) CreateStream(ctx context.Context, peerID peer.ID) (libp2pnet.Stream, error)

CreateStream returns an existing stream connected to the peer if it exists, or creates a new stream with it. All errors returned from this function can be considered benign.

func (*Node) GetIPPort

func (n *Node) GetIPPort() (string, string, error)

GetIPPort returns the IP and Port the libp2p node is listening on. All errors returned from this function can be considered benign.

func (*Node) GetPeersForProtocol

func (n *Node) GetPeersForProtocol(pid protocol.ID) peer.IDSlice

GetPeersForProtocol returns slice peer IDs for the specified protocol ID.

func (*Node) HasSubscription added in v0.29.0

func (n *Node) HasSubscription(topic channels.Topic) bool

HasSubscription returns true if the node currently has an active subscription to the topic.

func (*Node) Host

func (n *Node) Host() host.Host

Host returns pointer to host object of node.

func (*Node) IsConnected

func (n *Node) IsConnected(peerID peer.ID) (bool, error)

IsConnected returns true if address is a direct peer of this node else false. Peers are considered not connected if the underlying libp2p host reports the peers as not connected and there are no connections in the connection list. error returns:

  • network.ErrIllegalConnectionState if the underlying libp2p host reports connectedness as NotConnected but the connections list to the peer is not empty. This would normally indicate a bug within libp2p. Although the network.ErrIllegalConnectionState a bug in libp2p there is a small chance that this error will be returned due to a race condition between the time we check Connectedness and ConnsToPeer. There is a chance that a connection could be established after we check Connectedness but right before we check ConnsToPeer.

func (*Node) ListPeers

func (n *Node) ListPeers(topic string) []peer.ID

ListPeers returns list of peer IDs for peers subscribed to the topic.

func (*Node) PeerManagerComponent

func (n *Node) PeerManagerComponent() component.Component

PeerManagerComponent returns the component interface of the peer manager.

func (*Node) PeerScoreExposer added in v0.30.0

func (n *Node) PeerScoreExposer() (p2p.PeerScoreExposer, bool)

PeerScoreExposer returns the node's peer score exposer implementation. If the node's peer score exposer has not been set, the second return value will be false.

func (*Node) Publish

func (n *Node) Publish(ctx context.Context, topic channels.Topic, data []byte) error

Publish publishes the given payload on the topic. All errors returned from this function can be considered benign.

func (*Node) RemovePeer

func (n *Node) RemovePeer(peerID peer.ID) error

RemovePeer closes the connection with the peer. All errors returned from this function can be considered benign.

func (*Node) RequestPeerUpdate

func (n *Node) RequestPeerUpdate()

RequestPeerUpdate requests an update to the peer connections of this node using the peer manager.

func (*Node) Routing

func (n *Node) Routing() routing.Routing

Routing returns the node's routing implementation.

func (*Node) RoutingTable

func (n *Node) RoutingTable() *kbucket.RoutingTable

RoutingTable returns the node routing table

func (*Node) SetComponentManager added in v0.29.0

func (n *Node) SetComponentManager(cm *component.ComponentManager)

SetComponentManager sets the component manager for the node. SetComponentManager may be called at most once.

func (*Node) SetPeerScoreExposer added in v0.30.0

func (n *Node) SetPeerScoreExposer(e p2p.PeerScoreExposer)

SetPeerScoreExposer sets the node's peer score exposer implementation. SetPeerScoreExposer may be called at most once. It is an irrecoverable error to call this method if the node's peer score exposer has already been set.

func (*Node) SetPubSub

func (n *Node) SetPubSub(ps p2p.PubSubAdapter)

SetPubSub sets the node's pubsub implementation. SetPubSub may be called at most once.

func (*Node) SetRouting

func (n *Node) SetRouting(r routing.Routing)

SetRouting sets the node's routing implementation. SetRouting may be called at most once.

func (*Node) SetUnicastManager added in v0.30.0

func (n *Node) SetUnicastManager(uniMgr p2p.UnicastManager)

SetUnicastManager sets the unicast manager for the node. SetUnicastManager may be called at most once.

func (*Node) Start added in v0.29.0

func (n *Node) Start(ctx irrecoverable.SignalerContext)

func (*Node) Stop

func (n *Node) Stop() error

Stop terminates the libp2p node. All errors returned from this function can be considered benign.

func (*Node) Subscribe

func (n *Node) Subscribe(topic channels.Topic, topicValidator p2p.TopicValidatorFunc) (p2p.Subscription, error)

Subscribe subscribes the node to the given topic and returns the subscription All errors returned from this function can be considered benign.

func (*Node) UnSubscribe

func (n *Node) UnSubscribe(topic channels.Topic) error

UnSubscribe cancels the subscriber and closes the topic. All errors returned from this function can be considered benign.

func (*Node) WithDefaultUnicastProtocol

func (n *Node) WithDefaultUnicastProtocol(defaultHandler libp2pnet.StreamHandler, preferred []protocols.ProtocolName) error

WithDefaultUnicastProtocol overrides the default handler of the unicast manager and registers all preferred protocols.

func (*Node) WithPeersProvider

func (n *Node) WithPeersProvider(peersProvider p2p.PeersProvider)

WithPeersProvider sets the PeersProvider for the peer manager. If a peer manager factory is set, this method will set the peer manager's PeersProvider.

type ProtocolPeerCache

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

ProtocolPeerCache store a mapping from protocol ID to peers who support that protocol

func NewProtocolPeerCache

func NewProtocolPeerCache(logger zerolog.Logger, h host.Host) (*ProtocolPeerCache, error)

func (*ProtocolPeerCache) AddProtocols

func (p *ProtocolPeerCache) AddProtocols(peerID peer.ID, protocols []protocol.ID)

func (*ProtocolPeerCache) GetPeers

func (p *ProtocolPeerCache) GetPeers(pid protocol.ID) map[peer.ID]struct{}

func (*ProtocolPeerCache) RemovePeer

func (p *ProtocolPeerCache) RemovePeer(peerID peer.ID)

func (*ProtocolPeerCache) RemoveProtocols

func (p *ProtocolPeerCache) RemoveProtocols(peerID peer.ID, protocols []protocol.ID)

Jump to

Keyboard shortcuts

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