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

[tor-commits] [nyx/master] Speed connection panel up by a few seconds



commit 6f91af2feb26e915fdc418e335a20232a7b7e9b4
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sun Jul 12 12:40:44 2015 -0700

    Speed connection panel up by a few seconds
    
    The slowest part of initializing the connection panel is issuing the 'GETINFO
    ns/all' query to populate the FingerprintTracker. When the user starts nyx then
    immediately goes to the connection page this is a noticeable 3-4 second lag.
    
    Doing this asynchronously in the connection panel's thread, at the *end* of
    processing the first results. As a result the user doesn't see this lag at all.
    Rather, if they immediately go to the connection page the fingerprints and
    nicknames will simply be 'UNKNOWN' for a few seconds. Much better. :P
---
 nyx/connections/conn_entry.py |   20 +++++++++++++-------
 nyx/connections/conn_panel.py |    9 +++++++++
 2 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/nyx/connections/conn_entry.py b/nyx/connections/conn_entry.py
index cd463be..5cb4274 100644
--- a/nyx/connections/conn_entry.py
+++ b/nyx/connections/conn_entry.py
@@ -65,7 +65,7 @@ def get_fingerprint_tracker():
   global FINGERPRINT_TRACKER
 
   if FINGERPRINT_TRACKER is None:
-    FINGERPRINT_TRACKER = FingerprintTracker(tor_controller().get_network_statuses([]))
+    FINGERPRINT_TRACKER = FingerprintTracker()
 
   return FINGERPRINT_TRACKER
 
@@ -892,23 +892,29 @@ class ConnectionLine(entries.ConnectionPanelLine):
 
 
 class FingerprintTracker:
-  def __init__(self, router_status_entries):
+  def __init__(self):
     self._fingerprint_cache = {}  # {address => [(port, fingerprint), ..]} for relays
     self._nickname_cache = {}  # fingerprint => nickname lookup cache
 
-    for desc in router_status_entries:
-      self._fingerprint_cache.setdefault(desc.address, []).append((desc.or_port, desc.fingerprint))
-
     tor_controller().add_event_listener(self._new_consensus_event, stem.control.EventType.NEWCONSENSUS)
 
   def _new_consensus_event(self, event):
+    self._nickname_cache = {}
+    self.update(event.desc)
+
+  def update(self, router_status_entries):
+    """
+    Updates our cache with the given router status entries.
+
+    :param list router_status_entries: router status entries to populate our cache with
+    """
+
     new_fingerprint_cache = {}
 
-    for desc in event.desc:
+    for desc in router_status_entries:
       new_fingerprint_cache.setdefault(desc.address, []).append((desc.or_port, desc.fingerprint))
 
     self._fingerprint_cache = new_fingerprint_cache
-    self._nickname_cache = {}
 
   def get_relay_fingerprint(self, address, port = None):
     """
diff --git a/nyx/connections/conn_panel.py b/nyx/connections/conn_panel.py
index 2be5f8b..83b9d3a 100644
--- a/nyx/connections/conn_panel.py
+++ b/nyx/connections/conn_panel.py
@@ -325,6 +325,15 @@ class ConnectionPanel(panel.Panel, threading.Thread):
 
       self._update()
       self.redraw(True)
+
+      # If this is our first run then fill in our fingerprint tracker. This
+      # requires fetching all the router status entries which takes a few
+      # seconds, so best done when we're finished with the rest of the first
+      # iteration to hide the lag.
+
+      if last_ran == -1:
+        conn_entry.get_fingerprint_tracker().update(tor_controller().get_network_statuses([]))
+
       last_ran = time.time()
 
   def get_help(self):



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