core (disco): fixed disco capabilities (empty disco was used)

This commit is contained in:
Goffi 2018-05-22 09:59:58 +02:00
commit c0e2a4f84b
2 changed files with 10 additions and 5 deletions

View file

@ -84,7 +84,13 @@ class HashManager(object):
def fillHashes(hashes): def fillHashes(hashes):
for hash_, xml in hashes.iteritems(): for hash_, xml in hashes.iteritems():
element = xml_tools.ElementParser()(xml) element = xml_tools.ElementParser()(xml)
self.hashes[hash_] = disco.DiscoInfo.fromElement(element) disco_info = disco.DiscoInfo.fromElement(element)
if not disco_info.features and not disco_info.identities:
log.warning(_(u"no feature/identity found in disco element (hash: {cap_hash}), ignoring: {xml}").format(
cap_hash=hash_, xml=xml))
else:
self.hashes[hash_] = disco_info
log.info(u"Disco hashes loaded") log.info(u"Disco hashes loaded")
d = self.persistent.load() d = self.persistent.load()
d.addCallback(fillHashes) d.addCallback(fillHashes)
@ -158,10 +164,10 @@ class Discovery(object):
if jid_ is None: if jid_ is None:
jid_ = jid.JID(client.jid.host) jid_ = jid.JID(client.jid.host)
try: try:
cap_hash = self.host.memory.getEntityData(jid_, [C.ENTITY_CAP_HASH], client.profile)[C.ENTITY_CAP_HASH]
if not use_cache: if not use_cache:
# we ignore cache, so we pretend we haven't found it # we ignore cache, so we pretend we haven't found it
raise KeyError raise KeyError
cap_hash = self.host.memory.getEntityData(jid_, [C.ENTITY_CAP_HASH], client.profile)[C.ENTITY_CAP_HASH]
except (KeyError, exceptions.UnknownEntityError): except (KeyError, exceptions.UnknownEntityError):
# capability hash is not available, we'll compute one # capability hash is not available, we'll compute one
def infosCb(disco_infos): def infosCb(disco_infos):

View file

@ -79,11 +79,10 @@ class XEP_0115(object):
disco_infos = disco.DiscoInfo() disco_infos = disco.DiscoInfo()
for item in _infos: for item in _infos:
disco_infos.append(item) disco_infos.append(item)
disco_infos = disco.DiscoInfo()
cap_hash = client._caps_hash = self.host.memory.disco.generateHash(disco_infos) cap_hash = client._caps_hash = self.host.memory.disco.generateHash(disco_infos)
log.info("Our capability hash has been generated: [{cap_hash}]".format( log.info(u"Our capability hash has been generated: [{cap_hash}]".format(
cap_hash = cap_hash)) cap_hash = cap_hash))
log.debug("Generating capability domish.Element") log.debug(u"Generating capability domish.Element")
c_elt = domish.Element((NS_ENTITY_CAPABILITY, 'c')) c_elt = domish.Element((NS_ENTITY_CAPABILITY, 'c'))
c_elt['hash'] = 'sha-1' c_elt['hash'] = 'sha-1'
c_elt['node'] = C.APP_URL c_elt['node'] = C.APP_URL