Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0115.py @ 1244:c3884a63efde
plugin XEP-0115: better disco error handling
author | souliane <souliane@mailoo.org> |
---|---|
date | Sun, 19 Oct 2014 11:54:07 +0200 |
parents | 6b10442e8920 |
children | 8b891f9be183 |
comparison
equal
deleted
inserted
replaced
1243:b4a264915ea9 | 1244:c3884a63efde |
---|---|
21 from sat.core.constants import Const as C | 21 from sat.core.constants import Const as C |
22 from sat.core.log import getLogger | 22 from sat.core.log import getLogger |
23 log = getLogger(__name__) | 23 log = getLogger(__name__) |
24 from twisted.words.xish import domish | 24 from twisted.words.xish import domish |
25 from twisted.words.protocols.jabber import jid | 25 from twisted.words.protocols.jabber import jid |
26 from twisted.internet import defer | 26 from twisted.internet import defer, error |
27 from zope.interface import implements | 27 from zope.interface import implements |
28 from wokkel import disco, iwokkel | 28 from wokkel import disco, iwokkel |
29 | 29 |
30 try: | 30 try: |
31 from twisted.words.protocols.xmlstream import XMPPHandler | 31 from twisted.words.protocols.xmlstream import XMPPHandler |
125 return [disco.DiscoFeature(NS_ENTITY_CAPABILITY), disco.DiscoFeature(NS_CAPS_OPTIMIZE)] | 125 return [disco.DiscoFeature(NS_ENTITY_CAPABILITY), disco.DiscoFeature(NS_CAPS_OPTIMIZE)] |
126 | 126 |
127 def getDiscoItems(self, requestor, target, nodeIdentifier=''): | 127 def getDiscoItems(self, requestor, target, nodeIdentifier=''): |
128 return [] | 128 return [] |
129 | 129 |
130 @defer.inlineCallbacks | |
131 def update(self, presence): | 130 def update(self, presence): |
132 """ | 131 """ |
133 Manage the capabilities of the entity | 132 Manage the capabilities of the entity |
134 | 133 |
135 Check if we know the version of this capatilities and get the capibilities if necessary | 134 Check if we know the version of this capabilities and get the capabilities if necessary |
136 """ | 135 """ |
137 from_jid = jid.JID(presence['from']) | 136 from_jid = jid.JID(presence['from']) |
138 c_elem = presence.elements(NS_ENTITY_CAPABILITY, 'c').next() | 137 c_elem = presence.elements(NS_ENTITY_CAPABILITY, 'c').next() |
139 try: | 138 try: |
140 c_ver = c_elem['ver'] | 139 c_ver = c_elem['ver'] |
148 # we already know the hash, we update the jid entity | 147 # we already know the hash, we update the jid entity |
149 log.debug ("hash [%(hash)s] already in cache, updating entity [%(jid)s]" % {'hash': c_ver, 'jid': from_jid.full()}) | 148 log.debug ("hash [%(hash)s] already in cache, updating entity [%(jid)s]" % {'hash': c_ver, 'jid': from_jid.full()}) |
150 self.host.memory.updateEntityData(from_jid, C.ENTITY_CAP_HASH, c_ver, self.profile) | 149 self.host.memory.updateEntityData(from_jid, C.ENTITY_CAP_HASH, c_ver, self.profile) |
151 return | 150 return |
152 | 151 |
153 try: | 152 if c_hash != 'sha-1': # unknown hash method |
154 yield self.host.getDiscoInfos(from_jid, self.profile) | |
155 except Exception, e: | |
156 log.error(_("Couldn't retrieve disco info for {jid}: {error}").format(jid=from_jid.full(), error=e.condition)) | |
157 return | |
158 if c_hash != 'sha-1': | |
159 #unknown hash method | |
160 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}) | 153 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}) |
161 computed_hash = self.host.memory.getEntityDatum(from_jid, C.ENTITY_CAP_HASH, self.profile) | |
162 if computed_hash != c_ver: | |
163 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}) | |
164 | 154 |
155 def cb(dummy): | |
156 computed_hash = self.host.memory.getEntityDatum(from_jid, C.ENTITY_CAP_HASH, self.profile) | |
157 if computed_hash != c_ver: | |
158 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}) | |
159 | |
160 def eb(failure): | |
161 if isinstance(failure.value, error.ConnectionDone): | |
162 return | |
163 msg = failure.value.condition if hasattr(failure.value, 'condition') else failure.getErrorMessage() | |
164 log.error(_("Couldn't retrieve disco info for {jid}: {error}").format(jid=from_jid.full(), error=msg)) | |
165 | |
166 d = self.host.getDiscoInfos(from_jid, self.profile) | |
167 d.addCallbacks(cb, eb) | |
165 # TODO: me must manage the full algorithm described at XEP-0115 #5.4 part 3 | 168 # TODO: me must manage the full algorithm described at XEP-0115 #5.4 part 3 |