Skip to content

Commit bb97a9d

Browse files
improvement: create a new gossipsub constructor (#1078)
1 parent 1a707e1 commit bb97a9d

File tree

1 file changed

+74
-34
lines changed

1 file changed

+74
-34
lines changed

libp2p/protocols/pubsub/gossipsub.nim

+74-34
Original file line numberDiff line numberDiff line change
@@ -49,42 +49,80 @@ declareCounter(libp2p_gossipsub_received, "number of messages received (deduplic
4949
when defined(libp2p_expensive_metrics):
5050
declareCounter(libp2p_pubsub_received_messages, "number of messages received", labels = ["id", "topic"])
5151

52-
proc init*(_: type[GossipSubParams]): GossipSubParams =
52+
proc init*(
53+
_: type[GossipSubParams],
54+
explicit = true,
55+
pruneBackoff = 1.minutes,
56+
unsubscribeBackoff = 5.seconds,
57+
floodPublish = true,
58+
gossipFactor: float64 = 0.25,
59+
d = GossipSubD,
60+
dLow = GossipSubDlo,
61+
dHigh = GossipSubDhi,
62+
dScore = GossipSubDlo,
63+
dOut = GossipSubDlo - 1, # DLow - 1
64+
dLazy = GossipSubD, # Like D,
65+
heartbeatInterval = GossipSubHeartbeatInterval,
66+
historyLength = GossipSubHistoryLength,
67+
historyGossip = GossipSubHistoryGossip,
68+
fanoutTTL = GossipSubFanoutTTL,
69+
seenTTL = 2.minutes,
70+
gossipThreshold = -100.0,
71+
publishThreshold = -1000.0,
72+
graylistThreshold = -10000.0,
73+
opportunisticGraftThreshold = 0.0,
74+
decayInterval = 1.seconds,
75+
decayToZero = 0.01,
76+
retainScore = 2.minutes,
77+
appSpecificWeight = 0.0,
78+
ipColocationFactorWeight = 0.0,
79+
ipColocationFactorThreshold = 1.0,
80+
behaviourPenaltyWeight = -1.0,
81+
behaviourPenaltyDecay = 0.999,
82+
directPeers = initTable[PeerId, seq[MultiAddress]](),
83+
disconnectBadPeers = false,
84+
enablePX = false,
85+
bandwidthEstimatebps = 100_000_000, # 100 Mbps or 12.5 MBps
86+
overheadRateLimit = Opt.none(tuple[bytes: int, interval: Duration]),
87+
disconnectPeerAboveRateLimit = false,
88+
maxNumElementsInNonPriorityQueue = DefaultMaxNumElementsInNonPriorityQueue): GossipSubParams =
89+
5390
GossipSubParams(
5491
explicit: true,
55-
pruneBackoff: 1.minutes,
56-
unsubscribeBackoff: 5.seconds,
57-
floodPublish: true,
58-
gossipFactor: 0.25,
59-
d: GossipSubD,
60-
dLow: GossipSubDlo,
61-
dHigh: GossipSubDhi,
62-
dScore: GossipSubDlo,
63-
dOut: GossipSubDlo - 1, # DLow - 1
64-
dLazy: GossipSubD, # Like D
65-
heartbeatInterval: GossipSubHeartbeatInterval,
66-
historyLength: GossipSubHistoryLength,
67-
historyGossip: GossipSubHistoryGossip,
68-
fanoutTTL: GossipSubFanoutTTL,
69-
seenTTL: 2.minutes,
70-
gossipThreshold: -100,
71-
publishThreshold: -1000,
72-
graylistThreshold: -10000,
73-
opportunisticGraftThreshold: 0,
74-
decayInterval: 1.seconds,
75-
decayToZero: 0.01,
76-
retainScore: 2.minutes,
77-
appSpecificWeight: 0.0,
78-
ipColocationFactorWeight: 0.0,
79-
ipColocationFactorThreshold: 1.0,
80-
behaviourPenaltyWeight: -1.0,
81-
behaviourPenaltyDecay: 0.999,
82-
disconnectBadPeers: false,
83-
enablePX: false,
84-
bandwidthEstimatebps: 100_000_000, # 100 Mbps or 12.5 MBps
85-
overheadRateLimit: Opt.none(tuple[bytes: int, interval: Duration]),
86-
disconnectPeerAboveRateLimit: false,
87-
maxNumElementsInNonPriorityQueue: DefaultMaxNumElementsInNonPriorityQueue
92+
pruneBackoff: pruneBackoff,
93+
unsubscribeBackoff: unsubscribeBackoff,
94+
floodPublish: floodPublish,
95+
gossipFactor: gossipFactor,
96+
d: d,
97+
dLow: dLow,
98+
dHigh: dHigh,
99+
dScore: dScore,
100+
dOut: dOut,
101+
dLazy: dLazy,
102+
heartbeatInterval: heartbeatInterval,
103+
historyLength: historyLength,
104+
historyGossip: historyGossip,
105+
fanoutTTL: fanoutTTL,
106+
seenTTL: seenTTL,
107+
gossipThreshold: gossipThreshold,
108+
publishThreshold: publishThreshold,
109+
graylistThreshold: graylistThreshold,
110+
opportunisticGraftThreshold: opportunisticGraftThreshold,
111+
decayInterval: decayInterval,
112+
decayToZero: decayToZero,
113+
retainScore: retainScore,
114+
appSpecificWeight: appSpecificWeight,
115+
ipColocationFactorWeight: ipColocationFactorWeight,
116+
ipColocationFactorThreshold: ipColocationFactorThreshold,
117+
behaviourPenaltyWeight: behaviourPenaltyWeight,
118+
behaviourPenaltyDecay: behaviourPenaltyDecay,
119+
directPeers: directPeers,
120+
disconnectBadPeers: disconnectBadPeers,
121+
enablePX: enablePX,
122+
bandwidthEstimatebps: bandwidthEstimatebps,
123+
overheadRateLimit: overheadRateLimit,
124+
disconnectPeerAboveRateLimit: disconnectPeerAboveRateLimit,
125+
maxNumElementsInNonPriorityQueue: maxNumElementsInNonPriorityQueue
88126
)
89127

90128
proc validateParameters*(parameters: GossipSubParams): Result[void, cstring] =
@@ -115,6 +153,8 @@ proc validateParameters*(parameters: GossipSubParams): Result[void, cstring] =
115153
err("gossipsub: behaviourPenaltyWeight parameter error, Must be negative")
116154
elif parameters.behaviourPenaltyDecay < 0 or parameters.behaviourPenaltyDecay >= 1:
117155
err("gossipsub: behaviourPenaltyDecay parameter error, Must be between 0 and 1")
156+
elif parameters.maxNumElementsInNonPriorityQueue <= 0:
157+
err("gossipsub: maxNumElementsInNonPriorityQueue parameter error, Must be > 0")
118158
else:
119159
ok()
120160

0 commit comments

Comments
 (0)