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

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



commit 8869cf4f01341dd685508afb2b2a10b9b3ea0f26
Author: Isis Lovecruft <isis@xxxxxxxxxxxxxx>
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) {};



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits