Autonat dials dns addrs (#856)
This commit is contained in:
parent
e68186373b
commit
f89bd0c77c
|
@ -462,6 +462,7 @@ const
|
||||||
IP6* = mapEq("ip6")
|
IP6* = mapEq("ip6")
|
||||||
DNS* = mapOr(DNSANY, DNS4, DNS6, DNSADDR)
|
DNS* = mapOr(DNSANY, DNS4, DNS6, DNSADDR)
|
||||||
IP* = mapOr(IP4, IP6)
|
IP* = mapOr(IP4, IP6)
|
||||||
|
DNS_OR_IP* = mapOr(DNS, IP)
|
||||||
TCP* = mapOr(mapAnd(DNS, mapEq("tcp")), mapAnd(IP, mapEq("tcp")))
|
TCP* = mapOr(mapAnd(DNS, mapEq("tcp")), mapAnd(IP, mapEq("tcp")))
|
||||||
UDP* = mapOr(mapAnd(DNS, mapEq("udp")), mapAnd(IP, mapEq("udp")))
|
UDP* = mapOr(mapAnd(DNS, mapEq("udp")), mapAnd(IP, mapEq("udp")))
|
||||||
UTP* = mapAnd(UDP, mapEq("utp"))
|
UTP* = mapAnd(UDP, mapEq("utp"))
|
||||||
|
|
|
@ -55,7 +55,7 @@ method dialMe*(self: AutonatClient, switch: Switch, pid: PeerId, addrs: seq[Mult
|
||||||
else:
|
else:
|
||||||
await switch.dial(pid, addrs, AutonatCodec)
|
await switch.dial(pid, addrs, AutonatCodec)
|
||||||
except CatchableError as err:
|
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
|
# To bypass maxConnectionsPerPeer
|
||||||
let incomingConnection = switch.connManager.expectConnection(pid)
|
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():
|
if isRelayed.isErr() or isRelayed.get():
|
||||||
continue
|
continue
|
||||||
let maFirst = ma[0]
|
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
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -7,18 +7,24 @@ import
|
||||||
builders,
|
builders,
|
||||||
protocols/connectivity/autonat/client,
|
protocols/connectivity/autonat/client,
|
||||||
protocols/connectivity/autonat/server,
|
protocols/connectivity/autonat/server,
|
||||||
|
nameresolving/nameresolver,
|
||||||
|
nameresolving/mockresolver,
|
||||||
],
|
],
|
||||||
./helpers
|
./helpers
|
||||||
|
|
||||||
proc createAutonatSwitch(): Switch =
|
proc createAutonatSwitch(nameResolver: NameResolver = nil): Switch =
|
||||||
result = SwitchBuilder.new()
|
var builder = SwitchBuilder.new()
|
||||||
.withRng(newRng())
|
.withRng(newRng())
|
||||||
.withAddresses(@[ MultiAddress.init("/ip4/0.0.0.0/tcp/0").tryGet() ])
|
.withAddresses(@[ MultiAddress.init("/ip4/0.0.0.0/tcp/0").tryGet() ])
|
||||||
.withTcpTransport()
|
.withTcpTransport()
|
||||||
.withMplex()
|
.withMplex()
|
||||||
.withAutonat()
|
.withAutonat()
|
||||||
.withNoise()
|
.withNoise()
|
||||||
.build()
|
|
||||||
|
if nameResolver != nil:
|
||||||
|
builder = builder.withNameResolver(nameResolver)
|
||||||
|
|
||||||
|
return builder.build()
|
||||||
|
|
||||||
proc makeAutonatServicePrivate(): Switch =
|
proc makeAutonatServicePrivate(): Switch =
|
||||||
var autonatProtocol = new LPProtocol
|
var autonatProtocol = new LPProtocol
|
||||||
|
@ -88,3 +94,24 @@ suite "Autonat":
|
||||||
response.text.get() == "Dial timeout"
|
response.text.get() == "Dial timeout"
|
||||||
response.ma.isNone()
|
response.ma.isNone()
|
||||||
await allFutures(doesNothingListener.stop(), src.stop(), dst.stop())
|
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