changeset cac4252df282 in /home/hg/repos/gajim

details:http://hg.gajim.org/gajim?cmd=changeset;node=cac4252df282
description: send hash in session-init when the file is less than 10 mb

diffstat:

 src/common/connection_handlers_events.py |   4 ++++
 src/common/jingle_content.py             |   7 ++++++-
 src/common/jingle_ft.py                  |  30 ++++++++++++++++++++----------
 src/common/jingle_session.py             |  19 +++++++++----------
 4 files changed, 39 insertions(+), 21 deletions(-)

diffs (118 lines):

diff -r c157e198bae5 -r cac4252df282 src/common/connection_handlers_events.py
--- a/src/common/connection_handlers_events.py  Mon May 28 18:07:52 2012 -0400
+++ b/src/common/connection_handlers_events.py  Mon May 28 19:54:59 2012 -0400
@@ -1980,6 +1980,10 @@
                 if val is None:
                     continue
                 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')
         if file_desc_tag is not None:
             self.file_props['desc'] = file_desc_tag.getData()
diff -r c157e198bae5 -r cac4252df282 src/common/jingle_content.py
--- a/src/common/jingle_content.py      Mon May 28 18:07:52 2012 -0400
+++ b/src/common/jingle_content.py      Mon May 28 19:54:59 2012 -0400
@@ -162,7 +162,7 @@
         self.sent = True
         content.addChild(node=self.transport.make_transport())
 
-    def _fill_content(self, content, action):
+    def _fill_content(self, content):
         description_node = xmpp.simplexml.Node(
             tag=xmpp.NS_JINGLE_FILE_TRANSFER + ' description')
 
@@ -183,6 +183,11 @@
         if 'hash' in self.file_props:
             # TODO: use xep-300 for this bit
             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')
         if 'desc' in self.file_props:
             desc.setData(self.file_props['desc'])
diff -r c157e198bae5 -r cac4252df282 src/common/jingle_ft.py
--- a/src/common/jingle_ft.py   Mon May 28 18:07:52 2012 -0400
+++ b/src/common/jingle_ft.py   Mon May 28 19:54:59 2012 -0400
@@ -117,12 +117,27 @@
         gajim.nec.push_incoming_event(FileRequestReceivedEvent(None,
             conn=self.session.connection, stanza=stanza, 
jingle_content=content,
             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):
         # Calculate file_hash in a new thread
-        self.hashThread = threading.Thread(target=self.__calcHash)
-        self.hashThread.start()
+        # if we haven't sent the hash already.
+        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:
             return
         try:
@@ -139,13 +154,8 @@
             return
         self.file_props['hash'] = hash_
         h.addHash(hash_, self.session.hash_algo)
-        checksum = xmpp.Node(tag='checksum',  
-                             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 )
-    
-        
+        return h
+                
     def __on_session_accept(self, stanza, content, error, action):
         log.info("__on_session_accept")
         con = self.session.connection
diff -r c157e198bae5 -r cac4252df282 src/common/jingle_session.py
--- a/src/common/jingle_session.py      Mon May 28 18:07:52 2012 -0400
+++ b/src/common/jingle_session.py      Mon May 28 19:54:59 2012 -0400
@@ -433,17 +433,16 @@
         payload = jingle.getPayload()
         for p in payload:
             if p.getName() == 'checksum':
-                hashes = p.getTag('file').getTag(name='hashes', 
+                hash_ = p.getTag('file').getTag(name='hash', 
                                         namespace=xmpp.NS_HASHES)
-                for hash in hashes.getChildren():
-                    algo = hash.getAttr('algo')
-                    if algo in xmpp.Hashes.supported:
-                        self.hash_algo = algo
-                        data = hash.getData()
-                        # This only works because there is only one session
-                        # per file in jingleFT
-                        self.file_hash = data
-                        raise xmpp.NodeProcessed
+                algo = hash_.getAttr('algo')
+                if algo in xmpp.Hashes.supported:
+                    self.hash_algo = algo
+                    data = hash_.getData()
+                    # This only works because there is only one session
+                    # per file in jingleFT
+                    self.file_hash = data
+                    raise xmpp.NodeProcessed
         self.__send_error(stanza, 'feature-not-implemented', 
'unsupported-info', type_='modify')
         raise xmpp.NodeProcessed
         
_______________________________________________
Commits mailing list
[email protected]
http://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to