[tor-commits] [sbws/maint-1.1] fix: relaylist: Add methods to obtain exits that

juga at torproject.org juga at torproject.org
Tue Feb 23 07:22:32 UTC 2021


commit 55b76a84b9da3d13f2d2616cb83a29e4726b8a67
Author: juga0 <juga at riseup.net>
Date:   Tue Feb 2 11:46:21 2021 +0000

    fix: relaylist: Add methods to obtain exits that
    
    can exit to some IPs.
    To use them in the cases it will be more convenient.
---
 sbws/lib/relaylist.py | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/sbws/lib/relaylist.py b/sbws/lib/relaylist.py
index 863689e..3ff1f73 100644
--- a/sbws/lib/relaylist.py
+++ b/sbws/lib/relaylist.py
@@ -219,11 +219,34 @@ class Relay:
             return False
         return False
 
+    def can_exit_to_port_some_ips(self, port):
+        """
+        Returns True if the relay has an exit policy and the policy accepts
+        exiting to the given port and some public IPs or False otherwise.
+        """
+        assert isinstance(port, int)
+        try:
+            if self.exit_policy:
+                # Not using argument `strict`, to know whether it can exit
+                # some public IPs, though not all.
+                return (
+                    self.exit_policy.strip_private()
+                    .can_exit_to(port=port)
+                )
+        except TypeError:
+            return False
+        return False
+
     def is_exit_not_bad_allowing_port_all_ips(self, port):
         return (Flag.BADEXIT not in self.flags and
                 Flag.EXIT in self.flags and
                 self.can_exit_to_port_all_ips(port))
 
+    def is_exit_not_bad_allowing_port_some_ips(self, port):
+        return (Flag.BADEXIT not in self.flags and
+                Flag.EXIT in self.flags and
+                self.can_exit_to_port_some_ips(port))
+
     def increment_relay_recent_measurement_attempt(self):
         """
         Increment The number of times that a relay has been queued
@@ -457,6 +480,10 @@ class RelayList:
         return [r for r in self.exits
                 if r.is_exit_not_bad_allowing_port_all_ips(port)]
 
+    def exits_not_bad_allowing_port_some_ips(self, port):
+        return [r for r in self.exits
+                if r.is_exit_not_bad_allowing_port_some_ips(port)]
+
     def increment_recent_measurement_attempt(self):
         """
         Increment the number of times that any relay has been queued to be





More information about the tor-commits mailing list