mirror of
https://github.com/status-im/nim-libp2p.git
synced 2025-02-09 19:44:45 +00:00
wip parameters
This commit is contained in:
parent
6eb651d43a
commit
255d9d0324
@ -21,6 +21,8 @@ import pubsub,
|
|||||||
../../peerid,
|
../../peerid,
|
||||||
../../errors,
|
../../errors,
|
||||||
../../utility
|
../../utility
|
||||||
|
import stew/results
|
||||||
|
export results
|
||||||
|
|
||||||
logScope:
|
logScope:
|
||||||
topics = "gossipsub"
|
topics = "gossipsub"
|
||||||
@ -58,7 +60,11 @@ type
|
|||||||
dScore*: int
|
dScore*: int
|
||||||
dOut*: int
|
dOut*: int
|
||||||
|
|
||||||
|
gossipThreshold*: float
|
||||||
publishThreshold*: float
|
publishThreshold*: float
|
||||||
|
graylistThreshold*: float
|
||||||
|
acceptPXThreshold*: float
|
||||||
|
opportunisticGraftThreshold*: float
|
||||||
|
|
||||||
GossipSub* = ref object of FloodSub
|
GossipSub* = ref object of FloodSub
|
||||||
parameters*: GossipSubParams
|
parameters*: GossipSubParams
|
||||||
@ -94,7 +100,10 @@ proc init*(_: type[GossipSubParams]): GossipSubParams =
|
|||||||
gossipFactor: 0.25,
|
gossipFactor: 0.25,
|
||||||
dScore: 4,
|
dScore: 4,
|
||||||
dOut: 2,
|
dOut: 2,
|
||||||
publishThreshold: 1.0,
|
gossipThreshold: -10,
|
||||||
|
publishThreshold: -100,
|
||||||
|
graylistThreshold: -10000,
|
||||||
|
opportunisticGraftThreshold: 1
|
||||||
)
|
)
|
||||||
|
|
||||||
func addPeer(table: var PeerTable, topic: string, peer: PubSubPeer): bool =
|
func addPeer(table: var PeerTable, topic: string, peer: PubSubPeer): bool =
|
||||||
@ -186,6 +195,8 @@ proc rebalanceMesh(g: GossipSub, topic: string) {.async.} =
|
|||||||
# prune peers if we've gone over
|
# prune peers if we've gone over
|
||||||
# gather peers
|
# gather peers
|
||||||
var mesh = toSeq(g.mesh[topic])
|
var mesh = toSeq(g.mesh[topic])
|
||||||
|
# shuffle anyway, we might not use score
|
||||||
|
shuffle(mesh)
|
||||||
# sort peers by score
|
# sort peers by score
|
||||||
mesh.sort(proc (x, y: PubSubPeer): int =
|
mesh.sort(proc (x, y: PubSubPeer): int =
|
||||||
let
|
let
|
||||||
@ -625,9 +636,28 @@ method stop*(g: GossipSub) {.async.} =
|
|||||||
trace "awaiting last heartbeat"
|
trace "awaiting last heartbeat"
|
||||||
await g.heartbeatFut
|
await g.heartbeatFut
|
||||||
|
|
||||||
|
proc validateParameters(g: GossipSub): Result[void, cstring] =
|
||||||
|
if (g.parameters.dOut >= GossipSubDlo) or
|
||||||
|
(g.parameters.dOut > (GossipSubD div 2)):
|
||||||
|
err("gossipsub: dOut parameter error, Number of outbound connections to keep in the mesh. Must be less than D_lo and at most D/2")
|
||||||
|
elif g.parameters.gossipThreshold >= 0:
|
||||||
|
err("gossipsub: gossipThreshold parameter error, Must be < 0")
|
||||||
|
elif g.parameters.publishThreshold >= g.parameters.gossipThreshold:
|
||||||
|
err("gossipsub: publishThreshold parameter error, Must be < gossipThreshold")
|
||||||
|
elif g.parameters.graylistThreshold >= g.parameters.publishThreshold:
|
||||||
|
err("gossipsub: graylistThreshold parameter error, Must be < publishThreshold")
|
||||||
|
elif g.parameters.acceptPXThreshold < 0:
|
||||||
|
err("gossipsub: acceptPXThreshold parameter error, Must be >= 0")
|
||||||
|
elif g.parameters.opportunisticGraftThreshold < 0:
|
||||||
|
err("gossipsub: opportunisticGraftThreshold parameter error, Must be >= 0")
|
||||||
|
else:
|
||||||
|
ok()
|
||||||
|
|
||||||
method initPubSub*(g: GossipSub) =
|
method initPubSub*(g: GossipSub) =
|
||||||
procCall FloodSub(g).initPubSub()
|
procCall FloodSub(g).initPubSub()
|
||||||
|
|
||||||
|
g.validateParameters().tryGet()
|
||||||
|
|
||||||
randomize()
|
randomize()
|
||||||
g.mcache = newMCache(GossipSubHistoryGossip, GossipSubHistoryLength)
|
g.mcache = newMCache(GossipSubHistoryGossip, GossipSubHistoryLength)
|
||||||
g.mesh = initTable[string, HashSet[PubSubPeer]]() # meshes - topic to peer
|
g.mesh = initTable[string, HashSet[PubSubPeer]]() # meshes - topic to peer
|
||||||
|
@ -67,7 +67,8 @@ proc newStandardSwitch*(privKey = none(PrivateKey),
|
|||||||
triggerSelf = triggerSelf,
|
triggerSelf = triggerSelf,
|
||||||
verifySignature = verifySignature,
|
verifySignature = verifySignature,
|
||||||
sign = sign,
|
sign = sign,
|
||||||
msgIdProvider = msgIdProvider).PubSub
|
msgIdProvider = msgIdProvider,
|
||||||
|
params = GossipSubParams.init()).PubSub
|
||||||
else:
|
else:
|
||||||
newPubSub(FloodSub,
|
newPubSub(FloodSub,
|
||||||
peerInfo = peerInfo,
|
peerInfo = peerInfo,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user