diff --git a/beacon_chain/eth2_network.nim b/beacon_chain/eth2_network.nim index 80c8d9bf9..1a6547201 100644 --- a/beacon_chain/eth2_network.nim +++ b/beacon_chain/eth2_network.nim @@ -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: diff --git a/vendor/nim-snappy b/vendor/nim-snappy index 80cff583e..b1726ab7e 160000 --- a/vendor/nim-snappy +++ b/vendor/nim-snappy @@ -1 +1 @@ -Subproject commit 80cff583e33a026ac944ca3b6ea9ed95a3fc7e0e +Subproject commit b1726ab7e7bc28464ed5151c4327ed2381830116