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:
|
for node in d.bootstrapNodes:
|
||||||
d.addNode(node)
|
d.addNode(node)
|
||||||
|
|
||||||
|
proc start*(d: Protocol) =
|
||||||
# Might want to move these to a separate proc if this turns out to be needed.
|
# Might want to move these to a separate proc if this turns out to be needed.
|
||||||
d.lookupLoop = lookupLoop(d)
|
d.lookupLoop = lookupLoop(d)
|
||||||
d.revalidateLoop = revalidateLoop(d)
|
d.revalidateLoop = revalidateLoop(d)
|
||||||
|
|
||||||
proc close*(d: Protocol) =
|
proc close*(d: Protocol) =
|
||||||
doAssert(not d.lookupLoop.isNil() or not d.revalidateLoop.isNil())
|
|
||||||
doAssert(not d.transp.closed)
|
doAssert(not d.transp.closed)
|
||||||
|
|
||||||
debug "Closing discovery node", node = $d.localNode
|
debug "Closing discovery node", node = $d.localNode
|
||||||
d.revalidateLoop.cancel()
|
if not d.revalidateLoop.isNil:
|
||||||
d.lookupLoop.cancel()
|
d.revalidateLoop.cancel()
|
||||||
|
if not d.lookupLoop.isNil:
|
||||||
|
d.lookupLoop.cancel()
|
||||||
# TODO: unsure if close can't create issues in the not awaited cancellations
|
# TODO: unsure if close can't create issues in the not awaited cancellations
|
||||||
# above
|
# above
|
||||||
d.transp.close()
|
d.transp.close()
|
||||||
|
|
||||||
proc closeWait*(d: Protocol) {.async.} =
|
proc closeWait*(d: Protocol) {.async.} =
|
||||||
doAssert(not d.lookupLoop.isNil() or not d.revalidateLoop.isNil())
|
|
||||||
doAssert(not d.transp.closed)
|
doAssert(not d.transp.closed)
|
||||||
|
|
||||||
debug "Closing discovery node", node = $d.localNode
|
debug "Closing discovery node", node = $d.localNode
|
||||||
await allFutures([d.revalidateLoop.cancelAndWait(),
|
if not d.revalidateLoop.isNil:
|
||||||
d.lookupLoop.cancelAndWait()])
|
await d.revalidateLoop.cancelAndWait()
|
||||||
|
if not d.lookupLoop.isNil:
|
||||||
|
await d.lookupLoop.cancelAndWait()
|
||||||
|
|
||||||
await d.transp.closeWait()
|
await d.transp.closeWait()
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
|
|
|
@ -69,12 +69,14 @@ suite "Discovery v5 Tests":
|
||||||
nodeCount = 17
|
nodeCount = 17
|
||||||
|
|
||||||
let bootNode = initDiscoveryNode(newPrivateKey(), localAddress(20301), @[])
|
let bootNode = initDiscoveryNode(newPrivateKey(), localAddress(20301), @[])
|
||||||
|
bootNode.start()
|
||||||
|
|
||||||
var nodes = newSeqOfCap[discv5_protocol.Protocol](nodeCount)
|
var nodes = newSeqOfCap[discv5_protocol.Protocol](nodeCount)
|
||||||
nodes.add(bootNode)
|
nodes.add(bootNode)
|
||||||
for i in 1 ..< nodeCount:
|
for i in 1 ..< nodeCount:
|
||||||
nodes.add(initDiscoveryNode(newPrivateKey(), localAddress(20301 + i),
|
nodes.add(initDiscoveryNode(newPrivateKey(), localAddress(20301 + i),
|
||||||
@[bootNode.localNode.record]))
|
@[bootNode.localNode.record]))
|
||||||
|
nodes[i].start()
|
||||||
|
|
||||||
for i in 0..<nodeCount-1:
|
for i in 0..<nodeCount-1:
|
||||||
let target = nodes[i]
|
let target = nodes[i]
|
||||||
|
|
Loading…
Reference in New Issue