nil check peer before disconnect

This commit is contained in:
Giovanni Petrantoni 2020-07-09 17:20:45 +09:00
parent f9e0a1f069
commit 4e12d0d97a
2 changed files with 5 additions and 3 deletions

View File

@ -138,6 +138,7 @@ method publish*(f: FloodSub,
let (published, failed) = await f.sendHelper(f.floodsub.getOrDefault(topic), @[msg]) let (published, failed) = await f.sendHelper(f.floodsub.getOrDefault(topic), @[msg])
for p in failed: for p in failed:
let peer = f.peers.getOrDefault(p) let peer = f.peers.getOrDefault(p)
if not isNil(peer):
f.handleDisconnect(peer) # cleanup failed peers f.handleDisconnect(peer) # cleanup failed peers
libp2p_pubsub_messages_published.inc(labelValues = [topic]) libp2p_pubsub_messages_published.inc(labelValues = [topic])

View File

@ -450,7 +450,7 @@ method rpcHandler*(g: GossipSub,
let (published, failed) = await g.sendHelper(toSendPeers, m.messages) let (published, failed) = await g.sendHelper(toSendPeers, m.messages)
for p in failed: for p in failed:
let peer = g.peers.getOrDefault(p) let peer = g.peers.getOrDefault(p)
if not(isNil(peer)): if not isNil(peer):
g.handleDisconnect(peer) # cleanup failed peers g.handleDisconnect(peer) # cleanup failed peers
trace "forwared message to peers", peers = published.len trace "forwared message to peers", peers = published.len
@ -523,6 +523,7 @@ method publish*(g: GossipSub,
let (published, failed) = await g.sendHelper(peers, @[msg]) let (published, failed) = await g.sendHelper(peers, @[msg])
for p in failed: for p in failed:
let peer = g.peers.getOrDefault(p) let peer = g.peers.getOrDefault(p)
if not isNil(peer):
g.handleDisconnect(peer) # cleanup failed peers g.handleDisconnect(peer) # cleanup failed peers
if published.len > 0: if published.len > 0: