Gossipsub: Put Peer Exchange behind a flag (#715)
Add a flag to enable Peer Exchange in Gossipsub (disabled by default)
This commit is contained in:
parent
9ba5c069c8
commit
32ca1898d9
|
@ -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] =
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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]]
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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..<num:
|
||||
let switch = newStandardSwitch(secureManagers = secureManagers, sendSignedPeerRecord = sendSignedPeerRecord)
|
||||
|
@ -55,7 +56,7 @@ proc generateNodes*(
|
|||
msgIdProvider = msgIdProvider,
|
||||
anonymize = anonymize,
|
||||
maxMessageSize = maxMessageSize,
|
||||
parameters = (var p = GossipSubParams.init(); p.floodPublish = false; p.historyLength = 20; p.historyGossip = 20; p.unsubscribeBackoff = unsubscribeBackoff; p))
|
||||
parameters = (var p = GossipSubParams.init(); p.floodPublish = false; p.historyLength = 20; p.historyGossip = 20; p.unsubscribeBackoff = unsubscribeBackoff; p.enablePX = enablePX; p))
|
||||
# set some testing params, to enable scores
|
||||
g.topicParams.mgetOrPut("foobar", TopicParams.init()).topicWeight = 1.0
|
||||
g.topicParams.mgetOrPut("foo", TopicParams.init()).topicWeight = 1.0
|
||||
|
|
Loading…
Reference in New Issue