Restore compilation with -d:p2pdump

This commit is contained in:
Zahary Karadjov 2020-03-18 20:48:36 +02:00
parent 286d6e14da
commit 5868afe341
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609
5 changed files with 18 additions and 8 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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()

2
vendor/nim-eth vendored

@ -1 +1 @@
Subproject commit b3b5854003ebb10b99efa451d4391ef050f5951e
Subproject commit 9c442bf65b52a4c857cc6e51efe901352e8b6ebf

@ -1 +1 @@
Subproject commit ab53e009b980f93283ada1f4e496e1785cfc5496
Subproject commit 6350b72b5eda69f7ccfa57a94fd420509dbf6f49