[telepathy-gabble/master] Only ask (full) jids about caps nodes once.

Will Thompson will.thompson at collabora.co.uk
Thu Sep 10 06:44:10 PDT 2009


When Google clients sign in, they broadcast a whole series of presences
with supersets of the same caps bundles (in particular, the client
version doesn't change between each one). Previously, Gabble would send
it a new disco request for each one, which is obviously unnecessary.
---
 src/presence-cache.c               |   13 ++++++++
 tests/twisted/Makefile.am          |    1 +
 tests/twisted/caps/double-disco.py |   54 ++++++++++++++++++++++++++++++++++++
 3 files changed, 68 insertions(+), 0 deletions(-)
 create mode 100644 tests/twisted/caps/double-disco.py

diff --git a/src/presence-cache.c b/src/presence-cache.c
index 5a9e420..382a574 100644
--- a/src/presence-cache.c
+++ b/src/presence-cache.c
@@ -1233,6 +1233,19 @@ _process_caps_uri (GabblePresenceCache *cache,
           &value);
       waiters = (GSList *) value;
 
+      waiter = find_matching_waiter (waiters, handle, resource);
+
+      if (waiter != NULL)
+        {
+          /* We've already asked this jid about this node; just update the
+           * serial.
+           */
+          DEBUG ("updating serial for waiter (%s, %s) from %u to %u",
+              from, uri, waiter->serial, serial);
+          waiter->serial = serial;
+          return;
+        }
+
       waiter = disco_waiter_new (contact_repo, handle, resource,
           hash, ver, serial);
       waiters = g_slist_prepend (waiters, waiter);
diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am
index e7eb2b5..4c3be01 100644
--- a/tests/twisted/Makefile.am
+++ b/tests/twisted/Makefile.am
@@ -5,6 +5,7 @@ TWISTED_TESTS = \
 	caps/advertise-legacy.py \
 	caps/caps-cache.py \
 	caps/compat-bundles.py \
+	caps/double-disco.py \
 	caps/from-bare-jid.py \
 	caps/hashed-caps.py \
 	caps/initial-caps.py \
diff --git a/tests/twisted/caps/double-disco.py b/tests/twisted/caps/double-disco.py
new file mode 100644
index 0000000..140132e
--- /dev/null
+++ b/tests/twisted/caps/double-disco.py
@@ -0,0 +1,54 @@
+
+from twisted.words.xish import xpath
+
+from servicetest import EventPattern
+from gabbletest import exec_test, make_presence, sync_stream
+import constants as cs
+import ns
+
+def test(q, bus, conn, stream):
+    conn.Connect()
+    q.expect('dbus-signal', signal='StatusChanged',
+            args=[cs.CONN_STATUS_CONNECTED, cs.CSR_REQUESTED])
+
+    contact = 'grapes at graze.box/delicious'
+    presence = make_presence(contact, type='available', status='eat me!',
+        caps={ 'node': 'oh:hai',
+               'ver':  'thar',
+             })
+    thar_disco = EventPattern('stream-iq', to=contact,
+        query_ns=ns.DISCO_INFO, query_node='oh:hai#thar')
+
+    stream.send(presence)
+    q.expect_many(thar_disco)
+
+    # Okay, all good so far. But if we get the same caps node again from the
+    # same contact, we shouldn't disco it again: we won't get any more trust
+    # that way. This matters in practice, because Google's clients send a whole
+    # bunch of presence stanzas in quick succession when they sign on.
+    q.forbid_events([thar_disco])
+
+    stream.send(presence)
+    sync_stream(q, stream)
+
+    # If we get a presence update from this contact with some new ext=''
+    # bundles, we should disco those, but not the nodes we're already querying.
+    presence = make_presence(contact, type='available', status='eat me!',
+        caps={ 'node': 'oh:hai',
+               'ver':  'thar',
+               'ext':  'good-sir',
+             })
+    good_sir_disco = EventPattern('stream-iq', to=contact,
+        query_ns=ns.DISCO_INFO, query_node='oh:hai#good-sir')
+    stream.send(presence)
+
+    q.expect_many(good_sir_disco)
+    sync_stream(q, stream)
+
+    # We should only disco ext='' attributes once per jid, too.
+    q.forbid_events([good_sir_disco])
+    stream.send(presence)
+    sync_stream(q, stream)
+
+if __name__ == '__main__':
+    exec_test(test)
-- 
1.5.6.5




More information about the telepathy-commits mailing list