comparison src/plugins/plugin_xep_0065.py @ 1629:a34d7f621944

plugin XEP-0065: renamed _killSession to killSession as it make sense to kill a session from an other plugin
author Goffi <goffi@goffi.org>
date Thu, 19 Nov 2015 18:15:35 +0100
parents b57b4683dc33
children fd143578fe89
comparison
equal deleted inserted replaced
1628:e9936fcfaf91 1629:a34d7f621944
847 if proxy: 847 if proxy:
848 candidates.append(Candidate(proxy.host, proxy.port, XEP_0065.TYPE_PROXY, PRIORITY_PROXY, proxy.jid, priority_local=True)) 848 candidates.append(Candidate(proxy.host, proxy.port, XEP_0065.TYPE_PROXY, PRIORITY_PROXY, proxy.jid, priority_local=True))
849 849
850 # should be already sorted, but just in case the priorities get weird 850 # should be already sorted, but just in case the priorities get weird
851 candidates.sort(key=lambda c: c.priority, reverse=True) 851 candidates.sort(key=lambda c: c.priority, reverse=True)
852
853 defer.returnValue(candidates) 852 defer.returnValue(candidates)
854 853
855 def _addConnector(self, connector, candidate): 854 def _addConnector(self, connector, candidate):
856 """Add connector used to connect to candidate, and return client factory's connection Deferred 855 """Add connector used to connect to candidate, and return client factory's connection Deferred
857 856
948 """ 947 """
949 log.info(u"Socks5 Bytestream: TimeOut reached") 948 log.info(u"Socks5 Bytestream: TimeOut reached")
950 session = self.getSession(session_hash, client.profile) 949 session = self.getSession(session_hash, client.profile)
951 session[DEFER_KEY].errback(exceptions.TimeOutError) 950 session[DEFER_KEY].errback(exceptions.TimeOutError)
952 951
953 def _killSession(self, reason, session_hash, sid, client): 952 def killSession(self, reason, session_hash, sid, client):
954 """Clean the current session 953 """Clean the current session
955 954
956 @param session_hash(str): hash as returned by getSessionHash 955 @param session_hash(str): hash as returned by getSessionHash
957 @param sid(None, unicode): session id 956 @param sid(None, unicode): session id
958 or None if self.xep_0065_sid_session was not used 957 or None if self.xep_0065_sid_session was not used
1101 session_hash = getSessionHash(client.jid, to_jid, sid) 1100 session_hash = getSessionHash(client.jid, to_jid, sid)
1102 session_data = self._registerHash(session_hash, file_obj, profile) 1101 session_data = self._registerHash(session_hash, file_obj, profile)
1103 else: 1102 else:
1104 session_hash = getSessionHash(to_jid, client.jid, sid) 1103 session_hash = getSessionHash(to_jid, client.jid, sid)
1105 session_d = defer.Deferred() 1104 session_d = defer.Deferred()
1106 session_d.addBoth(self._killSession, session_hash, sid, client) 1105 session_d.addBoth(self.killSession, session_hash, sid, client)
1107 session_data = client._s5b_sessions[session_hash] = { 1106 session_data = client._s5b_sessions[session_hash] = {
1108 DEFER_KEY: session_d, 1107 DEFER_KEY: session_d,
1109 TIMER_KEY: reactor.callLater(TIMEOUT, self._timeOut, session_hash, client), 1108 TIMER_KEY: reactor.callLater(TIMEOUT, self._timeOut, session_hash, client),
1110 } 1109 }
1111 client.xep_0065_sid_session[sid] = session_data 1110 client.xep_0065_sid_session[sid] = session_data
1154 return (dict): session data 1153 return (dict): session data
1155 """ 1154 """
1156 client = self.host.getClient(profile) 1155 client = self.host.getClient(profile)
1157 assert session_hash not in client._s5b_sessions 1156 assert session_hash not in client._s5b_sessions
1158 session_d = defer.Deferred() 1157 session_d = defer.Deferred()
1159 session_d.addBoth(self._killSession, session_hash, None, client) 1158 session_d.addBoth(self.killSession, session_hash, None, client)
1160 session_data = client._s5b_sessions[session_hash] = { 1159 session_data = client._s5b_sessions[session_hash] = {
1161 "file": file_obj, 1160 "file": file_obj,
1162 DEFER_KEY: session_d, 1161 DEFER_KEY: session_d,
1163 TIMER_KEY: reactor.callLater(TIMEOUT, self._timeOut, session_hash, client), 1162 TIMER_KEY: reactor.callLater(TIMEOUT, self._timeOut, session_hash, client),
1164 } 1163 }