hotfix: fix the selecting of the syncing protocol handlers

This commit is contained in:
Zahary Karadjov 2020-04-16 15:01:19 +03:00
parent 7b8d6ea61c
commit a4830976ab
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609
2 changed files with 20 additions and 8 deletions

View File

@ -549,7 +549,7 @@ proc implementSendProcBody(sendProc: SendProc) =
sendProc.useStandardBody(nil, nil, sendCallGenerator)
proc handleIncomingStream(network: Eth2Node, conn: Connection,
proc handleIncomingStream(network: Eth2Node, conn: Connection, useSnappy: bool,
MsgType, Format: distinct type) {.async, gcsafe.} =
mixin callUserHandler, RecType
const msgName = typetraits.name(MsgType)
@ -567,14 +567,16 @@ proc handleIncomingStream(network: Eth2Node, conn: Connection,
handleIncomingPeer(peer)
try:
let
deadline = sleepAsync RESP_TIMEOUT
msgBytes = await readMsgBytes(conn, false, deadline)
let deadline = sleepAsync RESP_TIMEOUT
var msgBytes = await readMsgBytes(conn, false, deadline)
if msgBytes.len == 0:
await sendErrorResponse(peer, conn, ServerError, readTimeoutErrorMsg)
return
if useSnappy:
msgBytes = framingFormatUncompress(msgBytes)
type MsgRec = RecType(MsgType)
var msg: MsgRec
try:
@ -831,13 +833,23 @@ proc p2pProtocolBackendImpl*(p: P2PProtocol): Backend =
`userHandlerCall`
proc `protocolMounterName`(`networkVar`: `Eth2Node`) =
proc thunk(`streamVar`: `Connection`,
proc sszThunk(`streamVar`: `Connection`,
proto: string): Future[void] {.gcsafe.} =
return handleIncomingStream(`networkVar`, `streamVar`,
return handleIncomingStream(`networkVar`, `streamVar`, false,
`MsgStrongRecName`, `Format`)
mount `networkVar`.switch,
LPProtocol(codec: `codecNameLit`, handler: thunk)
LPProtocol(codec: `codecNameLit` & "ssz",
handler: sszThunk)
proc snappyThunk(`streamVar`: `Connection`,
proto: string): Future[void] {.gcsafe.} =
return handleIncomingStream(`networkVar`, `streamVar`, true,
`MsgStrongRecName`, `Format`)
mount `networkVar`.switch,
LPProtocol(codec: `codecNameLit` & "ssz_snappy",
handler: snappyThunk)
mounter = protocolMounterName
else:

2
vendor/nim-snappy vendored

@ -1 +1 @@
Subproject commit 80cff583e33a026ac944ca3b6ea9ed95a3fc7e0e
Subproject commit b1726ab7e7bc28464ed5151c4327ed2381830116