[telepathy-gabble/master] Refactor satisfy/redisco/keep-waiting loop

Will Thompson will.thompson at collabora.co.uk
Tue May 12 06:23:32 PDT 2009


I believe this logic to be approximately the same. I changed the "enough
trust" comparison not to subtract trust_inc. I believe that that was
subtracted to compensate for waiter_self being included in
disco_waiter_list_get_request_count (), but that's not necessary having
already removed waiter_self from waiters. (In fact it was not correct
before: waiter_self might already have been removed from waiters,
depending on the list's order.)
---
 src/presence-cache.c |   82 +++++++++++++++++++++++++-------------------------
 1 files changed, 41 insertions(+), 41 deletions(-)

diff --git a/src/presence-cache.c b/src/presence-cache.c
index 6f1dd96..17386c6 100644
--- a/src/presence-cache.c
+++ b/src/presence-cache.c
@@ -1072,64 +1072,64 @@ _caps_disco_cb (GabbleDisco *disco,
           per_channel_manager_caps, trust_inc);
     }
 
-  for (i = waiters; NULL != i;)
+  if (trust >= CAPABILITY_BUNDLE_ENOUGH_TRUST)
     {
-      DiscoWaiter *waiter;
+      /* We trust this caps node. Serve all its waiters. */
+      for (i = waiters; NULL != i; i = i->next)
+        {
+          DiscoWaiter *waiter = (DiscoWaiter *) i->data;
 
-      waiter = (DiscoWaiter *) i->data;
+          set_caps_for (waiter, cache, caps, per_channel_manager_caps, handle,
+              jid);
+          g_signal_emit (cache, signals[CAPABILITIES_DISCOVERED], 0, waiter->handle);
+        }
 
-      if (trust >= CAPABILITY_BUNDLE_ENOUGH_TRUST || waiter->handle == handle)
-        {
-          GSList *tmp;
-          gpointer key;
-          gpointer value;
+      g_hash_table_remove (priv->disco_pending, node);
+    }
+  else
+    {
+      gpointer key;
+      /* We don't trust this yet (either the hash was bad, or we haven't had
+       * enough responses, as appropriate).
+       */
 
-          /* FIXME: I think we should respect the caps, even if the hash is
-           * wrong, for the jid that answered the query.
-           */
-          if (!bad_hash)
-            set_caps_for (waiter, cache, caps, per_channel_manager_caps,
-                handle, jid);
+      /* Set caps for the contact that replied (if the hash was correct) and
+       * remove them from the list of waiters.
+       * FIXME I think we should respect the caps, even if the hash is wrong,
+       *       for the jid that answered the query.
+       */
+      if (!bad_hash)
+        set_caps_for (waiter_self, cache, caps, per_channel_manager_caps,
+            handle, jid);
 
-          tmp = i;
-          i = i->next;
+      waiters = g_slist_remove (waiters, waiter_self);
 
-          waiters = g_slist_delete_link (waiters, tmp);
+      if (!g_hash_table_lookup_extended (priv->disco_pending, node, &key, NULL))
+        g_assert_not_reached ();
 
-          if (!g_hash_table_lookup_extended (priv->disco_pending, node, &key,
-                &value))
-            g_assert_not_reached ();
+      g_hash_table_steal (priv->disco_pending, key);
+      g_hash_table_insert (priv->disco_pending, key, waiters);
 
-          g_hash_table_steal (priv->disco_pending, node);
-          g_hash_table_insert (priv->disco_pending, key, waiters);
+      g_signal_emit (cache, signals[CAPABILITIES_DISCOVERED], 0, waiter_self->handle);
+      disco_waiter_free (waiter_self);
 
-          g_signal_emit (cache, signals[CAPABILITIES_DISCOVERED], 0, waiter->handle);
-          disco_waiter_free (waiter);
-        }
-      else if (trust + disco_waiter_list_get_request_count (waiters) - trust_inc
-          < CAPABILITY_BUNDLE_ENOUGH_TRUST)
+      /* Ensure that we have enough pending requests to get enough trust for
+       * this node.
+       */
+      for (i = waiters; i != NULL; i = i->next)
         {
-          /* if the possible trust, not counting this guy, is too low,
-           * we have been poisoned and reset our trust meters - disco
-           * anybody we still haven't to be able to get more trusted replies */
+          DiscoWaiter *waiter = (DiscoWaiter *) i->data;
+
+          if (trust + disco_waiter_list_get_request_count (waiters)
+              >= CAPABILITY_BUNDLE_ENOUGH_TRUST)
+            break;
 
           if (!waiter->disco_requested)
             redisco (cache, disco, waiter, node, contact_repo);
-
-          i = i->next;
-        }
-      else
-        {
-          /* trust level still uncertain, don't do nothing */
-          i = i->next;
         }
     }
 
-  if (trust >= CAPABILITY_BUNDLE_ENOUGH_TRUST)
-    g_hash_table_remove (priv->disco_pending, node);
-
 OUT:
-
   if (handle)
     tp_handle_unref (contact_repo, handle);
 }
-- 
1.5.6.5




More information about the telepathy-commits mailing list