Exemplo n.º 1
0
 def test_lookupService(self):
     """
     See L{test_lookupAddress}
     """
     d = client.lookupService(self.hostname)
     d.addCallback(self.checkResult, dns.SRV)
     return d
Exemplo n.º 2
0
    def _fetchServers(self, host):
        try:
            service = "_matrix._tcp.%s" % host
            answers, auth, add = yield client.lookupService(service)
        except DNSNameError:
            answers = []

        if (len(answers) == 1
                and answers[0].type == dns.SRV
                and answers[0].payload
                and answers[0].payload.target == dns.Name(".")):
            raise DNSNameError("Service %s unavailable", service)

        servers = []

        for answer in answers:
            if answer.type != dns.SRV or not answer.payload:
                continue
            payload = answer.payload
            servers.append(ThreepidBinder._Server(
                host=str(payload.target),
                port=int(payload.port),
                priority=int(payload.priority),
                weight=int(payload.weight)
            ))

        servers.sort()
        defer.returnValue(servers)
Exemplo n.º 3
0
    def fetch_servers(self):
        try:
            answers, auth, add = yield client.lookupService(self.service_name)
        except DNSNameError:
            answers = []

        if (len(answers) == 1
                and answers[0].type == dns.SRV
                and answers[0].payload
                and answers[0].payload.target == dns.Name('.')):
            raise ConnectError("Service %s unavailable", self.service_name)

        self.servers = []
        self.used_servers = []

        for answer in answers:
            if answer.type != dns.SRV or not answer.payload:
                continue
            payload = answer.payload
            self.servers.append(self._Server(
                host=str(payload.target),
                port=int(payload.port),
                priority=int(payload.priority),
                weight=int(payload.weight)
            ))

        self.servers.sort()
Exemplo n.º 4
0
    def _fetchServers(self, host):
        try:
            service = "_matrix._tcp.%s" % host
            answers, auth, add = yield client.lookupService(service)
        except DNSNameError:
            answers = []

        if (len(answers) == 1
                and answers[0].type == dns.SRV
                and answers[0].payload
                and answers[0].payload.target == dns.Name(".")):
            raise DNSNameError("Service %s unavailable", service)

        servers = []

        for answer in answers:
            if answer.type != dns.SRV or not answer.payload:
                continue
            payload = answer.payload
            servers.append(ThreepidBinder._Server(
                host=str(payload.target),
                port=int(payload.port),
                priority=int(payload.priority),
                weight=int(payload.weight)
            ))

        servers.sort()
        defer.returnValue(servers)
Exemplo n.º 5
0
 def test_lookupService(self):
     """
     See L{test_lookupAddress}
     """
     d = client.lookupService(self.hostname)
     d.addCallback(self.checkResult, dns.SRV)
     return d
Exemplo n.º 6
0
    def connect(self):
        """Start connection to remote server."""
        self.factory.doStart()
        self.factory.startedConnecting(self)

        if not self.servers:
            if self.domain is None:
                self.connectionFailed(
                    error.DNSLookupError("Domain is not defined."),
                )
                return
            d = client.lookupService(
                "_%s._%s.%s"
                % (
                    nativeString(self.service),
                    nativeString(self.protocol),
                    nativeString(self.domain),
                ),
            )
            d.addCallbacks(self._cbGotServers, self._ebGotServers)
            d.addCallback(lambda x, self=self: self._reallyConnect())
            if self._defaultPort:
                d.addErrback(self._ebServiceUnknown)
            d.addErrback(self.connectionFailed)
        elif self.connector is None:
            self._reallyConnect()
        else:
            self.connector.connect()
Exemplo n.º 7
0
    def fetch_servers(self):
        try:
            answers, auth, add = yield client.lookupService(self.service_name)
        except DNSNameError:
            answers = []

        if (len(answers) == 1 and answers[0].type == dns.SRV
                and answers[0].payload
                and answers[0].payload.target == dns.Name('.')):
            raise ConnectError("Service %s unavailable", self.service_name)

        self.servers = []
        self.used_servers = []

        for answer in answers:
            if answer.type != dns.SRV or not answer.payload:
                continue
            payload = answer.payload
            self.servers.append(
                self._Server(host=str(payload.target),
                             port=int(payload.port),
                             priority=int(payload.priority),
                             weight=int(payload.weight)))

        self.servers.sort()
Exemplo n.º 8
0
 def getService(failure):
     service_fqdn = ".".join(("_mammatus._tcp", root_zone))
     d = client.lookupService(service_fqdn) 
     def gotSrvRecord(result):
         (answer, authority, additional) = result
         serviceUri = str(answer[0].payload.target)
         d = client.lookupText(".".join(getZone(serviceUri)))
         d.addCallbacks(getConfigFromText, gotFailure)
         return d
     d.addCallbacks(gotSrvRecord, gotFailure)
     return d
