core (disco): display a warning when a disco info/items request failed, and return empty DiscoInfo/DiscoITems
This commit is contained in:
parent
8aec15cecf
commit
b140240996
1 changed files with 24 additions and 5 deletions
|
|
@ -34,10 +34,8 @@ from base64 import b64encode
|
|||
from hashlib import sha1
|
||||
|
||||
|
||||
PRESENCE = '/presence'
|
||||
NS_ENTITY_CAPABILITY = 'http://jabber.org/protocol/caps'
|
||||
CAPABILITY_UPDATE = PRESENCE + '/c[@xmlns="' + NS_ENTITY_CAPABILITY + '"]'
|
||||
TIMEOUT = 15
|
||||
CAP_HASH_ERROR = 'ERROR'
|
||||
|
||||
class HashGenerationError(Exception):
|
||||
pass
|
||||
|
|
@ -64,7 +62,9 @@ class HashManager(object):
|
|||
"""
|
||||
|
||||
def __init__(self, persistent):
|
||||
self.hashes = {}
|
||||
self.hashes = {
|
||||
CAP_HASH_ERROR: disco.DiscoInfo(), # used when we can't get disco infos
|
||||
}
|
||||
self.persistent = persistent
|
||||
|
||||
def __getitem__(self, key):
|
||||
|
|
@ -90,6 +90,7 @@ class HashManager(object):
|
|||
d.addCallback(fillHashes)
|
||||
return d
|
||||
|
||||
|
||||
class Discovery(object):
|
||||
""" Manage capabilities of entities """
|
||||
|
||||
|
|
@ -165,8 +166,21 @@ class Discovery(object):
|
|||
self.hashes[cap_hash] = disco_infos
|
||||
self.host.memory.updateEntityData(jid_, C.ENTITY_CAP_HASH, cap_hash, profile_key=client.profile)
|
||||
return disco_infos
|
||||
def infosEb(fail):
|
||||
if fail.check(defer.CancelledError):
|
||||
reason = u"request time-out"
|
||||
else:
|
||||
try:
|
||||
reason = unicode(fail.value)
|
||||
except AttributeError:
|
||||
reason = unicode(fail)
|
||||
log.warning(u"Error while requesting disco infos from {jid}: {reason}".format(jid=jid_.full(), reason=reason))
|
||||
self.host.memory.updateEntityData(jid_, C.ENTITY_CAP_HASH, CAP_HASH_ERROR, profile_key=client.profile)
|
||||
disco_infos = self.hashes[CAP_HASH_ERROR]
|
||||
return disco_infos
|
||||
d = client.disco.requestInfo(jid_)
|
||||
d.addCallback(infosCb)
|
||||
d.addErrback(infosEb)
|
||||
return d
|
||||
else:
|
||||
disco_infos = self.hashes[cap_hash]
|
||||
|
|
@ -193,7 +207,12 @@ class Discovery(object):
|
|||
items = yield client.disco.requestItems(jid_, nodeIdentifier)
|
||||
self.host.memory.updateEntityData(jid_, "DISCO_ITEMS", items, profile_key=client.profile)
|
||||
else:
|
||||
items = yield client.disco.requestItems(jid_, nodeIdentifier)
|
||||
try:
|
||||
items = yield client.disco.requestItems(jid_, nodeIdentifier)
|
||||
except StanzaError as e:
|
||||
log.warning(u"Error while requesting items for {jid}: {reason}"
|
||||
.format(jid=jid_.full(), reason=e.condition))
|
||||
items = disco.DiscoItems()
|
||||
|
||||
defer.returnValue(items)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue