瀏覽代碼

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

Ian Goldberg 4 年之前
父節點
當前提交
b7a2edc1d9
共有 1 個文件被更改,包括 4 次插入6 次删除
  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")