Add relay notifications WIP

This commit is contained in:
kdeme 2023-04-28 22:30:26 +02:00
parent b1a99d5ea3
commit 89903c4524
No known key found for this signature in database
GPG Key ID: 4E8DD21420AF43F5
2 changed files with 18 additions and 1 deletions

View File

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

View File

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