[tor-commits] [nyx/master] Use get_hidden_service_conf() to read hidden service config

atagar at torproject.org atagar at torproject.org
Tue Sep 22 17:08:39 UTC 2015


commit 0bc5d0dc6d492089459495b43d860384bdfb2f1b
Author: Damian Johnson <atagar at torproject.org>
Date:   Tue Jul 7 09:53:12 2015 -0700

    Use get_hidden_service_conf() to read hidden service config
    
    Using Stem's get_hidden_service_conf() method to read the hidden service
    configuration rather than parsing it ourselves.
---
 nyx/connections/conn_entry.py |   50 ++++++-----------------------------------
 1 file changed, 7 insertions(+), 43 deletions(-)

diff --git a/nyx/connections/conn_entry.py b/nyx/connections/conn_entry.py
index 61f2508..dbfc097 100644
--- a/nyx/connections/conn_entry.py
+++ b/nyx/connections/conn_entry.py
@@ -241,7 +241,13 @@ class ConnectionLine(entries.ConnectionPanelLine):
     my_dir_port = controller.get_conf('DirPort', None)
     my_socks_port = controller.get_conf('SocksPort', '9050')
     my_ctl_port = controller.get_conf('ControlPort', None)
-    my_hidden_service_ports = get_hidden_service_ports(controller)
+
+    # get all target ports in our hidden service configuation
+
+    my_hidden_service_ports = []
+
+    for hs_config in controller.get_hidden_service_conf({}).values():
+      my_hidden_service_ports += [entry[2] for entry in hs_config['HiddenServicePort']]
 
     # the ORListenAddress can overwrite the ORPort
 
@@ -882,48 +888,6 @@ class ConnectionLine(entries.ConnectionPanelLine):
     return destination_address[:max_length]
 
 
-def get_hidden_service_ports(controller, default = []):
-  """
-  Provides the target ports hidden services are configured to use.
-
-  Arguments:
-    default - value provided back if unable to query the hidden service ports
-  """
-
-  result = []
-  hs_options = controller.get_conf_map('HiddenServiceOptions', {})
-
-  for entry in hs_options.get('HiddenServicePort', []):
-    # HiddenServicePort entries are of the form...
-    #
-    #   VIRTPORT [TARGET]
-    #
-    # ... with the TARGET being an address, port, or address:port. If the
-    # target port isn't defined then uses the VIRTPORT.
-
-    hs_port = None
-
-    if ' ' in entry:
-      virtport, target = entry.split(' ', 1)
-
-      if ':' in target:
-        hs_port = target.split(':', 1)[1]  # target is an address:port
-      elif target.isdigit():
-        hs_port = target  # target is a port
-      else:
-        hs_port = virtport  # target is an address
-    else:
-      hs_port = entry  # just has the virtual port
-
-    if hs_port.isdigit():
-      result.append(hs_port)
-
-  if result:
-    return result
-  else:
-    return default
-
-
 def is_exiting_allowed(controller, ip_address, port):
   """
   Checks if the given destination can be exited to by this relay, returning





More information about the tor-commits mailing list