[folks/folks-0-4] Bug 645680 — Use random integer IDs for Kf.Personas



commit 8203422ce88df80c1c3c40cf715d959359e1cfa8
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Mon Jan 17 15:42:24 2011 +0000

    Bug 645680 â?? Use random integer IDs for Kf.Personas
    
    Using consecutive integer IDs meant that IDs often got re-used as Personas
    were deleted and added, meaning that the same ID could, over time, be applied
    to several different Personas which contained completely different IM
    addresses. Any external references to such IDs which weren't updated over
    time with the IDs themselves (such as the to-be-added anti-links) would end
    up pointing to effectively the wrong Persona.
    
    A perfect solution would be to hash the IM addresses in each Persona and use
    that as the Persona's ID, but that's not possible as the set of IM addresses
    in a Kf.Persona can change over time, while the ID has to remain constant.
    Consequently, the use of a random integer evenly distributed over the space of
    unsigned 32-bit integers will do.
    
    Closes: bgo#645680

 NEWS                                    |    1 +
 backends/key-file/kf-persona-store.vala |   14 ++++++--------
 2 files changed, 7 insertions(+), 8 deletions(-)
---
diff --git a/NEWS b/NEWS
index 3d006a7..0181007 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,7 @@ Bugs fixed:
 * Bug 645430 â?? folks-inspect: Use LinkedHashSet to access im-addresses
 * Bug 645411 â?? folks-import segfaults on startup
 * Crasher when removing Personas
+* Bug 645680 â?? Use random integer IDs for Kf.Personas
 
 Overview of changes from libfolks 0.4.0 to libfolks 0.4.1
 =========================================================
diff --git a/backends/key-file/kf-persona-store.vala b/backends/key-file/kf-persona-store.vala
index 2bfc919..d67e1a1 100644
--- a/backends/key-file/kf-persona-store.vala
+++ b/backends/key-file/kf-persona-store.vala
@@ -34,7 +34,6 @@ public class Folks.Backends.Kf.PersonaStore : Folks.PersonaStore
   private HashTable<string, Persona> _personas;
   private File _file;
   private GLib.KeyFile _key_file;
-  private uint _first_unused_id = 0;
   private unowned Cancellable _save_key_file_cancellable = null;
   private bool _is_prepared = false;
 
@@ -228,9 +227,6 @@ public class Folks.Backends.Kf.PersonaStore : Folks.PersonaStore
               var groups = this._key_file.get_groups ();
               foreach (var persona_id in groups)
                 {
-                  if (int.parse (persona_id) == this._first_unused_id)
-                    this._first_unused_id++;
-
                   Persona persona = new Kf.Persona (this._key_file, persona_id,
                       this);
                   this._personas.insert (persona.iid, persona);
@@ -311,13 +307,15 @@ public class Folks.Backends.Kf.PersonaStore : Folks.PersonaStore
 
       debug ("Adding Persona from details.");
 
-      /* Find the first unused ID, taking into account that the IDs in the key
-       * file may not be contiguous. */
+      /* Generate a new random number for the persona's ID, so as to try and
+       * ensure that IDs don't get recycled; if they did, anti-links which were
+       * made against a key-file persona which used an ID which has been
+       * re-used would be applied to the wrong persona (the new one, instead of
+       * the old one, which could've been completely different). */
       string persona_id = null;
       do
         {
-          persona_id = this._first_unused_id.to_string ();
-          this._first_unused_id++;
+          persona_id = Random.next_int ().to_string ();
         }
       while (this._key_file.has_group (persona_id) == true);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]