async def handleRequest(self, request): rUrl = request.requestUrl() if not rUrl.isValid(): return self.urlInvalid(request) domain = rUrl.host() uPath = rUrl.path() if not domain or len(domain) > 512 or not domainValid(domain): log.info('EthDNS: invalid domain request') return self.urlInvalid(request) pathRaw = await self.ethResolver.resolveEnsDomain(domain) path = IPFSPath(pathRaw, autoCidConv=True) if path and path.valid: await ensDomainResolved.emit(domain, path) sPath = path.child(uPath) if uPath else path log.debug('EthDNS: {domain} resolved to {res}'.format( domain=domain, res=sPath.ipfsUrl)) return request.redirect(QUrl(sPath.dwebUrl)) else: log.info('EthDNS: {domain} resolve failed'.format(domain=domain)) return self.urlNotFound(request)
async def urlProxiedPath(self, rUrl): domain = rUrl.host() uPath = rUrl.path() if not domain or len(domain) > 512 or not domainValid(domain): return None pathRaw = await self.ethResolver.resolveEnsDomain(domain) path = IPFSPath(pathRaw, autoCidConv=True) if path and path.valid: return path.child(uPath) if uPath else path
async def handleRequest(self, ipfsop, request, uid): rUrl = request.requestUrl() domain = rUrl.host() if not domain or len(domain) > 512 or not domainValid(domain): logUser.info('EthDNS: invalid domain request') return self.urlInvalid(request) path = await self.urlProxiedPath(rUrl) if path and path.valid: return await self.fetchFromPath(ipfsop, request, path, uid) else: logUser.info( 'EthDNS: {domain} resolve failed'.format(domain=domain)) return self.urlNotFound(request)
async def handleRequest(self, ipfsop, request, uid): rUrl = request.requestUrl() scheme = rUrl.scheme() host = rUrl.host() if not host: return self.urlInvalid(request) if scheme == SCHEME_IPFS: # hostname = base32-encoded CID or FQDN # # We keep a list (deque) of CIDs that have been validated. # If you hit a page which references a lot of other resources # for instance, this should be faster than regexp if domainValid(host): ipfsPathS = joinIpns(host) + rUrl.path() else: if host not in self.validCids: if not ipfsRegSearchCid32(host): return self.urlInvalid(request) self.validCids.append(host) ipfsPathS = joinIpfs(host) + rUrl.path() elif scheme == SCHEME_IPNS: ipfsPathS = joinIpns(host) + rUrl.path() else: return self.urlInvalid(request) ipfsPath = IPFSPath(ipfsPathS) if not ipfsPath.valid: return self.urlInvalid(request) try: with async_timeout.timeout(self.requestTimeout): return await self.fetchFromPath(ipfsop, request, ipfsPath, uid) except asyncio.TimeoutError: return self.reqFailed(request) except Exception as err: # Any other error traceback.print_exc() self.debug(f'Unknown error while serving request: {err}') return self.reqFailed(request)