[tor-commits] [nyx/master] Only determine relay ports once

atagar at torproject.org atagar at torproject.org
Sun Oct 1 23:14:44 UTC 2017


commit 1f9ef690aadcfd121cbba9a59a65e3bcb6068339
Author: Damian Johnson <atagar at torproject.org>
Date:   Fri Sep 29 17:51:04 2017 -0700

    Only determine relay ports once
    
    No detectable difference when I lack any connections, but constructing this
    lists with every connection entry is silly (even if it is cached). Constructing
    a set once instead for constant time lookups.
---
 nyx/tracker.py | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/nyx/tracker.py b/nyx/tracker.py
index 1fbd80e..9f1d72d 100644
--- a/nyx/tracker.py
+++ b/nyx/tracker.py
@@ -541,15 +541,15 @@ class ConnectionTracker(Daemon):
         controller = tor_controller()
         consensus_tracker = get_consensus_tracker()
 
+        relay_ports = set(controller.get_ports(stem.control.Listener.OR, []))
+        relay_ports.update(controller.get_ports(stem.control.Listener.DIR, []))
+        relay_ports.update(controller.get_ports(stem.control.Listener.CONTROL, []))
+
         for conn in proc.connections(user = controller.get_user(None)):
           if conn.remote_port in consensus_tracker.get_relay_fingerprints(conn.remote_address):
             connections.append(conn)  # outbound to another relay
-          elif conn.local_port in controller.get_ports(stem.control.Listener.OR, []):
-            connections.append(conn)  # inbound to our ORPort
-          elif conn.local_port in controller.get_ports(stem.control.Listener.DIR, []):
-            connections.append(conn)  # inbound to our DirPort
-          elif conn.local_port in controller.get_ports(stem.control.Listener.CONTROL, []):
-            connections.append(conn)  # controller connection
+          elif conn.local_port in relay_ports:
+            connections.append(conn)
       else:
         connections = connection.get_connections(resolver, process_pid = process_pid, process_name = process_name)
 





More information about the tor-commits mailing list