Deal with the refactoring in status-im/nim-rlp#20
This commit is contained in:
parent
d808d9dc1a
commit
badc616be8
|
@ -350,7 +350,7 @@ proc dispatchMsg(peer: Peer, msgId: int, msgData: var Rlp): Future[void] =
|
|||
|
||||
return thunk(peer, msgData)
|
||||
|
||||
proc sendMsg(p: Peer, data: BytesRange) {.async.} =
|
||||
proc sendMsg(p: Peer, data: Bytes) {.async.} =
|
||||
# var rlp = rlpFromBytes(data)
|
||||
# echo "sending: ", rlp.read(int)
|
||||
# echo "payload: ", rlp.inspect
|
||||
|
|
|
@ -189,7 +189,7 @@ proc authMessageEIP8(h: var Handshake,
|
|||
int(padsize))) != int(padsize):
|
||||
return(RandomError)
|
||||
if encrypt:
|
||||
copyMem(addr buffer[0], payload.baseAddr, len(payload))
|
||||
copyMem(addr buffer[0], addr payload[0], len(payload))
|
||||
if len(output) < fullsize:
|
||||
return(BufferOverrun)
|
||||
bigEndian16(addr output, addr wosize)
|
||||
|
@ -260,7 +260,7 @@ proc ackMessageEIP8(h: var Handshake,
|
|||
if randomBytes(toa(buffer, PlainAckMessageEIP8Length,
|
||||
int(padsize))) != int(padsize):
|
||||
return(RandomError)
|
||||
copyMem(addr buffer[0], payload.baseAddr, len(payload))
|
||||
copyMem(addr buffer[0], addr payload[0], len(payload))
|
||||
if encrypt:
|
||||
if len(output) < fullsize:
|
||||
return(BufferOverrun)
|
||||
|
|
|
@ -106,14 +106,14 @@ proc send(d: DiscoveryProtocol, n: Node, data: seq[byte]) =
|
|||
|
||||
proc sendPing*(d: DiscoveryProtocol, n: Node): seq[byte] =
|
||||
let payload = rlp.encode((PROTO_VERSION, d.address, n.node.address,
|
||||
expiration()))
|
||||
expiration())).toRange
|
||||
let msg = pack(cmdPing, payload, d.privKey)
|
||||
result = msg[0 ..< MAC_SIZE]
|
||||
debug ">>> ping ", n
|
||||
d.send(n, msg)
|
||||
|
||||
proc sendPong*(d: DiscoveryProtocol, n: Node, token: MDigest[256]) =
|
||||
let payload = rlp.encode((n.node.address, token, expiration()))
|
||||
let payload = rlp.encode((n.node.address, token, expiration())).toRange
|
||||
let msg = pack(cmdPong, payload, d.privKey)
|
||||
debug ">>> pong ", n
|
||||
d.send(n, msg)
|
||||
|
@ -121,7 +121,7 @@ proc sendPong*(d: DiscoveryProtocol, n: Node, token: MDigest[256]) =
|
|||
proc sendFindNode*(d: DiscoveryProtocol, n: Node, targetNodeId: NodeId) =
|
||||
var data: array[64, byte]
|
||||
data[32 .. ^1] = targetNodeId.toByteArrayBE()
|
||||
let payload = rlp.encode((data, expiration()))
|
||||
let payload = rlp.encode((data, expiration())).toRange
|
||||
let msg = pack(cmdFindNode, payload, d.privKey)
|
||||
debug ">>> find_node to ", n#, ": ", msg.toHex()
|
||||
d.send(n, msg)
|
||||
|
@ -134,7 +134,7 @@ proc sendNeighbours*(d: DiscoveryProtocol, node: Node, neighbours: seq[Node]) =
|
|||
|
||||
template flush() =
|
||||
block:
|
||||
let payload = rlp.encode((nodes, expiration()))
|
||||
let payload = rlp.encode((nodes, expiration())).toRange
|
||||
let msg = pack(cmdNeighbours, payload, d.privkey)
|
||||
debug ">>> neighbours to ", node, ": ", nodes
|
||||
d.send(node, msg)
|
||||
|
|
|
@ -130,7 +130,7 @@ proc encrypt*(c: var SecretState, header: openarray[byte],
|
|||
copyMem(addr output[frameMacPos], addr frameMac.data[0], RlpHeaderLength)
|
||||
result = Success
|
||||
|
||||
proc encryptMsg*(msg: BytesRange, secrets: var SecretState): seq[byte] =
|
||||
proc encryptMsg*(msg: openarray[byte], secrets: var SecretState): seq[byte] =
|
||||
var header: RlpxHeader
|
||||
|
||||
if uint32(msg.len) > maxUInt24:
|
||||
|
@ -144,7 +144,7 @@ proc encryptMsg*(msg: BytesRange, secrets: var SecretState): seq[byte] =
|
|||
# XXX:
|
||||
# This would be safer if we use a thread-local sequ for the temporary buffer
|
||||
result = newSeq[byte](encryptedLength(msg.len))
|
||||
let s = encrypt(secrets, header, msg.toOpenArray, result)
|
||||
let s = encrypt(secrets, header, msg, result)
|
||||
assert s == Success
|
||||
|
||||
proc getBodySize*(a: RlpxHeader): int =
|
||||
|
|
Loading…
Reference in New Issue