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

[tor-commits] [arm/master] Rewriting header panel's exit policy section



commit de4d3930e01cc3c7104c3d7d1410839d3206eb17
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sun Jul 13 16:21:04 2014 -0700

    Rewriting header panel's exit policy section
    
    This is gonna take some more work. The last release of arm consulted our
    GETCONF ExitPolicy which excluded both the ExitPolicyRejectPrivate prefix and
    default suffix.
    
    We definitely want to condense the default suffix. As for the prefix, that's
    probably just extra noise. We could just snag the GETCONF like arm previously
    did, but I'd rather address this by making it better in Stem...
    
      https://trac.torproject.org/projects/tor/ticket/10107
---
 arm/header_panel.py |   69 ++++++++++++++++++++-------------------------------
 1 file changed, 27 insertions(+), 42 deletions(-)

diff --git a/arm/header_panel.py b/arm/header_panel.py
index c3ad440..435a78d 100644
--- a/arm/header_panel.py
+++ b/arm/header_panel.py
@@ -173,49 +173,10 @@ class HeaderPanel(panel.Panel, threading.Thread):
       if is_wide:
         self._draw_fingerprint_and_fd_usage(left_width, 1, right_width, vals)
         self._draw_flags(0, 2, left_width, vals)
+        self._draw_exit_policy(left_width, 2, right_width, vals)
       else:
         self._draw_fingerprint_and_fd_usage(0, 3, left_width, vals)
         self._draw_flags(0, 4, left_width, vals)
-
-      # Undisplayed / Line 3 Right (exit policy)
-
-      if is_wide:
-        exit_policy = vals.exit_policy
-
-        # adds note when default exit policy is appended
-
-        if exit_policy == '':
-          exit_policy = '<default>'
-        elif not exit_policy.endswith((' *:*', ' *')):
-          exit_policy += ', <default>'
-
-        self.addstr(2, left_width, 'exit policy: ')
-        x = left_width + 13
-
-        # color codes accepts to be green, rejects to be red, and default marker to be cyan
-
-        is_simple = len(exit_policy) > (right_width if is_wide else left_width) - 13
-        policies = exit_policy.split(', ')
-
-        for i in range(len(policies)):
-          policy = policies[i].strip()
-          policy_label = policy.replace('accept', '').replace('reject', '').strip() if is_simple else policy
-
-          policy_color = 'white'
-
-          if policy.startswith('accept'):
-            policy_color = 'green'
-          elif policy.startswith('reject'):
-            policy_color = 'red'
-          elif policy.startswith('<default>'):
-            policy_color = 'cyan'
-
-          self.addstr(2, x, policy_label, curses.A_BOLD | ui_tools.get_color(policy_color))
-          x += len(policy_label)
-
-          if i < len(policies) - 1:
-            self.addstr(2, x, ', ')
-            x += 2
     else:
       # (Client only) Undisplayed / Line 2 Right (new identity option)
 
@@ -355,7 +316,7 @@ class HeaderPanel(panel.Panel, threading.Thread):
 
   def _draw_flags(self, x, y, width, vals):
     """
-    Shows the flags held by our relay...
+    Presents flags held by our relay...
 
       flags: Running, Valid
     """
@@ -372,6 +333,30 @@ class HeaderPanel(panel.Panel, threading.Thread):
     else:
       self.addstr(y, x, 'none', curses.A_BOLD | ui_tools.get_color('cyan'))
 
+  def _draw_exit_policy(self, x, y, width, vals):
+    """
+    Presents our exit policy...
+
+      exit policy: reject *:*
+    """
+
+    x = self.addstr(y, x, 'exit policy: ')
+
+    if not vals.exit_policy:
+      return
+
+    # TODO: exclude private policy prefix?
+    # TODO: replace the default suffix policy with a cyan '<default>'
+
+    rules = list(vals.exit_policy)
+
+    for i, rule in enumerate(rules):
+      policy_color = 'green' if rule.is_accept else 'red'
+      x = self.addstr(y, x, str(rule), curses.A_BOLD | ui_tools.get_color(policy_color))
+
+      if i < len(rules) - 1:
+        x = self.addstr(y, x, ', ')
+
   def run(self):
     """
     Keeps stats updated, checking for new information at a set rate.
@@ -494,7 +479,7 @@ class Sampling(object):
     else:
       self.auth_type = 'open'
 
-    self.exit_policy = str(controller.get_exit_policy(''))
+    self.exit_policy = controller.get_exit_policy(None)
     self.flags = self._get_flags(controller)
     self.version = str(controller.get_version('Unknown')).split()[0]
     self.version_status = controller.get_info('status/version/current', 'Unknown')



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