Autonat dials dns addrs (#856)
This commit is contained in:
parent
e68186373b
commit
f89bd0c77c
|
@ -462,6 +462,7 @@ const
|
|||
IP6* = mapEq("ip6")
|
||||
DNS* = mapOr(DNSANY, DNS4, DNS6, DNSADDR)
|
||||
IP* = mapOr(IP4, IP6)
|
||||
DNS_OR_IP* = mapOr(DNS, IP)
|
||||
TCP* = mapOr(mapAnd(DNS, mapEq("tcp")), mapAnd(IP, mapEq("tcp")))
|
||||
UDP* = mapOr(mapAnd(DNS, mapEq("udp")), mapAnd(IP, mapEq("udp")))
|
||||
UTP* = mapAnd(UDP, mapEq("utp"))
|
||||
|
|
|
@ -55,7 +55,7 @@ method dialMe*(self: AutonatClient, switch: Switch, pid: PeerId, addrs: seq[Mult
|
|||
else:
|
||||
await switch.dial(pid, addrs, AutonatCodec)
|
||||
except CatchableError as err:
|
||||
raise newException(AutonatError, "Unexpected error when dialling", err)
|
||||
raise newException(AutonatError, "Unexpected error when dialling: " & err.msg, err)
|
||||
|
||||
# To bypass maxConnectionsPerPeer
|
||||
let incomingConnection = switch.connManager.expectConnection(pid)
|
||||
|
|
|
@ -117,7 +117,7 @@ proc handleDial(autonat: Autonat, conn: Connection, msg: AutonatMsg): Future[voi
|
|||
if isRelayed.isErr() or isRelayed.get():
|
||||
continue
|
||||
let maFirst = ma[0]
|
||||
if maFirst.isErr() or not IP.match(maFirst.get()):
|
||||
if maFirst.isErr() or not DNS_OR_IP.match(maFirst.get()):
|
||||
continue
|
||||
|
||||
try:
|
||||
|
|
|
@ -7,18 +7,24 @@ import
|
|||
builders,
|
||||
protocols/connectivity/autonat/client,
|
||||
protocols/connectivity/autonat/server,
|
||||
nameresolving/nameresolver,
|
||||
nameresolving/mockresolver,
|
||||
],
|
||||
./helpers
|
||||
|
||||
proc createAutonatSwitch(): Switch =
|
||||
result = SwitchBuilder.new()
|
||||
proc createAutonatSwitch(nameResolver: NameResolver = nil): Switch =
|
||||
var builder = SwitchBuilder.new()
|
||||
.withRng(newRng())
|
||||
.withAddresses(@[ MultiAddress.init("/ip4/0.0.0.0/tcp/0").tryGet() ])
|
||||
.withTcpTransport()
|
||||
.withMplex()
|
||||
.withAutonat()
|
||||
.withNoise()
|
||||
.build()
|
||||
|
||||
if nameResolver != nil:
|
||||
builder = builder.withNameResolver(nameResolver)
|
||||
|
||||
return builder.build()
|
||||
|
||||
proc makeAutonatServicePrivate(): Switch =
|
||||
var autonatProtocol = new LPProtocol
|
||||
|
@ -88,3 +94,24 @@ suite "Autonat":
|
|||
response.text.get() == "Dial timeout"
|
||||
response.ma.isNone()
|
||||
await allFutures(doesNothingListener.stop(), src.stop(), dst.stop())
|
||||
|
||||
asyncTest "dialMe dials dns and returns public address":
|
||||
let resolver = MockResolver.new()
|
||||
resolver.ipResponses[("localhost", false)] = @["127.0.0.1"]
|
||||
resolver.ipResponses[("localhost", true)] = @["::1"]
|
||||
|
||||
let
|
||||
src = newStandardSwitch()
|
||||
dst = createAutonatSwitch(nameResolver = resolver)
|
||||
|
||||
await src.start()
|
||||
await dst.start()
|
||||
|
||||
let testAddr = MultiAddress.init("/dns4/localhost/").tryGet() &
|
||||
dst.peerInfo.addrs[0][1].tryGet()
|
||||
|
||||
await src.connect(dst.peerInfo.peerId, dst.peerInfo.addrs)
|
||||
let ma = await AutonatClient.new().dialMe(src, dst.peerInfo.peerId, @[testAddr])
|
||||
|
||||
check ma in src.peerInfo.addrs
|
||||
await allFutures(src.stop(), dst.stop())
|
||||
|
|
Loading…
Reference in New Issue