changeset 1244:c3884a63efde

plugin XEP-0115: better disco error handling
author souliane <souliane@mailoo.org>
date Sun, 19 Oct 2014 11:54:07 +0200
parents b4a264915ea9
children 84d06701f5c4
files src/plugins/plugin_xep_0115.py
diffstat 1 files changed, 16 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0115.py	Sun Oct 19 02:48:11 2014 +0200
+++ b/src/plugins/plugin_xep_0115.py	Sun Oct 19 11:54:07 2014 +0200
@@ -23,7 +23,7 @@
 log = getLogger(__name__)
 from twisted.words.xish import domish
 from twisted.words.protocols.jabber import jid
-from twisted.internet import defer
+from twisted.internet import defer, error
 from zope.interface import implements
 from wokkel import disco, iwokkel
 
@@ -127,12 +127,11 @@
     def getDiscoItems(self, requestor, target, nodeIdentifier=''):
         return []
 
-    @defer.inlineCallbacks
     def update(self, presence):
         """
         Manage the capabilities of the entity
 
-        Check if we know the version of this capatilities and get the capibilities if necessary
+        Check if we know the version of this capabilities and get the capabilities if necessary
         """
         from_jid = jid.JID(presence['from'])
         c_elem = presence.elements(NS_ENTITY_CAPABILITY, 'c').next()
@@ -150,16 +149,20 @@
             self.host.memory.updateEntityData(from_jid, C.ENTITY_CAP_HASH, c_ver, self.profile)
             return
 
-        try:
-            yield self.host.getDiscoInfos(from_jid, self.profile)
-        except Exception, e:
-            log.error(_("Couldn't retrieve disco info for {jid}: {error}").format(jid=from_jid.full(), error=e.condition))
-            return
-        if c_hash != 'sha-1':
-            #unknown hash method
+        if c_hash != 'sha-1': # unknown hash method
             log.warning(_('Unknown hash method for entity capabilities: [%(hash_method)s] (entity: %(jid)s, node: %(node)s)') % {'hash_method':c_hash, 'jid': from_jid, 'node': c_node})
-        computed_hash = self.host.memory.getEntityDatum(from_jid, C.ENTITY_CAP_HASH, self.profile)
-        if computed_hash != c_ver:
-            log.warning(_('Computed hash differ from given hash:\ngiven: [%(given_hash)s]\ncomputed: [%(computed_hash)s]\n(entity: %(jid)s, node: %(node)s)') % {'given_hash':c_ver, 'computed_hash': computed_hash, 'jid': from_jid, 'node': c_node})
+
+        def cb(dummy):
+            computed_hash = self.host.memory.getEntityDatum(from_jid, C.ENTITY_CAP_HASH, self.profile)
+            if computed_hash != c_ver:
+                log.warning(_('Computed hash differ from given hash:\ngiven: [%(given_hash)s]\ncomputed: [%(computed_hash)s]\n(entity: %(jid)s, node: %(node)s)') % {'given_hash':c_ver, 'computed_hash': computed_hash, 'jid': from_jid, 'node': c_node})
 
+        def eb(failure):
+            if isinstance(failure.value, error.ConnectionDone):
+                return
+            msg = failure.value.condition if hasattr(failure.value, 'condition') else failure.getErrorMessage()
+            log.error(_("Couldn't retrieve disco info for {jid}: {error}").format(jid=from_jid.full(), error=msg))
+
+        d = self.host.getDiscoInfos(from_jid, self.profile)
+        d.addCallbacks(cb, eb)
         # TODO: me must manage the full algorithm described at XEP-0115 #5.4 part 3