示例#1
0
 def test_idempotent(self):
     """
     Multiple calls to L{client.getResolver} return the same L{IResolver}
     implementation.
     """
     with AlternateReactor(Clock()):
         a = client.getResolver()
         b = client.getResolver()
     self.assertIs(a, b)
示例#2
0
 def test_idempotent(self):
     """
     Multiple calls to L{client.getResolver} return the same L{IResolver}
     implementation.
     """
     with AlternateReactor(Clock()):
         a = client.getResolver()
         b = client.getResolver()
     self.assertIs(a, b)
示例#3
0
 def test_interface(self):
     """
     L{client.getResolver} returns an object providing L{IResolver}.
     """
     with AlternateReactor(Clock()):
         resolver = client.getResolver()
     self.assertTrue(verifyObject(IResolver, resolver))
示例#4
0
def _initResolver():
    global DebugResolver
    if DebugResolver is None:
        if config.Scheduling.iSchedule.DNSDebug:
            DebugResolver = FakeBindAuthority(config.Scheduling.iSchedule.DNSDebug)
        else:
            DebugResolver = getResolver()
示例#5
0
 def test_interface(self):
     """
     L{client.getResolver} returns an object providing L{IResolver}.
     """
     with AlternateReactor(Clock()):
         resolver = client.getResolver()
     self.assertTrue(verifyObject(IResolver, resolver))
示例#6
0
def _initResolver():
    global DebugResolver
    if DebugResolver is None:
        if config.Scheduling.iSchedule.DNSDebug:
            DebugResolver = FakeBindAuthority(config.Scheduling.iSchedule.DNSDebug)
        else:
            DebugResolver = getResolver()
    def __init__(self, config):
        MumbleProtocol.__init__(self, username=config["username"], password=config["password"], tokens=config["tokens"])

        self.config = config
        self.dns = DNSClient.getResolver()

        # Session is to identify us from other users
        self.session = None
        # Channel is to save the requested channel ID
        self.channel = None
        # Saves the sessions of the users
        self.users = {}
示例#8
0
def reverseResolve(ip: MaybeIPAddress,
                   resolver: IResolver = None) -> Optional[List[str]]:
    """Using the specified IResolver, reverse-resolves the specifed `ip`.

    :return: a sorted list of resolved hostnames (which the specified IP
        address reverse-resolves to). If the DNS lookup appeared to succeed,
        but no hostnames were found, returns an empty list. If the DNS lookup
        timed out or an error occurred, returns None.
    """
    if resolver is None:
        resolver = getResolver()
    ip = IPAddress(ip)
    try:
        data = yield resolver.lookupPointer(ip.reverse_dns,
                                            timeout=REVERSE_RESOLVE_RETRIES)
        # I love the concise way in which I can ask the Twisted data structure
        # what the list of hostnames is. This is great.
        results = sorted(
            (rr.payload.name.name.decode("idna") for rr in data[0]),
            key=preferred_hostnames_sort_key)
    except AuthoritativeDomainError:
        # "Failed to reverse-resolve '%s': authoritative failure." % ip
        # This means the name didn't resolve, so return an empty list.
        return []
    except DomainError:
        # "Failed to reverse-resolve '%s': no records found." % ip
        # This means the name didn't resolve, so return an empty list.
        return []
    except DNSQueryTimeoutError:
        # "Failed to reverse-resolve '%s': timed out." % ip
        # Don't return an empty list since this implies a temporary failure.
        pass
    except ResolverError:
        # "Failed to reverse-resolve '%s': rejected by local resolver." % ip
        # Don't return an empty list since this could be temporary (unclear).
        pass
    else:
        return results
    return None
示例#9
0
    def makeService(self, options):
        reactor = self.reactor
        if reactor is None:
            from twisted.internet import reactor

        resolver = self.resolver
        if resolver is None:
            resolver = getResolver()

        with open(options.config) as infile:
            config = yaml.safe_load(infile)

        multiService = MultiService()

        for proxy in config['proxies']:
            client = endpoints.clientFromString(reactor, str(proxy['client']))
            server = endpoints.serverFromString(reactor, str(proxy['server']))
            fac = ProxyFactory(client, resolver, proxy)
            service = StreamServerEndpointService(server, fac)
            service.setServiceParent(multiService)

        return multiService
