diff src/plugins/plugin_xep_0065.py @ 1845:2bde6fc7aabd

plugin XEP-0065: fixed timer cancellation when a profile is receiving a file
author Goffi <goffi@goffi.org>
date Mon, 08 Feb 2016 18:06:07 +0100
parents d17772b0fe22
children 2daf7b4c6756
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0065.py	Thu Feb 04 18:56:53 2016 +0100
+++ b/src/plugins/plugin_xep_0065.py	Mon Feb 08 18:06:07 2016 +0100
@@ -324,12 +324,19 @@
     @property
     def file_obj(self):
         if self._file_obj is None:
-            if self.server_mode:
-                self._file_obj = self.factory.getSession(self._session_hash)["file"]
-            else:
-                self._file_obj = self.factory.getSession()['file']
+            self._file_obj = self.getSession()['file']
         return self._file_obj
 
+    def getSession(self):
+        """Return session associated with this candidate
+
+        @return (dict): session data
+        """
+        if self.server_mode:
+            return self.factory.getSession(self._session_hash)
+        else:
+            return self.factory.getSession()
+
     def _startNegotiation(self):
         log.debug("starting negotiation (client mode)")
         self.state = STATE_CLIENT_AUTH
@@ -531,6 +538,7 @@
             self.file_obj.write(buf)
             if not self.active:
                 self.active = True
+                self.getSession()[TIMER_KEY].cancel()
             return
 
         self.buf = self.buf + buf
@@ -1151,7 +1159,7 @@
         return client._s5b_sessions[session_hash]
 
     def registerHash(self, *args, **kwargs):
-        """like [_registerHash] but resturn the session deferred instead of the whole session
+        """like [_registerHash] but return the session deferred instead of the whole session
         session deferred is fired when transfer is finished
         """
         return self._registerHash(*args, **kwargs)[DEFER_KEY]