From 89903c452425db8ff006e4b93769577e719b4266 Mon Sep 17 00:00:00 2001 From: kdeme Date: Fri, 28 Apr 2023 22:30:26 +0200 Subject: [PATCH] Add relay notifications WIP --- eth/p2p/discoveryv5/messages.nim | 17 ++++++++++++++++- eth/p2p/discoveryv5/messages_encoding.nim | 2 ++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/eth/p2p/discoveryv5/messages.nim b/eth/p2p/discoveryv5/messages.nim index 5dfe3d8..6cf6869 100644 --- a/eth/p2p/discoveryv5/messages.nim +++ b/eth/p2p/discoveryv5/messages.nim @@ -13,7 +13,7 @@ import std/[hashes, net], - ./enr + "."/[enr, node] type MessageKind* = enum @@ -25,12 +25,16 @@ type unused = 0x00 # The supported message types + # Request & response ping = 0x01 pong = 0x02 findNode = 0x03 nodes = 0x04 talkReq = 0x05 talkResp = 0x06 + # Notifications + relayInit = 0x07 + relayMsg = 0x08 RequestId* = object id*: seq[byte] @@ -57,9 +61,20 @@ type TalkRespMessage* = object response*: seq[byte] + RelayInitNotification* = object + initiatorEnr*: Record + targetId*: NodeId + nonce*: array[12, byte] # TODO: is this ok? + + RelayMsgNotification* = object + initiatorEnr*: Record + nonce*: array[12, byte] + SomeMessage* = PingMessage or PongMessage or FindNodeMessage or NodesMessage or TalkReqMessage or TalkRespMessage + SomeNotification* = RelayInitNotification or RelayMsgNotification + Message* = object reqId*: RequestId case kind*: MessageKind diff --git a/eth/p2p/discoveryv5/messages_encoding.nim b/eth/p2p/discoveryv5/messages_encoding.nim index cb02ae4..04c3a16 100644 --- a/eth/p2p/discoveryv5/messages_encoding.nim +++ b/eth/p2p/discoveryv5/messages_encoding.nim @@ -106,6 +106,8 @@ func decodeMessage*(body: openArray[byte]): Result[Message, cstring] = of nodes: rlp.decode(message.nodes) of talkReq: rlp.decode(message.talkReq) of talkResp: rlp.decode(message.talkResp) + of relayInit: return err("To implement") + of relayMsg: return err("To implement") except RlpError, ValueError: return err("Invalid message encoding")