[telepathy-gabble/master] Cache our own caps before announcing them.

Will Thompson will.thompson at collabora.co.uk
Mon Oct 19 06:59:10 PDT 2009


Previously, Gabble didn't put its own capabilities in the cache. So,
when it received its own presence echoed back by the server, it would...
disco itself.
---
 src/connection.c                    |    4 ++++
 src/presence-cache.c                |   31 +++++++++++++++++++++++++++++++
 src/presence-cache.h                |    3 +++
 tests/twisted/Makefile.am           |    1 +
 tests/twisted/caps/trust-thyself.py |   33 +++++++++++++++++++++++++++++++++
 5 files changed, 72 insertions(+), 0 deletions(-)
 create mode 100644 tests/twisted/caps/trust-thyself.py

diff --git a/src/connection.c b/src/connection.c
index f2bad01..392d3b8 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -1961,6 +1961,10 @@ _gabble_connection_signal_own_presence (GabbleConnection *self, GError **error)
     "ver",   caps_hash,
     NULL);
 
+  /* Ensure this set of capabilities is in the cache. */
+  gabble_presence_cache_add_own_caps (self->presence_cache, caps_hash,
+      gabble_presence_peek_caps (presence));
+
   /* XEP-0115 deprecates 'ext' feature bundles. But we still need
    * BUNDLE_VOICE_V1 it for backward-compatibility with Gabble 0.2 */
 
diff --git a/src/presence-cache.c b/src/presence-cache.c
index b99ec47..35af378 100644
--- a/src/presence-cache.c
+++ b/src/presence-cache.c
@@ -1693,6 +1693,37 @@ void gabble_presence_cache_add_bundle_caps (GabblePresenceCache *cache,
 }
 
 void
+gabble_presence_cache_add_own_caps (
+    GabblePresenceCache *cache,
+    const gchar *ver,
+    const GabbleCapabilitySet *cap_set)
+{
+  gchar *uri = g_strdup_printf ("%s#%s", NS_GABBLE_CAPS, ver);
+  CapabilityInfo *info = capability_info_get (cache, uri);
+
+  DEBUG ("caching our own caps (%s)", uri);
+
+  /* If this node was already in the cache, either the entry's correct, or
+   * someone's poisoning us with a SHA-1 collision. Let's update the entry just
+   * in case.
+   */
+  if (info->cap_set == NULL)
+    {
+      info->cap_set = gabble_capability_set_copy (cap_set);
+    }
+  else
+    {
+      gabble_capability_set_clear (info->cap_set);
+      gabble_capability_set_update (info->cap_set, cap_set);
+    }
+
+  info->trust = CAPABILITY_BUNDLE_ENOUGH_TRUST;
+  tp_intset_add (info->guys, cache->priv->conn->parent.self_handle);
+
+  g_free (uri);
+}
+
+void
 gabble_presence_cache_really_remove (
     GabblePresenceCache *cache,
     TpHandle handle)
diff --git a/src/presence-cache.h b/src/presence-cache.h
index 4fac4fb..d4fefbb 100644
--- a/src/presence-cache.h
+++ b/src/presence-cache.h
@@ -82,6 +82,9 @@ void gabble_presence_cache_maybe_remove (GabblePresenceCache *cache,
     TpHandle handle);
 void gabble_presence_cache_add_bundle_caps (GabblePresenceCache *cache,
     const gchar *node, const gchar *ns);
+void gabble_presence_cache_add_own_caps (GabblePresenceCache *cache,
+    const gchar *ver,
+    const GabbleCapabilitySet *cap_set);
 void gabble_presence_cache_really_remove (GabblePresenceCache *cache,
     TpHandle handle);
 
diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am
index 14568e3..1dc8e67 100644
--- a/tests/twisted/Makefile.am
+++ b/tests/twisted/Makefile.am
@@ -11,6 +11,7 @@ TWISTED_TESTS = \
 	caps/initial-caps.py \
 	caps/jingle-caps.py \
 	caps/receive-jingle.py \
+	caps/trust-thyself.py \
 	caps/tube-caps.py \
 	muc/name-conflict.py \
 	muc/renamed.py \
diff --git a/tests/twisted/caps/trust-thyself.py b/tests/twisted/caps/trust-thyself.py
new file mode 100644
index 0000000..8732dc5
--- /dev/null
+++ b/tests/twisted/caps/trust-thyself.py
@@ -0,0 +1,33 @@
+"""
+Test that we cache our own capabilities, so that we don't disco other people
+with the same caps hash.
+"""
+from twisted.words.xish import xpath
+
+from gabbletest import exec_test, make_presence, sync_stream
+from servicetest import EventPattern
+import ns
+
+def test(q, bus, conn, stream):
+    conn.Connect()
+    self_presence = q.expect('stream-presence')
+
+    c = xpath.queryForNodes('/presence/c', self_presence.stanza)[0]
+
+    jid = 'lol at great.big/omg'
+    p = make_presence(jid,
+        caps={'node': c['node'],
+              'hash': c['hash'],
+              'ver':  c['ver'],
+             })
+    stream.send(p)
+
+    uri = c['node'] + '#' + c['ver']
+    q.forbid_events([
+        EventPattern('stream-iq', to=jid, query_ns=ns.DISCO_INFO,
+            query_node=uri)
+    ])
+    sync_stream(q, stream)
+
+if __name__ == '__main__':
+    exec_test(test)
-- 
1.5.6.5




More information about the telepathy-commits mailing list