Add closeWait to EthereumNode

This commit is contained in:
jangko 2023-09-08 21:45:41 +07:00
parent 0d7e7448c4
commit ac680ed79b
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
1 changed files with 9 additions and 5 deletions

View File

@ -20,7 +20,7 @@ logScope:
topics = "eth p2p" topics = "eth p2p"
proc addCapability*(node: var EthereumNode, proc addCapability*(node: EthereumNode,
p: ProtocolInfo, p: ProtocolInfo,
networkState: RootRef = nil) = networkState: RootRef = nil) =
doAssert node.connectionState == ConnectionState.None doAssert node.connectionState == ConnectionState.None
@ -35,10 +35,10 @@ proc addCapability*(node: var EthereumNode,
if networkState.isNil.not: if networkState.isNil.not:
node.protocolStates[p.index] = networkState node.protocolStates[p.index] = networkState
template addCapability*(node: var EthereumNode, Protocol: type) = template addCapability*(node: EthereumNode, Protocol: type) =
addCapability(node, Protocol.protocolInfo) addCapability(node, Protocol.protocolInfo)
template addCapability*(node: var EthereumNode, template addCapability*(node: EthereumNode,
Protocol: type, Protocol: type,
networkState: untyped) = networkState: untyped) =
mixin NetworkState mixin NetworkState
@ -53,12 +53,12 @@ template addCapability*(node: var EthereumNode,
addCapability(node, Protocol.protocolInfo, addCapability(node, Protocol.protocolInfo,
cast[RootRef](networkState)) cast[RootRef](networkState))
proc replaceNetworkState*(node: var EthereumNode, proc replaceNetworkState*(node: EthereumNode,
p: ProtocolInfo, p: ProtocolInfo,
networkState: RootRef) = networkState: RootRef) =
node.protocolStates[p.index] = networkState node.protocolStates[p.index] = networkState
template replaceNetworkState*(node: var EthereumNode, template replaceNetworkState*(node: EthereumNode,
Protocol: type, Protocol: type,
networkState: untyped) = networkState: untyped) =
mixin NetworkState mixin NetworkState
@ -237,3 +237,7 @@ func hasPeer*(node: EthereumNode, n: Node): bool =
func hasPeer*(node: EthereumNode, n: Peer): bool = func hasPeer*(node: EthereumNode, n: Peer): bool =
n in node.peerPool n in node.peerPool
proc closeWait*(node: EthereumNode) {.async.} =
node.stopListening()
await node.listeningServer.closeWait()