mirror of https://github.com/status-im/nim-eth.git
Tweak some retry limits and timeouts
This commit is contained in:
parent
1369cf3a30
commit
74d0247e6b
|
@ -204,7 +204,13 @@ proc decodeAuthResp(c: Codec, fromId: NodeId, head: AuthHeader,
|
|||
newNode = newNode(authResp.record)
|
||||
return true
|
||||
|
||||
proc decodeEncrypted*(c: var Codec, fromId: NodeID, fromAddr: Address, input: seq[byte], authTag: var array[12, byte], newNode: var Node, packet: var Packet): bool =
|
||||
proc decodeEncrypted*(c: var Codec,
|
||||
fromId: NodeID,
|
||||
fromAddr: Address,
|
||||
input: seq[byte],
|
||||
authTag: var array[12, byte],
|
||||
newNode: var Node,
|
||||
packet: var Packet): bool =
|
||||
let input = input.toRange
|
||||
var r = rlpFromBytes(input[32 .. ^1])
|
||||
var auth: AuthHeader
|
||||
|
@ -218,13 +224,16 @@ proc decodeEncrypted*(c: var Codec, fromId: NodeID, fromAddr: Address, input: se
|
|||
|
||||
let challenge = c.handshakes.getOrDefault($fromId)
|
||||
if challenge.isNil:
|
||||
trace "Decoding failed (no challenge)"
|
||||
return false
|
||||
|
||||
if auth.idNonce != challenge.idNonce:
|
||||
trace "Decoding failed (different nonce)"
|
||||
return false
|
||||
|
||||
var sec: HandshakeSecrets
|
||||
if not c.decodeAuthResp(fromId, auth, challenge, sec, newNode):
|
||||
trace "Decoding failed (bad auth)"
|
||||
return false
|
||||
c.handshakes.del($fromId)
|
||||
|
||||
|
@ -240,6 +249,7 @@ proc decodeEncrypted*(c: var Codec, fromId: NodeID, fromAddr: Address, input: se
|
|||
auth.auth = authTag
|
||||
var writeKey: array[16, byte]
|
||||
if not c.db.loadKeys(fromId, fromAddr, readKey, writeKey):
|
||||
trace "Decoding failed (no keys)"
|
||||
return false
|
||||
# doAssert(false, "TODO: HANDLE ME!")
|
||||
|
||||
|
|
|
@ -27,7 +27,8 @@ type
|
|||
|
||||
const
|
||||
lookupRequestLimit = 15
|
||||
findnodeResultLimit = 15 # applies in FINDNODE handler
|
||||
findNodeResultLimit = 15 # applies in FINDNODE handler
|
||||
findNodeAttempts = 3
|
||||
|
||||
proc whoareyouMagic(toNode: NodeId): array[32, byte] =
|
||||
const prefix = "WHOAREYOU"
|
||||
|
@ -85,6 +86,7 @@ proc decodeWhoAreYou(d: Protocol, msg: Bytes): Whoareyou =
|
|||
result[] = rlp.decode(msg.toRange[32 .. ^1], WhoareyouObj)
|
||||
|
||||
proc sendWhoareyou(d: Protocol, address: Address, toNode: NodeId, authTag: array[12, byte]) =
|
||||
trace "sending who are you", to = $toNode, toAddress = $address
|
||||
let challenge = Whoareyou(authTag: authTag, recordSeq: 1)
|
||||
randomBytes(challenge.idNonce)
|
||||
d.codec.handshakes[$toNode] = challenge
|
||||
|
@ -241,7 +243,7 @@ proc lookupDistances(target, dest: NodeId): seq[uint32] =
|
|||
proc lookupWorker(p: Protocol, destNode: Node, target: NodeId): Future[seq[Node]] {.async.} =
|
||||
let dists = lookupDistances(target, destNode.id)
|
||||
var i = 0
|
||||
while i < lookupRequestLimit and result.len < findNodeResultLimit:
|
||||
while i < findNodeAttempts and result.len < findNodeResultLimit:
|
||||
let r = await p.findNode(destNode, dists[i])
|
||||
# TODO: Handle failures
|
||||
result.add(r)
|
||||
|
|
|
@ -46,7 +46,7 @@ type
|
|||
const
|
||||
BUCKET_SIZE = 16
|
||||
BITS_PER_HOP = 8
|
||||
REQUEST_TIMEOUT = chronos.milliseconds(900) # timeout of message round trips
|
||||
REQUEST_TIMEOUT = chronos.milliseconds(5000) # timeout of message round trips
|
||||
FIND_CONCURRENCY = 3 # parallel find node lookups
|
||||
ID_SIZE = 256
|
||||
|
||||
|
|
Loading…
Reference in New Issue