Fixed rlp related compile errors

This commit is contained in:
Yuriy Glukhov 2018-09-26 15:59:00 +03:00
parent d808d9dc1a
commit ff5e69fd53
4 changed files with 7 additions and 7 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: seq[byte]) {.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

@ -68,14 +68,14 @@ proc append(w: var RlpWriter, p: Port) {.inline.} = w.append(p.int)
proc append(w: var RlpWriter, pk: PublicKey) {.inline.} = w.append(pk.getRaw())
proc append(w: var RlpWriter, h: MDigest[256]) {.inline.} = w.append(h.data)
proc pack(cmdId: CommandId, payload: BytesRange, pk: PrivateKey): Bytes =
proc pack(cmdId: CommandId, payload: seq[byte], pk: PrivateKey): Bytes =
## Create and sign a UDP message to be sent to a remote node.
##
## See https://github.com/ethereum/devp2p/blob/master/rlpx.md#node-discovery for information on
## how UDP packets are structured.
# TODO: There is a lot of unneeded allocations here
let encodedData = @[cmdId.byte] & payload.toSeq()
let encodedData = @[cmdId.byte] & payload
let signature = @(pk.signMessage(encodedData).getRaw())
let msgHash = keccak256.digest(signature & encodedData)
result = @(msgHash.data) & signature & encodedData

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 =