[tor-bugs] #18881 [Core Tor/Stem]: speed up is_match() of stem/exit_policy.py

Tor Bug Tracker & Wiki blackhole at torproject.org
Tue Apr 26 14:34:07 UTC 2016


#18881: speed up is_match() of stem/exit_policy.py
---------------------------+------------------------
 Reporter:  toralf         |          Owner:  atagar
     Type:  defect         |         Status:  new
 Priority:  Medium         |      Milestone:
Component:  Core Tor/Stem  |        Version:
 Severity:  Normal         |     Resolution:
 Keywords:                 |  Actual Points:
Parent ID:                 |         Points:
 Reviewer:                 |        Sponsor:
---------------------------+------------------------

Comment (by toralf):

 Hi,

 "commenting out this section :
 {{{
     # validate our input and check if the argument doesn't match our
 address type

     """
     if address is not None:
       address_type = self.get_address_type()
       if stem.util.connection.is_valid_ipv4_address(address):
         if address_type == AddressType.IPv6:
           return False
       elif stem.util.connection.is_valid_ipv6_address(address,
 allow_brackets = True):
         if address_type == AddressType.IPv4:
           return False

         address = address.lstrip('[').rstrip(']')
       else:
         raise ValueError("'%s' isn't a valid IPv4 or IPv6 address" %
 address)

     if port is not None and not stem.util.connection.is_valid_port(port):
       raise ValueError("'%s' isn't a valid port" % port)
     """
 }}}
 speeds up the execution time by a factor of 2 and more.
 So I do wonder if both checks have to be made always ?

 Well, the background is to have a reasonable output by this script
 https://github.com/toralf/torutils/blob/master/ps.py w/o powering a whole
 CPU by 100% all the time (as it is currently doing).

--
Ticket URL: <https://trac.torproject.org/projects/tor/ticket/18881#comment:2>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online


More information about the tor-bugs mailing list