diff sat_pubsub/backend.py @ 467:d86e0f8a1405

privilege: store roster cache in database: - rosters are now stored on database and restored on startup. This way, presence map can be restored without the need to wait for all contact to send presence again - roster version are checked, if a new version is received, presence map is updated accordingly - roster are not retrieved if presence are received in a too short delay (see ROSTER_TTL), to avoid using too much resources if a client connect/disconnect a lot The current behaviour works around XEP-0356 limitations. An update of the XEP will be needed to get roster pushes and roster version.
author Goffi <goffi@goffi.org>
date Fri, 15 Oct 2021 15:30:18 +0200
parents 391aa65f72b2
children ed9e12701e0f
line wrap: on
line diff
--- a/sat_pubsub/backend.py	Fri Oct 15 13:40:59 2021 +0200
+++ b/sat_pubsub/backend.py	Fri Oct 15 15:30:18 2021 +0200
@@ -955,7 +955,7 @@
             if not roster[requestor].subscriptionFrom:
                 raise error.Forbidden()
 
-        d = self.getOwnerRoster(node)
+        d = defer.ensureDeferred(self.getOwnerRoster(node))
         d.addCallback(gotRoster)
         return d
 
@@ -966,7 +966,7 @@
         @param node(Node): node to check
         @param requestor(jid.JID): entity who want to access node
         """
-        roster = yield self.getOwnerRoster(node)
+        roster = yield defer.ensureDeferred(self.getOwnerRoster(node))
 
         if roster is None:
             raise error.Forbidden()
@@ -1077,11 +1077,10 @@
         d.addCallback(lambda items_data: [item_data.item for item_data in items_data])
         return d
 
-    @defer.inlineCallbacks
-    def getOwnerRoster(self, node, owners=None):
+    async def getOwnerRoster(self, node, owners=None):
         # FIXME: roster of publisher, not owner, must be used
         if owners is None:
-            owners = yield node.getOwners()
+            owners = await node.getOwners()
 
         if len(owners) != 1:
             log.msg('publisher-roster access is not allowed with more than 1 owner')
@@ -1090,13 +1089,13 @@
         owner_jid = owners[0]
 
         try:
-            roster = yield self.privilege.getRoster(owner_jid)
+            roster = await self.privilege.getRoster(owner_jid)
         except Exception as e:
             log.msg("Error while getting roster of {owner_jid}: {msg}".format(
                 owner_jid = owner_jid.full(),
                 msg = e))
             return
-        defer.returnValue(roster)
+        return roster
 
     async def getItemsData(self, nodeIdentifier, requestor, recipient, maxItems=None,
                        itemIdentifiers=None, ext_data=None):