[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [nyx/master] Move Category enum to panel
commit 4eda274e7aeef2f40bea415238f23ca23e17bb0f
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Mon Aug 31 08:44:31 2015 -0700
Move Category enum to panel
All submodules need this so lets localize it with the other enums in the
module. We'll be consolidating into a single module eventually, but in the
meantime this simplifies the imports.
---
nyx/connections/circ_entry.py | 4 ++--
nyx/connections/conn_entry.py | 38 ++++++--------------------------------
nyx/connections/conn_panel.py | 41 +++++++++++++++++++++++++++++++++--------
nyx/connections/entries.py | 12 ++++++------
4 files changed, 47 insertions(+), 48 deletions(-)
diff --git a/nyx/connections/circ_entry.py b/nyx/connections/circ_entry.py
index 3cf0147..cd42fc8 100644
--- a/nyx/connections/circ_entry.py
+++ b/nyx/connections/circ_entry.py
@@ -69,7 +69,7 @@ class CircHeaderLine(conn_entry.ConnectionLine):
def get_details(self, width):
if not self.is_built:
- detail_format = (curses.A_BOLD, conn_entry.CATEGORY_COLOR[self._entry.get_type()])
+ detail_format = (curses.A_BOLD, conn_panel.CATEGORY_COLOR[self._entry.get_type()])
return [('Building Circuit...', detail_format)]
else:
return conn_entry.ConnectionLine.get_details(self, width)
@@ -127,7 +127,7 @@ class CircLine(conn_entry.ConnectionLine):
return entries.ConnectionPanelLine.get_listing_entry(self, width, current_time, listing_type)
def _get_listing_entry(self, width, current_time, listing_type):
- line_format = nyx.util.ui_tools.get_color(conn_entry.CATEGORY_COLOR[self._entry.get_type()])
+ line_format = nyx.util.ui_tools.get_color(conn_panel.CATEGORY_COLOR[self._entry.get_type()])
# The required widths are the sum of the following:
# initial space (1 character)
diff --git a/nyx/connections/conn_entry.py b/nyx/connections/conn_entry.py
index b2fe648..fa85bc6 100644
--- a/nyx/connections/conn_entry.py
+++ b/nyx/connections/conn_entry.py
@@ -9,32 +9,10 @@ import nyx.util.tracker
import nyx.util.ui_tools
from nyx.util import tor_controller
-from nyx.connections import entries
-
-from stem.util import conf, connection, enum, str_tools
-
-# Connection Categories:
-# Inbound Relay connection, coming to us.
-# Outbound Relay connection, leaving us.
-# Exit Outbound relay connection leaving the Tor network.
-# Hidden Connections to a hidden service we're providing.
-# Socks Socks connections for applications using Tor.
-# Circuit Circuits our tor client has created.
-# Directory Fetching tor consensus information.
-# Control Tor controller (nyx, vidalia, etc).
-
-Category = enum.Enum('INBOUND', 'OUTBOUND', 'EXIT', 'HIDDEN', 'SOCKS', 'CIRCUIT', 'DIRECTORY', 'CONTROL')
-
-CATEGORY_COLOR = {
- Category.INBOUND: 'green',
- Category.OUTBOUND: 'blue',
- Category.EXIT: 'red',
- Category.HIDDEN: 'magenta',
- Category.SOCKS: 'yellow',
- Category.CIRCUIT: 'cyan',
- Category.DIRECTORY: 'magenta',
- Category.CONTROL: 'red',
-}
+from nyx.connections import conn_panel, entries
+from nyx.connections.conn_panel import Category
+
+from stem.util import conf, connection, str_tools
# static data for listing format
# <src> --> <dst> <etc><padding>
@@ -151,7 +129,7 @@ class ConnectionLine(entries.ConnectionPanelLine):
# category - "<type>"
# postType - ") "
- line_format = nyx.util.ui_tools.get_color(CATEGORY_COLOR[entry_type])
+ line_format = nyx.util.ui_tools.get_color(conn_panel.CATEGORY_COLOR[entry_type])
time_width = 6 if CONFIG['features.connection.markInitialConnections'] else 5
draw_entry = [(' ', line_format),
@@ -172,7 +150,7 @@ class ConnectionLine(entries.ConnectionPanelLine):
width - available space to display in
"""
- detail_format = (curses.A_BOLD, CATEGORY_COLOR[self._entry.get_type()])
+ detail_format = (curses.A_BOLD, conn_panel.CATEGORY_COLOR[self._entry.get_type()])
return [(line, detail_format) for line in self._get_detail_content(width)]
def get_etc_content(self, width, listing_type):
@@ -184,8 +162,6 @@ class ConnectionLine(entries.ConnectionPanelLine):
listing_type - primary attribute we're listing connections by
"""
- from nyx.connections import conn_panel
-
# for applications show the command/pid
if self._entry.get_type() in (Category.SOCKS, Category.HIDDEN, Category.CONTROL):
@@ -268,8 +244,6 @@ class ConnectionLine(entries.ConnectionPanelLine):
listing_type - primary attribute we're listing connections by
"""
- from nyx.connections import conn_panel
-
controller = tor_controller()
my_type = self._entry.get_type()
destination_address = self.get_destination_label(26, include_locale = True)
diff --git a/nyx/connections/conn_panel.py b/nyx/connections/conn_panel.py
index 2f6fde3..f2d613e 100644
--- a/nyx/connections/conn_panel.py
+++ b/nyx/connections/conn_panel.py
@@ -12,7 +12,7 @@ import threading
import nyx.popups
import nyx.util.tracker
-from nyx.connections import descriptor_popup, entries, conn_entry
+from nyx.connections import descriptor_popup, entries
from nyx.util import panel, tor_controller, ui_tools
from stem.control import State
@@ -29,6 +29,29 @@ Listing = enum.Enum(('IP_ADDRESS', 'IP Address'), 'FINGERPRINT', 'NICKNAME')
EXIT_USAGE_WIDTH = 15
UPDATE_RATE = 5 # rate in seconds at which we refresh
+# Connection Categories:
+# Inbound Relay connection, coming to us.
+# Outbound Relay connection, leaving us.
+# Exit Outbound relay connection leaving the Tor network.
+# Hidden Connections to a hidden service we're providing.
+# Socks Socks connections for applications using Tor.
+# Circuit Circuits our tor client has created.
+# Directory Fetching tor consensus information.
+# Control Tor controller (nyx, vidalia, etc).
+
+Category = enum.Enum('INBOUND', 'OUTBOUND', 'EXIT', 'HIDDEN', 'SOCKS', 'CIRCUIT', 'DIRECTORY', 'CONTROL')
+
+CATEGORY_COLOR = {
+ Category.INBOUND: 'green',
+ Category.OUTBOUND: 'blue',
+ Category.EXIT: 'red',
+ Category.HIDDEN: 'magenta',
+ Category.SOCKS: 'yellow',
+ Category.CIRCUIT: 'cyan',
+ Category.DIRECTORY: 'magenta',
+ Category.CONTROL: 'red',
+}
+
SortAttr = enum.Enum('CATEGORY', 'UPTIME', 'LISTING', 'IP_ADDRESS', 'PORT', 'FINGERPRINT', 'NICKNAME', 'COUNTRY')
SORT_COLORS = {
@@ -130,6 +153,8 @@ class ConnectionPanel(panel.Panel, threading.Thread):
# mark the initially exitsing connection uptimes as being estimates
+ from nyx.connections import conn_entry
+
for entry in self._entries:
if isinstance(entry, conn_entry.ConnectionEntry):
entry.get_lines()[0].is_initial_connection = True
@@ -199,7 +224,7 @@ class ConnectionPanel(panel.Panel, threading.Thread):
elif attr == SortAttr.NICKNAME:
return connection_line.get_nickname('z' * 20)
elif attr == SortAttr.CATEGORY:
- return conn_entry.Category.index_of(entry.get_type())
+ return Category.index_of(entry.get_type())
elif attr == SortAttr.UPTIME:
return connection_line.connection.start_time
elif attr == SortAttr.COUNTRY:
@@ -316,7 +341,7 @@ class ConnectionPanel(panel.Panel, threading.Thread):
if not selection:
break
- color = conn_entry.CATEGORY_COLOR[selection.get_type()]
+ color = CATEGORY_COLOR[selection.get_type()]
fingerprint = selection.get_fingerprint()
is_close_key = lambda key: key.is_selection() or key.match('d') or key.match('left') or key.match('right')
key = descriptor_popup.show_descriptor_popup(fingerprint, color, self.max_x, is_close_key)
@@ -488,7 +513,7 @@ class ConnectionPanel(panel.Panel, threading.Thread):
title = 'Connections:'
else:
counts = collections.Counter([entry.get_type() for entry in entries])
- count_labels = ['%i %s' % (counts[category], category.lower()) for category in conn_entry.Category if counts[category]]
+ count_labels = ['%i %s' % (counts[category], category.lower()) for category in Category if counts[category]]
title = 'Connections (%s):' % ', '.join(count_labels)
self.addstr(0, 0, title, curses.A_STANDOUT)
@@ -530,12 +555,12 @@ class ConnectionPanel(panel.Panel, threading.Thread):
for entry in new_entries:
entry_line = entry.get_lines()[0]
- if entry.is_private() and entry.get_type() == conn_entry.Category.INBOUND:
+ if entry.is_private() and entry.get_type() == Category.INBOUND:
client_locale = entry_line.get_locale(None)
if client_locale:
self._client_locale_usage[client_locale] = self._client_locale_usage.get(client_locale, 0) + 1
- elif entry.get_type() == conn_entry.Category.EXIT:
+ elif entry.get_type() == Category.EXIT:
exit_port = entry_line.connection.remote_port
self._exit_port_usage[exit_port] = self._exit_port_usage.get(exit_port, 0) + 1
@@ -550,9 +575,9 @@ class ConnectionPanel(panel.Panel, threading.Thread):
for entry in new_entries:
line = entry.get_lines()[0]
- if entry.get_type() in (conn_entry.Category.SOCKS, conn_entry.Category.CONTROL):
+ if entry.get_type() in (Category.SOCKS, Category.CONTROL):
local_ports.append(line.connection.remote_port)
- elif entry.get_type() == conn_entry.Category.HIDDEN:
+ elif entry.get_type() == Category.HIDDEN:
remote_ports.append(line.connection.local_port)
nyx.util.tracker.get_port_usage_tracker().query(local_ports, remote_ports)
diff --git a/nyx/connections/entries.py b/nyx/connections/entries.py
index 4c6fa9c..90de9d4 100644
--- a/nyx/connections/entries.py
+++ b/nyx/connections/entries.py
@@ -38,9 +38,9 @@ class Entry(object):
@staticmethod
def from_circuit(circ):
import nyx.connections.circ_entry
- import nyx.connections.conn_entry
+ from nyx.connections.conn_panel import Category
- entry = Entry(nyx.connections.conn_entry.Category.CIRCUIT)
+ entry = Entry(Category.CIRCUIT)
entry._lines = [nyx.connections.circ_entry.CircHeaderLine(entry, circ)]
for fingerprint, _ in circ.path:
@@ -67,19 +67,19 @@ class Entry(object):
:returns: **bool** indicating if connection information is sensive or not
"""
- import nyx.connections.conn_entry
+ from nyx.connections.conn_panel import Category
if not CONFIG['features.connection.showIps']:
return True
connection = self._lines[0].connection
- if self.get_type() == nyx.connections.conn_entry.Category.INBOUND:
+ if self.get_type() == Category.INBOUND:
controller = tor_controller()
if controller.is_user_traffic_allowed().inbound:
return len(nyx.util.tracker.get_consensus_tracker().get_all_relay_fingerprints(connection.remote_address)) == 0
- elif self.get_type() == nyx.connections.conn_entry.Category.EXIT:
+ elif self.get_type() == Category.EXIT:
# DNS connections exiting us aren't private (since they're hitting our
# resolvers). Everything else is.
@@ -162,7 +162,7 @@ class ConnectionPanelLine:
def get_type(connection):
- from nyx.connections.conn_entry import Category
+ from nyx.connections.conn_panel import Category
controller = tor_controller()
if connection.local_port in controller.get_ports(Listener.OR, []):
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits