From ac680ed79bf9e4e78ca14a001eb7f78acdf7b07d Mon Sep 17 00:00:00 2001 From: jangko Date: Fri, 8 Sep 2023 21:45:41 +0700 Subject: [PATCH] Add closeWait to EthereumNode --- eth/p2p.nim | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/eth/p2p.nim b/eth/p2p.nim index 2396acfb..fe6e11e9 100644 --- a/eth/p2p.nim +++ b/eth/p2p.nim @@ -20,7 +20,7 @@ logScope: topics = "eth p2p" -proc addCapability*(node: var EthereumNode, +proc addCapability*(node: EthereumNode, p: ProtocolInfo, networkState: RootRef = nil) = doAssert node.connectionState == ConnectionState.None @@ -35,10 +35,10 @@ proc addCapability*(node: var EthereumNode, if networkState.isNil.not: node.protocolStates[p.index] = networkState -template addCapability*(node: var EthereumNode, Protocol: type) = +template addCapability*(node: EthereumNode, Protocol: type) = addCapability(node, Protocol.protocolInfo) -template addCapability*(node: var EthereumNode, +template addCapability*(node: EthereumNode, Protocol: type, networkState: untyped) = mixin NetworkState @@ -53,12 +53,12 @@ template addCapability*(node: var EthereumNode, addCapability(node, Protocol.protocolInfo, cast[RootRef](networkState)) -proc replaceNetworkState*(node: var EthereumNode, +proc replaceNetworkState*(node: EthereumNode, p: ProtocolInfo, networkState: RootRef) = node.protocolStates[p.index] = networkState -template replaceNetworkState*(node: var EthereumNode, +template replaceNetworkState*(node: EthereumNode, Protocol: type, networkState: untyped) = mixin NetworkState @@ -237,3 +237,7 @@ func hasPeer*(node: EthereumNode, n: Node): bool = func hasPeer*(node: EthereumNode, n: Peer): bool = n in node.peerPool + +proc closeWait*(node: EthereumNode) {.async.} = + node.stopListening() + await node.listeningServer.closeWait()