mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-25 19:44:13 +01:00
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))
|
||||||
|
15
src/utils.py
15
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.
|
||||||
|
Loading…
Reference in New Issue
Block a user