summaryrefslogtreecommitdiff
path: root/sleekxmpp/clientxmpp.py
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2012-03-29 15:11:24 -0700
committerLance Stout <lancestout@gmail.com>2012-03-30 10:12:43 -0700
commitc1d36cad4679419679896c81e4d4520ec1627132 (patch)
tree04719dd43b2308a5ab99dbf690dfe94c84008af8 /sleekxmpp/clientxmpp.py
parentaad2eb31fcde345431a27994bdc771f58e480e38 (diff)
downloadslixmpp-c1d36cad4679419679896c81e4d4520ec1627132.tar.gz
slixmpp-c1d36cad4679419679896c81e4d4520ec1627132.tar.bz2
slixmpp-c1d36cad4679419679896c81e4d4520ec1627132.tar.xz
slixmpp-c1d36cad4679419679896c81e4d4520ec1627132.zip
Add better DNS resolver wrapper.
Diffstat (limited to 'sleekxmpp/clientxmpp.py')
-rw-r--r--sleekxmpp/clientxmpp.py41
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.