[tor-commits] [nyx/master] Populate connection panel soon as results are ready

atagar at torproject.org atagar at torproject.org
Mon Oct 17 01:59:32 UTC 2016


commit 9ad9e65d6aa1afbd2a673cbbbf66bd04251b2012
Author: Damian Johnson <atagar at torproject.org>
Date:   Sun Oct 16 18:58:22 2016 -0700

    Populate connection panel soon as results are ready
    
    When first starting up eagerly pulling connection results so we show
    information once it's available. I'm not really a fan of this code but does the
    trick.
---
 nyx/panel/connection.py | 31 ++++++++++++++++++++++++++-----
 1 file changed, 26 insertions(+), 5 deletions(-)

diff --git a/nyx/panel/connection.py b/nyx/panel/connection.py
index 344de43..d59293d 100644
--- a/nyx/panel/connection.py
+++ b/nyx/panel/connection.py
@@ -467,16 +467,35 @@ class ConnectionPanel(nyx.panel.DaemonPanel):
 
     global LAST_RETRIEVED_CIRCUITS, LAST_RETRIEVED_HS_CONF
 
+    conn_resolver = nyx.tracker.get_connection_tracker()
+    resolution_count = conn_resolver.run_counter()
+
+    # when first starting up wait a bit for initial results
+
+    if resolution_count == 0:
+      start_time = time.time()
+
+      while True:
+        with self._pause_condition:
+          if not self._halt:
+            self._pause_condition.wait(0.5)
+
+        resolution_count = conn_resolver.run_counter()
+
+        if resolution_count != 0:
+          break
+        elif time.time() - start_time > 5:
+          break
+        elif self._halt:
+          return
+
     controller = tor_controller()
     LAST_RETRIEVED_CIRCUITS = controller.get_circuits([])
     LAST_RETRIEVED_HS_CONF = controller.get_hidden_service_conf({})
 
-    conn_resolver = nyx.tracker.get_connection_tracker()
-    current_resolution_count = conn_resolver.run_counter()
-
     if not conn_resolver.is_alive():
       return  # if we're not fetching connections then this is a no-op
-    elif current_resolution_count == self._last_resource_fetch:
+    elif resolution_count == self._last_resource_fetch:
       return  # no new connections to process
 
     new_entries = [Entry.from_connection(conn) for conn in conn_resolver.get_value()]
@@ -502,7 +521,7 @@ class ConnectionPanel(nyx.panel.DaemonPanel):
         self._counted_connections.add(line.connection)
 
     self._entries = sorted(new_entries, key = lambda entry: [entry.sort_value(attr) for attr in self._sort_order])
-    self._last_resource_fetch = current_resolution_count
+    self._last_resource_fetch = resolution_count
 
     if CONFIG['features.connection.resolveApps']:
       local_ports, remote_ports = [], []
@@ -517,6 +536,8 @@ class ConnectionPanel(nyx.panel.DaemonPanel):
 
       nyx.tracker.get_port_usage_tracker().query(local_ports, remote_ports)
 
+    self.redraw()
+
 
 def _draw_title(subwindow, entries, showing_details):
   """



More information about the tor-commits mailing list