diff src/plugins/plugin_xep_0065.py @ 1576:d5f59ba166fe

plugins IP: getLocalIPs now return localhost IP instead of an empty list if no non-localhost ip can be found
author Goffi <goffi@goffi.org>
date Wed, 11 Nov 2015 18:19:49 +0100
parents 37d4be4a9fed
children d04d7402b8e9
line wrap: on
line diff
--- 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: