# HG changeset patch # User Goffi # Date 1447262389 -3600 # Node ID d5f59ba166fe00d288803127e4f31676dedb9b1e # Parent 833bdb227b16e55df991feb2c0313cb9ae719237 plugins IP: getLocalIPs now return localhost IP instead of an empty list if no non-localhost ip can be found diff -r 833bdb227b16 -r d5f59ba166fe src/plugins/plugin_misc_ip.py --- a/src/plugins/plugin_misc_ip.py Wed Nov 11 18:19:49 2015 +0100 +++ b/src/plugins/plugin_misc_ip.py Wed Nov 11 18:19:49 2015 +0100 @@ -187,14 +187,15 @@ @param profile): %(doc_profile)s @return (deferred): list of lan IP addresses - or empty list if it can't be discovered if there are several addresses, the one used with the server is put first + if no address is found, localhost IP will be in the list """ # TODO: manage permission requesting (e.g. for UMTS link) if self._local_ip_cache is not None: defer.returnValue(self._local_ip_cache) client = self.host.getClient(profile) addresses = [] + localhost = ['127.0.0.1'] # we first try our luck with netifaces if netifaces is not None: @@ -210,13 +211,13 @@ if self._filterAddresse(addresse): addresses.append(addresse) - # we first try with our connection to server + # then we use our connection to server ip = client.xmlstream.transport.getHost().host if self._filterAddresse(ip): self._insertFirst(addresses, ip) defer.returnValue(addresses) - # if not available, we try with NAT-Port + # if server is local, we try with NAT-Port if self._nat is not None: nat_ip = yield self._nat.getIP(local=True) if nat_ip is not None: @@ -226,17 +227,17 @@ if addresses: defer.returnValue(addresses) - # still not luck, we need to contact external website - allow_get_ip = yield self._externalAllowed(profile) + # still not luck, we need to contact external website + allow_get_ip = yield self._externalAllowed(profile) - if not allow_get_ip: - defer.returnValue(addresses) + if not allow_get_ip: + defer.returnValue(addresses or localhost) try: ip_tuple = yield self._getIPFromExternal(GET_IP_PAGE) except (internet_error.DNSLookupError, internet_error.TimeoutError): log.warning(u"Can't access Domain Name System") - defer.returnValue(addresses) + defer.returnValue(addresses or localhost) self._insertFirst(addresses, ip_tuple.local) defer.returnValue(addresses) diff -r 833bdb227b16 -r d5f59ba166fe src/plugins/plugin_xep_0065.py --- a/src/plugins/plugin_xep_0065.py Wed Nov 11 18:19:49 2015 +0100 +++ b/src/plugins/plugin_xep_0065.py Wed Nov 11 18:19:49 2015 +0100 @@ -814,20 +814,17 @@ external_ip = yield self._ip.getExternalIP(client.profile) local_ips = yield self._ip.getLocalIPs(client.profile) - if not local_ips: - log.warning(u"Can't find local IPs, we can't do direct connection") - else: - if external_ip is not None and self._external_port is None: - if external_ip != local_ips[0]: - log.info(u"We are probably behind a NAT") - if self._np is None: - log.warning(u"NAT port plugin not available, we can't map port") + if external_ip is not None and self._external_port is None: + if external_ip != local_ips[0]: + log.info(u"We are probably behind a NAT") + if self._np is None: + log.warning(u"NAT port plugin not available, we can't map port") + else: + ext_port = yield self._np.mapPort(local_port, desc=u"SaT socks5 stream") + if ext_port is None: + log.warning(u"Can't map NAT port") else: - ext_port = yield self._np.mapPort(local_port, desc=u"SaT socks5 stream") - if ext_port is None: - log.warning(u"Can't map NAT port") - else: - self._external_port = ext_port + self._external_port = ext_port defer.returnValue((local_port, self._external_port, local_ips, external_ip)) @@ -847,12 +844,12 @@ candidates = [] # first the direct ones - if local_ips: - # the preferred direct connection - ip = local_ips.pop(0) - candidates.append(Candidate(ip, local_port, XEP_0065.TYPE_DIRECT, PRIORITY_BEST_DIRECT, client.jid, priority_local=True, factory=server_factory)) - for ip in local_ips: - candidates.append(Candidate(ip, local_port, XEP_0065.TYPE_DIRECT, PRIORITY_DIRECT, client.jid, priority_local=True, factory=server_factory)) + + # the preferred direct connection + ip = local_ips.pop(0) + candidates.append(Candidate(ip, local_port, XEP_0065.TYPE_DIRECT, PRIORITY_BEST_DIRECT, client.jid, priority_local=True, factory=server_factory)) + for ip in local_ips: + candidates.append(Candidate(ip, local_port, XEP_0065.TYPE_DIRECT, PRIORITY_DIRECT, client.jid, priority_local=True, factory=server_factory)) # then the assisted one if ext_port is not None: