Add support for SRV records in domain name resolution.

This commit is contained in:
Valentin Lorentz 2014-03-01 09:22:14 +01:00
parent 108b0de0d1
commit dcb25db6e5
2 changed files with 7 additions and 5 deletions

View File

@ -290,9 +290,11 @@ class SocketDriver(drivers.IrcDriver, drivers.ServersMixin):
drivers.log.connectError(self.currentServer, e) drivers.log.connectError(self.currentServer, e)
self.scheduleReconnect() self.scheduleReconnect()
return return
port = server[1]
drivers.log.connect(self.currentServer) drivers.log.connect(self.currentServer)
try: try:
self.conn = utils.net.getSocket(address, socks_proxy) self.conn = utils.net.getSocket(address, port=port,
socks_proxy=socks_proxy)
except socket.error as e: except socket.error as e:
drivers.log.connectError(self.currentServer, e) drivers.log.connectError(self.currentServer, e)
self.scheduleReconnect() self.scheduleReconnect()

View File

@ -40,20 +40,20 @@ from .web import _ipAddr, _domain
emailRe = re.compile(r"^(\w&.+-]+!)*[\w&.+-]+@(%s|%s)$" % (_domain, _ipAddr), emailRe = re.compile(r"^(\w&.+-]+!)*[\w&.+-]+@(%s|%s)$" % (_domain, _ipAddr),
re.I) re.I)
def getAddressFromHostname(host, attempt=0): def getAddressFromHostname(host, port=None, attempt=0):
addrinfo = socket.getaddrinfo(host, None) addrinfo = socket.getaddrinfo(host, port)
addresses = [] addresses = []
for (family, socktype, proto, canonname, sockaddr) in addrinfo: for (family, socktype, proto, canonname, sockaddr) in addrinfo:
if sockaddr[0] not in addresses: if sockaddr[0] not in addresses:
addresses.append(sockaddr[0]) addresses.append(sockaddr[0])
return addresses[attempt % len(addresses)] return addresses[attempt % len(addresses)]
def getSocket(host, socks_proxy=None, vhost=None, vhostv6=None): def getSocket(host, port=None, socks_proxy=None, vhost=None, vhostv6=None):
"""Returns a socket of the correct AF_INET type (v4 or v6) in order to """Returns a socket of the correct AF_INET type (v4 or v6) in order to
communicate with host. communicate with host.
""" """
if not socks_proxy: if not socks_proxy:
addrinfo = socket.getaddrinfo(host, None) addrinfo = socket.getaddrinfo(host, port)
host = addrinfo[0][4][0] host = addrinfo[0][4][0]
if socks_proxy: if socks_proxy:
import socks import socks