mirror of https://github.com/vacp2p/nim-libp2p.git
Limit ihave emission (#462)
* add some limits to ihave emission, go has them, rust does not actually * restore shuffling of IDs * add some context
This commit is contained in:
parent
12db9a4cf2
commit
02b20440f2
|
@ -57,6 +57,10 @@ const
|
|||
BackoffSlackTime = 2 # seconds
|
||||
IWantPeerBudget = 25 # 25 messages per second ( reset every heartbeat )
|
||||
IHavePeerBudget = 10
|
||||
# the max amount of IHave to expose, not by spec, but go as example
|
||||
# rust sigp: https://github.com/sigp/rust-libp2p/blob/f53d02bc873fef2bf52cd31e3d5ce366a41d8a8c/protocols/gossipsub/src/config.rs#L572
|
||||
# go: https://github.com/libp2p/go-libp2p-pubsub/blob/08c17398fb11b2ab06ca141dddc8ec97272eb772/gossipsub.go#L155
|
||||
IHaveMaxLength = 5000
|
||||
|
||||
type
|
||||
TopicInfo* = object
|
||||
|
@ -618,7 +622,14 @@ proc getGossipPeers(g: GossipSub): Table[PubSubPeer, ControlMessage] {.gcsafe.}
|
|||
if not mids.len > 0:
|
||||
continue
|
||||
|
||||
let ihave = ControlIHave(topicID: topic, messageIDs: toSeq(mids))
|
||||
var midsSeq = toSeq(mids)
|
||||
# not in spec
|
||||
# similar to rust: https://github.com/sigp/rust-libp2p/blob/f53d02bc873fef2bf52cd31e3d5ce366a41d8a8c/protocols/gossipsub/src/behaviour.rs#L2101
|
||||
# and go https://github.com/libp2p/go-libp2p-pubsub/blob/08c17398fb11b2ab06ca141dddc8ec97272eb772/gossipsub.go#L582
|
||||
if midsSeq.len > IHaveMaxLength:
|
||||
shuffle(midsSeq)
|
||||
midsSeq.setLen(IHaveMaxLength)
|
||||
let ihave = ControlIHave(topicID: topic, messageIDs: midsSeq)
|
||||
|
||||
let mesh = g.mesh.getOrDefault(topic)
|
||||
let fanout = g.fanout.getOrDefault(topic)
|
||||
|
|
Loading…
Reference in New Issue