[tor-commits] [sbws/master] relaylist: add method to check exit policy with port

juga at torproject.org juga at torproject.org
Mon Dec 3 22:33:03 UTC 2018


commit d980582f240801ef2c98011d3066b5af9394c0c5
Author: juga0 <juga at riseup.net>
Date:   Thu Nov 22 14:18:40 2018 +0000

    relaylist: add method to check exit policy with port
    
    In order to do not relay on resolving a domain locally to check
    the IP in the exit policy.
---
 sbws/lib/relaylist.py | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/sbws/lib/relaylist.py b/sbws/lib/relaylist.py
index 9402574..9d5c050 100644
--- a/sbws/lib/relaylist.py
+++ b/sbws/lib/relaylist.py
@@ -127,6 +127,17 @@ class Relay:
         assert is_valid_ipv4_address(host) or is_valid_ipv6_address(host)
         return self.exit_policy.can_exit_to(host, port)
 
+    def can_exit_to_port(self, port):
+        """
+        Returns True if the relay has an exit policy and the policy accepts
+        exiting to the given portself or False otherwise.
+        """
+        assert isinstance(port, int)
+        # if dind't get the descriptor, there isn't exit policy
+        if not self.exit_policy:
+            return False
+        return self.exit_policy.can_exit_to(port=port)
+
 
 class RelayList:
     ''' Keeps a list of all relays in the current Tor network and updates it





More information about the tor-commits mailing list