Deal with the refactoring in status-im/nim-rlp#20

This commit is contained in:
Zahary Karadjov 2018-09-26 17:21:49 +03:00
parent d808d9dc1a
commit badc616be8
4 changed files with 9 additions and 9 deletions

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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 =