Browse Source

Now that pick_weighted_relay_index exists, have pick_weighted_relay just use it instead of duplicating code

Ian Goldberg 4 years ago
parent
commit
b7a2edc1d9
1 changed files with 4 additions and 6 deletions
  1. 4 6
      dirauth.py

+ 4 - 6
dirauth.py

@@ -296,15 +296,13 @@ class RelayPicker:
     def pick_weighted_relay(self):
         """Select a random relay with probability proportional to its bw
         weight."""
-        totbw = self.totbw
-        if totbw < 1:
-            raise ValueError("No relays to choose from")
-        idx = random.randint(0, totbw-1)
+        idx = self.pick_weighted_relay_index()
         return self.pick_relay_by_uniform_index(idx)
 
     def pick_weighted_relay_index(self):
-        """Select a random relay index (for use in Walkig Onions) with probability proportional to its bw
-        weight."""
+        """Select a random relay index (for use in Walking Onions)
+        uniformly, which will results in picking a relay with
+        probability proportional to its bw weight."""
         totbw = self.totbw
         if totbw < 1:
             raise ValueError("No relays to choose from")