Add support of IP-binding in non-IRC connections.

This commit is contained in:
Valentin Lorentz 2014-03-01 09:06:21 +01:00
parent 0fc2675139
commit 108b0de0d1
3 changed files with 19 additions and 6 deletions

View File

@ -1055,7 +1055,11 @@ registerGlobalValue(supybot.protocols.irc, 'umodes',
registerGlobalValue(supybot.protocols.irc, 'vhost', registerGlobalValue(supybot.protocols.irc, 'vhost',
registry.String('', _("""Determines what vhost the bot will bind to before registry.String('', _("""Determines what vhost the bot will bind to before
connecting to the IRC server."""))) connecting a server (IRC, HTTP, ) via IPv4.""")))
registerGlobalValue(supybot.protocols.irc, 'vhostv6',
registry.String('', _("""Determines what vhost the bot will bind to before
connecting a server (IRC, HTTP, ) via IPv6.""")))
registerGlobalValue(supybot.protocols.irc, 'maxHistoryLength', registerGlobalValue(supybot.protocols.irc, 'maxHistoryLength',
registry.Integer(1000, _("""Determines how many old messages the bot will registry.Integer(1000, _("""Determines how many old messages the bot will

View File

@ -293,8 +293,6 @@ class SocketDriver(drivers.IrcDriver, drivers.ServersMixin):
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, socks_proxy)
vhost = conf.supybot.protocols.irc.vhost()
self.conn.bind((vhost, 0))
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

@ -48,7 +48,7 @@ def getAddressFromHostname(host, attempt=0):
addresses.append(sockaddr[0]) addresses.append(sockaddr[0])
return addresses[attempt % len(addresses)] return addresses[attempt % len(addresses)]
def getSocket(host, socks_proxy=None): def getSocket(host, 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.
""" """
@ -62,10 +62,21 @@ def getSocket(host, socks_proxy=None):
s.setproxy(socks.PROXY_TYPE_SOCKS5, hostname, int(port), s.setproxy(socks.PROXY_TYPE_SOCKS5, hostname, int(port),
rdns=True) rdns=True)
return s return s
import supybot.conf as conf
if isIPV4(host): if isIPV4(host):
return socket.socket(socket.AF_INET, socket.SOCK_STREAM) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if not vhost:
vhost = conf.supybot.protocols.irc.vhost()
if vhost:
s.bind((vhost, 0))
return s
elif isIPV6(host): elif isIPV6(host):
return socket.socket(socket.AF_INET6, socket.SOCK_STREAM) s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
if not vhostv6:
vhostv6 = conf.supybot.protocols.irc.vhostv6()
if vhostv6:
s.bind((vhostv6, 0))
return s
else: else:
raise socket.error('Something wonky happened.') raise socket.error('Something wonky happened.')