send hash in session-init when the file is less than 10 mb
This commit is contained in:
parent
ae4596bd2e
commit
e195cfb188
4 changed files with 39 additions and 21 deletions
|
@ -1980,6 +1980,10 @@ class FileRequestReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
||||||
if val is None:
|
if val is None:
|
||||||
continue
|
continue
|
||||||
self.file_props[name] = val
|
self.file_props[name] = val
|
||||||
|
# Delete this, it shouldn't be necesary after file_props gets
|
||||||
|
# refactored.
|
||||||
|
if name == 'hash':
|
||||||
|
self.file_props['algo'] = child.getAttr('algo')
|
||||||
file_desc_tag = file_tag.getTag('desc')
|
file_desc_tag = file_tag.getTag('desc')
|
||||||
if file_desc_tag is not None:
|
if file_desc_tag is not None:
|
||||||
self.file_props['desc'] = file_desc_tag.getData()
|
self.file_props['desc'] = file_desc_tag.getData()
|
||||||
|
|
|
@ -162,7 +162,7 @@ class JingleContent(object):
|
||||||
self.sent = True
|
self.sent = True
|
||||||
content.addChild(node=self.transport.make_transport())
|
content.addChild(node=self.transport.make_transport())
|
||||||
|
|
||||||
def _fill_content(self, content, action):
|
def _fill_content(self, content):
|
||||||
description_node = xmpp.simplexml.Node(
|
description_node = xmpp.simplexml.Node(
|
||||||
tag=xmpp.NS_JINGLE_FILE_TRANSFER + ' description')
|
tag=xmpp.NS_JINGLE_FILE_TRANSFER + ' description')
|
||||||
|
|
||||||
|
@ -183,6 +183,11 @@ class JingleContent(object):
|
||||||
if 'hash' in self.file_props:
|
if 'hash' in self.file_props:
|
||||||
# TODO: use xep-300 for this bit
|
# TODO: use xep-300 for this bit
|
||||||
pass
|
pass
|
||||||
|
# if the file is less than 10 mb, then it is small
|
||||||
|
# lets calculate it right away
|
||||||
|
if int(self.file_props['size']) < 10000000:
|
||||||
|
h = self._calcHash()
|
||||||
|
file_tag.addChild(node=h)
|
||||||
desc = file_tag.setTag('desc')
|
desc = file_tag.setTag('desc')
|
||||||
if 'desc' in self.file_props:
|
if 'desc' in self.file_props:
|
||||||
desc.setData(self.file_props['desc'])
|
desc.setData(self.file_props['desc'])
|
||||||
|
|
|
@ -117,12 +117,27 @@ class JingleFileTransfer(JingleContent):
|
||||||
gajim.nec.push_incoming_event(FileRequestReceivedEvent(None,
|
gajim.nec.push_incoming_event(FileRequestReceivedEvent(None,
|
||||||
conn=self.session.connection, stanza=stanza, jingle_content=content,
|
conn=self.session.connection, stanza=stanza, jingle_content=content,
|
||||||
FT_content=self))
|
FT_content=self))
|
||||||
|
# Delete this after file_props refactoring this shouldn't be necesary
|
||||||
|
self.session.file_hash = self.file_props['hash']
|
||||||
|
self.session.hash_algo = self.file_props['algo']
|
||||||
def __on_session_initiate_sent(self, stanza, content, error, action):
|
def __on_session_initiate_sent(self, stanza, content, error, action):
|
||||||
# Calculate file_hash in a new thread
|
# Calculate file_hash in a new thread
|
||||||
self.hashThread = threading.Thread(target=self.__calcHash)
|
# if we haven't sent the hash already.
|
||||||
self.hashThread.start()
|
if 'hash' not in self.file_props:
|
||||||
|
self.hashThread = threading.Thread(target=self.__send_hash)
|
||||||
|
self.hashThread.start()
|
||||||
|
|
||||||
def __calcHash(self):
|
def __send_hash(self):
|
||||||
|
# Send hash in a session info
|
||||||
|
checksum = xmpp.Node(tag='checksum',
|
||||||
|
payload=[xmpp.Node(tag='file',
|
||||||
|
payload=[self._calcHash()])])
|
||||||
|
checksum.setNamespace(xmpp.NS_JINGLE_FILE_TRANSFER)
|
||||||
|
self.session.__session_info(checksum )
|
||||||
|
|
||||||
|
|
||||||
|
def _calcHash(self):
|
||||||
|
# Caculates the hash and returns a xep-300 hash stanza
|
||||||
if self.session.hash_algo == None:
|
if self.session.hash_algo == None:
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
|
@ -139,13 +154,8 @@ class JingleFileTransfer(JingleContent):
|
||||||
return
|
return
|
||||||
self.file_props['hash'] = hash_
|
self.file_props['hash'] = hash_
|
||||||
h.addHash(hash_, self.session.hash_algo)
|
h.addHash(hash_, self.session.hash_algo)
|
||||||
checksum = xmpp.Node(tag='checksum',
|
return h
|
||||||
payload=[xmpp.Node(tag='file', payload=[h])])
|
|
||||||
checksum.setNamespace(xmpp.NS_JINGLE_FILE_TRANSFER)
|
|
||||||
# Send hash in a session info
|
|
||||||
self.session.__session_info(checksum )
|
|
||||||
|
|
||||||
|
|
||||||
def __on_session_accept(self, stanza, content, error, action):
|
def __on_session_accept(self, stanza, content, error, action):
|
||||||
log.info("__on_session_accept")
|
log.info("__on_session_accept")
|
||||||
con = self.session.connection
|
con = self.session.connection
|
||||||
|
|
|
@ -433,17 +433,16 @@ class JingleSession(object):
|
||||||
payload = jingle.getPayload()
|
payload = jingle.getPayload()
|
||||||
for p in payload:
|
for p in payload:
|
||||||
if p.getName() == 'checksum':
|
if p.getName() == 'checksum':
|
||||||
hashes = p.getTag('file').getTag(name='hashes',
|
hash_ = p.getTag('file').getTag(name='hash',
|
||||||
namespace=xmpp.NS_HASHES)
|
namespace=xmpp.NS_HASHES)
|
||||||
for hash in hashes.getChildren():
|
algo = hash_.getAttr('algo')
|
||||||
algo = hash.getAttr('algo')
|
if algo in xmpp.Hashes.supported:
|
||||||
if algo in xmpp.Hashes.supported:
|
self.hash_algo = algo
|
||||||
self.hash_algo = algo
|
data = hash_.getData()
|
||||||
data = hash.getData()
|
# This only works because there is only one session
|
||||||
# This only works because there is only one session
|
# per file in jingleFT
|
||||||
# per file in jingleFT
|
self.file_hash = data
|
||||||
self.file_hash = data
|
raise xmpp.NodeProcessed
|
||||||
raise xmpp.NodeProcessed
|
|
||||||
self.__send_error(stanza, 'feature-not-implemented', 'unsupported-info', type_='modify')
|
self.__send_error(stanza, 'feature-not-implemented', 'unsupported-info', type_='modify')
|
||||||
raise xmpp.NodeProcessed
|
raise xmpp.NodeProcessed
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue