|
@@ -4,6 +4,7 @@ import random
|
|
|
import pickle
|
|
|
import logging
|
|
|
import math
|
|
|
+import bisect
|
|
|
from enum import Enum
|
|
|
|
|
|
|
|
@@ -302,10 +303,23 @@ class Network:
|
|
|
these to bootstrap when they know no other relays."""
|
|
|
self.fallbackrelays = fallbackrelays
|
|
|
|
|
|
- def getfallbackrelays(self):
|
|
|
- """Get the list of globally known fallback relays. Clients use
|
|
|
- these to bootstrap when they know no other relays."""
|
|
|
- return self.fallbackrelays
|
|
|
+
|
|
|
+
|
|
|
+ self.fallbackbwcdf = [0]
|
|
|
+ for r in fallbackrelays:
|
|
|
+ self.fallbackbwcdf.append(self.fallbackbwcdf[-1]+r.bw)
|
|
|
+
|
|
|
+
|
|
|
+ self.fallbacktotbw = self.fallbackbwcdf.pop()
|
|
|
+
|
|
|
+ def getfallbackrelay(self):
|
|
|
+ """Get a random one of the globally known fallback relays,
|
|
|
+ weighted by bw. Clients use these to bootstrap when they know
|
|
|
+ no other relays."""
|
|
|
+ idx = random.randint(0, self.fallbacktotbw-1)
|
|
|
+ i = bisect.bisect_right(self.fallbackbwcdf, idx)
|
|
|
+ r = self.fallbackrelays[i-1]
|
|
|
+ return r
|
|
|
|
|
|
def set_wo_style(self, womode, snipauthmode):
|
|
|
"""Set the Walking Onions mode and the SNIP authenticate mode
|