check for nil on start/stop

This commit is contained in:
Dmitriy Ryajov 2022-04-19 19:18:20 -06:00
parent 1e0cc290f8
commit 06e043871c
No known key found for this signature in database
GPG Key ID: DA8C680CE7C657A4
1 changed files with 22 additions and 8 deletions

View File

@ -44,10 +44,17 @@ type
discovery*: Discovery discovery*: Discovery
proc start*(node: DaggerNodeRef) {.async.} = proc start*(node: DaggerNodeRef) {.async.} =
await node.switch.start() if not node.switch.isNil:
await node.engine.start() await node.switch.start()
await node.erasure.start()
await node.discovery.start() if not node.engine.isNil:
await node.engine.start()
if not node.erasure.isNil:
await node.erasure.start()
if not node.discovery.isNil:
await node.discovery.start()
node.networkId = node.switch.peerInfo.peerId node.networkId = node.switch.peerInfo.peerId
notice "Started dagger node", id = $node.networkId, addrs = node.switch.peerInfo.addrs notice "Started dagger node", id = $node.networkId, addrs = node.switch.peerInfo.addrs
@ -55,10 +62,17 @@ proc start*(node: DaggerNodeRef) {.async.} =
proc stop*(node: DaggerNodeRef) {.async.} = proc stop*(node: DaggerNodeRef) {.async.} =
trace "Stopping node" trace "Stopping node"
await node.engine.stop() if not node.engine.isNil:
await node.switch.stop() await node.engine.stop()
await node.erasure.stop()
await node.discovery.stop() if not node.switch.isNil:
await node.switch.stop()
if not node.erasure.isNil:
await node.erasure.stop()
if not node.discovery.isNil:
await node.discovery.stop()
proc findPeer*( proc findPeer*(
node: DaggerNodeRef, node: DaggerNodeRef,