comparison src/plugins/plugin_xep_0065.py @ 2502:7ad5f2c4e34a

XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments: huge patch sorry :) many things are improved by this patch, notably: - updated to last protocol changes (urn:xmpp:jingle:apps:file-transfer:5 and urn:xmpp:hashes:2) - XEP-0234: file request implementation - XEP-0234: methods to parse and generate <file> element (can be used by other plugins easily) - XEP-0234: range data is now in a namedtuple - path and namespace can be specified when sending/requesting a file (not standard, but needed for file sharing) - better error/termination handling - trigger points to handle file requests by other plugins - preparation to use file plugins with components
author Goffi <goffi@goffi.org>
date Wed, 28 Feb 2018 18:28:39 +0100
parents e2a7bb875957
children
comparison
equal deleted inserted replaced
2501:3b67fe672206 2502:7ad5f2c4e34a
84 84
85 PLUGIN_INFO = { 85 PLUGIN_INFO = {
86 C.PI_NAME: "XEP 0065 Plugin", 86 C.PI_NAME: "XEP 0065 Plugin",
87 C.PI_IMPORT_NAME: "XEP-0065", 87 C.PI_IMPORT_NAME: "XEP-0065",
88 C.PI_TYPE: "XEP", 88 C.PI_TYPE: "XEP",
89 C.PI_MODES: C.PLUG_MODE_BOTH,
89 C.PI_PROTOCOLS: ["XEP-0065"], 90 C.PI_PROTOCOLS: ["XEP-0065"],
90 C.PI_DEPENDENCIES: ["IP"], 91 C.PI_DEPENDENCIES: ["IP"],
91 C.PI_RECOMMENDATIONS: ["NAT-PORT"], 92 C.PI_RECOMMENDATIONS: ["NAT-PORT"],
92 C.PI_MAIN: "XEP_0065", 93 C.PI_MAIN: "XEP_0065",
93 C.PI_HANDLER: "yes", 94 C.PI_HANDLER: "yes",
767 defer.returnValue(self._cache_proxies[server]) 768 defer.returnValue(self._cache_proxies[server])
768 except KeyError: 769 except KeyError:
769 pass 770 pass
770 try: 771 try:
771 proxy = (yield self.host.findServiceEntities(client, 'proxy', 'bytestreams')).pop() 772 proxy = (yield self.host.findServiceEntities(client, 'proxy', 'bytestreams')).pop()
772 except (defer.CancelledError, StopIteration): 773 except (defer.CancelledError, StopIteration, KeyError):
773 notFound(server) 774 notFound(server)
774 iq_elt = client.IQ('get') 775 iq_elt = client.IQ('get')
775 iq_elt['to'] = proxy.full() 776 iq_elt['to'] = proxy.full()
776 iq_elt.addElement((NS_BS, 'query')) 777 iq_elt.addElement((NS_BS, 'query'))
777 778
964 """ 965 """
965 log.info(u"Socks5 Bytestream: TimeOut reached") 966 log.info(u"Socks5 Bytestream: TimeOut reached")
966 session = self.getSession(client, session_hash) 967 session = self.getSession(client, session_hash)
967 session[DEFER_KEY].errback(exceptions.TimeOutError) 968 session[DEFER_KEY].errback(exceptions.TimeOutError)
968 969
969 def killSession(self, reason, session_hash, sid, client): 970 def killSession(self, failure_, session_hash, sid, client):
970 """Clean the current session 971 """Clean the current session
971 972
972 @param session_hash(str): hash as returned by getSessionHash 973 @param session_hash(str): hash as returned by getSessionHash
973 @param sid(None, unicode): session id 974 @param sid(None, unicode): session id
974 or None if self.xep_0065_sid_session was not used 975 or None if self.xep_0065_sid_session was not used
975 @param client: %(doc_client)s 976 @param client: %(doc_client)s
976 @param reason(None, failure.Failure): None if eveything was fine, a failure else 977 @param failure_(None, failure.Failure): None if eveything was fine, a failure else
977 @return (None, failure.Failure): reason is returned 978 @return (None, failure.Failure): failure_ is returned
978 """ 979 """
979 log.debug(u'Cleaning session with hash {hash}{id}: {reason}'.format( 980 log.debug(u'Cleaning session with hash {hash}{id}: {reason}'.format(
980 hash=session_hash, 981 hash=session_hash,
981 reason='' if reason is None else reason.value, 982 reason='' if failure_ is None else failure_.value,
982 id='' if sid is None else u' (id: {})'.format(sid), 983 id='' if sid is None else u' (id: {})'.format(sid),
983 )) 984 ))
984 985
985 try: 986 try:
986 assert self.hash_clients_map[session_hash] == client 987 assert self.hash_clients_map[session_hash] == client
1005 try: 1006 try:
1006 session_data['timer'].cancel() 1007 session_data['timer'].cancel()
1007 except (internet_error.AlreadyCalled, internet_error.AlreadyCancelled): 1008 except (internet_error.AlreadyCalled, internet_error.AlreadyCancelled):
1008 pass 1009 pass
1009 1010
1010 return reason 1011 return failure_
1011 1012
1012 def startStream(self, client, stream_object, to_jid, sid): 1013 def startStream(self, client, stream_object, to_jid, sid):
1013 """Launch the stream workflow 1014 """Launch the stream workflow
1014 1015
1015 @param streamProducer: stream_object to use 1016 @param streamProducer: stream_object to use