diff --git a/gajim/common/client.py b/gajim/common/client.py index 3c9b0470d18c87178edab61ad03794b04f3d6820..8def2001a68f1873628abcd5c28c439c9733f81d 100644 --- a/gajim/common/client.py +++ b/gajim/common/client.py @@ -129,6 +129,13 @@ def certificate(self): def features(self): return self._client.features + @property + def local_address(self): + address = self._client.local_address + if address is not None: + return address.to_string().split(':')[0] + return None + def set_remove_account(self, value): # Used by the RemoveAccount Assistant to make the Client # not react to any stream errors that happen while the diff --git a/gajim/common/jingle_transport.py b/gajim/common/jingle_transport.py index 6a8a6ea51b0a0f69d60ca71b4e31fef2f815f848..d12a466dcf932882f4900c46db6e1ba290312769 100644 --- a/gajim/common/jingle_transport.py +++ b/gajim/common/jingle_transport.py @@ -198,16 +198,21 @@ def _add_local_ips_as_candidates(self): hosts = set() local_ip_cand = [] - candidate = { - 'host': self.connection.peerhost[0], - 'candidate_id': generate_id(), - 'port': port, - 'type': 'direct', - 'jid': self.ourjid, - 'priority': priority - } - hosts.add(self.connection.peerhost[0]) - local_ip_cand.append(candidate) + my_ip = self.connection.local_address + if my_ip is None: + log.warning('No local address available') + + else: + candidate = { + 'host': my_ip, + 'candidate_id': generate_id(), + 'port': port, + 'type': 'direct', + 'jid': self.ourjid, + 'priority': priority + } + hosts.add(my_ip) + local_ip_cand.append(candidate) try: for addrinfo in socket.getaddrinfo(socket.gethostname(), None): diff --git a/gajim/common/modules/bytestream.py b/gajim/common/modules/bytestream.py index be8c95fae1a7467541286f4cbb07255a1e3ab6df..91392caa1925d8f9d756ca30ee64dd7140d4003d 100644 --- a/gajim/common/modules/bytestream.py +++ b/gajim/common/modules/bytestream.py @@ -303,9 +303,15 @@ def _add_local_ips_as_streamhosts_to_query(self, query, file_props): self._account, 'ft_send_local_ips'): return + + my_ip = self._con.local_address + if my_ip is None: + log.warning('No local address available') + return + try: # The ip we're connected to server with - my_ips = [self._con.peerhost[0]] + my_ips = [my_ip] # all IPs from local DNS for addr in socket.getaddrinfo(socket.gethostname(), None): if (not addr[4][0] in my_ips and @@ -333,12 +339,12 @@ def _add_addiditional_streamhosts_to_query(self, query, file_props): self._add_streamhosts_to_query(query, sender, port, add_hosts) def _add_upnp_igd_as_streamhost_to_query(self, query, file_props, iq): - if not app.is_installed('UPNP'): + my_ip = self._con.local_address + if my_ip is None or not app.is_installed('UPNP'): + log.warning('No local address available') self._con.connection.send(iq) return - my_ip = self._con.peerhost[0] - # check if we are connected with an IPv4 address try: socket.inet_aton(my_ip)