diff options
author | Chris Porter <slug@qwebirc.org> | 2010-06-06 19:57:55 (GMT) |
---|---|---|
committer | Chris Porter <slug@qwebirc.org> | 2010-06-06 19:57:55 (GMT) |
commit | 0dad5445d010875bf793abda6acce64b7d3d627c (patch) | |
tree | 0d7b71ac4221102a02307c5584ad0d5000992d3e | |
parent | f01a947dfd2bfee2ace58952e12c2b1264e35daf (diff) |
Switch to using SRV records.
-rw-r--r-- | config.py.example | 7 | ||||
-rw-r--r-- | qwebirc/ircclient.py | 21 |
2 files changed, 18 insertions, 10 deletions
diff --git a/config.py.example b/config.py.example index cff5ab0..7bdda5d 100644 --- a/config.py.example +++ b/config.py.example @@ -212,8 +212,11 @@ STATIC_BASE_URL = "" DYNAMIC_BASE_URL = "" # OPTION: CONNECTION_RESOLVER -# This specific object (if not None) will be used to resolve -# connections made to the IRC server. +# A list of (ip, port) tuples of resolvers to use for looking +# the SRV record(s) used for connecting to the name set in +# IRC_SERVER. +# The default value is None, and in this case qwebirc will use +# the system's default resolver(s). CONNECTION_RESOLVER = None # QUAKENET SPECIFIC VALUES diff --git a/qwebirc/ircclient.py b/qwebirc/ircclient.py index 7252669..efda3d4 100644 --- a/qwebirc/ircclient.py +++ b/qwebirc/ircclient.py @@ -1,12 +1,17 @@ import twisted, sys, codecs, traceback from twisted.words.protocols import irc -from twisted.internet import reactor, protocol +from twisted.internet import reactor, protocol, abstract from twisted.web import resource, server from twisted.protocols import basic - -import hmac, time, config, qwebirc.config_options as config_options +from twisted.names.client import Resolver +import hmac, time, config, random, qwebirc.config_options as config_options from config import HMACTEMPORAL +if config.get("CONNECTION_RESOLVER"): + CONNECTION_RESOLVER = Resolver(servers=config.get("CONNECTION_RESOLVER")) +else: + CONNECTION_RESOLVER = None + if hasattr(config, "WEBIRC_MODE") and config.WEBIRC_MODE == "hmac": HMACKEY = hmac.HMAC(key=config.HMACKEY) @@ -140,18 +145,18 @@ class QWebIRCFactory(protocol.ClientFactory): self.publisher.disconnect() def createIRC(*args, **kwargs): - resolver = config.get("CONNECTION_RESOLVER") f = QWebIRCFactory(*args, **kwargs) - if resolver is None: + if CONNECTION_RESOLVER is None: reactor.connectTCP(config.IRCSERVER, config.IRCPORT, f) return f - def callback(addr): - reactor.connectTCP(addr, config.IRCPORT, f) + def callback(result): + name, port = random.choice(sorted((str(x.payload.target), x.payload.port) for x in result[0])) + reactor.connectTCP(name, port, f) def errback(err): f.clientConnectionFailed(None, err) # None?! - d = resolver.getHostByName(config.IRCSERVER, (1, 3, 11)) + d = CONNECTION_RESOLVER.lookupService(config.IRCSERVER, (1, 3, 11)) d.addCallbacks(callback, errback) return f |