commit d2f1b3d8aa19a0e5124ee5650a52b4b7764fbe60 Author: Damian Johnson atagar@torproject.org Date: Fri Jul 17 08:27:35 2015 -0700
Use circuit struct in constructors
Backing our CircEntry class with a circuit, rather than passing in its attributes. I suspect we can go a lot further and simplify this, but one step at a time. --- nyx/connections/circ_entry.py | 10 ++++++---- nyx/connections/conn_panel.py | 7 +++---- 2 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/nyx/connections/circ_entry.py b/nyx/connections/circ_entry.py index 5e27243..02599e5 100644 --- a/nyx/connections/circ_entry.py +++ b/nyx/connections/circ_entry.py @@ -20,14 +20,16 @@ from stem.util import str_tools
class CircEntry(conn_entry.ConnectionEntry): - def __init__(self, circuit_id, status, purpose, path): + def __init__(self, circ): conn_entry.ConnectionEntry.__init__(self, nyx.util.tracker.Connection(time.time(), False, '127.0.0.1', 0, '127.0.0.1', 0, 'tcp'))
- self.circuit_id = circuit_id - self.status = status + self.circuit_id = circ.id + self.status = circ.status
# drops to lowercase except the first letter
+ purpose = circ.purpose + if len(purpose) >= 2: purpose = purpose[0].upper() + purpose[1:].lower()
@@ -38,7 +40,7 @@ class CircEntry(conn_entry.ConnectionEntry):
self.lines[0].base_type = conn_entry.Category.CIRCUIT
- self.update(status, path) + self.update(circ.status, [entry[0] for entry in circ.path])
def update(self, status, path): """ diff --git a/nyx/connections/conn_panel.py b/nyx/connections/conn_panel.py index 4fb3fd1..1bd1254 100644 --- a/nyx/connections/conn_panel.py +++ b/nyx/connections/conn_panel.py @@ -476,7 +476,7 @@ class ConnectionPanel(panel.Panel, threading.Thread): # fetches, not client circuits)
if not (circ.status == 'BUILT' and len(circ.path) == 1): - new_circuits[circ.id] = (circ.status, circ.purpose, [entry[0] for entry in circ.path]) + new_circuits[circ.id] = circ
# Populates new_entries with any of our old entries that still exist. # This is both for performance and to keep from resetting the uptime @@ -488,7 +488,7 @@ class ConnectionPanel(panel.Panel, threading.Thread): new_entry = new_circuits.get(old_entry.circuit_id)
if new_entry: - old_entry.update(new_entry[0], new_entry[2]) + old_entry.update(new_entry.status, [entry[0] for entry in new_entry.path]) new_entries.append(old_entry) del new_circuits[old_entry.circuit_id] elif isinstance(old_entry, conn_entry.ConnectionEntry): @@ -524,8 +524,7 @@ class ConnectionPanel(panel.Panel, threading.Thread): self._exit_port_usage[exit_port] = self._exit_port_usage.get(exit_port, 0) + 1
for circuit_id in new_circuits: - status, purpose, path = new_circuits[circuit_id] - new_entries.append(circ_entry.CircEntry(circuit_id, status, purpose, path)) + new_entries.append(circ_entry.CircEntry(new_circuits[circuit_id]))
# Counts the relays in each of the categories. This also flushes the # type cache for all of the connections (in case its changed since last
tor-commits@lists.torproject.org