Documentation
¶
Overview ¶
Package libp2p encapsulates the libp2p library
Index ¶
- Constants
- Variables
- func AsServer(enable bool) dht.Option
- func ConnectednessToString(connectedness network.Connectedness) (string, bool)
- func CountStream(host host.Host, targetID peer.ID, protocol core.ProtocolID, ...) int
- func DefaultLibP2PHost(ctx context.Context, address string, key fcrypto.PrivateKey, ...) (host.Host, error)
- func DefaultLibP2POptions(address string, key fcrypto.PrivateKey) ([]config.Option, error)
- func DefaultPubSub(ctx context.Context, host host.Host, psOption ...pubsub.Option) (*pubsub.PubSub, error)
- func DefaultValidators(log zerolog.Logger, flowID flow.Identifier) []network.MessageValidator
- func DirectionToString(direction network.Direction) (string, bool)
- func FindOutboundStream(host host.Host, targetID peer.ID, protocol core.ProtocolID) (network.Stream, bool)
- func FlowPublicKeyFromLibP2P(lpk lcrypto.PubKey) (fcrypto.PublicKey, error)
- func IPPortFromMultiAddress(addrs ...multiaddr.Multiaddr) (string, string, error)
- func IsUnconvertibleIdentitiesError(err error) bool
- func LibP2PPrivKeyFromFlow(fpk fcrypto.PrivateKey) (lcrypto.PrivKey, error)
- func LibP2PPublicKeyFromFlow(fpk fcrypto.PublicKey) (lcrypto.PubKey, error)
- func MultiAddressStr(ip, port string) string
- func NewDHT(ctx context.Context, host host.Host, options ...dht.Option) (*discovery.RoutingDiscovery, error)
- func NewUnconvertableIdentitiesError(errs map[flow.Identifier]error) error
- func PeerAddressInfo(identity flow.Identity) (peer.AddrInfo, error)
- func WithBootstrapPeers(bootstrapNodes flow.IdentityList) (dht.Option, error)
- type ChannelSubscriptionManager
- func (sm *ChannelSubscriptionManager) Channels() network.ChannelList
- func (sm *ChannelSubscriptionManager) GetEngine(channel network.Channel) (network.Engine, error)
- func (sm *ChannelSubscriptionManager) Register(channel network.Channel, engine network.Engine) error
- func (sm *ChannelSubscriptionManager) Unregister(channel network.Channel) error
- type CloseFunc
- type Conduit
- type ConnGater
- func (c *ConnGater) InterceptAccept(cm network.ConnMultiaddrs) bool
- func (c *ConnGater) InterceptAddrDial(_ peer.ID, ma multiaddr.Multiaddr) bool
- func (c *ConnGater) InterceptPeerDial(p peer.ID) bool
- func (c *ConnGater) InterceptSecured(dir network.Direction, p peer.ID, addr network.ConnMultiaddrs) bool
- func (c *ConnGater) InterceptUpgraded(network.Conn) (allow bool, reason control.DisconnectReason)
- type ConnManager
- func (c *ConnManager) Connected(n network.Network, con network.Conn)
- func (c *ConnManager) Disconnected(n network.Network, con network.Conn)
- func (c *ConnManager) IsProtected(id peer.ID, _ string) (protected bool)
- func (c *ConnManager) ListenCloseNotifee(n network.Network, m multiaddr.Multiaddr)
- func (c *ConnManager) ListenNotifee(n network.Network, m multiaddr.Multiaddr)
- func (c *ConnManager) Notifee() network.Notifiee
- func (c *ConnManager) ProtectPeer(id peer.ID)
- func (c *ConnManager) UnprotectPeer(id peer.ID)
- type Connector
- type DefaultLibP2PNodeBuilder
- func (builder *DefaultLibP2PNodeBuilder) Build(ctx context.Context) (*Node, error)
- func (builder *DefaultLibP2PNodeBuilder) SetConnectionGater(connGater *ConnGater) NodeBuilder
- func (builder *DefaultLibP2PNodeBuilder) SetConnectionManager(connMngr TagLessConnManager) NodeBuilder
- func (builder *DefaultLibP2PNodeBuilder) SetLogger(logger zerolog.Logger) NodeBuilder
- func (builder *DefaultLibP2PNodeBuilder) SetPingInfoProvider(pingInfoProvider PingInfoProvider) NodeBuilder
- func (builder *DefaultLibP2PNodeBuilder) SetPubsubOptions(opts ...PubsubOption) NodeBuilder
- func (builder *DefaultLibP2PNodeBuilder) SetResolver(resolver *madns.Resolver) NodeBuilder
- func (builder *DefaultLibP2PNodeBuilder) SetRootBlockID(rootBlockId string) NodeBuilder
- type LibP2PFactoryFunc
- type Middleware
- func (m *Middleware) GetIPPort() (string, string, error)
- func (m *Middleware) IsConnected(identity flow.Identity) (bool, error)
- func (m *Middleware) Me() flow.Identifier
- func (m *Middleware) Ping(targetID flow.Identifier) (message.PingResponse, time.Duration, error)
- func (m *Middleware) Publish(msg *message.Message, channel network.Channel) error
- func (m *Middleware) SendDirect(msg *message.Message, targetID flow.Identifier) error
- func (m *Middleware) Start(ov network.Overlay) error
- func (m *Middleware) Stop()
- func (m *Middleware) Subscribe(channel network.Channel) error
- func (m *Middleware) Unsubscribe(channel network.Channel) error
- func (m *Middleware) UpdateAllowList() error
- type MulticastFunc
- type Network
- func (n *Network) Done() <-chan struct{}
- func (n *Network) Identity() (map[flow.Identifier]flow.Identity, error)
- func (n *Network) Ready() <-chan struct{}
- func (n *Network) Receive(nodeID flow.Identifier, msg *message.Message) error
- func (n *Network) Register(channel network.Channel, engine network.Engine) (network.Conduit, error)
- func (n *Network) SetIDs(ids flow.IdentityList) error
- func (n *Network) Topology() (flow.IdentityList, error)
- type Node
- func (n *Node) AddPeer(ctx context.Context, identity flow.Identity) error
- func (n *Node) CreateStream(ctx context.Context, identity flow.Identity) (libp2pnet.Stream, error)
- func (n *Node) GetIPPort() (string, string, error)
- func (n *Node) Host() host.Host
- func (n *Node) IsConnected(identity flow.Identity) (bool, error)
- func (n *Node) Ping(ctx context.Context, identity flow.Identity) (message.PingResponse, time.Duration, error)
- func (n *Node) Publish(ctx context.Context, topic flownet.Topic, data []byte) error
- func (n *Node) RemovePeer(ctx context.Context, identity flow.Identity) error
- func (n *Node) SetFlowProtocolStreamHandler(handler libp2pnet.StreamHandler)
- func (n *Node) SetPingStreamHandler(handler libp2pnet.StreamHandler)
- func (n *Node) Stop() (chan struct{}, error)
- func (n *Node) Subscribe(ctx context.Context, topic flownet.Topic) (*pubsub.Subscription, error)
- func (n *Node) UnSubscribe(topic flownet.Topic) error
- func (n *Node) UpdateAllowList(identities flow.IdentityList) error
- type NodeBuilder
- type NodeIDRefresher
- type Option
- type PeerManager
- type PingInfoProvider
- type PingInfoProviderImpl
- type PingService
- type PublishFunc
- type PubsubOption
- type RcvCache
- type RcvCacheEntry
- type ReadyDoneAwareNetwork
- type TagLessConnManager
- type UnconvertibleIdentitiesError
- type UnicastFunc
Constants ¶
const ( NoOp communicationMode = iota OneToOne OneToK )
const ( // defines maximum message size in publish and multicast modes DefaultMaxPubSubMsgSize = 5 * mb // 5 mb // defines maximum message size in unicast mode for most messages DefaultMaxUnicastMsgSize = 10 * mb // 10 mb // defines maximum message size in unicast mode for large messages LargeMsgMaxUnicastMsgSize = gb // 1 gb // default maximum time to wait for a default unicast request to complete // assuming at least a 1mb/sec connection DefaultUnicastTimeout = 5 * time.Second // maximum time to wait for a unicast request to complete for large message size LargeMsgUnicastTimeout = 1000 * time.Second )
const ( // The common prefix for all Libp2p protocol IDs used for Flow // ALL Flow libp2p protocols must start with this prefix FlowLibP2PProtocolCommonPrefix = "/flow" // A unique Libp2p protocol ID prefix for Flow (https://docs.libp2p.io/concepts/protocols/) // All nodes communicate with each other using this protocol id suffixed with the id of the root block FlowLibP2POneToOneProtocolIDPrefix = FlowLibP2PProtocolCommonPrefix + "/push/" // the Flow Ping protocol prefix FlowLibP2PPingProtocolPrefix = FlowLibP2PProtocolCommonPrefix + "/ping/" )
Flow Libp2p protocols
const DefaultCacheSize = 10e6
const ( // Maximum time to wait for a ping reply from a remote node PingTimeout = time.Second * 4 )
Variables ¶
var DefaultPeerUpdateInterval = 10 * time.Minute
DefaultPeerUpdateInterval is default duration for which the peer manager waits in between attempts to update peer connections
var NetworkingSetFilter = filter.Not(filter.Ejected)
NetworkingSetFilter is an identity filter that, when applied to the identity table at a given snapshot, returns all nodes that we should communicate with over the networking layer.
NOTE: The protocol state includes nodes from the previous/next epoch that should be included in network communication. We omit any nodes that have been ejected.
Functions ¶
func AsServer ¶ added in v0.21.0
DHT defaults to ModeAuto which will automatically switch the DHT between Server and Client modes based on whether the node appears to be publicly reachable (e.g. not behind a NAT and with a public IP address). This default tends to make test setups fail (since the test nodes are normally not reachable by the public network), but is useful for improving the stability and performance of live public networks. While we could force all nodes to be DHT Servers, a bunch of nodes otherwise not reachable by most of the network => network partition
func ConnectednessToString ¶
func ConnectednessToString(connectedness network.Connectedness) (string, bool)
ConnectednessToString reverse translates libp2p network connectedness to string
func CountStream ¶
func CountStream(host host.Host, targetID peer.ID, protocol core.ProtocolID, dir network.Direction) int
CountStream finds total number of outbound stream to the target id
func DefaultLibP2PHost ¶ added in v0.21.0
func DefaultLibP2PHost(ctx context.Context, address string, key fcrypto.PrivateKey, options ...config.Option) (host.Host, error)
DefaultLibP2PHost returns a libp2p host initialized to listen on the given address and using the given private key and customized with options
func DefaultLibP2POptions ¶ added in v0.21.0
DefaultLibP2POptions creates and returns the standard LibP2P host options that are used for the Flow Libp2p network
func DefaultPubSub ¶ added in v0.21.0
func DefaultPubSub(ctx context.Context, host host.Host, psOption ...pubsub.Option) (*pubsub.PubSub, error)
DefaultPubSub returns initializes and returns a GossipSub object for the given libp2p host and options
func DefaultValidators ¶ added in v0.20.0
func DefaultValidators(log zerolog.Logger, flowID flow.Identifier) []network.MessageValidator
func DirectionToString ¶
DirectionToString reverse translates libp2p network direction to string
func FindOutboundStream ¶
func FindOutboundStream(host host.Host, targetID peer.ID, protocol core.ProtocolID) (network.Stream, bool)
FindOutboundStream finds an existing outbound stream to the target id if it exists by querying libp2p
func FlowPublicKeyFromLibP2P ¶ added in v0.21.0
This converts some libp2p PubKeys to a flow PublicKey - the supported key types are ECDSA P-256 and ECDSA Secp256k1 public keys, - libp2p also supports RSA and Ed25519 keys, which Flow doesn't, their conversion will return an error.
func IPPortFromMultiAddress ¶
IPPortFromMultiAddress returns the IP/hostname and the port for the given multi-addresses associated with a libp2p host
func IsUnconvertibleIdentitiesError ¶ added in v0.14.0
IsUnconvertibleIdentitiesError returns whether the given error is an UnconvertibleIdentitiesError error
func LibP2PPrivKeyFromFlow ¶ added in v0.21.0
func LibP2PPrivKeyFromFlow(fpk fcrypto.PrivateKey) (lcrypto.PrivKey, error)
PrivKey converts a Flow private key to a LibP2P Private key
func LibP2PPublicKeyFromFlow ¶ added in v0.21.0
PublicKey converts a Flow public key to a LibP2P public key
func MultiAddressStr ¶ added in v0.13.0
MultiAddressStr receives a node ip and port and returns its corresponding Libp2p MultiAddressStr in string format in current implementation IP part of the node address is either an IP or a dns4. https://docs.libp2p.io/concepts/addressing/
func NewDHT ¶ added in v0.21.0
func NewDHT(ctx context.Context, host host.Host, options ...dht.Option) (*discovery.RoutingDiscovery, error)
This produces a new IPFS DHT on the name, see https://github.com/libp2p/go-libp2p-kad-dht/issues/337
func NewUnconvertableIdentitiesError ¶ added in v0.14.0
func NewUnconvertableIdentitiesError(errs map[flow.Identifier]error) error
func PeerAddressInfo ¶ added in v0.13.0
PeerAddressInfo generates the libp2p peer.AddrInfo for the given Flow.Identity. A node in flow is defined by a flow.Identity while it is defined by a peer.AddrInfo in libp2p. flow.Identity ---> peer.AddrInfo
|-- Address ---> |-- []multiaddr.Multiaddr |-- NetworkPublicKey ---> |-- ID
func WithBootstrapPeers ¶ added in v0.21.0
func WithBootstrapPeers(bootstrapNodes flow.IdentityList) (dht.Option, error)
Types ¶
type ChannelSubscriptionManager ¶
type ChannelSubscriptionManager struct {
// contains filtered or unexported fields
}
ChannelSubscriptionManager manages subscriptions of engines running on the node to channels. Each channel should be taken by at most a single engine.
func NewChannelSubscriptionManager ¶
func NewChannelSubscriptionManager(mw network.Middleware) *ChannelSubscriptionManager
func (*ChannelSubscriptionManager) Channels ¶ added in v0.14.0
func (sm *ChannelSubscriptionManager) Channels() network.ChannelList
Channels returns all the channels registered in this subscription manager.
func (*ChannelSubscriptionManager) Register ¶
func (sm *ChannelSubscriptionManager) Register(channel network.Channel, engine network.Engine) error
Register registers an engine on the channel into the subscription manager.
func (*ChannelSubscriptionManager) Unregister ¶
func (sm *ChannelSubscriptionManager) Unregister(channel network.Channel) error
Unregister removes the engine associated with a channel.
type Conduit ¶
type Conduit struct {
// contains filtered or unexported fields
}
Conduit is a helper of the overlay layer which functions as an accessor for sending messages within a single engine process. It sends all messages to what can be considered a bus reserved for that specific engine.
func (*Conduit) Multicast ¶
func (c *Conduit) Multicast(event interface{}, num uint, targetIDs ...flow.Identifier) error
Multicast unreliably sends the specified event to the specified number of recipients selected from the specified subset. The recipients are selected randomly from targetIDs
func (*Conduit) Publish ¶
func (c *Conduit) Publish(event interface{}, targetIDs ...flow.Identifier) error
Publish sends an event to the network layer for unreliable delivery to subscribers of the given event on the network layer. It uses a publish-subscribe layer and can thus not guarantee that the specified recipients received the event.
type ConnGater ¶ added in v0.21.0
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 ¶ added in v0.21.0
func (*ConnGater) InterceptAccept ¶ added in v0.21.0
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 ¶ added in v0.21.0
InterceptAddrDial is not used. Currently, allowlisting is only implemented by Peer IDs and not multi-addresses
func (*ConnGater) InterceptPeerDial ¶ added in v0.21.0
InterceptPeerDial - a callback which allows or disallows outbound connection
func (*ConnGater) InterceptSecured ¶ added in v0.21.0
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 ¶ added in v0.21.0
Decision to continue or drop the connection should have been made before this call
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 (c *ConnManager) Connected(n network.Network, con network.Conn)
called by libp2p when a connection opened
func (*ConnManager) Disconnected ¶
func (c *ConnManager) Disconnected(n network.Network, con network.Conn)
called by libp2p when a connection closed
func (*ConnManager) IsProtected ¶ added in v0.18.3
func (c *ConnManager) IsProtected(id peer.ID, _ string) (protected bool)
IsProtected returns true is there is at least one stream setup in progress for the given peer.ID else false
func (*ConnManager) ListenCloseNotifee ¶
func (c *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 (c *ConnManager) ListenNotifee(n network.Network, m multiaddr.Multiaddr)
called by libp2p when network starts listening on an addr
func (*ConnManager) Notifee ¶
func (c *ConnManager) Notifee() network.Notifiee
func (*ConnManager) ProtectPeer ¶ added in v0.18.3
func (c *ConnManager) ProtectPeer(id peer.ID)
ProtectPeer increments the stream setup count for the peer.ID
func (*ConnManager) UnprotectPeer ¶ added in v0.18.3
func (c *ConnManager) UnprotectPeer(id peer.ID)
UnprotectPeer decrements the stream setup count for the peer.ID. If the count reaches zero, the id is removed from the map
type Connector ¶
type Connector interface { // UpdatePeers connects to the given flow.Identities and returns a map of identifiers which failed. It also // disconnects from any other peers with which it may have previously established connection. // UpdatePeers implementation should be idempotent such that multiple calls to connect to the same peer should not // return an error or create multiple connections UpdatePeers(ctx context.Context, ids flow.IdentityList) error }
Connector connects to peer and disconnects from peer using the underlying networking library
type DefaultLibP2PNodeBuilder ¶ added in v0.21.0
type DefaultLibP2PNodeBuilder struct {
// contains filtered or unexported fields
}
func (*DefaultLibP2PNodeBuilder) Build ¶ added in v0.21.0
func (builder *DefaultLibP2PNodeBuilder) Build(ctx context.Context) (*Node, error)
func (*DefaultLibP2PNodeBuilder) SetConnectionGater ¶ added in v0.21.0
func (builder *DefaultLibP2PNodeBuilder) SetConnectionGater(connGater *ConnGater) NodeBuilder
func (*DefaultLibP2PNodeBuilder) SetConnectionManager ¶ added in v0.21.0
func (builder *DefaultLibP2PNodeBuilder) SetConnectionManager(connMngr TagLessConnManager) NodeBuilder
func (*DefaultLibP2PNodeBuilder) SetLogger ¶ added in v0.21.0
func (builder *DefaultLibP2PNodeBuilder) SetLogger(logger zerolog.Logger) NodeBuilder
func (*DefaultLibP2PNodeBuilder) SetPingInfoProvider ¶ added in v0.21.0
func (builder *DefaultLibP2PNodeBuilder) SetPingInfoProvider(pingInfoProvider PingInfoProvider) NodeBuilder
func (*DefaultLibP2PNodeBuilder) SetPubsubOptions ¶ added in v0.21.0
func (builder *DefaultLibP2PNodeBuilder) SetPubsubOptions(opts ...PubsubOption) NodeBuilder
func (*DefaultLibP2PNodeBuilder) SetResolver ¶ added in v0.21.0
func (builder *DefaultLibP2PNodeBuilder) SetResolver(resolver *madns.Resolver) NodeBuilder
func (*DefaultLibP2PNodeBuilder) SetRootBlockID ¶ added in v0.21.0
func (builder *DefaultLibP2PNodeBuilder) SetRootBlockID(rootBlockId string) NodeBuilder
type LibP2PFactoryFunc ¶ added in v0.13.0
LibP2PFactoryFunc is a factory function type for generating libp2p Node instances.
func DefaultLibP2PNodeFactory ¶ added in v0.13.0
func DefaultLibP2PNodeFactory(ctx context.Context, log zerolog.Logger, me flow.Identifier, address string, flowKey fcrypto.PrivateKey, rootBlockID string, maxPubSubMsgSize int, metrics module.NetworkMetrics, pingInfoProvider PingInfoProvider) (LibP2PFactoryFunc, error)
DefaultLibP2PNodeFactory returns a LibP2PFactoryFunc which generates the libp2p host initialized with the default options for the host, the pubsub and the ping service.
type Middleware ¶
Middleware handles the input & output on the direct connections we have to our neighbours on the peer-to-peer network.
func NewMiddleware ¶
func NewMiddleware(log zerolog.Logger, libP2PNodeFactory LibP2PFactoryFunc, flowID flow.Identifier, metrics module.NetworkMetrics, rootBlockID string, peerUpdateInterval time.Duration, unicastMessageTimeout time.Duration, connectionGating bool, managePeerConnections bool, validators ...network.MessageValidator) *Middleware
NewMiddleware creates a new middleware instance libP2PNodeFactory is the factory used to create a LibP2PNode flowID is this node's Flow ID metrics is the interface to report network related metrics peerUpdateInterval is the interval when the PeerManager's peer update runs unicastMessageTimeout is the timeout used for unicast messages connectionGating if set to True, restricts this node to only talk to other nodes which are part of the identity list managePeerConnections if set to True, enables the default PeerManager which continuously updates the node's peer connections validators are the set of the different message validators that each inbound messages is passed through
func (*Middleware) GetIPPort ¶
func (m *Middleware) GetIPPort() (string, string, error)
GetIPPort returns the ip address and port number associated with the middleware
func (*Middleware) IsConnected ¶
func (m *Middleware) IsConnected(identity flow.Identity) (bool, error)
IsConnected returns true if this node is connected to the node with id nodeID.
func (*Middleware) Me ¶
func (m *Middleware) Me() flow.Identifier
Me returns the flow identifier of the this middleware
func (*Middleware) Ping ¶
func (m *Middleware) Ping(targetID flow.Identifier) (message.PingResponse, time.Duration, error)
Ping pings the target node and returns the ping RTT or an error
func (*Middleware) Publish ¶
Publish publishes a message on the channel. It models a distributed broadcast where the message is meant for all or a many nodes subscribing to the channel. It does not guarantee the delivery though, and operates on a best effort.
func (*Middleware) SendDirect ¶
func (m *Middleware) SendDirect(msg *message.Message, targetID flow.Identifier) error
SendDirect sends msg on a 1-1 direct connection to the target ID. It models a guaranteed delivery asynchronous direct one-to-one connection on the underlying network. No intermediate node on the overlay is utilized as the router.
Dispatch should be used whenever guaranteed delivery to a specific target is required. Otherwise, Publish is a more efficient candidate.
func (*Middleware) Start ¶
func (m *Middleware) Start(ov network.Overlay) error
Start will start the middleware.
func (*Middleware) Stop ¶
func (m *Middleware) Stop()
Stop will end the execution of the middleware and wait for it to end.
func (*Middleware) Subscribe ¶
func (m *Middleware) Subscribe(channel network.Channel) error
Subscribe subscribes the middleware to a channel.
func (*Middleware) Unsubscribe ¶
func (m *Middleware) Unsubscribe(channel network.Channel) error
Unsubscribe unsubscribes the middleware from a channel.
func (*Middleware) UpdateAllowList ¶
func (m *Middleware) UpdateAllowList() error
UpdateAllowList fetches the most recent identity of the nodes from overlay and updates the underlying libp2p node.
type MulticastFunc ¶
type MulticastFunc func(channel network.Channel, event interface{}, num uint, targetIDs ...flow.Identifier) error
MulticastFunc is a function that unreliably sends the event in the underlying network to randomly chosen subset of nodes from targetIDs
type Network ¶
type Network struct { sync.RWMutex ReadyDoneAwareNetwork // contains filtered or unexported fields }
Network represents the overlay network of our peer-to-peer network, including the protocols for handshakes, authentication, gossiping and heartbeats.
func NewNetwork ¶
func NewNetwork( log zerolog.Logger, codec network.Codec, ids flow.IdentityList, me module.Local, mw network.Middleware, csize int, top network.Topology, sm network.SubscriptionManager, metrics module.NetworkMetrics, ) (*Network, error)
NewNetwork creates a new naive overlay network, using the given middleware to communicate to direct peers, using the given codec for serialization, and using the given state & cache interfaces to track volatile information. csize determines the size of the cache dedicated to keep track of received messages
func (*Network) Done ¶
func (n *Network) Done() <-chan struct{}
Done returns a channel that will close when shutdown is complete.
func (*Network) Identity ¶
Identity returns a map of all flow.Identifier to flow identity by querying the flow state
func (*Network) Ready ¶
func (n *Network) Ready() <-chan struct{}
Ready returns a channel that will close when the network stack is ready.
func (*Network) Register ¶
Register will register the given engine with the given unique engine engineID, returning a conduit to directly submit messages to the message bus of the engine.
func (*Network) SetIDs ¶
func (n *Network) SetIDs(ids flow.IdentityList) error
SetIDs updates the identity list cached by the network layer
func (*Network) Topology ¶
func (n *Network) Topology() (flow.IdentityList, error)
Topology returns the identities of a uniform subset of nodes in protocol state using the topology provided earlier. Independent invocations of Topology on different nodes collectively constructs a connected network graph.
type Node ¶
Node is a wrapper around the LibP2P host.
func (*Node) AddPeer ¶
AddPeer adds a peer to this node by adding it to this node's peerstore and connecting to it
func (*Node) CreateStream ¶
CreateStream returns an existing stream connected to identity, if it exists or adds one to identity as a peer and creates a new stream with it.
func (*Node) IsConnected ¶
IsConnected returns true is address is a direct peer of this node else false
func (*Node) Ping ¶
func (n *Node) Ping(ctx context.Context, identity flow.Identity) (message.PingResponse, time.Duration, error)
Ping pings a remote node and returns the time it took to ping the remote node if successful or the error
func (*Node) RemovePeer ¶
RemovePeer closes the connection with the identity.
func (*Node) SetFlowProtocolStreamHandler ¶ added in v0.17.0
func (n *Node) SetFlowProtocolStreamHandler(handler libp2pnet.StreamHandler)
SetFlowProtocolStreamHandler sets the stream handler of Flow libp2p Protocol
func (*Node) SetPingStreamHandler ¶ added in v0.17.0
func (n *Node) SetPingStreamHandler(handler libp2pnet.StreamHandler)
SetPingStreamHandler sets the stream handler for the Flow Ping protocol.
func (*Node) Subscribe ¶
Subscribe subscribes the node to the given topic and returns the subscription Currently only one subscriber is allowed per topic. NOTE: A node will receive its own published messages.
func (*Node) UnSubscribe ¶
UnSubscribe cancels the subscriber and closes the topic.
func (*Node) UpdateAllowList ¶ added in v0.13.0
func (n *Node) UpdateAllowList(identities flow.IdentityList) error
UpdateAllowList allows the peer allow list to be updated.
type NodeBuilder ¶ added in v0.21.0
type NodeBuilder interface { SetRootBlockID(string) NodeBuilder SetConnectionManager(TagLessConnManager) NodeBuilder SetConnectionGater(*ConnGater) NodeBuilder SetPubsubOptions(...PubsubOption) NodeBuilder SetPingInfoProvider(PingInfoProvider) NodeBuilder SetLogger(zerolog.Logger) NodeBuilder SetResolver(resolver *madns.Resolver) NodeBuilder Build(context.Context) (*Node, error) }
func NewDefaultLibP2PNodeBuilder ¶ added in v0.21.0
func NewDefaultLibP2PNodeBuilder(id flow.Identifier, address string, flowKey fcrypto.PrivateKey) NodeBuilder
type NodeIDRefresher ¶
type NodeIDRefresher struct {
// contains filtered or unexported fields
}
NodeIDRefresher derives the latest list of flow identities with which the network should be communicating based on identity table changes in the protocol state.
func NewNodeIDRefresher ¶
func NewNodeIDRefresher(logger zerolog.Logger, state protocol.State, callBack func(list flow.IdentityList) error) *NodeIDRefresher
func (*NodeIDRefresher) OnIdentityTableChanged ¶
func (listener *NodeIDRefresher) OnIdentityTableChanged()
OnIdentityTableChanged updates the networking layer's list of nodes to connect to when the identity table changes in the protocol state.
type Option ¶ added in v0.18.0
type Option func(*PeerManager)
Option represents an option for the peer manager.
func WithInterval ¶ added in v0.18.0
type PeerManager ¶
type PeerManager struct {
// contains filtered or unexported fields
}
PeerManager adds and removes connections to peers periodically and on request
func NewPeerManager ¶
func NewPeerManager(logger zerolog.Logger, idsProvider func() (flow.IdentityList, error), connector Connector, options ...Option) *PeerManager
NewPeerManager creates a new peer manager which calls the idsProvider callback to get a list of peers to connect to and it uses the connector to actually connect or disconnect from peers.
func (*PeerManager) Done ¶
func (pm *PeerManager) Done() <-chan struct{}
func (*PeerManager) Ready ¶
func (pm *PeerManager) Ready() <-chan struct{}
Ready kicks off the ambient periodic connection updates.
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.
type PingInfoProvider ¶ added in v0.17.0
PingInfoProvider is the interface used by the PingService to respond to incoming PingRequest with a PingResponse populated with the necessary details
type PingInfoProviderImpl ¶ added in v0.17.0
type PingInfoProviderImpl struct { SoftwareVersionFun func() string SealedBlockHeightFun func() (uint64, error) }
func (PingInfoProviderImpl) SealedBlockHeight ¶ added in v0.17.1
func (p PingInfoProviderImpl) SealedBlockHeight() uint64
func (PingInfoProviderImpl) SoftwareVersion ¶ added in v0.17.0
func (p PingInfoProviderImpl) SoftwareVersion() string
type PingService ¶ added in v0.17.0
type PingService struct {
// contains filtered or unexported fields
}
PingService handles the outbound and inbound ping requests and response
func NewPingService ¶ added in v0.17.0
func NewPingService(h host.Host, pingProtocolID protocol.ID, pingInfoProvider PingInfoProvider, logger zerolog.Logger) *PingService
func (*PingService) Ping ¶ added in v0.17.0
func (ps *PingService) Ping(ctx context.Context, p peer.ID) (message.PingResponse, time.Duration, error)
Ping sends a Ping request to the remote node and returns the response, rtt and error if any.
func (*PingService) PingHandler ¶ added in v0.17.0
func (ps *PingService) PingHandler(s network.Stream)
PingHandler receives the inbound stream for Flow ping protocol and respond back with the PingResponse message
type PublishFunc ¶
type PublishFunc func(channel network.Channel, event interface{}, targetIDs ...flow.Identifier) error
PublishFunc is a function that broadcasts the specified event to all participants on the given channel.
type PubsubOption ¶ added in v0.21.0
PubsubOption generates a libp2p pubsub.Option from the given context and host
func DefaultPubsubOptions ¶ added in v0.21.0
func DefaultPubsubOptions(maxPubSubMsgSize int) []PubsubOption
func WithDHTDiscovery ¶ added in v0.21.0
func WithDHTDiscovery(option ...dht.Option) PubsubOption
type RcvCache ¶
type RcvCache struct {
// contains filtered or unexported fields
}
RcvCache implements an LRU cache of the received eventIDs that delivered to their engines
type RcvCacheEntry ¶
type RcvCacheEntry struct {
// contains filtered or unexported fields
}
RcvCacheEntry represents an entry for the RcvCache
type ReadyDoneAwareNetwork ¶ added in v0.20.0
type ReadyDoneAwareNetwork interface { module.Network module.ReadyDoneAware }
type TagLessConnManager ¶ added in v0.21.0
type TagLessConnManager interface { connmgr.ConnManager // ProtectPeer increments the stream setup count for the peer.ID ProtectPeer(id peer.ID) // UnprotectPeer decrements the stream setup count for the peer.ID. // If the count reaches zero, the id is removed from the map UnprotectPeer(id peer.ID) }
TagLessConnManager is a companion interface to libp2p-core.connmgr.ConnManager which implements a (simplified) tagless variant of the Protect / Unprotect logic
type UnconvertibleIdentitiesError ¶ added in v0.14.0
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 ¶ added in v0.14.0
func (e UnconvertibleIdentitiesError) Error() string
type UnicastFunc ¶
type UnicastFunc func(channel network.Channel, event interface{}, targetID flow.Identifier) error
UnicastFunc is a function that reliably sends the event via reliable 1-1 direct connection in the underlying network to the target ID.