No hard limit for auth msg, rlpx encoding corrected, cosmetics.
This commit is contained in:
parent
74f0b705f0
commit
98cf6376c8
|
@ -213,6 +213,9 @@ proc dispatchMsg(peer: Peer, msgId: int, msgData: var Rlp) =
|
|||
thunk(peer, msgData)
|
||||
|
||||
proc send(p: Peer, data: BytesRange) {.async.} =
|
||||
# var rlp = rlpFromBytes(data)
|
||||
# echo "sending: ", rlp.read(int)
|
||||
# echo "payload: ", rlp.inspect
|
||||
var cipherText = encryptMsg(data, p.secretsState)
|
||||
await p.socket.send(addr cipherText[0], cipherText.len)
|
||||
|
||||
|
@ -419,8 +422,10 @@ macro rlpxProtocol*(protoIdentifier: untyped,
|
|||
newEmptyNode(),
|
||||
msgTypeFields)
|
||||
|
||||
var paramCount = 0
|
||||
# implement sending proc
|
||||
for param, paramType in n.typedParams(skip = 1):
|
||||
inc paramCount
|
||||
appendParams.add quote do:
|
||||
`append`(`rlpWriter`, `param`)
|
||||
|
||||
|
@ -450,9 +455,11 @@ macro rlpxProtocol*(protoIdentifier: untyped,
|
|||
else:
|
||||
quote: `append`(`rlpWriter`, `nextId`)
|
||||
|
||||
let paramCountNode = newLit(paramCount)
|
||||
n.body = quote do:
|
||||
var `rlpWriter` = `initRlpWriter`()
|
||||
`writeMsgId`
|
||||
`rlpWriter`.startList(`paramCountNode`)
|
||||
`appendParams`
|
||||
return `send`(`peer`, `finish`(`rlpWriter`))
|
||||
|
||||
|
@ -536,20 +543,17 @@ proc rlpxConnect*(myKeys: KeyPair, listenPort: Port, remote: Node): Future[Peer]
|
|||
result.remote = remote
|
||||
await result.socket.connect($remote.node.address.ip, remote.node.address.tcpPort)
|
||||
|
||||
const encryptionEnabled = true
|
||||
|
||||
var handshake = newHandshake({Initiator})
|
||||
handshake.host = myKeys
|
||||
|
||||
var authMsg: array[AuthMessageMaxEIP8, byte]
|
||||
var authMsgLen = 0
|
||||
check authMessage(handshake, remote.node.pubkey, authMsg, authMsgLen,
|
||||
encrypt = encryptionEnabled)
|
||||
check authMessage(handshake, remote.node.pubkey, authMsg, authMsgLen)
|
||||
|
||||
await result.socket.send(addr authMsg[0], authMsgLen)
|
||||
|
||||
var ackMsg: array[AckMessageMaxEIP8, byte]
|
||||
let ackMsgLen = handshake.ackSize(encrypt = encryptionEnabled)
|
||||
let ackMsgLen = handshake.ackSize()
|
||||
await result.socket.fullRecvInto(addr ackMsg, ackMsgLen)
|
||||
|
||||
check handshake.decodeAckMessage(^ackMsg)
|
||||
|
@ -574,18 +578,15 @@ proc rlpxConnectIncoming*(myKeys: KeyPair, listenPort: Port, address: IpAddress,
|
|||
var handshake = newHandshake({Responder})
|
||||
handshake.host = myKeys
|
||||
|
||||
var authMsg: array[4086, byte]
|
||||
var authMsgLen = AuthMessageV4Length
|
||||
var authMsg = newSeqOfCap[byte](1024)
|
||||
authMsg.setLen(AuthMessageV4Length)
|
||||
|
||||
await s.fullRecvInto(addr authMsg[0], authMsgLen)
|
||||
var ret = handshake.decodeAuthMessage(^authMsg)
|
||||
await s.fullRecvInto(authMsg)
|
||||
var ret = handshake.decodeAuthMessage(authMsg)
|
||||
if ret == AuthStatus.IncompleteError: # Eip8 auth message is likely
|
||||
let expectedLen = expectedAuthMsgLenEip8(authMsg).int + 2
|
||||
if expectedLen > authMsg.len:
|
||||
raise newException(Exception, "Auth message too big: " & $authMsgLen)
|
||||
await s.fullRecvInto(addr authMsg[authMsgLen], expectedLen - authMsgLen)
|
||||
authMsgLen = expectedLen
|
||||
ret = handshake.decodeAuthMessage(^authMsg)
|
||||
authMsg.setLen(expectedAuthMsgLenEip8(authMsg).int + 2)
|
||||
await s.fullRecvInto(addr authMsg[AuthMessageV4Length], authMsg.len - AuthMessageV4Length)
|
||||
ret = handshake.decodeAuthMessage(authMsg)
|
||||
|
||||
check ret
|
||||
|
||||
|
@ -594,7 +595,7 @@ proc rlpxConnectIncoming*(myKeys: KeyPair, listenPort: Port, address: IpAddress,
|
|||
check handshake.ackMessage(ackMsg, ackMsgLen)
|
||||
|
||||
await s.send(addr ackMsg[0], ackMsgLen)
|
||||
initSecretState(handshake, ^authMsg, ^ackMsg, result)
|
||||
initSecretState(handshake, authMsg, ^ackMsg, result)
|
||||
|
||||
var response = await result.nextMsg(p2p.hello, discardOthers = true)
|
||||
discard result.hello(baseProtocolVersion, clienId,
|
||||
|
|
Loading…
Reference in New Issue