示例#1
0
 def resolveHostName(self, receiver, hostName, portNumber=0):
     """
     Implement IHostnameResolver which always returns 127.0.0.1:31337
     """
     resolution = HostResolution(hostName)
     receiver.resolutionBegan(resolution)
     receiver.addressResolved(
         IPv4Address('TCP', '127.0.0.1',
                     31337 if portNumber == 0 else portNumber))
     receiver.resolutionComplete()
            def resolveHostName(
                _self,
                resolutionReceiver,
                hostName,
                portNumber=0,
                addressTypes=None,
                transportSemantics="TCP",
            ):

                resolution = HostResolution(hostName)
                resolutionReceiver.resolutionBegan(resolution)
                if hostName not in self.lookups:
                    raise DNSLookupError("OH NO")

                for i in self.lookups[hostName]:
                    resolutionReceiver.addressResolved(i[0]("TCP", i[1], portNumber))
                resolutionReceiver.resolutionComplete()
                return resolutionReceiver
示例#3
0
            def resolveHostName(
                _self,
                resolutionReceiver: IResolutionReceiver,
                hostName: str,
                portNumber: int = 0,
                addressTypes: Optional[Sequence[Type[IAddress]]] = None,
                transportSemantics: str = "TCP",
            ) -> IResolutionReceiver:

                resolution = HostResolution(hostName)
                resolutionReceiver.resolutionBegan(resolution)
                if hostName not in self.lookups:
                    raise DNSLookupError("OH NO")

                for i in self.lookups[hostName]:
                    resolutionReceiver.addressResolved(i[0]("TCP", i[1],
                                                            portNumber))
                resolutionReceiver.resolutionComplete()
                return resolutionReceiver
示例#4
0
    def resolveHostName(
        self,
        resolutionReceiver,
        hostName,
        portNumber=0,
        addressTypes=None,
        transportSemantics="TCP",
    ):

        cached_addresses = dnscache.get(hostName)
        if cached_addresses:
            resolutionReceiver.resolutionBegan(HostResolution(hostName))
            for address in cached_addresses:
                resolutionReceiver.addressResolved(address)
            resolutionReceiver.resolutionComplete()
            return resolutionReceiver

        @provider(IResolutionReceiver)
        class CachingResolutionReceiver:

            def __init__(self):
                self.addresses = []

            def resolutionBegan(self, resolution):
                resolutionReceiver.resolutionBegan(resolution)

            def addressResolved(self, address):
                resolutionReceiver.addressResolved(address)
                self.addresses.append(address)

            def resolutionComplete(self):
                resolutionReceiver.resolutionComplete()
                if self.addresses:
                    dnscache[hostName] = tuple(self.addresses)

        return self.original_resolver.resolveHostName(
            CachingResolutionReceiver(),
            hostName,
            portNumber,
            addressTypes,
            transportSemantics,
        )