comparison 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
comparison
equal deleted inserted replaced
1575:833bdb227b16 1576:d5f59ba166fe
812 self.getSocks5ServerFactory() 812 self.getSocks5ServerFactory()
813 local_port = self._server_factory_port 813 local_port = self._server_factory_port
814 external_ip = yield self._ip.getExternalIP(client.profile) 814 external_ip = yield self._ip.getExternalIP(client.profile)
815 local_ips = yield self._ip.getLocalIPs(client.profile) 815 local_ips = yield self._ip.getLocalIPs(client.profile)
816 816
817 if not local_ips: 817 if external_ip is not None and self._external_port is None:
818 log.warning(u"Can't find local IPs, we can't do direct connection") 818 if external_ip != local_ips[0]:
819 else: 819 log.info(u"We are probably behind a NAT")
820 if external_ip is not None and self._external_port is None: 820 if self._np is None:
821 if external_ip != local_ips[0]: 821 log.warning(u"NAT port plugin not available, we can't map port")
822 log.info(u"We are probably behind a NAT") 822 else:
823 if self._np is None: 823 ext_port = yield self._np.mapPort(local_port, desc=u"SaT socks5 stream")
824 log.warning(u"NAT port plugin not available, we can't map port") 824 if ext_port is None:
825 log.warning(u"Can't map NAT port")
825 else: 826 else:
826 ext_port = yield self._np.mapPort(local_port, desc=u"SaT socks5 stream") 827 self._external_port = ext_port
827 if ext_port is None:
828 log.warning(u"Can't map NAT port")
829 else:
830 self._external_port = ext_port
831 828
832 defer.returnValue((local_port, self._external_port, local_ips, external_ip)) 829 defer.returnValue((local_port, self._external_port, local_ips, external_ip))
833 830
834 @defer.inlineCallbacks 831 @defer.inlineCallbacks
835 def getCandidates(self, profile): 832 def getCandidates(self, profile):
845 842
846 # its time to gather the candidates 843 # its time to gather the candidates
847 candidates = [] 844 candidates = []
848 845
849 # first the direct ones 846 # first the direct ones
850 if local_ips: 847
851 # the preferred direct connection 848 # the preferred direct connection
852 ip = local_ips.pop(0) 849 ip = local_ips.pop(0)
853 candidates.append(Candidate(ip, local_port, XEP_0065.TYPE_DIRECT, PRIORITY_BEST_DIRECT, client.jid, priority_local=True, factory=server_factory)) 850 candidates.append(Candidate(ip, local_port, XEP_0065.TYPE_DIRECT, PRIORITY_BEST_DIRECT, client.jid, priority_local=True, factory=server_factory))
854 for ip in local_ips: 851 for ip in local_ips:
855 candidates.append(Candidate(ip, local_port, XEP_0065.TYPE_DIRECT, PRIORITY_DIRECT, client.jid, priority_local=True, factory=server_factory)) 852 candidates.append(Candidate(ip, local_port, XEP_0065.TYPE_DIRECT, PRIORITY_DIRECT, client.jid, priority_local=True, factory=server_factory))
856 853
857 # then the assisted one 854 # then the assisted one
858 if ext_port is not None: 855 if ext_port is not None:
859 candidates.append(Candidate(external_ip, ext_port, XEP_0065.TYPE_ASSISTED, PRIORITY_ASSISTED, client.jid, priority_local=True, factory=server_factory)) 856 candidates.append(Candidate(external_ip, ext_port, XEP_0065.TYPE_ASSISTED, PRIORITY_ASSISTED, client.jid, priority_local=True, factory=server_factory))
860 857