mirror of https://github.com/vacp2p/nim-libp2p.git
throw exception if handshake failed
This commit is contained in:
parent
f4e9bc8bfb
commit
4faf35c52c
|
@ -38,6 +38,12 @@ type
|
||||||
na: string
|
na: string
|
||||||
ls: string
|
ls: string
|
||||||
|
|
||||||
|
MultistreamHandshakeException* = object of CatchableError
|
||||||
|
|
||||||
|
proc newMultistreamHandshakeException*(): ref Exception {.inline.} =
|
||||||
|
result = newException(MultistreamHandshakeException,
|
||||||
|
"could not perform multistream handshake")
|
||||||
|
|
||||||
proc newMultistream*(): MultistreamSelect =
|
proc newMultistream*(): MultistreamSelect =
|
||||||
new result
|
new result
|
||||||
result.codec = MSCodec
|
result.codec = MSCodec
|
||||||
|
@ -58,8 +64,8 @@ proc select*(m: MultistreamSelect,
|
||||||
result = cast[string]((await conn.readLp())) # read ms header
|
result = cast[string]((await conn.readLp())) # read ms header
|
||||||
result.removeSuffix("\n")
|
result.removeSuffix("\n")
|
||||||
if result != Codec:
|
if result != Codec:
|
||||||
trace "handshake failed", codec = result.toHex()
|
error "handshake failed", codec = result.toHex()
|
||||||
return ""
|
raise newMultistreamHandshakeException()
|
||||||
|
|
||||||
if proto.len() == 0: # no protocols, must be a handshake call
|
if proto.len() == 0: # no protocols, must be a handshake call
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue