diff --git a/src/common/config.py b/src/common/config.py index 39aed3d25..40208e477 100644 --- a/src/common/config.py +++ b/src/common/config.py @@ -128,6 +128,8 @@ class Config: 'confirm_close_muc': [opt_bool, True], # confirm closing MUC window 'notify_on_file_complete': [opt_bool, True], # notif. on file complete 'file_transfers_port': [opt_int, 28011], # port, used for file transfers + # custom host in case user did address translation/port forward + 'ft_custom_host': [opt_str, ''], 'conversation_font': [opt_str, ''], # IEC standard says KiB = 1024 bytes KB = 1000 bytes 'use_kib_mib': [opt_bool, False], diff --git a/src/common/connection.py b/src/common/connection.py index b022c51d4..680da69b6 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -716,6 +716,7 @@ class Connection: if type(self.peerhost) != tuple: return port = gajim.config.get('file_transfers_port') + custom_host = gajim.config.get('ft_custom_host') cfg_proxies = gajim.config.get_per('accounts', self.name, 'file_transfer_proxies') if receiver is None: receiver = file_props['receiver'] @@ -742,6 +743,8 @@ class Connection: sha_str = self._get_sha(file_props['sid'], sender, receiver) file_props['sha_str'] = sha_str + if not custom_host: + custom_host = self.peerhost[0] listener = gajim.socks5queue.start_listener(self.peerhost[0], port, sha_str, self.result_socks5_sid, file_props['sid']) if listener == None: @@ -758,7 +761,7 @@ class Connection: query.setAttr('sid', file_props['sid']) streamhost = query.setTag('streamhost') streamhost.setAttr('port', str(port)) - streamhost.setAttr('host', self.peerhost[0]) + streamhost.setAttr('host', custom_host) streamhost.setAttr('jid', sender) if fast and proxyhosts != []: file_props['proxy_receiver'] = str(receiver) diff --git a/src/common/socks5.py b/src/common/socks5.py index 73af733b9..8d8190ffe 100644 --- a/src/common/socks5.py +++ b/src/common/socks5.py @@ -105,12 +105,13 @@ class SocksQueue: return streamhost['state'] = -1 self.remove_receiver(idx) + if file_props.has_key('streamhosts'): + for host in file_props['streamhosts']: + if host['state'] != -1: + return if file_props['failure_cb']: file_props['failure_cb'](streamhost['initiator'], streamhost['id'], code = 404) - else: - # show error dialog, it seems to be the last try - pass def add_receiver(self, account, sock5_receiver): ''' add new file request ''' @@ -737,7 +738,7 @@ class Socks5Receiver(Socks5): self.streamhost = streamhost self.queue = None self.file_props = file_props - + self.connect_timeout = 0 self.connected = False self.pauses = 0 if not self.file_props: @@ -754,7 +755,7 @@ class Socks5Receiver(Socks5): def connect(self): ''' create the socket and start the connect loop ''' self._sock=socket.socket(socket.AF_INET, socket.SOCK_STREAM) - self._sock.settimeout(5) + self._sock.settimeout(50) # this will not block the GUI self._sock.setblocking(False) self.state = 0 # about to be connected @@ -769,7 +770,8 @@ class Socks5Receiver(Socks5): self._recv=self._sock.recv except Exception, ee: (errnum, errstr) = ee - if errnum == 111: + self.connect_timeout += 1 + if errnum == 111 or self.connect_timeout > 1000: self.queue._connection_refused(self.streamhost, self.file_props, self.queue_idx) return None