Handle dial error correctly (#830)

This commit is contained in:
diegomrsantos 2022-12-22 17:33:59 +01:00 committed by GitHub
parent 63e1872516
commit d521c57b82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View File

@ -211,7 +211,8 @@ method dialMe*(a: Autonat, pid: PeerId, addrs: seq[MultiAddress] = newSeq[MultiA
if autonatMsg.isNone() or if autonatMsg.isNone() or
autonatMsg.get().msgType != DialResponse or autonatMsg.get().msgType != DialResponse or
autonatMsg.get().response.isNone() or autonatMsg.get().response.isNone() or
autonatMsg.get().response.get().ma.isNone(): (autonatMsg.get().response.get().status == Ok and
autonatMsg.get().response.get().ma.isNone()):
raise newException(AutonatError, "Unexpected response") raise newException(AutonatError, "Unexpected response")
else: else:
autonatMsg.get().response.get() autonatMsg.get().response.get()

View File

@ -34,7 +34,7 @@ suite "Autonat":
teardown: teardown:
checkTrackers() checkTrackers()
asyncTest "Simple test": asyncTest "dialMe returns public address":
let let
src = newStandardSwitch() src = newStandardSwitch()
dst = createAutonatSwitch() dst = createAutonatSwitch()
@ -43,9 +43,10 @@ suite "Autonat":
await src.connect(dst.peerInfo.peerId, dst.peerInfo.addrs) await src.connect(dst.peerInfo.peerId, dst.peerInfo.addrs)
let ma = await Autonat.new(src).dialMe(dst.peerInfo.peerId, dst.peerInfo.addrs) let ma = await Autonat.new(src).dialMe(dst.peerInfo.peerId, dst.peerInfo.addrs)
check ma in src.peerInfo.addrs
await allFutures(src.stop(), dst.stop()) await allFutures(src.stop(), dst.stop())
asyncTest "Simple failed test": asyncTest "dialMe handles dial error msg":
let let
src = newStandardSwitch() src = newStandardSwitch()
dst = makeAutonatServicePrivate() dst = makeAutonatServicePrivate()
@ -54,6 +55,6 @@ suite "Autonat":
await dst.start() await dst.start()
await src.connect(dst.peerInfo.peerId, dst.peerInfo.addrs) await src.connect(dst.peerInfo.peerId, dst.peerInfo.addrs)
expect AutonatError: expect AutonatUnreachableError:
discard await Autonat.new(src).dialMe(dst.peerInfo.peerId, dst.peerInfo.addrs) discard await Autonat.new(src).dialMe(dst.peerInfo.peerId, dst.peerInfo.addrs)
await allFutures(src.stop(), dst.stop()) await allFutures(src.stop(), dst.stop())