commit 68e66330bb5b042be05261cd0c7e4aae70634cc5 Author: Damian Johnson atagar@torproject.org Date: Sat Aug 29 14:27:12 2015 -0700
Simplify sorting by address
Lots more verbose than this needs to be. Lets make it simple... --- nyx/connections/entries.py | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-)
diff --git a/nyx/connections/entries.py b/nyx/connections/entries.py index 70ca6ac..78945f0 100644 --- a/nyx/connections/entries.py +++ b/nyx/connections/entries.py @@ -28,15 +28,6 @@ SORT_COLORS = { SortAttr.COUNTRY: 'blue', }
-# maximum number of ports a system can have - -PORT_COUNT = 65536 - -# sort value for scrubbed ip addresses - -SCRUBBED_IP_VAL = 255 ** 4 -ADDRESS_CACHE = {} - CONFIG = conf.config_dict('nyx', { 'features.connection.showIps': True, }) @@ -46,19 +37,6 @@ def to_unix_time(dt): return (dt - datetime.datetime(1970, 1, 1)).total_seconds()
-def address_to_int(address): - if address not in ADDRESS_CACHE: - ip_value = 0 - - for comp in address.split('.'): - ip_value *= 255 - ip_value += int(comp) - - ADDRESS_CACHE[address] = ip_value - - return ADDRESS_CACHE[address] - - class ConnectionPanelEntry: def __init__(self, connection_type, start_time): self.lines = [] @@ -141,11 +119,14 @@ class ConnectionPanelEntry:
if attr == SortAttr.IP_ADDRESS: if self.is_private(): - return SCRUBBED_IP_VAL # orders at the end + return 255 ** 4 # orders at the end + + ip_value = 0 + + for octet in connection_line.connection.remote_address.split('.'): + ip_value = ip_value * 255 + int(octet)
- sort_value = address_to_int(connection_line.connection.remote_address) * PORT_COUNT - sort_value += connection_line.connection.remote_port - return sort_value + return ip_value * 65536 + connection_line.connection.remote_port elif attr == SortAttr.PORT: return connection_line.connection.remote_port elif attr == SortAttr.FINGERPRINT:
tor-commits@lists.torproject.org