plugin XEP-0115: better disco error handling

This commit is contained in:
souliane 2014-10-19 11:54:07 +02:00
commit 7eac1b2323

View file

@ -23,7 +23,7 @@ from sat.core.log import getLogger
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 @@ class XEP_0115_handler(XMPPHandler):
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 @@ class XEP_0115_handler(XMPPHandler):
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