mirror of https://github.com/status-im/nim-eth.git
discv5: add start call
This commit is contained in:
parent
a9ff761d68
commit
f46f9f1418
|
@ -451,28 +451,32 @@ proc open*(d: Protocol) =
|
|||
for node in d.bootstrapNodes:
|
||||
d.addNode(node)
|
||||
|
||||
proc start*(d: Protocol) =
|
||||
# Might want to move these to a separate proc if this turns out to be needed.
|
||||
d.lookupLoop = lookupLoop(d)
|
||||
d.revalidateLoop = revalidateLoop(d)
|
||||
|
||||
proc close*(d: Protocol) =
|
||||
doAssert(not d.lookupLoop.isNil() or not d.revalidateLoop.isNil())
|
||||
doAssert(not d.transp.closed)
|
||||
|
||||
debug "Closing discovery node", node = $d.localNode
|
||||
d.revalidateLoop.cancel()
|
||||
d.lookupLoop.cancel()
|
||||
if not d.revalidateLoop.isNil:
|
||||
d.revalidateLoop.cancel()
|
||||
if not d.lookupLoop.isNil:
|
||||
d.lookupLoop.cancel()
|
||||
# TODO: unsure if close can't create issues in the not awaited cancellations
|
||||
# above
|
||||
d.transp.close()
|
||||
|
||||
proc closeWait*(d: Protocol) {.async.} =
|
||||
doAssert(not d.lookupLoop.isNil() or not d.revalidateLoop.isNil())
|
||||
doAssert(not d.transp.closed)
|
||||
|
||||
debug "Closing discovery node", node = $d.localNode
|
||||
await allFutures([d.revalidateLoop.cancelAndWait(),
|
||||
d.lookupLoop.cancelAndWait()])
|
||||
if not d.revalidateLoop.isNil:
|
||||
await d.revalidateLoop.cancelAndWait()
|
||||
if not d.lookupLoop.isNil:
|
||||
await d.lookupLoop.cancelAndWait()
|
||||
|
||||
await d.transp.closeWait()
|
||||
|
||||
when isMainModule:
|
||||
|
|
|
@ -69,12 +69,14 @@ suite "Discovery v5 Tests":
|
|||
nodeCount = 17
|
||||
|
||||
let bootNode = initDiscoveryNode(newPrivateKey(), localAddress(20301), @[])
|
||||
bootNode.start()
|
||||
|
||||
var nodes = newSeqOfCap[discv5_protocol.Protocol](nodeCount)
|
||||
nodes.add(bootNode)
|
||||
for i in 1 ..< nodeCount:
|
||||
nodes.add(initDiscoveryNode(newPrivateKey(), localAddress(20301 + i),
|
||||
@[bootNode.localNode.record]))
|
||||
nodes[i].start()
|
||||
|
||||
for i in 0..<nodeCount-1:
|
||||
let target = nodes[i]
|
||||
|
|
Loading…
Reference in New Issue