plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:

/!\ SI File Transfert (plugin XEP-0096) is temporarily broken
    /!\ proxy handling is temporarily broken
    plugin XEP-0096: use of Deferred for plugin XEP-0065 in the same way as for plugin XEP-0047
    plugin XEP-0065:
        - use of Deferred for sessions
        - plugin IP is a dependency
        - plugin NAT-PORT is used if available
        - everything is now automatic, params are disabled for now (may be re-used in the future to force port or proxy)
        - proxy infos are managed with a namedtuple
        - connexion candidates are managed with a dedicate class
        - priorities can be used for candidates, as needed for XEP-0260
        - transfer can now be managed in both direction, with client or server
        - socks5 server is launcher on demand, once for all profiles
        - helper methods to try and find best candidate
        - connection test and file transfer are done in 2 times
This commit is contained in:
Goffi 2015-11-02 22:02:41 +01:00
commit c3ff0a1513
2 changed files with 768 additions and 308 deletions

File diff suppressed because it is too large Load diff

View file

@ -155,23 +155,23 @@ class XEP_0096(object):
dest_path = frontend_data['dest_path']
except KeyError:
log.error(_('dest path not found in frontend_data'))
del(client._xep_0096_waiting_for_approval[sid])
del client._xep_0096_waiting_for_approval[sid]
return
if stream_method == self.host.plugins["XEP-0065"].NAMESPACE:
file_obj = self._getFileObject(dest_path, can_range)
range_offset = file_obj.tell()
self.host.plugins["XEP-0065"].prepareToReceive(jid.JID(data['from']), sid, file_obj, int(data["size"]), self._transferSucceeded, self._transferFailed, profile)
plugin = self.host.plugins["XEP-0065"]
elif stream_method == self.host.plugins["XEP-0047"].NAMESPACE:
file_obj = self._getFileObject(dest_path, can_range)
range_offset = file_obj.tell()
d = self.host.plugins["XEP-0047"].createSession(file_obj, jid.JID(data['from']), sid, int(data["size"]), profile)
d.addCallback(self._transferSucceeded, sid, file_obj, self.host.plugins["XEP-0047"].NAMESPACE, profile)
d.addErrback(self._transferFailed, sid, file_obj, self.host.plugins["XEP-0047"].NAMESPACE, profile)
plugin = self.host.plugins["XEP-0047"]
else:
log.error(_("Unknown stream method, this should not happen at this stage, cancelling transfer"))
del(client._xep_0096_waiting_for_approval[sid])
del client._xep_0096_waiting_for_approval[sid]
return
file_obj = self._getFileObject(dest_path, can_range)
range_offset = file_obj.tell()
d = plugin.createSession(file_obj, jid.JID(data['from']), sid, int(data["size"]), profile)
d.addCallback(self._transferSucceeded, sid, file_obj, stream_method, profile)
d.addErrback(self._transferFailed, sid, file_obj, stream_method, profile)
#we can send the iq result
feature_elt = self.host.plugins["XEP-0020"].chooseOption({'stream-method': stream_method})
misc_elts = []
@ -249,27 +249,27 @@ class XEP_0096(object):
return
range_offset = 0
range_length = None
# range_length = None
range_elts = filter(lambda elt: elt.name == 'range', si_elt.elements())
if range_elts:
range_elt = range_elts[0]
range_offset = range_elt.getAttribute("offset", 0)
range_length = range_elt.getAttribute("length")
# range_length = range_elt.getAttribute("length")
if stream_method == self.host.plugins["XEP-0065"].NAMESPACE:
file_obj = open(filepath, 'r')
if range_offset:
file_obj.seek(range_offset)
self.host.plugins["XEP-0065"].startStream(file_obj, jid.JID(IQ['from']), sid, range_length, self._sendSuccessCb, self._sendFailureCb, size, profile)
plugin = self.host.plugins["XEP-0065"]
elif stream_method == self.host.plugins["XEP-0047"].NAMESPACE:
file_obj = open(filepath, 'r')
if range_offset:
file_obj.seek(range_offset)
d = self.host.plugins["XEP-0047"].startStream(file_obj, jid.JID(IQ['from']), sid, profile=profile)
d.addCallback(self.sendSuccessCb, sid, file_obj, self.host.plugins["XEP-0047"].NAMESPACE, profile)
d.addErrback(self.sendFailureCb, sid, file_obj, self.host.plugins["XEP-0047"].NAMESPACE, profile)
plugin = self.host.plugins["XEP-0047"]
else:
log.warning(_("Invalid stream method received"))
log.error(u"Invalid stream method received")
return
file_obj = open(filepath, 'r')
if range_offset:
file_obj.seek(range_offset)
d = plugin.startStream(file_obj, jid.JID(IQ['from']), sid, profile=profile)
d.addCallback(self.sendSuccessCb, sid, file_obj, stream_method, profile)
d.addErrback(self.sendFailureCb, sid, file_obj, stream_method, profile)
def sendFile(self, to_jid, filepath, data={}, profile_key=C.PROF_KEY_NONE):
"""send a file using XEP-0096