# HG changeset patch # User souliane # Date 1413712447 -7200 # Node ID c3884a63efdec3557ee6a77cdd8dccab1d6b4b45 # Parent b4a264915ea9ec687d3af82da1b53348cf8ea18b plugin XEP-0115: better disco error handling diff -r b4a264915ea9 -r c3884a63efde src/plugins/plugin_xep_0115.py --- 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