comparison 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
comparison
equal deleted inserted replaced
1844:489b968b3723 1845:2bde6fc7aabd
322 # used by factories to know when the finished Deferred can be triggered 322 # used by factories to know when the finished Deferred can be triggered
323 323
324 @property 324 @property
325 def file_obj(self): 325 def file_obj(self):
326 if self._file_obj is None: 326 if self._file_obj is None:
327 if self.server_mode: 327 self._file_obj = self.getSession()['file']
328 self._file_obj = self.factory.getSession(self._session_hash)["file"]
329 else:
330 self._file_obj = self.factory.getSession()['file']
331 return self._file_obj 328 return self._file_obj
329
330 def getSession(self):
331 """Return session associated with this candidate
332
333 @return (dict): session data
334 """
335 if self.server_mode:
336 return self.factory.getSession(self._session_hash)
337 else:
338 return self.factory.getSession()
332 339
333 def _startNegotiation(self): 340 def _startNegotiation(self):
334 log.debug("starting negotiation (client mode)") 341 log.debug("starting negotiation (client mode)")
335 self.state = STATE_CLIENT_AUTH 342 self.state = STATE_CLIENT_AUTH
336 self.transport.write(struct.pack('!3B', SOCKS5_VER, 1, AUTHMECH_ANON)) 343 self.transport.write(struct.pack('!3B', SOCKS5_VER, 1, AUTHMECH_ANON))
529 if self.state == STATE_READY: 536 if self.state == STATE_READY:
530 # Everything is set, we just have to write the incoming data 537 # Everything is set, we just have to write the incoming data
531 self.file_obj.write(buf) 538 self.file_obj.write(buf)
532 if not self.active: 539 if not self.active:
533 self.active = True 540 self.active = True
541 self.getSession()[TIMER_KEY].cancel()
534 return 542 return
535 543
536 self.buf = self.buf + buf 544 self.buf = self.buf + buf
537 if self.state == STATE_INITIAL: 545 if self.state == STATE_INITIAL:
538 self._parseNegotiation() 546 self._parseNegotiation()
1149 raise e 1157 raise e
1150 client = self.host.getClient(profile) 1158 client = self.host.getClient(profile)
1151 return client._s5b_sessions[session_hash] 1159 return client._s5b_sessions[session_hash]
1152 1160
1153 def registerHash(self, *args, **kwargs): 1161 def registerHash(self, *args, **kwargs):
1154 """like [_registerHash] but resturn the session deferred instead of the whole session 1162 """like [_registerHash] but return the session deferred instead of the whole session
1155 session deferred is fired when transfer is finished 1163 session deferred is fired when transfer is finished
1156 """ 1164 """
1157 return self._registerHash(*args, **kwargs)[DEFER_KEY] 1165 return self._registerHash(*args, **kwargs)[DEFER_KEY]
1158 1166
1159 def _registerHash(self, session_hash, file_obj, profile): 1167 def _registerHash(self, session_hash, file_obj, profile):