comparison src/plugins/plugin_xep_0065.py @ 1757:abd6d6f89006

plugins XEP-0065, XEP-0260: fixed session creation order: session is created earlied, and file object associated in a second time if needed
author Goffi <goffi@goffi.org>
date Thu, 17 Dec 2015 22:37:58 +0100
parents 244a605623d6
children a66d34353f34
comparison
equal deleted inserted replaced
1756:061011fad5b1 1757:abd6d6f89006
1146 1146
1147 def _registerHash(self, session_hash, file_obj, profile): 1147 def _registerHash(self, session_hash, file_obj, profile):
1148 """Create a session_data associated to hash 1148 """Create a session_data associated to hash
1149 1149
1150 @param session_hash(str): hash of the session 1150 @param session_hash(str): hash of the session
1151 @param file_obj(file): file-like object 1151 @param file_obj(file, None): file-like object
1152 None if it will be filled later
1152 @param profile: %(doc_profile)s 1153 @param profile: %(doc_profile)s
1153 return (dict): session data 1154 return (dict): session data
1154 """ 1155 """
1155 client = self.host.getClient(profile) 1156 client = self.host.getClient(profile)
1156 assert session_hash not in client._s5b_sessions 1157 assert session_hash not in client._s5b_sessions
1157 session_d = defer.Deferred() 1158 session_d = defer.Deferred()
1158 session_d.addBoth(self.killSession, session_hash, None, client) 1159 session_d.addBoth(self.killSession, session_hash, None, client)
1159 session_data = client._s5b_sessions[session_hash] = { 1160 session_data = client._s5b_sessions[session_hash] = {
1160 "file": file_obj,
1161 DEFER_KEY: session_d, 1161 DEFER_KEY: session_d,
1162 TIMER_KEY: reactor.callLater(TIMEOUT, self._timeOut, session_hash, client), 1162 TIMER_KEY: reactor.callLater(TIMEOUT, self._timeOut, session_hash, client),
1163 } 1163 }
1164
1165 if file_obj is not None:
1166 session_data['file'] = file_obj
1167
1164 if session_hash in self.hash_profiles_map: 1168 if session_hash in self.hash_profiles_map:
1165 # The only case when 2 profiles want to register the same hash 1169 # The only case when 2 profiles want to register the same hash
1166 # is when they are on the same instance 1170 # is when they are on the same instance
1167 log.info(u"Both Socks5 peers are on the same instance") 1171 log.info(u"Both Socks5 peers are on the same instance")
1168 # XXX:If both peers are on the same instance, they'll register the same 1172 # XXX:If both peers are on the same instance, they'll register the same
1179 else: 1183 else:
1180 self.hash_profiles_map[session_hash] = profile 1184 self.hash_profiles_map[session_hash] = profile
1181 1185
1182 return session_data 1186 return session_data
1183 1187
1188 def associateFileObj(self, session_hash, file_obj, profile):
1189 """Associate a file obj with a session"""
1190 session_data = self.getSession(session_hash, profile)
1191 assert 'file' not in session_data
1192 session_data['file'] = file_obj
1193
1184 def streamQuery(self, iq_elt, profile): 1194 def streamQuery(self, iq_elt, profile):
1185 log.debug(u"BS stream query") 1195 log.debug(u"BS stream query")
1186 client = self.host.getClient(profile) 1196 client = self.host.getClient(profile)
1187 1197
1188 iq_elt.handled = True 1198 iq_elt.handled = True