mirror of https://github.com/status-im/nim-eth.git
Retry bootstrapping in case of failure
This commit is contained in:
parent
ac766bf7b3
commit
b84c228364
|
@ -416,11 +416,21 @@ proc resolve*(k: KademliaProtocol, id: NodeId): Future[Node] {.async.} =
|
||||||
for n in closest:
|
for n in closest:
|
||||||
if n.id == id: return n
|
if n.id == id: return n
|
||||||
|
|
||||||
proc bootstrap*(k: KademliaProtocol, bootstrapNodes: seq[Node]) {.async.} =
|
proc bootstrap*(k: KademliaProtocol, bootstrapNodes: seq[Node], retries = 0) {.async.} =
|
||||||
let bonded = await all(bootstrapNodes.mapIt(k.bond(it)))
|
## Bond with bootstrap nodes and do initial lookup. Retry `retries` times
|
||||||
if true notin bonded:
|
## in case of failure, or indefinitely if `retries` is 0.
|
||||||
info "Failed to bond with bootstrap nodes "
|
var numTries = 0
|
||||||
return
|
while true:
|
||||||
|
let bonded = await all(bootstrapNodes.mapIt(k.bond(it)))
|
||||||
|
if true notin bonded:
|
||||||
|
info "Failed to bond with bootstrap nodes"
|
||||||
|
inc numTries
|
||||||
|
if retries == 0 or numTries < retries:
|
||||||
|
info "Retrying"
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
break
|
||||||
discard await k.lookupRandom()
|
discard await k.lookupRandom()
|
||||||
|
|
||||||
proc recvPong*(k: KademliaProtocol, n: Node, token: seq[byte]) =
|
proc recvPong*(k: KademliaProtocol, n: Node, token: seq[byte]) =
|
||||||
|
|
Loading…
Reference in New Issue