From badc616be896f89843208b4000d3d51f1c81304f Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Wed, 26 Sep 2018 17:21:49 +0300 Subject: [PATCH] Deal with the refactoring in status-im/nim-rlp#20 --- eth_p2p.nim | 2 +- eth_p2p/auth.nim | 4 ++-- eth_p2p/discovery.nim | 8 ++++---- eth_p2p/rlpxcrypt.nim | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/eth_p2p.nim b/eth_p2p.nim index 6791d98..035a135 100644 --- a/eth_p2p.nim +++ b/eth_p2p.nim @@ -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 diff --git a/eth_p2p/auth.nim b/eth_p2p/auth.nim index 853c2a6..97d896c 100644 --- a/eth_p2p/auth.nim +++ b/eth_p2p/auth.nim @@ -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) diff --git a/eth_p2p/discovery.nim b/eth_p2p/discovery.nim index 95131c1..8a3503c 100644 --- a/eth_p2p/discovery.nim +++ b/eth_p2p/discovery.nim @@ -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) diff --git a/eth_p2p/rlpxcrypt.nim b/eth_p2p/rlpxcrypt.nim index 022a08c..0df00ae 100644 --- a/eth_p2p/rlpxcrypt.nim +++ b/eth_p2p/rlpxcrypt.nim @@ -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 =