[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [nyx/master] Merge CircEntry class into its parent
commit 24092722fcf6b5eb8620e244ffd5816f7c3ffb19
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Sat Jul 25 14:52:03 2015 -0700
Merge CircEntry class into its parent
Now that we're no longer doing in-place modifications the CircEntry is just a
constructor. Making it a factory method of the parent class rather than its
own. Still more opportunity for simplification, but one step at a time.
---
nyx/connections/circ_entry.py | 74 ++---------------------------------------
nyx/connections/conn_panel.py | 4 +--
nyx/connections/entries.py | 42 +++++++++++++++++++++++
3 files changed, 47 insertions(+), 73 deletions(-)
diff --git a/nyx/connections/circ_entry.py b/nyx/connections/circ_entry.py
index a80bc8a..c49dbc4 100644
--- a/nyx/connections/circ_entry.py
+++ b/nyx/connections/circ_entry.py
@@ -9,7 +9,6 @@ followed by an entry for each hop in the circuit. For instance:
"""
import curses
-import datetime
import nyx.util.tracker
import nyx.util.ui_tools
@@ -19,73 +18,6 @@ from nyx.connections import entries, conn_entry
from stem.util import str_tools
-def to_unix_time(dt):
- return (dt - datetime.datetime(1970, 1, 1)).total_seconds()
-
-
-class CircEntry(conn_entry.ConnectionEntry):
- def __init__(self, circ):
- conn_entry.ConnectionEntry.__init__(self, nyx.util.tracker.Connection(to_unix_time(circ.created), False, '127.0.0.1', 0, '127.0.0.1', 0, 'tcp'))
-
- self._circuit = circ
- 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()
-
- self.lines = [CircHeaderLine(circ)]
-
- # Overwrites attributes of the initial line to make it more fitting as the
- # header for our listing.
-
- self.lines[0].base_type = conn_entry.Category.CIRCUIT
-
- self.update(circ.status, [entry[0] for entry in circ.path])
-
- def update(self, status, path):
- """
- Our status and path can change over time if the circuit is still in the
- process of being built. Updates these attributes of our relay.
-
- Arguments:
- status - new status of the circuit
- path - list of fingerprints for the series of relays involved in the
- circuit
- """
-
- self.status = status
- self.lines = [self.lines[0]]
-
- if status == 'BUILT' and not self.lines[0].is_built:
- exit_ip, exit_port = nyx.util.tracker.get_consensus_tracker().get_relay_address(path[-1], ('192.168.0.1', 0))
- self.lines[0].set_exit(exit_ip, exit_port, path[-1])
-
- for i in range(len(path)):
- relay_fingerprint = path[i]
- relay_ip, relay_port = nyx.util.tracker.get_consensus_tracker().get_relay_address(relay_fingerprint, ('192.168.0.1', 0))
-
- if i == len(path) - 1:
- if status == 'BUILT':
- placement_type = 'Exit'
- else:
- placement_type = 'Extending'
- elif i == 0:
- placement_type = 'Guard'
- else:
- placement_type = 'Middle'
-
- placement_label = '%i / %s' % (i + 1, placement_type)
-
- self.lines.append(CircLine(relay_ip, relay_port, relay_fingerprint, placement_label, to_unix_time(self._circuit.created)))
-
- self.lines[-1].is_last = True
-
-
class CircHeaderLine(conn_entry.ConnectionLine):
"""
Initial line of a client entry. This has the same basic format as connection
@@ -93,11 +25,11 @@ class CircHeaderLine(conn_entry.ConnectionLine):
"""
def __init__(self, circ):
- conn_entry.ConnectionLine.__init__(self, nyx.util.tracker.Connection(to_unix_time(circ.created), False, '127.0.0.1', 0, '0.0.0.0', 0, 'tcp'), False, False)
+ conn_entry.ConnectionLine.__init__(self, nyx.util.tracker.Connection(entries.to_unix_time(circ.created), False, '127.0.0.1', 0, '0.0.0.0', 0, 'tcp'), False, False)
self.circuit_id = circ.id
- self.purpose = circ.purpose
+ self.purpose = circ.purpose.capitalize()
self.is_built = False
- self._timestamp = to_unix_time(circ.created)
+ self._timestamp = entries.to_unix_time(circ.created)
def set_exit(self, exit_address, exit_port, exit_fingerprint):
conn_entry.ConnectionLine.__init__(self, nyx.util.tracker.Connection(self._timestamp, False, '127.0.0.1', 0, exit_address, exit_port, 'tcp'), False, False)
diff --git a/nyx/connections/conn_panel.py b/nyx/connections/conn_panel.py
index 695c32e..364c42f 100644
--- a/nyx/connections/conn_panel.py
+++ b/nyx/connections/conn_panel.py
@@ -12,7 +12,7 @@ import threading
import nyx.popups
import nyx.util.tracker
-from nyx.connections import descriptor_popup, entries, conn_entry, circ_entry
+from nyx.connections import descriptor_popup, entries, conn_entry
from nyx.util import panel, tor_controller, tracker, ui_tools
from stem.control import State
@@ -477,7 +477,7 @@ class ConnectionPanel(panel.Panel, threading.Thread):
# fetches, not client circuits)
if not (circ.status == 'BUILT' and len(circ.path) == 1):
- new_entries.append(circ_entry.CircEntry(circ))
+ new_entries.append(entries.ConnectionPanelEntry.from_circuit(circ))
# update stats for client and exit connections
diff --git a/nyx/connections/entries.py b/nyx/connections/entries.py
index 9215b37..f4693b0 100644
--- a/nyx/connections/entries.py
+++ b/nyx/connections/entries.py
@@ -4,6 +4,8 @@ entry itself (ie, Tor connection, client circuit, etc) and the lines it
consists of in the listing.
"""
+import datetime
+
from stem.util import enum
# attributes we can list entries by
@@ -28,6 +30,10 @@ SORT_COLORS = {
PORT_COUNT = 65536
+def to_unix_time(dt):
+ return (dt - datetime.datetime(1970, 1, 1)).total_seconds()
+
+
class ConnectionPanelEntry:
"""
Common parent for connection panel entries. This consists of a list of lines
@@ -39,6 +45,42 @@ class ConnectionPanelEntry:
self.lines = []
self.flush_cache = True
+ @staticmethod
+ def from_circuit(circ):
+ import nyx.connections.circ_entry
+ import nyx.connections.conn_entry
+ import nyx.util.tracker
+
+ # TODO: should be ConnectionPanelEntry rather than a ConnectionEntry, but
+ # looks like that presently provides sorting
+
+ entry = nyx.connections.conn_entry.ConnectionEntry(nyx.util.tracker.Connection(to_unix_time(circ.created), False, '127.0.0.1', 0, '127.0.0.1', 0, 'tcp'))
+ entry.lines = [nyx.connections.circ_entry.CircHeaderLine(circ)]
+
+ path = [path_entry[0] for path_entry in circ.path]
+
+ if circ.status == 'BUILT':
+ exit_ip, exit_port = nyx.util.tracker.get_consensus_tracker().get_relay_address(path[-1], ('192.168.0.1', 0))
+ entry.lines[0].set_exit(exit_ip, exit_port, path[-1])
+
+ for i, relay_fingerprint in enumerate(path):
+ relay_ip, relay_port = nyx.util.tracker.get_consensus_tracker().get_relay_address(relay_fingerprint, ('192.168.0.1', 0))
+
+ if i == len(path) - 1:
+ placement_type = 'Exit' if circ.status == 'BUILT' else 'Extending'
+ elif i == 0:
+ placement_type = 'Guard'
+ else:
+ placement_type = 'Middle'
+
+ placement_label = '%i / %s' % (i + 1, placement_type)
+
+ entry.lines.append(nyx.connections.circ_entry.CircLine(relay_ip, relay_port, relay_fingerprint, placement_label, to_unix_time(circ.created)))
+
+ entry.lines[-1].is_last = True
+
+ return entry
+
def get_lines(self):
"""
Provides the individual lines in the connection listing.
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits