Fixed rlp related compile errors
This commit is contained in:
parent
d808d9dc1a
commit
ff5e69fd53
|
@ -350,7 +350,7 @@ proc dispatchMsg(peer: Peer, msgId: int, msgData: var Rlp): Future[void] =
|
||||||
|
|
||||||
return thunk(peer, msgData)
|
return thunk(peer, msgData)
|
||||||
|
|
||||||
proc sendMsg(p: Peer, data: BytesRange) {.async.} =
|
proc sendMsg(p: Peer, data: seq[byte]) {.async.} =
|
||||||
# var rlp = rlpFromBytes(data)
|
# var rlp = rlpFromBytes(data)
|
||||||
# echo "sending: ", rlp.read(int)
|
# echo "sending: ", rlp.read(int)
|
||||||
# echo "payload: ", rlp.inspect
|
# echo "payload: ", rlp.inspect
|
||||||
|
|
|
@ -189,7 +189,7 @@ proc authMessageEIP8(h: var Handshake,
|
||||||
int(padsize))) != int(padsize):
|
int(padsize))) != int(padsize):
|
||||||
return(RandomError)
|
return(RandomError)
|
||||||
if encrypt:
|
if encrypt:
|
||||||
copyMem(addr buffer[0], payload.baseAddr, len(payload))
|
copyMem(addr buffer[0], addr payload[0], len(payload))
|
||||||
if len(output) < fullsize:
|
if len(output) < fullsize:
|
||||||
return(BufferOverrun)
|
return(BufferOverrun)
|
||||||
bigEndian16(addr output, addr wosize)
|
bigEndian16(addr output, addr wosize)
|
||||||
|
@ -260,7 +260,7 @@ proc ackMessageEIP8(h: var Handshake,
|
||||||
if randomBytes(toa(buffer, PlainAckMessageEIP8Length,
|
if randomBytes(toa(buffer, PlainAckMessageEIP8Length,
|
||||||
int(padsize))) != int(padsize):
|
int(padsize))) != int(padsize):
|
||||||
return(RandomError)
|
return(RandomError)
|
||||||
copyMem(addr buffer[0], payload.baseAddr, len(payload))
|
copyMem(addr buffer[0], addr payload[0], len(payload))
|
||||||
if encrypt:
|
if encrypt:
|
||||||
if len(output) < fullsize:
|
if len(output) < fullsize:
|
||||||
return(BufferOverrun)
|
return(BufferOverrun)
|
||||||
|
|
|
@ -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, pk: PublicKey) {.inline.} = w.append(pk.getRaw())
|
||||||
proc append(w: var RlpWriter, h: MDigest[256]) {.inline.} = w.append(h.data)
|
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.
|
## 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
|
## See https://github.com/ethereum/devp2p/blob/master/rlpx.md#node-discovery for information on
|
||||||
## how UDP packets are structured.
|
## how UDP packets are structured.
|
||||||
|
|
||||||
# TODO: There is a lot of unneeded allocations here
|
# 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 signature = @(pk.signMessage(encodedData).getRaw())
|
||||||
let msgHash = keccak256.digest(signature & encodedData)
|
let msgHash = keccak256.digest(signature & encodedData)
|
||||||
result = @(msgHash.data) & signature & encodedData
|
result = @(msgHash.data) & signature & encodedData
|
||||||
|
|
|
@ -130,7 +130,7 @@ proc encrypt*(c: var SecretState, header: openarray[byte],
|
||||||
copyMem(addr output[frameMacPos], addr frameMac.data[0], RlpHeaderLength)
|
copyMem(addr output[frameMacPos], addr frameMac.data[0], RlpHeaderLength)
|
||||||
result = Success
|
result = Success
|
||||||
|
|
||||||
proc encryptMsg*(msg: BytesRange, secrets: var SecretState): seq[byte] =
|
proc encryptMsg*(msg: openarray[byte], secrets: var SecretState): seq[byte] =
|
||||||
var header: RlpxHeader
|
var header: RlpxHeader
|
||||||
|
|
||||||
if uint32(msg.len) > maxUInt24:
|
if uint32(msg.len) > maxUInt24:
|
||||||
|
@ -144,7 +144,7 @@ proc encryptMsg*(msg: BytesRange, secrets: var SecretState): seq[byte] =
|
||||||
# XXX:
|
# XXX:
|
||||||
# This would be safer if we use a thread-local sequ for the temporary buffer
|
# This would be safer if we use a thread-local sequ for the temporary buffer
|
||||||
result = newSeq[byte](encryptedLength(msg.len))
|
result = newSeq[byte](encryptedLength(msg.len))
|
||||||
let s = encrypt(secrets, header, msg.toOpenArray, result)
|
let s = encrypt(secrets, header, msg, result)
|
||||||
assert s == Success
|
assert s == Success
|
||||||
|
|
||||||
proc getBodySize*(a: RlpxHeader): int =
|
proc getBodySize*(a: RlpxHeader): int =
|
||||||
|
|
Loading…
Reference in New Issue