diff --git a/libp2p/nameresolving/dnsresolver.nim b/libp2p/nameresolving/dnsresolver.nim index b384ede4c4..699ff1f526 100644 --- a/libp2p/nameresolving/dnsresolver.nim +++ b/libp2p/nameresolving/dnsresolver.nim @@ -52,8 +52,9 @@ proc questionToBuf(address: string, kind: QKind): seq[byte] = proc getDnsResponse( dnsServer: TransportAddress, address: string, kind: QKind -): Future[Response] {.async: (raises: [ - CancelledError, IOError, OSError, TransportError, ValueError]).} = +): Future[Response] {. + async: (raises: [CancelledError, IOError, OSError, TransportError, ValueError]) +.} = var sendBuf = questionToBuf(address, kind) if sendBuf.len == 0: @@ -98,18 +99,18 @@ proc getDnsResponse( await sock.closeWait() method resolveIp*( - self: DnsResolver, - address: string, - port: Port, - domain: Domain = Domain.AF_UNSPEC + self: DnsResolver, address: string, port: Port, domain: Domain = Domain.AF_UNSPEC ): Future[seq[TransportAddress]] {. - async: (raises: [CancelledError, TransportAddressError]).} = - trace "Resolving IP using DNS", - address, servers = self.nameServers.mapIt($it), domain + async: (raises: [CancelledError, TransportAddressError]) +.} = + trace "Resolving IP using DNS", address, servers = self.nameServers.mapIt($it), domain for _ in 0 ..< self.nameServers.len: let server = self.nameServers[0] - var responseFutures: seq[Future[Response].Raising([ - CancelledError, IOError, OSError, TransportError, ValueError])] + var responseFutures: seq[ + Future[Response].Raising( + [CancelledError, IOError, OSError, TransportError, ValueError] + ) + ] if domain == Domain.AF_INET or domain == Domain.AF_UNSPEC: responseFutures.add(getDnsResponse(server, address, A)) @@ -128,6 +129,7 @@ method resolveIp*( info "Failed to query DNS", address, error = e.msg resolveFailed = true break + for fut in responseFutures: try: let resp = await fut @@ -172,6 +174,7 @@ method resolveTxt*( self.nameServers.add(self.nameServers[0]) self.nameServers.delete(0) continue + try: let response = await getDnsResponse(server, address, TXT) trace "Got TXT response", diff --git a/libp2p/nameresolving/mockresolver.nim b/libp2p/nameresolving/mockresolver.nim index 54a31a0a27..418678a090 100644 --- a/libp2p/nameresolving/mockresolver.nim +++ b/libp2p/nameresolving/mockresolver.nim @@ -24,12 +24,10 @@ type MockResolver* = ref object of NameResolver ipResponses*: Table[(string, bool), seq[string]] method resolveIp*( - self: MockResolver, - address: string, - port: Port, - domain: Domain = Domain.AF_UNSPEC + self: MockResolver, address: string, port: Port, domain: Domain = Domain.AF_UNSPEC ): Future[seq[TransportAddress]] {. - async: (raises: [CancelledError, TransportAddressError]).} = + async: (raises: [CancelledError, TransportAddressError]) +.} = var res: seq[TransportAddress] if domain == Domain.AF_INET or domain == Domain.AF_UNSPEC: diff --git a/libp2p/nameresolving/nameresolver.nim b/libp2p/nameresolving/nameresolver.nim index ead09691e9..e6d0320da5 100644 --- a/libp2p/nameresolving/nameresolver.nim +++ b/libp2p/nameresolving/nameresolver.nim @@ -25,12 +25,10 @@ method resolveTxt*( raiseAssert "Not implemented!" method resolveIp*( - self: NameResolver, - address: string, - port: Port, - domain: Domain = Domain.AF_UNSPEC + self: NameResolver, address: string, port: Port, domain: Domain = Domain.AF_UNSPEC ): Future[seq[TransportAddress]] {. - async: (raises: [CancelledError, TransportAddressError]), base.} = + async: (raises: [CancelledError, TransportAddressError]), base +.} = ## Resolve the specified address raiseAssert "Not implemented!" @@ -45,12 +43,10 @@ proc getHostname*(ma: MultiAddress): string = "" proc resolveOneAddress( - self: NameResolver, - ma: MultiAddress, - domain: Domain = Domain.AF_UNSPEC, - prefix = "" + self: NameResolver, ma: MultiAddress, domain: Domain = Domain.AF_UNSPEC, prefix = "" ): Future[seq[MultiAddress]] {. - async: (raises: [CancelledError, MaError, TransportAddressError]).} = + async: (raises: [CancelledError, MaError, TransportAddressError]) +.} = # Resolve a single address let portPart = ma[1].valueOr: raise maErr error @@ -80,7 +76,8 @@ proc resolveOneAddress( proc resolveDnsAddr*( self: NameResolver, ma: MultiAddress, depth: int = 0 ): Future[seq[MultiAddress]] {. - async: (raises: [CancelledError, MaError, TransportAddressError]).} = + async: (raises: [CancelledError, MaError, TransportAddressError]) +.} = if not DNSADDR.matchPartial(ma): return @[ma] @@ -127,7 +124,8 @@ proc resolveDnsAddr*( proc resolveMAddress*( self: NameResolver, address: MultiAddress ): Future[seq[MultiAddress]] {. - async: (raises: [CancelledError, MaError, TransportAddressError]).} = + async: (raises: [CancelledError, MaError, TransportAddressError]) +.} = var res = initOrderedSet[MultiAddress]() if not DNS.matchPartial(address): res.incl(address)