Documentation
¶
Index ¶
- func EnsureNoPubsubExchangeBetweenGroups(t *testing.T, ctx context.Context, groupANodes []p2p.LibP2PNode, ...)
- func EnsureNoPubsubMessageExchange(t *testing.T, ctx context.Context, from []p2p.LibP2PNode, to []p2p.LibP2PNode, ...)
- func EnsureNotConnectedBetweenGroups(t *testing.T, ctx context.Context, groupA []p2p.LibP2PNode, ...)
- func EnsurePubsubMessageExchange(t *testing.T, ctx context.Context, nodes []p2p.LibP2PNode, ...)
- func EnsurePubsubMessageExchangeFromNode(t *testing.T, ctx context.Context, sender p2p.LibP2PNode, ...)
- func EnsureStreamCreationInBothDirections(t *testing.T, ctx context.Context, nodes []p2p.LibP2PNode)
- func LetNodesDiscoverEachOther(t *testing.T, ctx context.Context, nodes []p2p.LibP2PNode, ...)
- func NetworkingKeyFixtures(t *testing.T) crypto.PrivateKey
- func NewConnectionGater(idProvider module.IdentityProvider, allowListFilter p2p.PeerFilter) p2p.ConnectionGater
- func NodeFixture(t *testing.T, sporkID flow.Identifier, dhtPrefix string, ...) (p2p.LibP2PNode, flow.Identity)
- func NodesFixture(t *testing.T, sporkID flow.Identifier, dhtPrefix string, count int, ...) ([]p2p.LibP2PNode, flow.IdentityList)
- func PeerIdFixture(t testing.TB) peer.ID
- func PeerIdSliceFixture(t *testing.T, n int) peer.IDSlice
- func PeerManagerConfigFixture(opts ...func(*p2pconfig.PeerManagerConfig)) *p2pconfig.PeerManagerConfig
- func PubsubMessageFixture(t *testing.T, opts ...func(*pb.Message)) *pb.Message
- func RequireConnectedEventually(t *testing.T, nodes []p2p.LibP2PNode, tick time.Duration, ...)
- func RequireEventuallyNotConnected(t *testing.T, groupA []p2p.LibP2PNode, groupB []p2p.LibP2PNode, ...)
- func StartNode(t *testing.T, ctx irrecoverable.SignalerContext, node p2p.LibP2PNode)
- func StartNodes(t *testing.T, ctx irrecoverable.SignalerContext, nodes []p2p.LibP2PNode)
- func StopNode(t *testing.T, node p2p.LibP2PNode, cancel context.CancelFunc)
- func StopNodes(t *testing.T, nodes []p2p.LibP2PNode, cancel context.CancelFunc)
- func StreamHandlerFixture(t *testing.T) (func(s network.Stream), chan string)
- func TryConnectionAndEnsureConnected(t *testing.T, ctx context.Context, nodes []p2p.LibP2PNode)
- func WithFrom(from peer.ID) func(*pb.Message)
- func WithTopic(topic string) func(*pb.Message)
- func WithZeroJitterAndZeroBackoff(t *testing.T) func(*p2pconfig.PeerManagerConfig)
- func WithoutSignature() func(*pb.Message)
- func WithoutSignerId() func(*pb.Message)
- type MockStream
- func (m *MockStream) Close() error
- func (m *MockStream) CloseRead() error
- func (m *MockStream) CloseWrite() error
- func (m *MockStream) Conn() network.Conn
- func (m *MockStream) ID() string
- func (m *MockStream) Protocol() protocol.ID
- func (m *MockStream) Read(p []byte) (int, error)
- func (m *MockStream) Reset() error
- func (m *MockStream) Scope() network.StreamScope
- func (m *MockStream) SetDeadline(_ time.Time) error
- func (m *MockStream) SetProtocol(_ protocol.ID) error
- func (m *MockStream) SetReadDeadline(_ time.Time) error
- func (m *MockStream) SetWriteDeadline(_ time.Time) error
- func (m *MockStream) Stat() network.Stats
- func (m *MockStream) Write(p []byte) (int, error)
- type NodeFixtureParameterOption
- func EnablePeerScoringWithOverride(override *p2p.PeerScoringConfigOverride) NodeFixtureParameterOption
- func OverrideFlowConfig(cfg *config.FlowConfig) NodeFixtureParameterOption
- func OverrideGossipSubRpcInspectorSuiteFactory(factory p2p.GossipSubRpcInspectorSuiteFactoryFunc) NodeFixtureParameterOption
- func WithConnectionGater(connGater p2p.ConnectionGater) NodeFixtureParameterOption
- func WithConnectionManager(connManager connmgr.ConnManager) NodeFixtureParameterOption
- func WithCreateStreamRetryDelay(delay time.Duration) NodeFixtureParameterOption
- func WithDHTOptions(opts ...dht.Option) NodeFixtureParameterOption
- func WithDefaultResourceManager() NodeFixtureParameterOption
- func WithDefaultStreamHandler(handler network.StreamHandler) NodeFixtureParameterOption
- func WithGossipSubTracer(tracer p2p.PubSubTracer) NodeFixtureParameterOption
- func WithLogger(logger zerolog.Logger) NodeFixtureParameterOption
- func WithMetricsCollector(metrics module.NetworkMetrics) NodeFixtureParameterOption
- func WithNetworkingAddress(address string) NodeFixtureParameterOption
- func WithNetworkingPrivateKey(key crypto.PrivateKey) NodeFixtureParameterOption
- func WithPeerManagerEnabled(cfg *p2pconfig.PeerManagerConfig, peerProvider p2p.PeersProvider) NodeFixtureParameterOption
- func WithPeerScoreParamsOption(cfg *p2p.PeerScoringConfigOverride) NodeFixtureParameterOption
- func WithPeerScoreTracerInterval(interval time.Duration) NodeFixtureParameterOption
- func WithPreferredUnicasts(unicasts []protocols.ProtocolName) NodeFixtureParameterOption
- func WithRole(role flow.Role) NodeFixtureParameterOption
- func WithUnicastHandlerFunc(handler network.StreamHandler) NodeFixtureParameterOption
- func WithUnicastRateLimitDistributor(distributor p2p.UnicastRateLimiterDistributor) NodeFixtureParameterOption
- type NodeFixtureParameters
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnsureNoPubsubExchangeBetweenGroups ¶ added in v0.31.0
func EnsureNoPubsubExchangeBetweenGroups( t *testing.T, ctx context.Context, groupANodes []p2p.LibP2PNode, groupAIdentifiers flow.IdentifierList, groupBNodes []p2p.LibP2PNode, groupBIdentifiers flow.IdentifierList, topic channels.Topic, count int, messageFactory func() interface{}, )
EnsureNoPubsubExchangeBetweenGroups ensures that no pubsub message is exchanged between the given groups of nodes. Args: - t: *testing.T instance - ctx: context.Context instance - groupANodes: first group of nodes- no message should be exchanged from any node of this group to the other group. - groupAIdentifiers: identifiers of the nodes in the first group. - groupBNodes: second group of nodes- no message should be exchanged from any node of this group to the other group. - groupBIdentifiers: identifiers of the nodes in the second group. - topic: pubsub topic- no message should be exchanged on this topic. - count: number of messages to be exchanged- no message should be exchanged. - messageFactory: function to create a unique message to be published by the node.
func EnsureNoPubsubMessageExchange ¶ added in v0.31.0
func EnsureNoPubsubMessageExchange( t *testing.T, ctx context.Context, from []p2p.LibP2PNode, to []p2p.LibP2PNode, toIdentifiers flow.IdentifierList, topic channels.Topic, count int, messageFactory func() interface{}, )
EnsureNoPubsubMessageExchange ensures that the no pubsub message is exchanged "from" the given nodes "to" the given nodes. Args:
- from: the nodes that send messages to the other group but their message must not be received by the other group.
- to: the nodes that are the target of the messages sent by the other group ("from") but must not receive any message from them. - topic: the topic to exchange messages on. - count: the number of messages to exchange from each node. - messageFactory: a function that creates a unique message to be published by the node.
func EnsureNotConnectedBetweenGroups ¶ added in v0.31.0
func EnsureNotConnectedBetweenGroups(t *testing.T, ctx context.Context, groupA []p2p.LibP2PNode, groupB []p2p.LibP2PNode)
EnsureNotConnectedBetweenGroups ensures no connection exists between the given groups of nodes.
func EnsurePubsubMessageExchange ¶ added in v0.30.0
func EnsurePubsubMessageExchange( t *testing.T, ctx context.Context, nodes []p2p.LibP2PNode, topic channels.Topic, count int, messageFactory func() interface{})
EnsurePubsubMessageExchange ensures that the given connected nodes exchange the given message on the given channel through pubsub. Args:
- nodes: the nodes to exchange messages
- ctx: the context- the test will fail if the context expires.
- topic: the topic to exchange messages on
- count: the number of messages to exchange from each node.
- messageFactory: a function that creates a unique message to be published by the node. The function should return a different message each time it is called.
Note-1: this function assumes a timeout of 5 seconds for each message to be received. Note-2: TryConnectionAndEnsureConnected() must be called to connect all nodes before calling this function.
func EnsurePubsubMessageExchangeFromNode ¶ added in v0.32.0
func EnsurePubsubMessageExchangeFromNode( t *testing.T, ctx context.Context, sender p2p.LibP2PNode, receiverNode p2p.LibP2PNode, receiverIdentifier flow.Identifier, topic channels.Topic, count int, messageFactory func() interface{}, )
EnsurePubsubMessageExchangeFromNode ensures that the given node exchanges the given message on the given channel through pubsub with the other nodes. Args:
- node: the node to exchange messages
- ctx: the context- the test will fail if the context expires. - sender: the node that sends the message to the other node. - receiverNode: the node that receives the message from the other node. - receiverIdentifier: the identifier of the receiver node. - topic: the topic to exchange messages on. - count: the number of messages to exchange from `sender` to `receiver`. - messageFactory: a function that creates a unique message to be published by the node.
func EnsureStreamCreationInBothDirections ¶ added in v0.30.0
func EnsureStreamCreationInBothDirections(t *testing.T, ctx context.Context, nodes []p2p.LibP2PNode)
EnsureStreamCreationInBothDirections ensure that between each pair of nodes in the given list, a stream is created in both directions.
func LetNodesDiscoverEachOther ¶
func LetNodesDiscoverEachOther(t *testing.T, ctx context.Context, nodes []p2p.LibP2PNode, ids flow.IdentityList)
LetNodesDiscoverEachOther connects all nodes to each other on the pubsub mesh.
func NetworkingKeyFixtures ¶
func NetworkingKeyFixtures(t *testing.T) crypto.PrivateKey
NetworkingKeyFixtures is a test helper that generates a ECDSA flow key pair.
func NewConnectionGater ¶ added in v0.32.0
func NewConnectionGater(idProvider module.IdentityProvider, allowListFilter p2p.PeerFilter) p2p.ConnectionGater
NewConnectionGater creates a new connection gater for testing with given allow listing filter.
func NodeFixture ¶
func NodeFixture( t *testing.T, sporkID flow.Identifier, dhtPrefix string, idProvider module.IdentityProvider, opts ...NodeFixtureParameterOption, ) (p2p.LibP2PNode, flow.Identity)
NodeFixture is a test fixture that creates a single libp2p node with the given key, spork id, and options. It returns the node and its identity.
func NodesFixture ¶
func NodesFixture( t *testing.T, sporkID flow.Identifier, dhtPrefix string, count int, idProvider module.IdentityProvider, opts ...NodeFixtureParameterOption) ( []p2p.LibP2PNode, flow.IdentityList)
NodesFixture is a test fixture that creates a number of libp2p nodes with the given callback function for stream handling. It returns the nodes and their identities.
func PeerIdFixture ¶ added in v0.30.0
PeerIdFixture returns a random peer ID for testing. peer ID is the identifier of a node on the libp2p network.
func PeerIdSliceFixture ¶ added in v0.31.0
PeerIdSliceFixture returns a slice of random peer IDs for testing. peer ID is the identifier of a node on the libp2p network. Args: - t: *testing.T instance - n: number of peer IDs to generate Returns: - peer.IDSlice: slice of peer IDs
func PeerManagerConfigFixture ¶ added in v0.32.0
func PeerManagerConfigFixture(opts ...func(*p2pconfig.PeerManagerConfig)) *p2pconfig.PeerManagerConfig
PeerManagerConfigFixture is a test fixture that sets the default config for the peer manager.
func PubsubMessageFixture ¶ added in v0.32.0
PubsubMessageFixture is a test helper that returns a random pubsub message with the given options applied. If no options are provided, the message will be random. Args:
t: testing.T
opt: variadic list of options to apply to the message Returns: *pb.Message: pubsub message
func RequireConnectedEventually ¶ added in v0.32.0
func RequireConnectedEventually(t *testing.T, nodes []p2p.LibP2PNode, tick time.Duration, timeout time.Duration)
RequireConnectedEventually ensures eventually that the given nodes are already connected to each other. It fails the test if any of the nodes is not connected to any other node. Args: - nodes: the nodes to check - tick: the tick duration - timeout: the timeout duration
func RequireEventuallyNotConnected ¶ added in v0.32.0
func RequireEventuallyNotConnected( t *testing.T, groupA []p2p.LibP2PNode, groupB []p2p.LibP2PNode, tick time.Duration, timeout time.Duration)
RequireEventuallyNotConnected ensures eventually that the given groups of nodes are not connected to each other. It fails the test if any of the nodes from groupA is connected to any of the nodes from groupB. Args: - groupA: the first group of nodes - groupB: the second group of nodes - tick: the tick duration - timeout: the timeout duration
func StartNode ¶
func StartNode(t *testing.T, ctx irrecoverable.SignalerContext, node p2p.LibP2PNode)
StartNode start a single node using the provided context, timing out if nodes are not all Ready() before duration expires, (i.e., 2 seconds). Args: - t: testing.T- the test object. - ctx: context to use. - node: node to start.
func StartNodes ¶
func StartNodes(t *testing.T, ctx irrecoverable.SignalerContext, nodes []p2p.LibP2PNode)
StartNodes start all nodes in the input slice using the provided context, timing out if nodes are not all Ready() before duration expires
func StopNode ¶
func StopNode(t *testing.T, node p2p.LibP2PNode, cancel context.CancelFunc)
StopNode stops a single node using the provided cancel func, timing out if nodes are not all Done() before duration expires, (i.e., 2 seconds). Args: - t: testing.T- the test object. - node: node to stop. - cancel: cancel func, the function first cancels the context and then waits for the nodes to be done.
func StopNodes ¶
func StopNodes(t *testing.T, nodes []p2p.LibP2PNode, cancel context.CancelFunc)
StopNodes stops all nodes in the input slice using the provided cancel func, timing out if nodes are not all Done() before duration expires (i.e., 5 seconds). Args: - t: testing.T- the test object. - nodes: nodes to stop. - cancel: cancel func, the function first cancels the context and then waits for the nodes to be done.
func StreamHandlerFixture ¶
StreamHandlerFixture returns a stream handler that writes the received message to the given channel.
func TryConnectionAndEnsureConnected ¶ added in v0.32.0
TryConnectionAndEnsureConnected tries connecting nodes to each other and ensures that the given nodes are connected to each other. It fails the test if any of the nodes is not connected to any other node.
func WithFrom ¶ added in v0.32.0
WithFrom is a test helper that returns a function that sets the from field of a pubsub message to the given peer id.
func WithTopic ¶ added in v0.32.0
WithTopic is a test helper that returns a function that sets the topic of a pubsub message to the given topic.
func WithZeroJitterAndZeroBackoff ¶ added in v0.32.0
func WithZeroJitterAndZeroBackoff(t *testing.T) func(*p2pconfig.PeerManagerConfig)
WithZeroJitterAndZeroBackoff is a test fixture that sets the default config for the peer manager. It uses a backoff connector with zero jitter and zero backoff.
func WithoutSignature ¶ added in v0.32.0
WithoutSignature is a test helper that returns a function that sets the signature of a pubsub message to nil, effectively removing the signature.
func WithoutSignerId ¶ added in v0.32.0
WithoutSignerId is a test helper that returns a function that sets the from field of a pubsub message to nil, effectively removing the signer id.
Types ¶
type MockStream ¶ added in v0.32.2
type MockStream struct {
// contains filtered or unexported fields
}
MockStream is a mocked libp2p stream that is implemented as a pipe with a reader and writer. Whatever is written on the stream is written by the writer on the pipe, which in turn makes it available for read by the reader.
func NewMockStream ¶ added in v0.32.2
func NewMockStream(pw *io.PipeWriter, pr *io.PipeReader) *MockStream
func (*MockStream) Close ¶ added in v0.32.2
func (m *MockStream) Close() error
func (*MockStream) CloseRead ¶ added in v0.32.2
func (m *MockStream) CloseRead() error
func (*MockStream) CloseWrite ¶ added in v0.32.2
func (m *MockStream) CloseWrite() error
func (*MockStream) Conn ¶ added in v0.32.2
func (m *MockStream) Conn() network.Conn
func (*MockStream) ID ¶ added in v0.32.2
func (m *MockStream) ID() string
func (*MockStream) Protocol ¶ added in v0.32.2
func (m *MockStream) Protocol() protocol.ID
func (*MockStream) Reset ¶ added in v0.32.2
func (m *MockStream) Reset() error
func (*MockStream) Scope ¶ added in v0.32.2
func (m *MockStream) Scope() network.StreamScope
func (*MockStream) SetDeadline ¶ added in v0.32.2
func (m *MockStream) SetDeadline(_ time.Time) error
func (*MockStream) SetProtocol ¶ added in v0.32.2
func (m *MockStream) SetProtocol(_ protocol.ID) error
func (*MockStream) SetReadDeadline ¶ added in v0.32.2
func (m *MockStream) SetReadDeadline(_ time.Time) error
func (*MockStream) SetWriteDeadline ¶ added in v0.32.2
func (m *MockStream) SetWriteDeadline(_ time.Time) error
func (*MockStream) Stat ¶ added in v0.32.2
func (m *MockStream) Stat() network.Stats
type NodeFixtureParameterOption ¶
type NodeFixtureParameterOption func(*NodeFixtureParameters)
func EnablePeerScoringWithOverride ¶ added in v0.32.0
func EnablePeerScoringWithOverride(override *p2p.PeerScoringConfigOverride) NodeFixtureParameterOption
EnablePeerScoringWithOverride enables peer scoring for the GossipSub pubsub system with the given override. Any existing peer scoring config attribute that is set in the override will override the default peer scoring config. Anything that is left to nil or zero value in the override will be ignored and the default value will be used. Note: it is not recommended to override the default peer scoring config in production unless you know what you are doing. Default Use Tip: use p2p.PeerScoringConfigNoOverride as the argument to this function to enable peer scoring without any override. Args:
- PeerScoringConfigOverride: override for the peer scoring config- Recommended to use p2p.PeerScoringConfigNoOverride for production or when you don't want to override the default peer scoring config.
Returns: - NodeFixtureParameterOption: a function that can be passed to the NodeFixture function to enable peer scoring.
func OverrideFlowConfig ¶ added in v0.32.0
func OverrideFlowConfig(cfg *config.FlowConfig) NodeFixtureParameterOption
func OverrideGossipSubRpcInspectorSuiteFactory ¶ added in v0.32.0
func OverrideGossipSubRpcInspectorSuiteFactory(factory p2p.GossipSubRpcInspectorSuiteFactoryFunc) NodeFixtureParameterOption
func WithConnectionGater ¶
func WithConnectionGater(connGater p2p.ConnectionGater) NodeFixtureParameterOption
func WithConnectionManager ¶ added in v0.30.0
func WithConnectionManager(connManager connmgr.ConnManager) NodeFixtureParameterOption
func WithCreateStreamRetryDelay ¶ added in v0.30.0
func WithCreateStreamRetryDelay(delay time.Duration) NodeFixtureParameterOption
func WithDHTOptions ¶
func WithDHTOptions(opts ...dht.Option) NodeFixtureParameterOption
func WithDefaultResourceManager ¶ added in v0.30.0
func WithDefaultResourceManager() NodeFixtureParameterOption
WithDefaultResourceManager sets the resource manager to nil, which will cause the node to use the default resource manager. Otherwise, it uses the resource manager provided by the test (the infinite resource manager).
func WithDefaultStreamHandler ¶
func WithDefaultStreamHandler(handler network.StreamHandler) NodeFixtureParameterOption
func WithGossipSubTracer ¶ added in v0.30.0
func WithGossipSubTracer(tracer p2p.PubSubTracer) NodeFixtureParameterOption
func WithLogger ¶
func WithLogger(logger zerolog.Logger) NodeFixtureParameterOption
func WithMetricsCollector ¶ added in v0.30.0
func WithMetricsCollector(metrics module.NetworkMetrics) NodeFixtureParameterOption
func WithNetworkingAddress ¶
func WithNetworkingAddress(address string) NodeFixtureParameterOption
func WithNetworkingPrivateKey ¶
func WithNetworkingPrivateKey(key crypto.PrivateKey) NodeFixtureParameterOption
func WithPeerManagerEnabled ¶
func WithPeerManagerEnabled(cfg *p2pconfig.PeerManagerConfig, peerProvider p2p.PeersProvider) NodeFixtureParameterOption
func WithPeerScoreParamsOption ¶ added in v0.30.0
func WithPeerScoreParamsOption(cfg *p2p.PeerScoringConfigOverride) NodeFixtureParameterOption
func WithPeerScoreTracerInterval ¶ added in v0.30.0
func WithPeerScoreTracerInterval(interval time.Duration) NodeFixtureParameterOption
func WithPreferredUnicasts ¶
func WithPreferredUnicasts(unicasts []protocols.ProtocolName) NodeFixtureParameterOption
func WithRole ¶
func WithRole(role flow.Role) NodeFixtureParameterOption
func WithUnicastHandlerFunc ¶ added in v0.32.0
func WithUnicastHandlerFunc(handler network.StreamHandler) NodeFixtureParameterOption
func WithUnicastRateLimitDistributor ¶ added in v0.32.0
func WithUnicastRateLimitDistributor(distributor p2p.UnicastRateLimiterDistributor) NodeFixtureParameterOption
type NodeFixtureParameters ¶
type NodeFixtureParameters struct { HandlerFunc network.StreamHandler NetworkingType flownet.NetworkingType Unicasts []protocols.ProtocolName UnicastConfig *p2pconfig.UnicastConfig Key crypto.PrivateKey Address string DhtOptions []dht.Option Role flow.Role Logger zerolog.Logger PeerScoringEnabled bool IdProvider module.IdentityProvider PeerScoringConfigOverride *p2p.PeerScoringConfigOverride PeerManagerConfig *p2pconfig.PeerManagerConfig PeerProvider p2p.PeersProvider // peer manager parameter ConnGater p2p.ConnectionGater ConnManager connmgr.ConnManager GossipSubFactory p2p.GossipSubFactoryFunc GossipSubConfig p2p.GossipSubAdapterConfigFunc MetricsCfg *p2pconfig.MetricsConfig ResourceManager network.ResourceManager PubSubTracer p2p.PubSubTracer GossipSubPeerScoreTracerInterval time.Duration // intervals at which the peer score is updated and logged. GossipSubRpcInspectorSuiteFactory p2p.GossipSubRpcInspectorSuiteFactoryFunc FlowConfig *config.FlowConfig }