示例#10
0
文件: utils.py 项目: calston/tensor
 def __init__(self):
     self.recs = {}
     
     self.resolver = client.getResolver()
示例#11
0
文件: conf.py 项目: glguy/twisted-opm
def makeService(options):
    from twisted.names.client import getResolver
    resolver = getResolver()
    # HACK: I want a better resolver than the threaded one, and lack a
    # non-terrible place to install it.
    from twisted.internet import reactor
    if not options['keep-resolver']:  # pragma: no cover
        reactor.installResolver(resolver)

    # HACK: warn about suboptimal reactor usage
    if not options['force-select']:  # pragma: no cover
        from twisted.internet import selectreactor
        if isinstance(reactor, selectreactor.SelectReactor):
            print('The select reactor is probably a bad idea.')
            print('Please use a reactor with better support for lots of fds.')
            print('(-r epoll for example)')
            print('You can bypass this check using --force-select')
            print()
            raise ValueError('unfortunate reactor choice')

    m = service.MultiService()

    checkerFactories = plugin.getCheckerFactories()

    default_user_reason = options['conf'].get('user-reason', '')
    default_oper_reason = options['conf'].get('oper-reason', '')

    scansets = {}
    for name, d in options['conf']['scansets'].items():
        scans = []
        for args in d['protocols']:
            poolname = args.pop(0)
            checkername = args.pop(0)
            checker = checkerFactories[checkername](*args)
            scans.append((poolname, checker.check))

        user_reason = d.get('user-reason', default_user_reason)
        oper_reason = d.get('oper-reason', default_oper_reason)
        scansets[name] = scanner.ScanSet(d['timeout'], scans, user_reason,
                                         oper_reason)

    # XXXX the target_blah passing here is horrible, but I intend to
    # make this less global in the future anyway, so laaaaaaaaater
    env = {}
    for k in [
            'target_ip', 'target_port', 'target_url', 'target_strings',
            'max_bytes', 'bind_address'
    ]:
        env[k] = options['conf'].get(k)

    theScanner = scanner.Scanner(reactor, resolver, options['conf']['pools'],
                                 scansets, env)

    for name, net in options['conf'].get('irc', {}).items():
        # XXX terrible, see also similar complaints in ircpresence.
        # Split this up later.
        factory = ircpresence.Factory(
            net['nick'],
            net['channel'],
            password=net.get('pass'),
            opername=net.get('opername', net['nick']),
            operpass=net.get('operpass'),
            operkey=net.get('operkey'),
            opermode=net.get('opermode'),
            away=net.get('away'),
            connregex=net.get('connregex'),
            scanner=theScanner,
            masks=options['conf'].get('masks', {}),
            actions=net.get('actions'),
            onconnectmsgs=net.get('onconnectmsgs', ()),
            verbose=options['irc-log'],
            flood_exempt=net.get('flood_exempt', False),
            username=net.get('username'),
            cache_time=net.get("scan-cache-time", 120),
            cache_size=net.get("scan-cache-size", 1_000_000))
        if net.get('ssl', False):
            ctxf = ssl.ClientContextFactory()
            serv = internet.SSLClient(net['host'], net['port'], factory, ctxf)
        else:
            serv = internet.TCPClient(net['host'], net['port'], factory)
        serv.setName(name)
        serv.setServiceParent(m)

    return m
示例#12
0
 def tearDown(self):
     # XXX HACK
     resolver = getResolver()
     call = resolver.resolvers[-1]._parseCall
     if call.active():
         call.cancel()
示例#13
0
文件: utils.py 项目: geostarling/duct
 def __init__(self):
     self.recs = {}
     self.resolver = client.getResolver()