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,7 +138,8 @@ method publish*(f: FloodSub,
let (published, failed) = await f.sendHelper(f.floodsub.getOrDefault(topic), @[msg])
for p in failed:
let peer = f.peers.getOrDefault(p)
f.handleDisconnect(peer) # cleanup failed peers
if not isNil(peer):
f.handleDisconnect(peer) # cleanup failed peers
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)
for p in failed:
let peer = g.peers.getOrDefault(p)
if not(isNil(peer)):
if not isNil(peer):
g.handleDisconnect(peer) # cleanup failed peers
trace "forwared message to peers", peers = published.len
@ -523,7 +523,8 @@ method publish*(g: GossipSub,
let (published, failed) = await g.sendHelper(peers, @[msg])
for p in failed:
let peer = g.peers.getOrDefault(p)
g.handleDisconnect(peer) # cleanup failed peers
if not isNil(peer):
g.handleDisconnect(peer) # cleanup failed peers
if published.len > 0:
libp2p_pubsub_messages_published.inc(labelValues = [topic])