[tor-commits] [tor-launcher/master] Bug 18113: Randomly permutate available default bridges of chosen type.

gk at torproject.org gk at torproject.org
Sat Jan 23 20:30:43 UTC 2016


commit 8869cf4f01341dd685508afb2b2a10b9b3ea0f26
Author: Isis Lovecruft <isis at torproject.org>
Date:   Thu Jan 21 03:37:43 2016 +0000

    Bug 18113: Randomly permutate available default bridges of chosen type.
    
     * ADDS a new function to TorLauncherUtil, rearrangeBridges() which
       takes an array of items and returns a random permutation of that
       array.
    
     * CHANGE defaultBridges() getter to call this.rearrangeBridges()
       before returning the default bridges.  This causing the ordering of
       the default bridges in the torrc to vary among clients, resulting
       in a more even distribution of clients to default bridges.
---
 src/modules/tl-util.jsm |   14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/src/modules/tl-util.jsm b/src/modules/tl-util.jsm
index 812b32b..7f93f39 100644
--- a/src/modules/tl-util.jsm
+++ b/src/modules/tl-util.jsm
@@ -246,6 +246,19 @@ let TorLauncherUtil =  // Public
     } catch (e) {}
   },
 
+  // Currently, this returns a random permutation of an array, bridgeArray.
+  // Later, we might want to change this function to weight based on the
+  // bridges' bandwidths.
+  rearrangeBridges: function(bridgeArray)
+  {
+    for (var j, x, i = bridgeArray.length; i;
+           j = parseInt(Math.random() * i),
+           x = bridgeArray[--i],
+           bridgeArray[i] = bridgeArray[j],
+           bridgeArray[j] = x);
+    return bridgeArray;
+  },
+
   get shouldStartAndOwnTor()
   {
     const kPrefStartTor = "extensions.torlauncher.start_tor";
@@ -361,6 +374,7 @@ let TorLauncherUtil =  // Public
             bridgeArray.push(s);
         }
       }
+      this.rearrangeBridges(bridgeArray);
 
       return bridgeArray;
     } catch(e) {};





More information about the tor-commits mailing list