diff --git a/libp2p/protocols/pubsub/gossipsub.nim b/libp2p/protocols/pubsub/gossipsub.nim index 8354247..175e695 100644 --- a/libp2p/protocols/pubsub/gossipsub.nim +++ b/libp2p/protocols/pubsub/gossipsub.nim @@ -71,7 +71,8 @@ proc init*(_: type[GossipSubParams]): GossipSubParams = ipColocationFactorThreshold: 1.0, behaviourPenaltyWeight: -1.0, behaviourPenaltyDecay: 0.999, - disconnectBadPeers: false + disconnectBadPeers: false, + enablePX: false ) proc validateParameters*(parameters: GossipSubParams): Result[void, cstring] = diff --git a/libp2p/protocols/pubsub/gossipsub/behavior.nim b/libp2p/protocols/pubsub/gossipsub/behavior.nim index 39418b3..66bd69d 100644 --- a/libp2p/protocols/pubsub/gossipsub/behavior.nim +++ b/libp2p/protocols/pubsub/gossipsub/behavior.nim @@ -79,6 +79,8 @@ proc handleBackingOff*(t: var BackoffTable, topic: string) {.raises: [Defect].} v[].del(peer) proc peerExchangeList*(g: GossipSub, topic: string): seq[PeerInfoMsg] {.raises: [Defect].} = + if not g.parameters.enablePX: + return @[] var peers = g.gossipsub.getOrDefault(topic, initHashSet[PubSubPeer]()).toSeq() peers.keepIf do (x: PubSubPeer) -> bool: x.score >= 0.0 diff --git a/libp2p/protocols/pubsub/gossipsub/types.nim b/libp2p/protocols/pubsub/gossipsub/types.nim index a91c7b4..5736c01 100644 --- a/libp2p/protocols/pubsub/gossipsub/types.nim +++ b/libp2p/protocols/pubsub/gossipsub/types.nim @@ -138,6 +138,7 @@ type directPeers*: Table[PeerId, seq[MultiAddress]] disconnectBadPeers*: bool + enablePX*: bool BackoffTable* = Table[string, Table[PeerId, Moment]] ValidationSeenTable* = Table[MessageID, HashSet[PubSubPeer]] diff --git a/tests/pubsub/testgossipsub.nim b/tests/pubsub/testgossipsub.nim index f12a829..416368d 100644 --- a/tests/pubsub/testgossipsub.nim +++ b/tests/pubsub/testgossipsub.nim @@ -945,7 +945,8 @@ suite "GossipSub": let nodes = generateNodes( 2, - gossip = true) & + gossip = true, + enablePX = true) & generateNodes(1, gossip = true, sendSignedPeerRecord = true) # start switches @@ -988,7 +989,7 @@ suite "GossipSub": ) nodes[1].unsubscribe("foobar", handler) - await passed + await passed.wait(5.seconds) await allFuturesThrowing( nodes[0].switch.stop(), diff --git a/tests/pubsub/utils.nim b/tests/pubsub/utils.nim index 05f0299..993efdd 100644 --- a/tests/pubsub/utils.nim +++ b/tests/pubsub/utils.nim @@ -42,7 +42,8 @@ proc generateNodes*( sign: bool = libp2p_pubsub_sign, sendSignedPeerRecord = false, unsubscribeBackoff = 1.seconds, - maxMessageSize: int = 1024 * 1024): seq[PubSub] = + maxMessageSize: int = 1024 * 1024, + enablePX: bool = false): seq[PubSub] = for i in 0..