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,
|
ipColocationFactorThreshold: 1.0,
|
||||||
behaviourPenaltyWeight: -1.0,
|
behaviourPenaltyWeight: -1.0,
|
||||||
behaviourPenaltyDecay: 0.999,
|
behaviourPenaltyDecay: 0.999,
|
||||||
disconnectBadPeers: false
|
disconnectBadPeers: false,
|
||||||
|
enablePX: false
|
||||||
)
|
)
|
||||||
|
|
||||||
proc validateParameters*(parameters: GossipSubParams): Result[void, cstring] =
|
proc validateParameters*(parameters: GossipSubParams): Result[void, cstring] =
|
||||||
|
|
|
@ -79,6 +79,8 @@ proc handleBackingOff*(t: var BackoffTable, topic: string) {.raises: [Defect].}
|
||||||
v[].del(peer)
|
v[].del(peer)
|
||||||
|
|
||||||
proc peerExchangeList*(g: GossipSub, topic: string): seq[PeerInfoMsg] {.raises: [Defect].} =
|
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()
|
var peers = g.gossipsub.getOrDefault(topic, initHashSet[PubSubPeer]()).toSeq()
|
||||||
peers.keepIf do (x: PubSubPeer) -> bool:
|
peers.keepIf do (x: PubSubPeer) -> bool:
|
||||||
x.score >= 0.0
|
x.score >= 0.0
|
||||||
|
|
|
@ -138,6 +138,7 @@ type
|
||||||
directPeers*: Table[PeerId, seq[MultiAddress]]
|
directPeers*: Table[PeerId, seq[MultiAddress]]
|
||||||
|
|
||||||
disconnectBadPeers*: bool
|
disconnectBadPeers*: bool
|
||||||
|
enablePX*: bool
|
||||||
|
|
||||||
BackoffTable* = Table[string, Table[PeerId, Moment]]
|
BackoffTable* = Table[string, Table[PeerId, Moment]]
|
||||||
ValidationSeenTable* = Table[MessageID, HashSet[PubSubPeer]]
|
ValidationSeenTable* = Table[MessageID, HashSet[PubSubPeer]]
|
||||||
|
|
|
@ -945,7 +945,8 @@ suite "GossipSub":
|
||||||
let
|
let
|
||||||
nodes = generateNodes(
|
nodes = generateNodes(
|
||||||
2,
|
2,
|
||||||
gossip = true) &
|
gossip = true,
|
||||||
|
enablePX = true) &
|
||||||
generateNodes(1, gossip = true, sendSignedPeerRecord = true)
|
generateNodes(1, gossip = true, sendSignedPeerRecord = true)
|
||||||
|
|
||||||
# start switches
|
# start switches
|
||||||
|
@ -988,7 +989,7 @@ suite "GossipSub":
|
||||||
)
|
)
|
||||||
nodes[1].unsubscribe("foobar", handler)
|
nodes[1].unsubscribe("foobar", handler)
|
||||||
|
|
||||||
await passed
|
await passed.wait(5.seconds)
|
||||||
|
|
||||||
await allFuturesThrowing(
|
await allFuturesThrowing(
|
||||||
nodes[0].switch.stop(),
|
nodes[0].switch.stop(),
|
||||||
|
|
|
@ -42,7 +42,8 @@ proc generateNodes*(
|
||||||
sign: bool = libp2p_pubsub_sign,
|
sign: bool = libp2p_pubsub_sign,
|
||||||
sendSignedPeerRecord = false,
|
sendSignedPeerRecord = false,
|
||||||
unsubscribeBackoff = 1.seconds,
|
unsubscribeBackoff = 1.seconds,
|
||||||
maxMessageSize: int = 1024 * 1024): seq[PubSub] =
|
maxMessageSize: int = 1024 * 1024,
|
||||||
|
enablePX: bool = false): seq[PubSub] =
|
||||||
|
|
||||||
for i in 0..<num:
|
for i in 0..<num:
|
||||||
let switch = newStandardSwitch(secureManagers = secureManagers, sendSignedPeerRecord = sendSignedPeerRecord)
|
let switch = newStandardSwitch(secureManagers = secureManagers, sendSignedPeerRecord = sendSignedPeerRecord)
|
||||||
|
@ -55,7 +56,7 @@ proc generateNodes*(
|
||||||
msgIdProvider = msgIdProvider,
|
msgIdProvider = msgIdProvider,
|
||||||
anonymize = anonymize,
|
anonymize = anonymize,
|
||||||
maxMessageSize = maxMessageSize,
|
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
|
# set some testing params, to enable scores
|
||||||
g.topicParams.mgetOrPut("foobar", TopicParams.init()).topicWeight = 1.0
|
g.topicParams.mgetOrPut("foobar", TopicParams.init()).topicWeight = 1.0
|
||||||
g.topicParams.mgetOrPut("foo", TopicParams.init()).topicWeight = 1.0
|
g.topicParams.mgetOrPut("foo", TopicParams.init()).topicWeight = 1.0
|
||||||
|
|
Loading…
Reference in New Issue