[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [nyx/master] Move more initialization logic into CircLine



commit 94e48a725930af385a4a58dd54ca4f18e08c7c41
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sat Aug 1 18:17:41 2015 -0700

    Move more initialization logic into CircLine
    
    The caller was doing more to initialize CircLine than it needed. The
    constructor can figure out its own position in the circuit.
---
 nyx/connections/circ_entry.py |   24 ++++++++++++++++++------
 nyx/connections/entries.py    |   20 ++------------------
 2 files changed, 20 insertions(+), 24 deletions(-)

diff --git a/nyx/connections/circ_entry.py b/nyx/connections/circ_entry.py
index 0e6ca3f..b1d95c7 100644
--- a/nyx/connections/circ_entry.py
+++ b/nyx/connections/circ_entry.py
@@ -77,17 +77,29 @@ class CircLine(conn_entry.ConnectionLine):
   caching, etc).
   """
 
-  def __init__(self, entry, remote_address, remote_port, remote_fingerprint, placement_label, timestamp):
-    conn_entry.ConnectionLine.__init__(self, entry, nyx.util.tracker.Connection(timestamp, False, '127.0.0.1', 0, remote_address, remote_port, 'tcp'), False)
-    self._remote_fingerprint = remote_fingerprint
-    self.placement_label = placement_label
+  def __init__(self, entry, circ, fingerprint, timestamp):
+    relay_ip, relay_port = nyx.util.tracker.get_consensus_tracker().get_relay_address(fingerprint, ('192.168.0.1', 0))
+    conn_entry.ConnectionLine.__init__(self, entry, nyx.util.tracker.Connection(timestamp, False, '127.0.0.1', 0, relay_ip, relay_port, 'tcp'), False)
+    self._fingerprint = fingerprint
+
+    circ_path = [path_entry[0] for path_entry in circ.path]
+    circ_index = circ_path.index(fingerprint)
+
+    if circ_index == len(circ_path) - 1:
+      placement_type = 'Exit' if circ.status == 'BUILT' else 'Extending'
+    elif circ_index == 0:
+      placement_type = 'Guard'
+    else:
+      placement_type = 'Middle'
+
+    self.placement_label = '%i / %s' % (circ_index + 1, placement_type)
 
     # determines the sort of left hand bracketing we use
 
-    self.is_last = False
+    self.is_last = circ_index == len(circ_path) - 1
 
   def get_fingerprint(self, default = None):
-    self._remote_fingerprint
+    self._fingerprint
 
   def get_listing_prefix(self):
     if self.is_last:
diff --git a/nyx/connections/entries.py b/nyx/connections/entries.py
index a4e2014..4fb981d 100644
--- a/nyx/connections/entries.py
+++ b/nyx/connections/entries.py
@@ -77,28 +77,12 @@ class ConnectionPanelEntry:
   def from_circuit(circ):
     import nyx.connections.circ_entry
     import nyx.connections.conn_entry
-    import nyx.util.tracker
 
     entry = ConnectionPanelEntry(nyx.connections.conn_entry.Category.CIRCUIT, to_unix_time(circ.created))
     entry.lines = [nyx.connections.circ_entry.CircHeaderLine(entry, circ)]
 
-    path = [path_entry[0] for path_entry in circ.path]
-
-    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(entry, relay_ip, relay_port, relay_fingerprint, placement_label, to_unix_time(circ.created)))
-
-    entry.lines[-1].is_last = True
+    for fingerprint, _ in circ.path:
+      entry.lines.append(nyx.connections.circ_entry.CircLine(entry, circ, fingerprint, to_unix_time(circ.created)))
 
     return entry
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits