Skip to content

Commit

Permalink
Missing flood protection check for number of message IDs when handlin…
Browse files Browse the repository at this point in the history
…g `Ihave` messages (#560)

* check msgIDs in Ihave per topic

* remove coments as suggested
  • Loading branch information
cortze authored Jun 27, 2024
1 parent dbd1c9e commit 8e498e9
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions gossipsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,6 @@ func (gs *GossipSubRouter) handleIHave(p peer.ID, ctl *pb.ControlMessage) []*pb.
log.Debugf("IHAVE: peer %s has advertised too many times (%d) within this heartbeat interval; ignoring", p, gs.peerhave[p])
return nil
}

if gs.iasked[p] >= gs.params.MaxIHaveLength {
log.Debugf("IHAVE: peer %s has already advertised too many messages (%d); ignoring", p, gs.iasked[p])
return nil
Expand All @@ -706,7 +705,14 @@ func (gs *GossipSubRouter) handleIHave(p peer.ID, ctl *pb.ControlMessage) []*pb.
continue
}

for _, mid := range ihave.GetMessageIDs() {
checkIwantMsgsLoop:
for msgIdx, mid := range ihave.GetMessageIDs() {
// prevent remote peer from sending too many msg_ids on a single IHAVE message
if msgIdx >= gs.params.MaxIHaveLength {
log.Debugf("IHAVE: peer %s has sent IHAVE on topic %s with too many messages (%d); ignoring remaining msgs", p, topic, len(ihave.MessageIDs))
break checkIwantMsgsLoop
}

if gs.p.seenMessage(mid) {
continue
}
Expand Down

0 comments on commit 8e498e9

Please sign in to comment.