Exemplo n.º 9
0
 def _do_lookup(self):
     defers = []
     for addr, port, is_domain in RelayConfig.dispatchers:
         if is_domain:
             defer = lookupService("_sip._udp.%s" % addr)
             defer.addCallback(self._cb_got_srv, port)
             defer.addErrback(self._eb_no_srv, addr, port)
             defers.append(defer)
         else:
             defers.append(succeed((addr, port)))
     defer = DeferredList(defers)
     defer.addCallback(self._cb_got_all)
     return KeepRunning
Exemplo n.º 10
0
 def _do_lookup(self):
     defers = []
     for addr, port, is_domain in RelayConfig.dispatchers:
         if is_domain:
             defer = lookupService("_sip._udp.%s" % addr)
             defer.addCallback(self._cb_got_srv, port)
             defer.addErrback(self._eb_no_srv, addr, port)
             defers.append(defer)
         else:
             defers.append(succeed((addr, port)))
     defer = DeferredList(defers)
     defer.addCallback(self._cb_got_all)
     return KeepRunning
Exemplo n.º 11
0
Arquivo: net.py Projeto: elmom/pypsyc
 def __init__(self, center, target, myname = None):
     # TODO: dont try to resolve IP addresses ;)
     # must subclass
     if not self.factory_type: raise NotImplementedError
     try:
         self.factory = self.factory_type(center, target, myname)
     except:
         print self.factory_type
         raise
     u = parseUNL(target)
     self.host = u['host']
     d = client.lookupService('_psyc._tcp.' + self.host)
     d.addCallback(self.srvResolved)
Exemplo n.º 12
0
def rjid_dns(x):
    z=None
    global RJID_C
    from twisted.names import client as dns
    d = dns.lookupService('_xmpp-client._tcp.'+x, timeout = [2,10])
    d.addCallback(rjid_clbc)
    d.addErrback(rjid_pass)
    t=time.time()
    while not RJID_C and time.time()-t<4.5:
        time.sleep(1)
        pass
    if not RJID_C:
        return 
    r = random.choice(RJID_C[0])
    RJID_C = None
    return unicode(r.payload.target), int(r.payload.port)
Exemplo n.º 13
0
    def connect(self):
        """Start connection to remote server."""
        self.factory.doStart()
        self.factory.startedConnecting(self)

        if not self.servers:
            if self.domain is None:
                self.connectionFailed(error.DNSLookupError("Domain is not defined."))
                return
            d = client.lookupService("_%s._%s.%s" % (self.service, self.protocol, self.domain))
            d.addCallbacks(self._cbGotServers, self._ebGotServers)
            d.addCallback(lambda x, self=self: self._reallyConnect())
            d.addErrback(self.connectionFailed)
        elif self.connector is None:
            self._reallyConnect()
        else:
            self.connector.connect()
Exemplo n.º 14
0
    def connect(self):
        """Start connection to remote server."""
        self.factory.doStart()
        self.factory.startedConnecting(self)

        if not self.servers:
            if self.domain is None:
                self.connectionFailed(error.DNSLookupError("Domain is not defined."))
                return
            d = client.lookupService('_%s._%s.%s' % (self.service,
                                                     self.protocol,
                                                     self.domain))
            d.addCallbacks(self._cbGotServers, self._ebGotServers)
            d.addCallback(lambda x, self=self: self._reallyConnect())
            d.addErrback(self.connectionFailed)
        elif self.connector is None:
            self._reallyConnect()
        else:
            self.connector.connect()
Exemplo n.º 15
0
    def lookupService(self, name, timeouts=[2]):
        self.logger.debug("lookupService(name=%r, timeouts=%r)", name, timeouts)
        deferred = client.lookupService(name, timeouts)

        def cb(result):
            self.logger.debug("lookupService() cb(result=%r)", result)
            payload = result[0][0].payload
            port = payload.port
            name = payload.target.name
            return (name, port)

        def eb(failure):
            self.logger.warning("lookupService(name=%r, timeouts=%r) eb(failure=%r)",
                                name, timeouts, failure)
            if isinstance(failure.type, Exception):
                util.logTwistedFailure(self.logger, failure,
                                       "lookupService(name=%r, timeouts=%r) threw exception",
                                       name, timeouts)
            self.logger.warning("failure.__dict__: %r", failure.__dict__)
            return (None, None)

        deferred.addCallbacks(cb, eb)
        return deferred
Exemplo n.º 16
0
 def connect(self):
     from twisted.names import client as dns
     d = dns.lookupService('_xmpp-client._tcp.'+self.servername, timeout = [2,10])
     d.addCallback(self._dnsLookup)
     d.addErrback(self._dnsLookupErr)