Skip to content

Commit

Permalink
don't send empty messages
Browse files Browse the repository at this point in the history
  • Loading branch information
dryajov committed Aug 2, 2020
1 parent 65eed4e commit 01cdd11
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions libp2p/protocols/pubsub/gossipsub.nim
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,14 @@ proc getGossipPeers(g: GossipSub): Table[string, ControlMessage] {.gcsafe.} =

let gossipPeers = mesh + fanout
let mids = g.mcache.window(topic)
if mids.len <= 0:
if not mids.len > 0:
continue

let ihave = ControlIHave(topicID: topic,
messageIDs: toSeq(mids))

if topic notin g.gossipsub:
trace "topic not in gossip array, skipping", topicID = topic
continue

let ihave = ControlIHave(topicID: topic, messageIDs: toSeq(mids))
for peer in allPeers:
if result.len >= GossipSubD:
trace "got gossip peers", peers = result.len
Expand Down Expand Up @@ -436,8 +434,9 @@ method rpcHandler*(g: GossipSub,
let messages = g.handleIWant(peer, control.iwant)

if respControl.graft.len > 0 or respControl.prune.len > 0 or
respControl.ihave.len > 0 or respControl.iwant.len > 0:
respControl.ihave.len > 0:
try:
info "sending control message", msg = respControl
await peer.send(
RPCMsg(control: some(respControl), messages: messages))
except CancelledError as exc:
Expand Down

0 comments on commit 01cdd11

Please sign in to comment.