diff options
Diffstat (limited to 'sleekxmpp/clientxmpp.py')
-rw-r--r-- | sleekxmpp/clientxmpp.py | 41 |
1 files changed, 10 insertions, 31 deletions
diff --git a/sleekxmpp/clientxmpp.py b/sleekxmpp/clientxmpp.py index 590192db..d2f24d16 100644 --- a/sleekxmpp/clientxmpp.py +++ b/sleekxmpp/clientxmpp.py @@ -84,6 +84,8 @@ class ClientXMPP(BaseXMPP): self._stream_feature_handlers = {} self._stream_feature_order = [] + self.dns_service = 'xmpp-client' + #TODO: Use stream state here self.authenticated = False self.sessionstarted = False @@ -139,43 +141,20 @@ class ClientXMPP(BaseXMPP): should be used. Defaults to ``False``. """ self.session_started_event.clear() - if not address: + + # If an address was provided, disable using DNS SRV lookup; + # otherwise, use the domain from the client JID with the standard + # XMPP client port and allow SRV lookup. + if address: + self.dns_service = None + else: address = (self.boundjid.host, 5222) + self.dns_service = 'xmpp-client' return XMLStream.connect(self, address[0], address[1], use_tls=use_tls, use_ssl=use_ssl, reattempt=reattempt) - def get_dns_records(self, domain, port=None): - """Get the DNS records for a domain, including SRV records. - - :param domain: The domain in question. - :param port: If the results don't include a port, use this one. - """ - if port is None: - port = self.default_port - if DNSPYTHON: - try: - record = "_xmpp-client._tcp.%s" % domain - answers = [] - log.debug("Querying SRV records for %s" % domain) - for answer in dns.resolver.query(record, dns.rdatatype.SRV): - address = (answer.target.to_text()[:-1], answer.port) - log.debug("Found SRV record: %s", address) - answers.append((address, answer.priority, answer.weight)) - except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer): - log.warning("No SRV records for %s", domain) - answers = super(ClientXMPP, self).get_dns_records(domain, port) - except dns.exception.Timeout: - log.warning("DNS resolution timed out " + \ - "for SRV record of %s", domain) - answers = super(ClientXMPP, self).get_dns_records(domain, port) - return answers - else: - log.warning("dnspython is not installed -- " + \ - "relying on OS A/AAAA record resolution") - return [((domain, port), 0, 0)] - def register_feature(self, name, handler, restart=False, order=5000): """Register a stream feature handler. |