[telepathy-gabble/master] Add compatibility bundles to the cache
Will Thompson
will.thompson at collabora.co.uk
Mon Oct 5 08:44:04 PDT 2009
---
src/capabilities.c | 9 +++++
src/presence-cache.c | 58 +++++++++++++++++++++++++++++++++--
src/presence-cache.h | 3 ++
tests/twisted/caps/trust-thyself.py | 15 ++++++--
4 files changed, 78 insertions(+), 7 deletions(-)
diff --git a/src/capabilities.c b/src/capabilities.c
index ddec4de..3a24a38 100644
--- a/src/capabilities.c
+++ b/src/capabilities.c
@@ -340,6 +340,15 @@ capabilities_fill_cache (GabblePresenceCache *cache)
GOOGLE_BUNDLE ("camera-v1", NULL);
#undef GOOGLE_BUNDLE
+
+ /* We should also cache the ext='' bundles Gabble advertises: older Gabbles
+ * advertise these and don't support hashed caps, and we shouldn't need to
+ * disco them.
+ */
+ gabble_presence_cache_add_bundle_caps (cache,
+ NS_GABBLE_CAPS "#" BUNDLE_VOICE_V1, NS_GOOGLE_FEAT_VOICE);
+ gabble_presence_cache_add_bundle_caps (cache,
+ NS_GABBLE_CAPS "#" BUNDLE_VIDEO_V1, NS_GOOGLE_FEAT_VIDEO);
}
const CapabilityConversionData capabilities_conversions[] =
diff --git a/src/presence-cache.c b/src/presence-cache.c
index 35af378..d79477f 100644
--- a/src/presence-cache.c
+++ b/src/presence-cache.c
@@ -218,6 +218,12 @@ struct _CapabilityInfo
TpIntSet *guys;
guint trust;
+
+ /* TRUE if this cache entry is one of our own, so between caps and
+ * per_channel_manager_caps it holds the complete set of features for the
+ * node.
+ */
+ gboolean complete;
};
static CapabilityInfo *
@@ -1701,11 +1707,14 @@ gabble_presence_cache_add_own_caps (
gchar *uri = g_strdup_printf ("%s#%s", NS_GABBLE_CAPS, ver);
CapabilityInfo *info = capability_info_get (cache, uri);
+ if (info->complete)
+ goto out;
+
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 this node was already in the cache but not labelled as complete, 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)
{
@@ -1717,10 +1726,53 @@ gabble_presence_cache_add_own_caps (
gabble_capability_set_update (info->cap_set, cap_set);
}
+ info->complete = TRUE;
info->trust = CAPABILITY_BUNDLE_ENOUGH_TRUST;
tp_intset_add (info->guys, cache->priv->conn->parent.self_handle);
+ /* FIXME: we should satisfy any waiters for this node now, but I think that
+ * can wait till 0.9.
+ */
+
+out:
+ g_free (uri);
+}
+
+/**
+ * gabble_presence_cache_peek_own_caps:
+ * @cache: a presence cache
+ * @ver: a verification string or bundle name
+ *
+ * If the capabilities corresponding to @ver have been added to the cache with
+ * gabble_presence_cache_add_own_caps(), returns a set of those capabilities;
+ * otherwise, returns %NULL.
+ *
+ * Since the cache only records features Gabble understands (omitting unknown
+ * features, identities, and data forms), we can only serve up disco replies
+ * from the cache if we know we once advertised exactly this verification
+ * string ourselves.
+ *
+ * Returns: a set of capabilities, if we know exactly what @ver means.
+ */
+const GabbleCapabilitySet *
+gabble_presence_cache_peek_own_caps (
+ GabblePresenceCache *cache,
+ const gchar *ver)
+{
+ gchar *uri = g_strdup_printf ("%s#%s", NS_GABBLE_CAPS, ver);
+ CapabilityInfo *info = capability_info_get (cache, uri);
+
g_free (uri);
+
+ if (info->complete)
+ {
+ g_assert (info->cap_set != NULL);
+ return info->cap_set;
+ }
+ else
+ {
+ return NULL;
+ }
}
void
diff --git a/src/presence-cache.h b/src/presence-cache.h
index d4fefbb..a984868 100644
--- a/src/presence-cache.h
+++ b/src/presence-cache.h
@@ -85,6 +85,9 @@ 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);
+const GabbleCapabilitySet *gabble_presence_cache_peek_own_caps (
+ GabblePresenceCache *cache,
+ const gchar *ver);
void gabble_presence_cache_really_remove (GabblePresenceCache *cache,
TpHandle handle);
diff --git a/tests/twisted/caps/trust-thyself.py b/tests/twisted/caps/trust-thyself.py
index 8732dc5..55bdd97 100644
--- a/tests/twisted/caps/trust-thyself.py
+++ b/tests/twisted/caps/trust-thyself.py
@@ -1,6 +1,6 @@
"""
Test that we cache our own capabilities, so that we don't disco other people
-with the same caps hash.
+with the same caps hash or ext='' bundles.
"""
from twisted.words.xish import xpath
@@ -22,12 +22,19 @@ def test(q, bus, conn, stream):
})
stream.send(p)
- uri = c['node'] + '#' + c['ver']
q.forbid_events([
- EventPattern('stream-iq', to=jid, query_ns=ns.DISCO_INFO,
- query_node=uri)
+ EventPattern('stream-iq', to=jid, query_ns=ns.DISCO_INFO),
])
sync_stream(q, stream)
+ p = make_presence(jid,
+ caps={'node': c['node'],
+ 'ver': c['ver'],
+ # omitting hash='' so Gabble doesn't ignore ext=''
+ 'ext': 'voice-v1 video-v1',
+ })
+ stream.send(p)
+ sync_stream(q, stream)
+
if __name__ == '__main__':
exec_test(test)
--
1.5.6.5
More information about the telepathy-commits
mailing list