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

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



commit 55b76a84b9da3d13f2d2616cb83a29e4726b8a67
Author: juga0 <juga@xxxxxxxxxx>
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



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