core (disco), plugin XEP-0115: client use + capabilities hash improvment:
- modified a couple of method from memory to use client instead of profile
- XEP-0115: don't use unique hash for all clients anymore, as disco can be different between clients/components, and even between clients (different identity for instance).
hash is now generated per client on each new session.
This commit is contained in:
parent
6f8834f9da
commit
7ffb8efb92
4 changed files with 64 additions and 73 deletions
|
|
@ -62,53 +62,47 @@ class XEP_0115(object):
|
|||
def getHandler(self, client):
|
||||
return XEP_0115_handler(self, client.profile)
|
||||
|
||||
def _checkHash(self, disco_d, profile):
|
||||
client = self.host.getClient(profile)
|
||||
client.caps_optimize = None
|
||||
|
||||
if XEP_0115.cap_hash is None:
|
||||
disco_d.addCallback(lambda dummy: self.host.hasFeature(client, NS_CAPS_OPTIMIZE))
|
||||
def updateOptimize(optimize):
|
||||
client.caps_optimize = optimize
|
||||
if optimize:
|
||||
log.info(_("Caps optimisation enabled"))
|
||||
client.caps_sent = False
|
||||
else:
|
||||
log.warning(_("Caps optimisation not available"))
|
||||
disco_d.addCallback(updateOptimize)
|
||||
disco_d.addCallback(lambda dummy: self.recalculateHash(profile))
|
||||
return True
|
||||
|
||||
def _presenceTrigger(self, client, obj):
|
||||
if XEP_0115.cap_hash is not None:
|
||||
if client.caps_optimize:
|
||||
if client.caps_sent:
|
||||
return True
|
||||
client.caps_sent = True
|
||||
obj.addChild(XEP_0115.c_elt)
|
||||
return True
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def recalculateHash(self, profile):
|
||||
client = self.host.getClient(profile)
|
||||
def profileConnected(self, client):
|
||||
# we have to calculate hash for client
|
||||
# because disco infos/identities may change between clients
|
||||
|
||||
# optimize check
|
||||
client._caps_optimize = yield self.host.hasFeature(client, NS_CAPS_OPTIMIZE)
|
||||
if client._caps_optimize:
|
||||
log.info(_(u"Caps optimisation enabled"))
|
||||
client._caps_sent = False
|
||||
else:
|
||||
log.warning(_(u"Caps optimisation not available"))
|
||||
|
||||
# hash generation
|
||||
_infos = yield client.discoHandler.info(client.jid, client.jid, '')
|
||||
disco_infos = disco.DiscoInfo()
|
||||
for item in _infos:
|
||||
disco_infos.append(item)
|
||||
cap_hash = self.host.memory.disco.generateHash(disco_infos)
|
||||
log.info("Our capability hash has been generated: [%s]" % cap_hash)
|
||||
disco_infos = disco.DiscoInfo()
|
||||
cap_hash = client._caps_hash = self.host.memory.disco.generateHash(disco_infos)
|
||||
log.info("Our capability hash has been generated: [{cap_hash}]".format(
|
||||
cap_hash = cap_hash))
|
||||
log.debug("Generating capability domish.Element")
|
||||
c_elt = domish.Element((NS_ENTITY_CAPABILITY, 'c'))
|
||||
c_elt['hash'] = 'sha-1'
|
||||
c_elt['node'] = C.APP_URL
|
||||
c_elt['ver'] = cap_hash
|
||||
XEP_0115.cap_hash = cap_hash
|
||||
XEP_0115.c_elt = c_elt
|
||||
if client.caps_optimize:
|
||||
client.caps_sent = False
|
||||
client._caps_elt = c_elt
|
||||
if client._caps_optimize:
|
||||
client._caps_sent = False
|
||||
if cap_hash not in self.host.memory.disco.hashes:
|
||||
self.host.memory.disco.hashes[cap_hash] = disco_infos
|
||||
self.host.memory.updateEntityData(client.jid, C.ENTITY_CAP_HASH, cap_hash, profile_key=profile)
|
||||
self.host.memory.updateEntityData(client.jid, C.ENTITY_CAP_HASH, cap_hash, profile_key=client.profile)
|
||||
|
||||
def _presenceTrigger(self, client, obj):
|
||||
if client._caps_optimize:
|
||||
if client._caps_sent:
|
||||
return True
|
||||
client.caps_sent = True
|
||||
obj.addChild(client._caps_elt)
|
||||
return True
|
||||
|
||||
|
||||
class XEP_0115_handler(XMPPHandler):
|
||||
|
|
|
|||
|
|
@ -204,6 +204,7 @@ class XEP_0329(object):
|
|||
host.bridge.addMethod("FISList", ".plugin", in_sign='ssa{ss}s', out_sign='aa{ss}', method=self._listFiles, async=True)
|
||||
host.bridge.addMethod("FISSharePath", ".plugin", in_sign='ssss', out_sign='s', method=self._sharePath)
|
||||
host.trigger.add("XEP-0234_fileSendingRequest", self._fileSendingRequestTrigger)
|
||||
host.registerNamespace('fis', NS_FIS)
|
||||
|
||||
def getHandler(self, client):
|
||||
return XEP_0329_handler(self)
|
||||
|
|
|
|||
Loading…
Reference in a new issue