From 5868afe341d4d454d1048674afb9736141d4daaa Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Wed, 18 Mar 2020 20:48:36 +0200 Subject: [PATCH] Restore compilation with -d:p2pdump --- beacon_chain/libp2p_backend.nim | 6 +++++- beacon_chain/libp2p_backends_common.nim | 9 +++++---- beacon_chain/libp2p_daemon_backend.nim | 7 ++++++- vendor/nim-eth | 2 +- vendor/nim-json-serialization | 2 +- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/beacon_chain/libp2p_backend.nim b/beacon_chain/libp2p_backend.nim index 069626986..b9f320be8 100644 --- a/beacon_chain/libp2p_backend.nim +++ b/beacon_chain/libp2p_backend.nim @@ -107,6 +107,9 @@ const template `$`*(peer: Peer): string = id(peer.info) chronicles.formatIt(Peer): $it +template remote*(peer: Peer): untyped = + peer.info.peerId + # TODO: This exists only as a compatibility layer between the daemon # APIs and the native LibP2P ones. It won't be necessary once the # daemon is removed. @@ -351,6 +354,7 @@ proc p2pProtocolBackendImpl*(p: P2PProtocol): Backend = msgName = $msg.ident msgNameLit = newLit msgName MsgRecName = msg.recName + MsgStrongRecName = msg.strongRecName codecNameLit = getRequestProtoName(msg.procDef) if msg.procDef.body.kind != nnkEmpty and msg.kind == msgRequest: @@ -388,7 +392,7 @@ proc p2pProtocolBackendImpl*(p: P2PProtocol): Backend = proc thunk(`streamVar`: `P2PStream`, proto: string): Future[void] {.gcsafe.} = return handleIncomingStream(`networkVar`, `streamVar`, - `MsgRecName`, `Format`) + `MsgStrongRecName`, `Format`) mount `networkVar`.switch, LPProtocol(codec: `codecNameLit`, handler: thunk) diff --git a/beacon_chain/libp2p_backends_common.nim b/beacon_chain/libp2p_backends_common.nim index 7de5ab87a..500ab194f 100644 --- a/beacon_chain/libp2p_backends_common.nim +++ b/beacon_chain/libp2p_backends_common.nim @@ -358,7 +358,7 @@ proc implementSendProcBody(sendProc: SendProc) = proc handleIncomingStream(network: Eth2Node, stream: P2PStream, MsgType, Format: distinct type) {.async, gcsafe.} = - mixin callUserHandler + mixin callUserHandler, RecType const msgName = typetraits.name(MsgType) ## Uncomment this to enable tracing on all incoming requests @@ -384,9 +384,10 @@ proc handleIncomingStream(network: Eth2Node, stream: P2PStream, await sendErrorResponse(peer, stream, ServerError, readTimeoutErrorMsg) return - var msg: MsgType + type MsgRec = RecType(MsgType) + var msg: MsgRec try: - msg = decode(Format, msgBytes, MsgType) + msg = decode(Format, msgBytes, MsgRec) except SerializationError as err: await sendErrorResponse(peer, stream, err, msgName, msgBytes) return @@ -399,7 +400,7 @@ proc handleIncomingStream(network: Eth2Node, stream: P2PStream, raise err try: - logReceivedMsg(peer, msg) + logReceivedMsg(peer, MsgType(msg)) await callUserHandler(peer, stream, msg) except CatchableError as err: await sendErrorResponse(peer, stream, ServerError, err.msg) diff --git a/beacon_chain/libp2p_daemon_backend.nim b/beacon_chain/libp2p_daemon_backend.nim index 2ce39c9ab..4d57d927a 100644 --- a/beacon_chain/libp2p_daemon_backend.nim +++ b/beacon_chain/libp2p_daemon_backend.nim @@ -101,6 +101,10 @@ template openStream(node: Eth2Node, peer: Peer, protocolId: string): untyped = proc init*(T: type Peer, network: Eth2Node, id: PeerID): Peer {.gcsafe.} +template remote*(peer: Peer): untyped = + # TODO: Can we get a proper address here? + peer.id + proc getPeer*(node: Eth2Node, peerId: PeerID): Peer {.gcsafe.} = result = node.peers.getOrDefault(peerId) if result == nil: @@ -211,6 +215,7 @@ proc p2pProtocolBackendImpl*(p: P2PProtocol): Backend = msgName = $msg.ident msgNameLit = newLit msgName MsgRecName = msg.recName + MsgStrongRecName = msg.strongRecName if msg.procDef.body.kind != nnkEmpty and msg.kind == msgRequest: # Request procs need an extra param - the stream where the response @@ -235,7 +240,7 @@ proc p2pProtocolBackendImpl*(p: P2PProtocol): Backend = proc `thunkName`(`daemonVar`: `DaemonAPI`, `streamVar`: `P2PStream`): Future[void] {.gcsafe.} = return handleIncomingStream(`Eth2Node`(`daemonVar`.userData), `streamVar`, - `MsgRecName`, `Format`) + `MsgStrongRecName`, `Format`) else: thunkName = newNilLit() diff --git a/vendor/nim-eth b/vendor/nim-eth index b3b585400..9c442bf65 160000 --- a/vendor/nim-eth +++ b/vendor/nim-eth @@ -1 +1 @@ -Subproject commit b3b5854003ebb10b99efa451d4391ef050f5951e +Subproject commit 9c442bf65b52a4c857cc6e51efe901352e8b6ebf diff --git a/vendor/nim-json-serialization b/vendor/nim-json-serialization index ab53e009b..6350b72b5 160000 --- a/vendor/nim-json-serialization +++ b/vendor/nim-json-serialization @@ -1 +1 @@ -Subproject commit ab53e009b980f93283ada1f4e496e1785cfc5496 +Subproject commit 6350b72b5eda69f7ccfa57a94fd420509dbf6f49