diff src/plugins/plugin_misc_ip.py @ 2489:e2a7bb875957

plugin pipe/stream, file transfert: refactoring and improvments: this is a big patch as things had to be changed at the same time. - changed methods using profile argument to use client instead - move SatFile in a new tools.stream module, has it should be part of core, not a plugin - new IStreamProducer interface, to handler starting a pull producer - new FileStreamObject which create a stream producer/consumer from a SatFile - plugin pipe is no more using unix named pipe, as it complicate the thing, special care need to be taken to not block, and it's generally not necessary. Instead a socket is now used, so the plugin has been renomed to jingle stream. - bad connection/error should be better handler in jingle stream plugin, and code should not block anymore - jp pipe commands have been updated accordingly fix bug 237
author Goffi <goffi@goffi.org>
date Thu, 08 Feb 2018 00:37:42 +0100
parents 0046283a285d
children 67cc54b01a12
line wrap: on
line diff
--- a/src/plugins/plugin_misc_ip.py	Thu Feb 01 07:24:34 2018 +0100
+++ b/src/plugins/plugin_misc_ip.py	Thu Feb 08 00:37:42 2018 +0100
@@ -111,11 +111,10 @@
         self._external_ip_cache = None
         self._local_ip_cache = None
 
-    def _externalAllowed(self, profile):
+    def _externalAllowed(self, client):
         """Return value of parameter with autorisation of user to do external requests
 
         if parameter is not set, a dialog is shown to use to get its confirmation, and parameted is set according to answer
-        @param profile: %(doc_profile)s
         @return (defer.Deferred[bool]): True if external request is autorised
         """
         allow_get_ip = self.host.memory.params.getParamA(GET_IP_NAME, GET_IP_CATEGORY, use_default=False)
@@ -127,7 +126,7 @@
                 #        need to be fixed when params will be refactored
                 self.host.memory.setParam(GET_IP_NAME, C.boolConst(allowed), GET_IP_CATEGORY)
                 return allowed
-            d = xml_tools.deferConfirm(self.host, _(GET_IP_CONFIRM), _(GET_IP_CONFIRM_TITLE), profile=profile)
+            d = xml_tools.deferConfirm(self.host, _(GET_IP_CONFIRM), _(GET_IP_CONFIRM_TITLE), profile=client.profile)
             d.addCallback(setParam)
             return d
 
@@ -185,10 +184,9 @@
         return d
 
     @defer.inlineCallbacks
-    def getLocalIPs(self, profile):
+    def getLocalIPs(self, client):
         """Try do discover local area network IPs
 
-        @param profile): %(doc_profile)s
         @return (deferred): list of lan IP addresses
             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
@@ -196,7 +194,6 @@
         # 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']
 
@@ -231,7 +228,7 @@
                 defer.returnValue(addresses)
 
         # still not luck, we need to contact external website
-        allow_get_ip = yield self._externalAllowed(profile)
+        allow_get_ip = yield self._externalAllowed(client)
 
         if not allow_get_ip:
             defer.returnValue(addresses or localhost)
@@ -245,22 +242,19 @@
         defer.returnValue(addresses)
 
     @defer.inlineCallbacks
-    def getExternalIP(self, profile):
+    def getExternalIP(self, client):
         """Try to discover external IP
 
-        @param profile: %(doc_profile)s
         @return (deferred): external IP address or None if it can't be discovered
         """
         if self._external_ip_cache is not None:
             defer.returnValue(self._external_ip_cache)
 
-        client = self.host.getClient(profile)
 
         # we first try with XEP-0279
         ip_check = yield self.host.hasFeature(client, NS_IP_CHECK)
         if ip_check:
             log.debug(u"Server IP Check available, we use it to retrieve our IP")
-            client = self.host.getClient(profile)
             iq_elt = client.IQ("get")
             iq_elt.addElement((NS_IP_CHECK, 'address'))
             try:
@@ -287,7 +281,7 @@
                 defer.returnValue(nat_ip)
 
         # and finally by requesting external website
-        allow_get_ip = yield self._externalAllowed(profile)
+        allow_get_ip = yield self._externalAllowed(client)
         try:
             ip = (yield webclient.getPage(GET_IP_PAGE)) if allow_get_ip else None
         except (internet_error.DNSLookupError, internet_error.TimeoutError):