From 8a0c47e4a04d4665cdc53168347d9f9a478d732b Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Sun, 28 Jan 2007 19:11:39 +0000 Subject: [PATCH] [Michal Vaner] add ability to send several ip when we do file transfers, and send all local IPs. fixes #2953 --- src/common/config.py | 2 +- src/common/connection_handlers.py | 43 +++++++++++++------ .../zeroconf/connection_handlers_zeroconf.py | 40 +++++++++++------ 3 files changed, 57 insertions(+), 28 deletions(-) diff --git a/src/common/config.py b/src/common/config.py index 414bf8d54..c46c48c9e 100644 --- a/src/common/config.py +++ b/src/common/config.py @@ -161,7 +161,7 @@ class Config: 'noconfirm_close_muc_rooms': [opt_str, '', _('Never ask before closing group chat tab/window in this space separated list of group chat jids.')], 'notify_on_file_complete': [opt_bool, True], 'file_transfers_port': [opt_int, 28011], - 'ft_override_host_to_send': [opt_str, '', _('Overrides the host we send for File Transfer in case of address translation/port forwarding.')], + 'ft_add_hosts_to_send': [opt_str, '', _('Comma separated list of hosts that we send, in addition of local interfaces, for File Transfer in case of address translation/port forwarding.')], 'conversation_font': [opt_str, ''], 'use_kib_mib': [opt_bool, False, _('IEC standard says KiB = 1024 bytes, KB = 1000 bytes.')], 'notify_on_all_muc_messages': [opt_bool, False], diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index 5f145ec5c..8916e8b3d 100644 --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -133,7 +133,7 @@ class ConnectionBytestream: if type(self.peerhost) != tuple: return port = gajim.config.get('file_transfers_port') - ft_override_host_to_send = gajim.config.get('ft_override_host_to_send') + ft_add_hosts_to_send = gajim.config.get('ft_add_hosts_to_send') cfg_proxies = gajim.config.get_per('accounts', self.name, 'file_transfer_proxies') if receiver is None: @@ -168,14 +168,16 @@ class ConnectionBytestream: sha_str = helpers.get_auth_sha(file_props['sid'], sender, receiver) file_props['sha_str'] = sha_str - if not ft_override_host_to_send: - ft_override_host_to_send = self.peerhost[0] - try: - ft_override_host_to_send = socket.gethostbyname( - ft_override_host_to_send) - except socket.gaierror: - self.dispatch('ERROR', (_('Wrong host'), _('The host you configured as the ft_override_host_to_send advanced option is not valid, so ignored.'))) - ft_override_host_to_send = self.peerhost[0] + ft_add_hosts = [] + if ft_add_hosts_to_send: + ft_add_hosts_to_send = map(lambda e:e.strip(), + ft_add_hosts_to_send.split(',')) + for ft_host in ft_add_hosts_to_send: + try: + ft_host = socket.gethostbyname(ft_host) + ft_add_hosts.append(ft_host) + except socket.gaierror: + self.dispatch('ERROR', (_('Wrong host'), _('The host %s you configured as the ft_add_hosts_to_send advanced option is not valid, so ignored.') % ft_host)) listener = gajim.socks5queue.start_listener(port, sha_str, self._result_socks5_sid, file_props['sid']) if listener == None: @@ -194,10 +196,25 @@ class ConnectionBytestream: query.setNamespace(common.xmpp.NS_BYTESTREAM) query.setAttr('mode', 'tcp') query.setAttr('sid', file_props['sid']) - streamhost = query.setTag('streamhost') - streamhost.setAttr('port', unicode(port)) - streamhost.setAttr('host', ft_override_host_to_send) - streamhost.setAttr('jid', sender) + for ft_host in ft_add_hosts: + # The streamhost, if set + ostreamhost = common.xmpp.Node(tag = 'streamhost') + query.addChild(node = ostreamhost) + ostreamhost.setAttr('port', unicode(port)) + ostreamhost.setAttr('host', ft_host) + ostreamhost.setAttr('jid', sender) + for thehost in self.peerhost: + try: + thehost = self.peerhost[0] + streamhost = common.xmpp.Node(tag = 'streamhost') # My IP + query.addChild(node = streamhost) + streamhost.setAttr('port', unicode(port)) + streamhost.setAttr('host', thehost) + streamhost.setAttr('jid', sender) + except socket.gaierror: + self.dispatch('ERROR', (_('Wrong host'), + _('Invalid local address? :-O'))) + if fast and proxyhosts != [] and gajim.config.get_per('accounts', self.name, 'use_ft_proxies'): file_props['proxy_receiver'] = unicode(receiver) diff --git a/src/common/zeroconf/connection_handlers_zeroconf.py b/src/common/zeroconf/connection_handlers_zeroconf.py index 03d7264b1..2d36d4661 100644 --- a/src/common/zeroconf/connection_handlers_zeroconf.py +++ b/src/common/zeroconf/connection_handlers_zeroconf.py @@ -6,7 +6,7 @@ ## - Nikos Kouremenos ## - Dimitur Kirov ## - Travis Shirk -## - Stefan Bethge +## - Stefan Bethge ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published @@ -215,7 +215,7 @@ class ConnectionBytestream: if type(self.peerhost) != tuple: return port = gajim.config.get('file_transfers_port') - ft_override_host_to_send = gajim.config.get('ft_override_host_to_send') + ft_add_hosts_to_send = gajim.config.get('ft_add_hosts_to_send') if receiver is None: receiver = file_props['receiver'] if sender is None: @@ -224,14 +224,16 @@ class ConnectionBytestream: sha_str = helpers.get_auth_sha(file_props['sid'], sender, receiver) file_props['sha_str'] = sha_str - if not ft_override_host_to_send: - ft_override_host_to_send = self.peerhost[0] - try: - ft_override_host_to_send = socket.gethostbyname( - ft_override_host_to_send) - except socket.gaierror: - self.dispatch('ERROR', (_('Wrong host'), _('The host you configured as the ft_override_host_to_send advanced option is not valid, so ignored.'))) - ft_override_host_to_send = self.peerhost[0] + ft_add_hosts = [] + if ft_add_hosts_to_send: + ft_add_hosts_to_send = map(lambda e:e.strip(), + ft_add_hosts_to_send.split(',')) + for ft_host in ft_add_hosts_to_send: + try: + ft_host = socket.gethostbyname(ft_host) + ft_add_hosts.append(ft_host) + except socket.gaierror: + self.dispatch('ERROR', (_('Wrong host'), _('The host %s you configured as the ft_add_hosts_to_send advanced option is not valid, so ignored.') % ft_host)) listener = gajim.socks5queue.start_listener(port, sha_str, self._result_socks5_sid, file_props['sid']) if listener == None: @@ -250,10 +252,20 @@ class ConnectionBytestream: query.setNamespace(common.xmpp.NS_BYTESTREAM) query.setAttr('mode', 'tcp') query.setAttr('sid', file_props['sid']) - streamhost = query.setTag('streamhost') - streamhost.setAttr('port', unicode(port)) - streamhost.setAttr('host', ft_override_host_to_send) - streamhost.setAttr('jid', sender) + for ft_host in ft_add_hosts: + # The streamhost, if set + ostreamhost = common.xmpp.Node(tag = 'streamhost') + query.addChild(node = ostreamhost) + ostreamhost.setAttr('port', unicode(port)) + ostreamhost.setAttr('host', ft_host) + ostreamhost.setAttr('jid', sender) + for thehost in self.peerhost: + thehost = self.peerhost[0] + streamhost = common.xmpp.Node(tag = 'streamhost') # My IP + query.addChild(node = streamhost) + streamhost.setAttr('port', unicode(port)) + streamhost.setAttr('host', thehost) + streamhost.setAttr('jid', sender) self.connection.send(iq) def send_file_rejection(self, file_props):