plugin XEP-0065: chunk size optimization: 64Kio is used except for proxy were it is set to 4Kio, to avoid wild disconnection by Prosody's proxy
This commit is contained in:
parent
73139e59ba
commit
455a7e00f7
1 changed files with 17 additions and 8 deletions
|
|
@ -274,7 +274,11 @@ class Candidate(object):
|
|||
return iq_elt.send()
|
||||
|
||||
def startTransfer(self, session_hash=None):
|
||||
self.factory.startTransfer(session_hash)
|
||||
if self.type == XEP_0065.TYPE_PROXY:
|
||||
chunk_size = 4096 # Prosody's proxy reject bigger chunks by default
|
||||
else:
|
||||
chunk_size = None
|
||||
self.factory.startTransfer(session_hash, chunk_size=chunk_size)
|
||||
|
||||
|
||||
def getSessionHash(from_jid, to_jid, sid):
|
||||
|
|
@ -289,7 +293,7 @@ def getSessionHash(from_jid, to_jid, sid):
|
|||
|
||||
|
||||
class SOCKSv5(protocol.Protocol, FileSender):
|
||||
CHUNK_SIZE = 4096
|
||||
CHUNK_SIZE = 2**16
|
||||
|
||||
def __init__(self, session_hash=None):
|
||||
"""
|
||||
|
|
@ -484,8 +488,13 @@ class SOCKSv5(protocol.Protocol, FileSender):
|
|||
self._session_hash = addr
|
||||
self.connectCompleted(addr, 0)
|
||||
|
||||
def startTransfer(self):
|
||||
"""Callback called when the result iq is received"""
|
||||
def startTransfer(self, chunk_size):
|
||||
"""Callback called when the result iq is received
|
||||
|
||||
@param chunk_size(None, int): size of the buffer, or None for default
|
||||
"""
|
||||
if chunk_size is not None:
|
||||
self.CHUNK_SIZE = chunk_size
|
||||
log.debug(u"Starting file transfer")
|
||||
d = self.beginFileTransfer(self.file_obj, self.transport)
|
||||
d.addCallback(self.fileTransfered)
|
||||
|
|
@ -554,14 +563,14 @@ class Socks5ServerFactory(protocol.ServerFactory):
|
|||
def getSession(self, session_hash):
|
||||
return self.parent.getSession(session_hash, None)
|
||||
|
||||
def startTransfer(self, session_hash):
|
||||
def startTransfer(self, session_hash, chunk_size=None):
|
||||
session = self.getSession(session_hash)
|
||||
try:
|
||||
protocol = session['protocols'][0]
|
||||
except (KeyError, IndexError):
|
||||
log.error(u"Can't start file transfer, can't find protocol")
|
||||
else:
|
||||
protocol.startTransfer()
|
||||
protocol.startTransfer(chunk_size)
|
||||
|
||||
def addToSession(self, session_hash, protocol):
|
||||
"""Check is session_hash is valid, and associate protocol with it
|
||||
|
|
@ -631,8 +640,8 @@ class Socks5ClientFactory(protocol.ClientFactory):
|
|||
def getSession(self):
|
||||
return self.session
|
||||
|
||||
def startTransfer(self, dummy=None):
|
||||
self._protocol_instance.startTransfer()
|
||||
def startTransfer(self, dummy=None, chunk_size=None):
|
||||
self._protocol_instance.startTransfer(chunk_size)
|
||||
|
||||
def clientConnectionFailed(self, connector, reason):
|
||||
log.debug(u"Connection failed")
|
||||
|
|
|
|||
Loading…
Reference in a new issue