Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle dial error correctly #830

Merged
merged 2 commits into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion libp2p/protocols/connectivity/autonat.nim
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ method dialMe*(a: Autonat, pid: PeerId, addrs: seq[MultiAddress] = newSeq[MultiA
if autonatMsg.isNone() or
autonatMsg.get().msgType != DialResponse 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")
else:
autonatMsg.get().response.get()
Expand Down
7 changes: 4 additions & 3 deletions tests/testautonat.nim
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ suite "Autonat":
teardown:
checkTrackers()

asyncTest "Simple test":
asyncTest "dialMe returns public address":
let
src = newStandardSwitch()
dst = createAutonatSwitch()
Expand All @@ -43,9 +43,10 @@ suite "Autonat":

await src.connect(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())

asyncTest "Simple failed test":
asyncTest "dialMe handles dial error msg":
let
src = newStandardSwitch()
dst = makeAutonatServicePrivate()
Expand All @@ -54,6 +55,6 @@ suite "Autonat":
await dst.start()

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)
await allFutures(src.stop(), dst.stop())