chore: handle currupted message in rendezvous

This commit is contained in:
Václav Pavlín 2023-06-01 16:33:11 +02:00
parent 67102873ba
commit 73cba0c33a
No known key found for this signature in database
GPG Key ID: 66AADA19AAF53527
1 changed files with 23 additions and 4 deletions

View File

@ -457,12 +457,19 @@ proc advertisePeer(rdv: RendezVous,
await conn.writeLp(msg)
let
buf = await conn.readLp(4096)
msgRecv = Message.decode(buf).get()
decodedMsg = Message.decode(buf)
if decodedMsg.isNone():
trace "Failed to decode message", peer
return
let msgRecv = decodedMsg.get()
if msgRecv.msgType != MessageType.RegisterResponse:
trace "Unexpected register response", peer, msgType = msgRecv.msgType
elif msgRecv.registerResponse.isNone() or
msgRecv.registerResponse.get().status != ResponseStatus.Ok:
msgRecv.registerResponse.get().status != ResponseStatus.Ok:
trace "Refuse to register", peer, response = msgRecv.registerResponse
except CatchableError as exc:
trace "exception in the advertise", error = exc.msg
finally:
@ -530,7 +537,13 @@ proc request*(rdv: RendezVous,
discover: some(d))).buffer)
let
buf = await conn.readLp(65536)
msgRcv = Message.decode(buf).get()
decodedMsg = Message.decode(buf)
if decodedMsg.isNone():
trace "Failed to decode message", peer
return
let msgRcv = decodedMsg.get()
if msgRcv.msgType != MessageType.DiscoverResponse or
msgRcv.discoverResponse.isNone():
debug "Unexpected discover response", msgType = msgRcv.msgType
@ -627,7 +640,13 @@ proc new*(T: typedesc[RendezVous],
try:
let
buf = await conn.readLp(4096)
msg = Message.decode(buf).get()
decodedMsg = Message.decode(buf)
if decodedMsg.isNone():
trace "Failed to decode message"
return
let msg = decodedMsg.get()
case msg.msgType:
of MessageType.Register: await rdv.register(conn, msg.register.get())
of MessageType.RegisterResponse: