Fix segfault when there is no peer_pool (no connectToNetwork() ran).

e.g. tserver test would segfault.
This commit is contained in:
deme 2018-11-12 13:54:15 +01:00 committed by zah
parent 19cd8201b0
commit f62ca5607d
1 changed files with 9 additions and 8 deletions

View File

@ -58,14 +58,15 @@ proc processIncoming(server: StreamServer,
yield peerfut
if not peerfut.failed:
let peer = peerfut.read()
if peer.remote notin node.peerPool.connectedNodes:
node.peerPool.connectedNodes[peer.remote] = peer
for o in node.peerPool.observers.values:
if not o.onPeerConnected.isNil:
o.onPeerConnected(peer)
else:
debug "Disconnecting already connected node"
await peer.disconnect(AlreadyConnected)
if node.peerPool != nil:
if peer.remote notin node.peerPool.connectedNodes:
node.peerPool.connectedNodes[peer.remote] = peer
for o in node.peerPool.observers.values:
if not o.onPeerConnected.isNil:
o.onPeerConnected(peer)
else:
debug "Disconnecting already connected node"
await peer.disconnect(AlreadyConnected)
else:
remote.close()