mirror of https://github.com/Mikaela/Limnoria.git
Add handling of opening sockets to communicate with IPV6 hosts.
This commit is contained in:
parent
17a40423ee
commit
9d9c3020ca
|
@ -59,9 +59,16 @@ class DCC(callbacks.Privmsg):
|
||||||
text = privmsgs.getArgs(args)
|
text = privmsgs.getArgs(args)
|
||||||
def openChatPort():
|
def openChatPort():
|
||||||
try:
|
try:
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
||||||
sock.settimeout(60)
|
|
||||||
host = ircutils.hostFromHostmask(irc.prefix)
|
host = ircutils.hostFromHostmask(irc.prefix)
|
||||||
|
try:
|
||||||
|
inet = utils.getSocket(host)
|
||||||
|
except socket.error, e:
|
||||||
|
s = 'Error connecting to %s: %s'
|
||||||
|
self.log.warning(s, host, e)
|
||||||
|
irc.replyError()
|
||||||
|
return
|
||||||
|
sock = socket.socket(inet, socket.SOCK_STREAM)
|
||||||
|
sock.settimeout(60)
|
||||||
if conf.supybot.externalIP():
|
if conf.supybot.externalIP():
|
||||||
ip = conf.supybot.externalIP()
|
ip = conf.supybot.externalIP()
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -139,7 +139,13 @@ class SocketDriver(drivers.IrcDriver):
|
||||||
self._scheduleReconnect()
|
self._scheduleReconnect()
|
||||||
return
|
return
|
||||||
self.irc.reset()
|
self.irc.reset()
|
||||||
self.conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
try:
|
||||||
|
inet = utils.getSocket(self.server[0])
|
||||||
|
except socket.error, e:
|
||||||
|
log.warning('Error connecting to %s: %s', self.server[0], e)
|
||||||
|
self.reconnect(wait=True)
|
||||||
|
return
|
||||||
|
self.conn = socket.socket(inet, socket.SOCK_STREAM)
|
||||||
# We allow more time for the connect here, since it might take longer.
|
# We allow more time for the connect here, since it might take longer.
|
||||||
# At least 10 seconds.
|
# At least 10 seconds.
|
||||||
self.conn.settimeout(max(10, conf.supybot.drivers.poll()*10))
|
self.conn.settimeout(max(10, conf.supybot.drivers.poll()*10))
|
||||||
|
|
21
src/utils.py
21
src/utils.py
|
@ -555,6 +555,21 @@ def changeFunctionName(f, name, doc=None):
|
||||||
newf.__doc__ = doc
|
newf.__doc__ = doc
|
||||||
return newf
|
return newf
|
||||||
|
|
||||||
|
def getSocket(host):
|
||||||
|
"""Returns a socket of the correct AF_INET type (v4 or v6) in order to
|
||||||
|
communicate with host.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
host = socket.gethostbyname(host)
|
||||||
|
except socket.error:
|
||||||
|
raise
|
||||||
|
if isIP(host):
|
||||||
|
return socket.socket(socket.INET, socket.SOCK_STREAM)
|
||||||
|
elif isIPV6(host):
|
||||||
|
return socket.socket(socket.INET6, socket.SOCK_STREAM)
|
||||||
|
else:
|
||||||
|
raise socket.error, 'Something wonky happened.'
|
||||||
|
|
||||||
_ipchars = string.digits + '.'
|
_ipchars = string.digits + '.'
|
||||||
def isIP(s):
|
def isIP(s):
|
||||||
"""Returns whether or not a given string is an IPV4 address.
|
"""Returns whether or not a given string is an IPV4 address.
|
||||||
|
@ -606,7 +621,7 @@ class InsensitivePreservingDict(UserDict.DictMixin, object):
|
||||||
d[key] = s
|
d[key] = s
|
||||||
return d
|
return d
|
||||||
fromkeys = classmethod(fromkeys)
|
fromkeys = classmethod(fromkeys)
|
||||||
|
|
||||||
def __getitem__(self, k):
|
def __getitem__(self, k):
|
||||||
return self.data[self.key(k)][1]
|
return self.data[self.key(k)][1]
|
||||||
|
|
||||||
|
@ -624,7 +639,7 @@ class InsensitivePreservingDict(UserDict.DictMixin, object):
|
||||||
for (k, _) in self.iteritems():
|
for (k, _) in self.iteritems():
|
||||||
L.append(k)
|
L.append(k)
|
||||||
return L
|
return L
|
||||||
|
|
||||||
def __reduce__(self):
|
def __reduce__(self):
|
||||||
return (self.__class__, (dict(self.data.values()),))
|
return (self.__class__, (dict(self.data.values()),))
|
||||||
|
|
||||||
|
@ -632,7 +647,7 @@ def mungeEmailForWeb(s):
|
||||||
s = s.replace('@', ' AT ')
|
s = s.replace('@', ' AT ')
|
||||||
s = s.replace('.', ' DOT ')
|
s = s.replace('.', ' DOT ')
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import sys, doctest
|
import sys, doctest
|
||||||
|
|
Loading…
Reference in New Issue