tor-commits
Threads by month
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
February 2016
- 18 participants
- 834 discussions
commit 9f77a2d3d2085198a85fd4957d8df1337a2a8715
Author: Damian Johnson <atagar(a)torproject.org>
Date: Mon Jan 18 08:57:39 2016 -0800
Drop unused torrc panel config option
More config options nobody's probably ever used (or wanted).
---
nyx/torrc_panel.py | 20 ++++----------------
nyx/util/tor_config.py | 8 ++------
nyxrc.sample | 3 ---
3 files changed, 6 insertions(+), 25 deletions(-)
diff --git a/nyx/torrc_panel.py b/nyx/torrc_panel.py
index f312553..4248ae0 100644
--- a/nyx/torrc_panel.py
+++ b/nyx/torrc_panel.py
@@ -6,23 +6,12 @@ import math
import curses
import threading
-import nyx.popups
-
from nyx.util import expand_path, panel, tor_config, tor_controller, ui_tools
from stem.control import State
-from stem.util import conf, log, str_tools
-
-
-def conf_handler(key, value):
- if key == 'features.config.file.max_lines_per_entry':
- return max(1, value)
-
+from stem.util import log, str_tools
-CONFIG = conf.config_dict('nyx', {
- 'features.config.file.showScrollbars': True,
- 'features.config.file.max_lines_per_entry': 8,
-}, conf_handler)
+MAX_WRAP_PER_LINE = 8
class TorrcPanel(panel.Panel):
@@ -173,7 +162,7 @@ class TorrcPanel(panel.Panel):
scroll_offset = 0
- if CONFIG['features.config.file.showScrollbars'] and self._last_content_height > height - 1:
+ if self._last_content_height > height - 1:
scroll_offset = 3
self.add_scroll_bar(self.scroll, self.scroll + height - 1, self._last_content_height, 1)
@@ -264,7 +253,6 @@ class TorrcPanel(panel.Panel):
# draws the rest of the components with line wrap
cursor_location, line_offset = line_number_offset + scroll_offset, 0
- max_lines_per_entry = CONFIG['features.config.file.max_lines_per_entry']
display_queue = [line_comp[entry] for entry in ('option', 'argument', 'correction', 'comment')]
while display_queue:
@@ -275,7 +263,7 @@ class TorrcPanel(panel.Panel):
if len(msg) >= max_msg_size:
# message is too long - break it up
- if line_offset == max_lines_per_entry - 1:
+ if line_offset == MAX_WRAP_PER_LINE - 1:
msg = str_tools.crop(msg, max_msg_size)
else:
include_break = True
diff --git a/nyx/util/tor_config.py b/nyx/util/tor_config.py
index 7bc462b..22abff7 100644
--- a/nyx/util/tor_config.py
+++ b/nyx/util/tor_config.py
@@ -2,13 +2,9 @@
Helper functions for working with tor's configuration file.
"""
-import threading
+from nyx.util import tor_controller
-import stem.version
-
-from nyx.util import tor_controller, ui_tools
-
-from stem.util import conf, enum, log, str_tools, system
+from stem.util import conf, enum, str_tools, system
CONFIG = conf.config_dict('nyx', {
'features.torrc.validate': True,
diff --git a/nyxrc.sample b/nyxrc.sample
index 03dd833..64eb7a3 100644
--- a/nyxrc.sample
+++ b/nyxrc.sample
@@ -104,15 +104,12 @@ features.log.maxRefreshRate 300
# state.showVirtualOptions
# virtual options are placeholders for other option groups, never having
# values or being setable themselves
-# file.showScrollbars
-# displays scrollbars when the torrc content is longer than the display
# file.maxLinesPerEntry
# max number of lines to display for a single entry in the torrc
features.config.order MAN_PAGE_ENTRY, NAME, IS_SET
features.config.state.showPrivateOptions false
features.config.state.showVirtualOptions false
-features.config.file.showScrollbars true
features.config.file.maxLinesPerEntry 8
# Descriptions for tor's configuration options can be loaded from its man page
1
0
commit f269fc5846abc952a8d12a135ab94130814b6da9
Author: Damian Johnson <atagar(a)torproject.org>
Date: Sat Feb 6 10:15:51 2016 -0800
Fix unit tests
Quite a few broken assertions due to recent changes.
---
nyx/controller.py | 2 +-
nyx/util/tor_config.py | 15 ---------------
setup.py | 2 +-
test/arguments.py | 8 ++++----
test/util/tracker/connection_tracker.py | 9 ++++++---
5 files changed, 12 insertions(+), 24 deletions(-)
diff --git a/nyx/controller.py b/nyx/controller.py
index b520aa7..aa6da8c 100644
--- a/nyx/controller.py
+++ b/nyx/controller.py
@@ -25,7 +25,7 @@ from stem.control import State
from nyx.util import panel, tor_controller, ui_tools
-from stem.util import conf, log, system
+from stem.util import conf, log
NYX_CONTROLLER = None
diff --git a/nyx/util/tor_config.py b/nyx/util/tor_config.py
index 22abff7..3ffb435 100644
--- a/nyx/util/tor_config.py
+++ b/nyx/util/tor_config.py
@@ -50,24 +50,9 @@ TIME_MULT = {'sec': 1, 'min': 60, 'hour': 3600, 'day': 86400, 'week': 604800}
ValidationError = enum.Enum('DUPLICATE', 'MISMATCH', 'MISSING', 'IS_DEFAULT')
-TORRC = None # singleton torrc instance
MULTILINE_PARAM = None # cached multiline parameters (lazily loaded)
-def get_torrc():
- """
- Singleton constructor for a Controller. Be aware that this starts as being
- unloaded, needing the torrc contents to be loaded before being functional.
- """
-
- global TORRC
-
- if TORRC is None:
- TORRC = Torrc()
-
- return TORRC
-
-
def get_config_location():
"""
Provides the location of the torrc, raising an IOError with the reason if the
diff --git a/setup.py b/setup.py
index f5b1c05..13ae6af 100644
--- a/setup.py
+++ b/setup.py
@@ -102,6 +102,6 @@ setup(
packages = ['nyx', 'nyx.menu', 'nyx.util'],
keywords = 'tor onion controller',
install_requires = ['stem>=1.4.1'],
- package_data = {'nyx': ['config/*', 'resources/*']},
+ package_data = {'nyx': ['settings/*', 'resources/*']},
cmdclass = {'install': NyxInstaller},
)
diff --git a/test/arguments.py b/test/arguments.py
index 2336fdc..d27281c 100644
--- a/test/arguments.py
+++ b/test/arguments.py
@@ -67,7 +67,7 @@ class TestArgumentParsing(unittest.TestCase):
class TestExpandEvents(unittest.TestCase):
def test_examples(self):
- self.assertEqual(set(['INFO', 'NOTICE', 'UNKNOWN', 'STATUS_CLIENT']), expand_events('inUt'))
+ self.assertEqual(set(['INFO', 'NOTICE', 'UNKNOWN', 'TRANSPORT_LAUNCHED']), expand_events('inUt'))
self.assertEqual(set(['NOTICE', 'WARN', 'ERR', 'NYX_WARN', 'NYX_ERR']), expand_events('N4'))
self.assertEqual(set(), expand_events('cfX'))
@@ -89,13 +89,13 @@ class TestExpandEvents(unittest.TestCase):
# providing results even if there's other invalid options.
self.assertEqual(set(), expand_events('z*X*z'))
- self.assertEqual(28, len(expand_events('z*A*z')))
+ self.assertEqual(39, len(expand_events('z*A*z')))
def test_invalid_flags(self):
self._expect_invalid_flags('D1*', '*')
self._expect_invalid_flags('*D1', '*')
- self._expect_invalid_flags('zzD1zz', 'z')
- self._expect_invalid_flags('z*D1*z', 'z*')
+ self._expect_invalid_flags('zzD1Zz', 'Z')
+ self._expect_invalid_flags('Z*D1*z', 'Z*')
def _expect_invalid_flags(self, argument, expected):
try:
diff --git a/test/util/tracker/connection_tracker.py b/test/util/tracker/connection_tracker.py
index 0f3c93f..797c76b 100644
--- a/test/util/tracker/connection_tracker.py
+++ b/test/util/tracker/connection_tracker.py
@@ -7,9 +7,9 @@ from stem.util import connection
from mock import Mock, patch
-STEM_CONNECTION_1 = connection.Connection('127.0.0.1', 3531, '75.119.206.243', 22, 'tcp')
-STEM_CONNECTION_2 = connection.Connection('127.0.0.1', 1766, '86.59.30.40', 443, 'tcp')
-STEM_CONNECTION_3 = connection.Connection('127.0.0.1', 1059, '74.125.28.106', 80, 'tcp')
+STEM_CONNECTION_1 = connection.Connection('127.0.0.1', 3531, '75.119.206.243', 22, 'tcp', False)
+STEM_CONNECTION_2 = connection.Connection('127.0.0.1', 1766, '86.59.30.40', 443, 'tcp', False)
+STEM_CONNECTION_3 = connection.Connection('127.0.0.1', 1059, '74.125.28.106', 80, 'tcp', False)
class TestConnectionTracker(unittest.TestCase):
@@ -19,6 +19,7 @@ class TestConnectionTracker(unittest.TestCase):
@patch('nyx.util.tracker.connection.system_resolvers', Mock(return_value = [connection.Resolver.NETSTAT]))
def test_fetching_connections(self, get_value_mock, tor_controller_mock):
tor_controller_mock().get_pid.return_value = 12345
+ tor_controller_mock().get_conf.return_value = '0'
get_value_mock.return_value = [STEM_CONNECTION_1, STEM_CONNECTION_2, STEM_CONNECTION_3]
with ConnectionTracker(0.04) as daemon:
@@ -42,6 +43,7 @@ class TestConnectionTracker(unittest.TestCase):
@patch('nyx.util.tracker.connection.system_resolvers', Mock(return_value = [connection.Resolver.NETSTAT, connection.Resolver.LSOF]))
def test_resolver_failover(self, get_value_mock, tor_controller_mock):
tor_controller_mock().get_pid.return_value = 12345
+ tor_controller_mock().get_conf.return_value = '0'
get_value_mock.side_effect = IOError()
with ConnectionTracker(0.01) as daemon:
@@ -81,6 +83,7 @@ class TestConnectionTracker(unittest.TestCase):
@patch('nyx.util.tracker.connection.system_resolvers', Mock(return_value = [connection.Resolver.NETSTAT]))
def test_tracking_uptime(self, get_value_mock, tor_controller_mock):
tor_controller_mock().get_pid.return_value = 12345
+ tor_controller_mock().get_conf.return_value = '0'
get_value_mock.return_value = [STEM_CONNECTION_1]
first_start_time = time.time()
1
0
commit 0b4715ca0702a75b76d0b18e01ce9fc0c88e015a
Author: Damian Johnson <atagar(a)torproject.org>
Date: Mon Jan 18 09:21:12 2016 -0800
Drop torrc panel lock
Might not be safe yet but as with the other panels, I'll be making this thread
safe.
---
nyx/menu/actions.py | 1 -
nyx/torrc_panel.py | 284 ++++++++++++++++++++++++++--------------------------
2 files changed, 140 insertions(+), 145 deletions(-)
diff --git a/nyx/menu/actions.py b/nyx/menu/actions.py
index 32313b4..b6a4ae3 100644
--- a/nyx/menu/actions.py
+++ b/nyx/menu/actions.py
@@ -290,7 +290,6 @@ def make_torrc_menu(torrc_panel):
"""
torrc_menu = nyx.menu.item.Submenu('Torrc')
- torrc_menu.add(nyx.menu.item.MenuItem('Reload', torrc_panel.reload_torrc))
if torrc_panel.strip_comments:
label, arg = 'Show', True
diff --git a/nyx/torrc_panel.py b/nyx/torrc_panel.py
index 4248ae0..01d12fc 100644
--- a/nyx/torrc_panel.py
+++ b/nyx/torrc_panel.py
@@ -4,7 +4,6 @@ Panel displaying the torrc or nyxrc with the validation done against it.
import math
import curses
-import threading
from nyx.util import expand_path, panel, tor_config, tor_controller, ui_tools
@@ -23,7 +22,6 @@ class TorrcPanel(panel.Panel):
def __init__(self, stdscr):
panel.Panel.__init__(self, stdscr, 'torrc', 0)
- self._vals_lock = threading.RLock()
self.scroll = 0
self.show_line_num = True # shows left aligned line numbers
self.strip_comments = False # drops comments and extra whitespace
@@ -85,22 +83,21 @@ class TorrcPanel(panel.Panel):
self.redraw(True)
def handle_key(self, key):
- with self._vals_lock:
- if key.is_scroll():
- page_height = self.get_preferred_size()[0] - 1
- new_scroll = ui_tools.get_scroll_position(key, self.scroll, page_height, self._last_content_height)
-
- if self.scroll != new_scroll:
- self.scroll = new_scroll
- self.redraw(True)
- elif key.match('n'):
- self.set_line_number_visible(not self.show_line_num)
- elif key.match('s'):
- self.set_comments_visible(self.strip_comments)
- else:
- return False
-
- return True
+ if key.is_scroll():
+ page_height = self.get_preferred_size()[0] - 1
+ new_scroll = ui_tools.get_scroll_position(key, self.scroll, page_height, self._last_content_height)
+
+ if self.scroll != new_scroll:
+ self.scroll = new_scroll
+ self.redraw(True)
+ elif key.match('n'):
+ self.set_line_number_visible(not self.show_line_num)
+ elif key.match('s'):
+ self.set_comments_visible(self.strip_comments)
+ else:
+ return False
+
+ return True
def set_visible(self, is_visible):
if not is_visible:
@@ -120,180 +117,179 @@ class TorrcPanel(panel.Panel):
]
def draw(self, width, height):
- with self._vals_lock:
- # If true, we assume that the cached value in self._last_content_height is
- # still accurate, and stop drawing when there's nothing more to display.
- # Otherwise the self._last_content_height is suspect, and we'll process all
- # the content to check if it's right (and redraw again with the corrected
- # height if not).
+ # If true, we assume that the cached value in self._last_content_height is
+ # still accurate, and stop drawing when there's nothing more to display.
+ # Otherwise the self._last_content_height is suspect, and we'll process all
+ # the content to check if it's right (and redraw again with the corrected
+ # height if not).
- trust_last_content_height = self._last_content_height_args == (width, height)
+ trust_last_content_height = self._last_content_height_args == (width, height)
- # restricts scroll location to valid bounds
+ # restricts scroll location to valid bounds
- self.scroll = max(0, min(self.scroll, self._last_content_height - height + 1))
+ self.scroll = max(0, min(self.scroll, self._last_content_height - height + 1))
- if self.torrc_content is None:
- rendered_contents = ['### Unable to load the torrc ###']
- corrections = {}
- else:
- rendered_contents = [ui_tools.get_printable(line.replace('\t', ' ')) for line in self.torrc_content]
+ if self.torrc_content is None:
+ rendered_contents = ['### Unable to load the torrc ###']
+ corrections = {}
+ else:
+ rendered_contents = [ui_tools.get_printable(line.replace('\t', ' ')) for line in self.torrc_content]
- if self.strip_comments:
- for i in range(len(rendered_contents)):
- line = rendered_contents[i]
+ if self.strip_comments:
+ for i in range(len(rendered_contents)):
+ line = rendered_contents[i]
- if line and '#' in line:
- rendered_contents[i] = line[:line.find('#')].strip()
+ if line and '#' in line:
+ rendered_contents[i] = line[:line.find('#')].strip()
- corrections = dict((line_number, (issue, msg)) for line_number, issue, msg in tor_config.validate(self.torrc_content))
+ corrections = dict((line_number, (issue, msg)) for line_number, issue, msg in tor_config.validate(self.torrc_content))
- # offset to make room for the line numbers
+ # offset to make room for the line numbers
- line_number_offset = 0
+ line_number_offset = 0
- if self.show_line_num:
- if len(rendered_contents) == 0:
- line_number_offset = 2
- else:
- line_number_offset = int(math.log10(len(rendered_contents))) + 2
+ if self.show_line_num:
+ if len(rendered_contents) == 0:
+ line_number_offset = 2
+ else:
+ line_number_offset = int(math.log10(len(rendered_contents))) + 2
- # draws left-hand scroll bar if content's longer than the height
+ # draws left-hand scroll bar if content's longer than the height
- scroll_offset = 0
+ scroll_offset = 0
- if self._last_content_height > height - 1:
- scroll_offset = 3
- self.add_scroll_bar(self.scroll, self.scroll + height - 1, self._last_content_height, 1)
+ if self._last_content_height > height - 1:
+ scroll_offset = 3
+ self.add_scroll_bar(self.scroll, self.scroll + height - 1, self._last_content_height, 1)
- display_line = -self.scroll + 1 # line we're drawing on
+ display_line = -self.scroll + 1 # line we're drawing on
- # draws the top label
+ # draws the top label
- if self.is_title_visible():
- location_label = ' (%s)' % self.torrc_location
- self.addstr(0, 0, 'Tor Configuration File%s:' % (location_label), curses.A_STANDOUT)
+ if self.is_title_visible():
+ location_label = ' (%s)' % self.torrc_location
+ self.addstr(0, 0, 'Tor Configuration File%s:' % (location_label), curses.A_STANDOUT)
- is_multiline = False # true if we're in the middle of a multiline torrc entry
+ is_multiline = False # true if we're in the middle of a multiline torrc entry
- for line_number in range(0, len(rendered_contents)):
- line_text = rendered_contents[line_number]
- line_text = line_text.rstrip() # remove ending whitespace
+ for line_number in range(0, len(rendered_contents)):
+ line_text = rendered_contents[line_number]
+ line_text = line_text.rstrip() # remove ending whitespace
- # blank lines are hidden when stripping comments
+ # blank lines are hidden when stripping comments
- if self.strip_comments and not line_text:
- continue
+ if self.strip_comments and not line_text:
+ continue
- # splits the line into its component (msg, format) tuples
+ # splits the line into its component (msg, format) tuples
- line_comp = {
- 'option': ['', (curses.A_BOLD, 'green')],
- 'argument': ['', (curses.A_BOLD, 'cyan')],
- 'correction': ['', (curses.A_BOLD, 'cyan')],
- 'comment': ['', ('white',)],
- }
+ line_comp = {
+ 'option': ['', (curses.A_BOLD, 'green')],
+ 'argument': ['', (curses.A_BOLD, 'cyan')],
+ 'correction': ['', (curses.A_BOLD, 'cyan')],
+ 'comment': ['', ('white',)],
+ }
- # parses the comment
+ # parses the comment
- comment_index = line_text.find('#')
+ comment_index = line_text.find('#')
- if comment_index != -1:
- line_comp['comment'][0] = line_text[comment_index:]
- line_text = line_text[:comment_index]
+ if comment_index != -1:
+ line_comp['comment'][0] = line_text[comment_index:]
+ line_text = line_text[:comment_index]
- # splits the option and argument, preserving any whitespace around them
+ # splits the option and argument, preserving any whitespace around them
- stripped_line = line_text.strip()
- option_index = stripped_line.find(' ')
+ stripped_line = line_text.strip()
+ option_index = stripped_line.find(' ')
- if is_multiline:
- # part of a multiline entry started on a previous line so everything
- # is part of the argument
- line_comp['argument'][0] = line_text
- elif option_index == -1:
- # no argument provided
- line_comp['option'][0] = line_text
- else:
- option_text = stripped_line[:option_index]
- option_end = line_text.find(option_text) + len(option_text)
- line_comp['option'][0] = line_text[:option_end]
- line_comp['argument'][0] = line_text[option_end:]
+ if is_multiline:
+ # part of a multiline entry started on a previous line so everything
+ # is part of the argument
+ line_comp['argument'][0] = line_text
+ elif option_index == -1:
+ # no argument provided
+ line_comp['option'][0] = line_text
+ else:
+ option_text = stripped_line[:option_index]
+ option_end = line_text.find(option_text) + len(option_text)
+ line_comp['option'][0] = line_text[:option_end]
+ line_comp['argument'][0] = line_text[option_end:]
- # flags following lines as belonging to this multiline entry if it ends
- # with a slash
+ # flags following lines as belonging to this multiline entry if it ends
+ # with a slash
- if stripped_line:
- is_multiline = stripped_line.endswith('\\')
+ if stripped_line:
+ is_multiline = stripped_line.endswith('\\')
- # gets the correction
+ # gets the correction
- if line_number in corrections:
- line_issue, line_issue_msg = corrections[line_number]
+ if line_number in corrections:
+ line_issue, line_issue_msg = corrections[line_number]
- if line_issue in (tor_config.ValidationError.DUPLICATE, tor_config.ValidationError.IS_DEFAULT):
- line_comp['option'][1] = (curses.A_BOLD, 'blue')
- line_comp['argument'][1] = (curses.A_BOLD, 'blue')
- elif line_issue == tor_config.ValidationError.MISMATCH:
- line_comp['argument'][1] = (curses.A_BOLD, 'red')
- line_comp['correction'][0] = ' (%s)' % line_issue_msg
- else:
- # For some types of configs the correction field is simply used to
- # provide extra data (for instance, the type for tor state fields).
+ if line_issue in (tor_config.ValidationError.DUPLICATE, tor_config.ValidationError.IS_DEFAULT):
+ line_comp['option'][1] = (curses.A_BOLD, 'blue')
+ line_comp['argument'][1] = (curses.A_BOLD, 'blue')
+ elif line_issue == tor_config.ValidationError.MISMATCH:
+ line_comp['argument'][1] = (curses.A_BOLD, 'red')
+ line_comp['correction'][0] = ' (%s)' % line_issue_msg
+ else:
+ # For some types of configs the correction field is simply used to
+ # provide extra data (for instance, the type for tor state fields).
- line_comp['correction'][0] = ' (%s)' % line_issue_msg
- line_comp['correction'][1] = (curses.A_BOLD, 'magenta')
+ line_comp['correction'][0] = ' (%s)' % line_issue_msg
+ line_comp['correction'][1] = (curses.A_BOLD, 'magenta')
- # draws the line number
+ # draws the line number
- if self.show_line_num and display_line < height and display_line >= 1:
- line_number_str = ('%%%ii' % (line_number_offset - 1)) % (line_number + 1)
- self.addstr(display_line, scroll_offset, line_number_str, curses.A_BOLD, 'yellow')
+ if self.show_line_num and display_line < height and display_line >= 1:
+ line_number_str = ('%%%ii' % (line_number_offset - 1)) % (line_number + 1)
+ self.addstr(display_line, scroll_offset, line_number_str, curses.A_BOLD, 'yellow')
- # draws the rest of the components with line wrap
+ # draws the rest of the components with line wrap
- cursor_location, line_offset = line_number_offset + scroll_offset, 0
- display_queue = [line_comp[entry] for entry in ('option', 'argument', 'correction', 'comment')]
+ cursor_location, line_offset = line_number_offset + scroll_offset, 0
+ display_queue = [line_comp[entry] for entry in ('option', 'argument', 'correction', 'comment')]
- while display_queue:
- msg, format = display_queue.pop(0)
+ while display_queue:
+ msg, format = display_queue.pop(0)
- max_msg_size, include_break = width - cursor_location, False
+ max_msg_size, include_break = width - cursor_location, False
- if len(msg) >= max_msg_size:
- # message is too long - break it up
+ if len(msg) >= max_msg_size:
+ # message is too long - break it up
- if line_offset == MAX_WRAP_PER_LINE - 1:
- msg = str_tools.crop(msg, max_msg_size)
- else:
- include_break = True
- msg, remainder = str_tools.crop(msg, max_msg_size, 4, 4, str_tools.Ending.HYPHEN, True)
- display_queue.insert(0, (remainder.strip(), format))
+ if line_offset == MAX_WRAP_PER_LINE - 1:
+ msg = str_tools.crop(msg, max_msg_size)
+ else:
+ include_break = True
+ msg, remainder = str_tools.crop(msg, max_msg_size, 4, 4, str_tools.Ending.HYPHEN, True)
+ display_queue.insert(0, (remainder.strip(), format))
- draw_line = display_line + line_offset
+ draw_line = display_line + line_offset
- if msg and draw_line < height and draw_line >= 1:
- self.addstr(draw_line, cursor_location, msg, *format)
+ if msg and draw_line < height and draw_line >= 1:
+ self.addstr(draw_line, cursor_location, msg, *format)
- # If we're done, and have added content to this line, then start
- # further content on the next line.
+ # If we're done, and have added content to this line, then start
+ # further content on the next line.
- cursor_location += len(msg)
- include_break |= not display_queue and cursor_location != line_number_offset + scroll_offset
+ cursor_location += len(msg)
+ include_break |= not display_queue and cursor_location != line_number_offset + scroll_offset
- if include_break:
- line_offset += 1
- cursor_location = line_number_offset + scroll_offset
+ if include_break:
+ line_offset += 1
+ cursor_location = line_number_offset + scroll_offset
- display_line += max(line_offset, 1)
+ display_line += max(line_offset, 1)
- if trust_last_content_height and display_line >= height:
- break
+ if trust_last_content_height and display_line >= height:
+ break
- if not trust_last_content_height:
- self._last_content_height_args = (width, height)
- new_content_height = display_line + self.scroll - 1
+ if not trust_last_content_height:
+ self._last_content_height_args = (width, height)
+ new_content_height = display_line + self.scroll - 1
- if self._last_content_height != new_content_height:
- self._last_content_height = new_content_height
- self.redraw(True)
+ if self._last_content_height != new_content_height:
+ self._last_content_height = new_content_height
+ self.redraw(True)
1
0
commit 4e885b2878145995735bec9819a9612136b93547
Author: Damian Johnson <atagar(a)torproject.org>
Date: Sat Feb 6 12:41:45 2016 -0800
Drop unused get_config_location()
---
nyx/util/tor_config.py | 22 +---------------------
1 file changed, 1 insertion(+), 21 deletions(-)
diff --git a/nyx/util/tor_config.py b/nyx/util/tor_config.py
index fd610f7..8a382c9 100644
--- a/nyx/util/tor_config.py
+++ b/nyx/util/tor_config.py
@@ -4,7 +4,7 @@ Helper functions for working with tor's configuration file.
from nyx.util import tor_controller
-from stem.util import conf, enum, str_tools, system
+from stem.util import conf, enum, str_tools
CONFIG = conf.config_dict('nyx', {
'torrc.alias': {},
@@ -48,26 +48,6 @@ ValidationError = enum.Enum('DUPLICATE', 'MISMATCH', 'IS_DEFAULT')
MULTILINE_PARAM = None # cached multiline parameters (lazily loaded)
-def get_config_location():
- """
- Provides the location of the torrc, raising an IOError with the reason if the
- path can't be determined.
- """
-
- controller = tor_controller()
- config_location = controller.get_info('config-file', None)
- tor_pid, tor_prefix = controller.controller.get_pid(None), CONFIG['tor.chroot']
-
- if not config_location:
- raise IOError('unable to query the torrc location')
-
- try:
- tor_cwd = system.cwd(tor_pid)
- return tor_prefix + system.expand_path(config_location, tor_cwd)
- except IOError as exc:
- raise IOError("querying tor's pwd failed because %s" % exc)
-
-
def get_multiline_parameters():
"""
Provides parameters that can be defined multiple times in the torrc without
1
0
commit b546ab920681e9403a65fb9af8110941b8cb5c74
Author: Damian Johnson <atagar(a)torproject.org>
Date: Sat Feb 6 13:01:16 2016 -0800
Merge _get_unit_type() into caller
Helper isn't providing any better readability so merging it into its caller.
---
nyx/util/tor_config.py | 37 +++++++++----------------------------
1 file changed, 9 insertions(+), 28 deletions(-)
diff --git a/nyx/util/tor_config.py b/nyx/util/tor_config.py
index 8a382c9..22e7938 100644
--- a/nyx/util/tor_config.py
+++ b/nyx/util/tor_config.py
@@ -79,7 +79,7 @@ def get_multiline_parameters():
return tuple(MULTILINE_PARAM)
-def validate(contents = None):
+def validate(contents):
"""
Performs validation on the given torrc contents, providing back a listing of
(line number, issue, msg) tuples for issues found. If the issue occures on a
@@ -91,7 +91,7 @@ def validate(contents = None):
controller = tor_controller()
- config_text = tor_controller().get_info('config-text', None)
+ config_text = controller.get_info('config-text', None)
config_lines = config_text.splitlines() if config_text else []
custom_options = list(set([line.split(' ')[0] for line in config_lines]))
@@ -228,37 +228,18 @@ def _parse_conf_value(conf_arg):
if conf_arg.count(' ') == 1:
val, unit = conf_arg.lower().split(' ', 1)
- if not val.isdigit():
- return conf_arg, ValueType.UNRECOGNIZED
+ if val.isdigit():
+ for label in SIZE_MULT:
+ if unit in CONFIG['torrc.units.size.' + label]:
+ return str(int(val) * SIZE_MULT[label]), ValueType.SIZE
- mult, mult_type = _get_unit_type(unit)
-
- if mult is not None:
- return str(int(val) * mult), mult_type
+ for label in TIME_MULT:
+ if unit in CONFIG['torrc.units.time.' + label]:
+ return str(int(val) * TIME_MULT[label]), ValueType.TIME
return conf_arg, ValueType.UNRECOGNIZED
-def _get_unit_type(unit):
- """
- Provides the type and multiplier for an argument's unit. The multiplier is
- None if the unit isn't recognized.
-
- Arguments:
- unit - string representation of a unit
- """
-
- for label in SIZE_MULT:
- if unit in CONFIG['torrc.units.size.' + label]:
- return SIZE_MULT[label], ValueType.SIZE
-
- for label in TIME_MULT:
- if unit in CONFIG['torrc.units.time.' + label]:
- return TIME_MULT[label], ValueType.TIME
-
- return None, ValueType.UNRECOGNIZED
-
-
def _strip_comments(contents):
"""
Removes comments and extra whitespace from the given torrc contents.
1
0
[nyx/master] Validation for missing torrc entries no longer used
by atagar@torproject.org 13 Feb '16
by atagar@torproject.org 13 Feb '16
13 Feb '16
commit 2c0461af5690b17b47e59dc356415e63a8b3c0a0
Author: Damian Johnson <atagar(a)torproject.org>
Date: Sat Feb 6 12:36:19 2016 -0800
Validation for missing torrc entries no longer used
Now that we no longer log torrc validation issues checking for missing options
is moot.
---
nyx/util/tor_config.py | 22 +---------------------
nyxrc.sample | 15 ---------------
2 files changed, 1 insertion(+), 36 deletions(-)
diff --git a/nyx/util/tor_config.py b/nyx/util/tor_config.py
index 3ffb435..fd610f7 100644
--- a/nyx/util/tor_config.py
+++ b/nyx/util/tor_config.py
@@ -7,7 +7,6 @@ from nyx.util import tor_controller
from stem.util import conf, enum, str_tools, system
CONFIG = conf.config_dict('nyx', {
- 'features.torrc.validate': True,
'torrc.alias': {},
'torrc.units.size.b': [],
'torrc.units.size.kb': [],
@@ -19,9 +18,6 @@ CONFIG = conf.config_dict('nyx', {
'torrc.units.time.hour': [],
'torrc.units.time.day': [],
'torrc.units.time.week': [],
- 'startup.data_directory': '~/.nyx',
- 'features.config.descriptions.enabled': True,
- 'features.config.descriptions.persist': True,
'tor.chroot': '',
})
@@ -45,10 +41,9 @@ TIME_MULT = {'sec': 1, 'min': 60, 'hour': 3600, 'day': 86400, 'week': 604800}
# enums for issues found during torrc validation:
# DUPLICATE - entry is ignored due to being a duplicate
# MISMATCH - the value doesn't match tor's current state
-# MISSING - value differs from its default but is missing from the torrc
# IS_DEFAULT - the configuration option matches tor's default
-ValidationError = enum.Enum('DUPLICATE', 'MISMATCH', 'MISSING', 'IS_DEFAULT')
+ValidationError = enum.Enum('DUPLICATE', 'MISMATCH', 'IS_DEFAULT')
MULTILINE_PARAM = None # cached multiline parameters (lazily loaded)
@@ -237,21 +232,6 @@ def validate(contents = None):
issues_found.append((line_number, ValidationError.MISMATCH, ', '.join(display_values)))
- # checks if any custom options are missing from the torrc
-
- for option in custom_options:
- # In new versions the 'DirReqStatistics' option is true by default and
- # disabled on startup if geoip lookups are unavailable. If this option is
- # missing then that's most likely the reason.
- #
- # https://trac.torproject.org/projects/tor/ticket/4237
-
- if option == 'DirReqStatistics':
- continue
-
- if option not in seen_options:
- issues_found.append((None, ValidationError.MISSING, option))
-
return issues_found
diff --git a/nyxrc.sample b/nyxrc.sample
index 64eb7a3..186df2b 100644
--- a/nyxrc.sample
+++ b/nyxrc.sample
@@ -33,9 +33,6 @@ features.colorOverride none
# Includes unicode characters in the interface.
features.printUnicode true
-# Checks the torrc for issues, warning and hilighting problems if true
-features.torrc.validate true
-
# Set this if you're running in a chroot jail or other environment where tor's
# resources (log, state, etc) should have a prefix in their paths.
@@ -112,18 +109,6 @@ features.config.state.showPrivateOptions false
features.config.state.showVirtualOptions false
features.config.file.maxLinesPerEntry 8
-# Descriptions for tor's configuration options can be loaded from its man page
-# to give usage information on the settings page. They can also be persisted to
-# a file to speed future lookups.
-# ---------------------------
-# enabled
-# allows the descriptions to be fetched from the man page if true
-# persist
-# caches the descriptions (substantially saving on future startup times)
-
-features.config.descriptions.enabled true
-features.config.descriptions.persist true
-
# General graph parameters
# ------------------------
# height
1
0
commit 8327b73398530c4731bc381ddea9e3e530ced704
Author: Damian Johnson <atagar(a)torproject.org>
Date: Sat Feb 6 10:03:56 2016 -0800
Rename nyx/config/* to nyx/settings/*
I hate it when tab completion has multiple matches. He had both a config
directory and a config_panel.py. Renaming the former to the name I usually
use for stem config files.
---
nyx/config/attributes.cfg | 94 --------------------------------------
nyx/config/dedup.cfg | 91 -------------------------------------
nyx/config/strings.cfg | 107 --------------------------------------------
nyx/config/torrc.cfg | 53 ----------------------
nyx/settings/attributes.cfg | 94 ++++++++++++++++++++++++++++++++++++++
nyx/settings/dedup.cfg | 91 +++++++++++++++++++++++++++++++++++++
nyx/settings/strings.cfg | 107 ++++++++++++++++++++++++++++++++++++++++++++
nyx/settings/torrc.cfg | 53 ++++++++++++++++++++++
nyx/util/__init__.py | 2 +-
9 files changed, 346 insertions(+), 346 deletions(-)
diff --git a/nyx/config/attributes.cfg b/nyx/config/attributes.cfg
deleted file mode 100644
index 1942de9..0000000
--- a/nyx/config/attributes.cfg
+++ /dev/null
@@ -1,94 +0,0 @@
-# General configuration data used by nyx.
-
-attr.flag_colors Authority => white
-attr.flag_colors BadExit => red
-attr.flag_colors BadDirectory => red
-attr.flag_colors Exit => cyan
-attr.flag_colors Fast => yellow
-attr.flag_colors Guard => green
-attr.flag_colors HSDir => magenta
-attr.flag_colors Named => blue
-attr.flag_colors Stable => blue
-attr.flag_colors Running => yellow
-attr.flag_colors Unnamed => magenta
-attr.flag_colors Valid => green
-attr.flag_colors V2Dir => cyan
-attr.flag_colors V3Dir => white
-
-attr.version_status_colors new => blue
-attr.version_status_colors new in series => blue
-attr.version_status_colors obsolete => red
-attr.version_status_colors recommended => green
-attr.version_status_colors old => red
-attr.version_status_colors unrecommended => red
-attr.version_status_colors unknown => cyan
-
-attr.hibernate_color awake => green
-attr.hibernate_color soft => yellow
-attr.hibernate_color hard => red
-
-attr.graph.title bandwidth => Bandwidth
-attr.graph.title connections => Connection Count
-attr.graph.title resources => System Resources
-
-attr.graph.header.primary bandwidth => Download
-attr.graph.header.primary connections => Inbound
-attr.graph.header.primary resources => CPU
-
-attr.graph.header.secondary bandwidth => Upload
-attr.graph.header.secondary connections => Outbound
-attr.graph.header.secondary resources => Memory
-
-attr.log_color DEBUG => magenta
-attr.log_color INFO => blue
-attr.log_color NOTICE => green
-attr.log_color WARN => yellow
-attr.log_color ERR => red
-
-attr.log_color NYX_DEBUG => magenta
-attr.log_color NYX_INFO => blue
-attr.log_color NYX_NOTICE => green
-attr.log_color NYX_WARN => yellow
-attr.log_color NYX_ERR => red
-
-attr.log_color CIRC => yellow
-attr.log_color BW => cyan
-attr.log_color NS => blue
-attr.log_color NEWCONSENSUS => blue
-attr.log_color GUARD => yellow
-
-attr.connection.category_color Inbound => green
-attr.connection.category_color Outbound => blue
-attr.connection.category_color Exit => red
-attr.connection.category_color Hidden => magenta
-attr.connection.category_color Socks => yellow
-attr.connection.category_color Circuit => cyan
-attr.connection.category_color Directory => magenta
-attr.connection.category_color Control => red
-
-attr.connection.sort_color Category => red
-attr.connection.sort_color Uptime => yellow
-attr.connection.sort_color Listing => green
-attr.connection.sort_color Ip Address => blue
-attr.connection.sort_color Port => blue
-attr.connection.sort_color Fingerprint => cyan
-attr.connection.sort_color Nickname => cyan
-attr.connection.sort_color Country => blue
-
-attr.config.category_color General => green
-attr.config.category_color Client => blue
-attr.config.category_color Relay => yellow
-attr.config.category_color Directory => magenta
-attr.config.category_color Authority => red
-attr.config.category_color Hidden Service => cyan
-attr.config.category_color Testing => white
-attr.config.category_color Unknown => white
-
-attr.config.sort_color Name => blue
-attr.config.sort_color Value => cyan
-attr.config.sort_color Value Type => green
-attr.config.sort_color Category => red
-attr.config.sort_color Usage => yellow
-attr.config.sort_color Summary => green
-attr.config.sort_color Description => white
-attr.config.sort_color Man Page Entry => blue
diff --git a/nyx/config/dedup.cfg b/nyx/config/dedup.cfg
deleted file mode 100644
index 42d8102..0000000
--- a/nyx/config/dedup.cfg
+++ /dev/null
@@ -1,91 +0,0 @@
-################################################################################
-#
-# Snippets from common log messages. These are used to determine when entries
-# with dynamic content (hostnames, numbers, etc) are the same. If this matches
-# the start of both messages then the entries are flagged as duplicates. If the
-# entry begins with an asterisk (*) then it checks if the substrings exist
-# anywhere in the messages.
-#
-# Examples for the complete messages:
-#
-# [BW] READ: 0, WRITTEN: 0
-# [DEBUG] connection_handle_write(): After TLS write of 512: 0 read, 586 written
-# [DEBUG] flush_chunk_tls(): flushed 512 bytes, 0 ready to flush, 0 remain.
-# [DEBUG] conn_read_callback(): socket 7 wants to read.
-# [DEBUG] conn_write_callback(): socket 51 wants to write.
-# [DEBUG] connection_remove(): removing socket -1 (type OR), n_conns now 50
-# [DEBUG] connection_or_process_cells_from_inbuf(): 7: starting, inbuf_datalen
-# 0 (0 pending in tls object).
-# [DEBUG] connection_read_to_buf(): 38: starting, inbuf_datalen 0 (0 pending in
-# tls object). at_most 12800.
-# [DEBUG] connection_read_to_buf(): TLS connection closed on read. Closing.
-# (Nickname moria1, address 128.31.0.34)
-# [INFO] run_connection_housekeeping(): Expiring non-open OR connection to fd
-# 16 (79.193.61.171:443).
-# [INFO] rep_hist_downrate_old_runs(): Discounting all old stability info by a
-# factor of 0.950000
-# [NOTICE] Circuit build timeout of 96803ms is beyond the maximum build time we
-# have ever observed. Capping it to 96107ms.
-# The above NOTICE changes to an INFO message in maint-0.2.2
-# [NOTICE] Based on 1000 circuit times, it looks like we don't need to wait so
-# long for circuits to finish. We will now assume a circuit is too slow
-# to use after waiting 65 seconds.
-# [NOTICE] We stalled too much while trying to write 150 bytes to address
-# [scrubbed]. If this happens a lot, either something is wrong with
-# your network connection, or something is wrong with theirs. (fd 238,
-# type Directory, state 1, marked at main.c:702).
-# [NOTICE] I learned some more directory information, but not enough to build a
-# circuit: We have only 469/2027 usable descriptors.
-# [NOTICE] Attempt by %s to open a stream from unknown relay. Closing.
-# [NOTICE] Average packaged cell fullness: 70.976%. TLS write overhead: 11%
-# [NOTICE] Heartbeat: Tor's uptime is 8 days 6:00 hours, with 0 circuits open.
-# I've sent 3.53 MB and received 90.61 MB.
-# [WARN] You specified a server "Amunet8" by name, but this name is not
-# registered
-# [WARN] I have no descriptor for the router named "Amunet8" in my declared
-# family; I'll use the nickname as is, but this may confuse clients.
-# [WARN] Controller gave us config lines that didn't validate: Value
-# 'BandwidthRate ' is malformed or out of bounds.
-# [WARN] Problem bootstrapping. Stuck at 80%: Connecting to the Tor network.
-# (Network is unreachable; NOROUTE; count 47; recommendation warn)
-# [WARN] 4 unknown, 1 missing key, 3 good, 0 bad, 1 no signature, 4 required
-# [NYX_DEBUG] refresh rate: 0.001 seconds
-# [NYX_DEBUG] proc call (process connections): /proc/net/[tcp|udp] (runtime: 0.0018)
-# [NYX_DEBUG] system call: ps -p 2354 -o %cpu,rss,%mem,etime (runtime: 0.02)
-# [NYX_DEBUG] system call: netstat -npt | grep 2354/tor (runtime: 0.02)
-# [NYX_DEBUG] recreating panel 'graph' with the dimensions of 14/124
-# [NYX_DEBUG] redrawing the log panel with the corrected content height (estimat was off by 4)
-# [NYX_DEBUG] GETINFO accounting/bytes-left (runtime: 0.0006)
-# [NYX_DEBUG] GETINFO traffic/read (runtime: 0.0004)
-# [NYX_DEBUG] GETINFO traffic/written (runtime: 0.0002)
-# [NYX_DEBUG] GETCONF MyFamily (runtime: 0.0007)
-# [NYX_DEBUG] Unable to query process resource usage from ps, waiting 6.25 seconds (unrecognized output from ps: ...)
-#
-################################################################################
-
-dedup.BW READ:
-dedup.DEBUG connection_handle_write(): After TLS write of
-dedup.DEBUG flush_chunk_tls(): flushed
-dedup.DEBUG conn_read_callback(): socket
-dedup.DEBUG conn_write_callback(): socket
-dedup.DEBUG connection_remove(): removing socket
-dedup.DEBUG connection_or_process_cells_from_inbuf():
-dedup.DEBUG *pending in tls object). at_most
-dedup.DEBUG connection_read_to_buf(): TLS connection closed on read. Closing.
-dedup.INFO run_connection_housekeeping(): Expiring
-dedup.INFO rep_hist_downrate_old_runs(): Discounting all old stability info by a factor of
-dedup.INFO *build time we have ever observed. Capping it to
-dedup.NOTICE *build time we have ever observed. Capping it to
-dedup.NOTICE *We will now assume a circuit is too slow to use after waiting
-dedup.NOTICE We stalled too much while trying to write
-dedup.NOTICE I learned some more directory information, but not enough to build a circuit
-dedup.NOTICE Attempt by
-dedup.NOTICE *Loading relay descriptors.
-dedup.NOTICE Average packaged cell fullness:
-dedup.NOTICE Heartbeat: Tor's uptime is
-dedup.WARN You specified a server
-dedup.WARN I have no descriptor for the router named
-dedup.WARN Controller gave us config lines that didn't validate
-dedup.WARN Problem bootstrapping. Stuck at
-dedup.WARN *missing key,
-
diff --git a/nyx/config/strings.cfg b/nyx/config/strings.cfg
deleted file mode 100644
index 85b4f8d..0000000
--- a/nyx/config/strings.cfg
+++ /dev/null
@@ -1,107 +0,0 @@
-################################################################################
-#
-# User facing strings. These are sorted into the following namespaces...
-#
-# * config parsing or handling configuration options
-# * debug concerns the --debug argument
-# * misc anything that doesn't fit into a present namespace
-# * panel used after startup by our curses panels
-# * setup notificaitons or issues arising while starting nyx
-# * tracker related to tracking resource usage or connections
-# * usage usage information about starting and running nyx
-#
-################################################################################
-
-msg.wrap {text}
-
-msg.config.unable_to_read_file Failed to load configuration (using defaults): "{error}"
-msg.config.nothing_loaded No nyxrc loaded, using defaults. You can customize nyx by placing a configuration file at {path} (see the nyxrc.sample for its options).
-
-msg.debug.saving_to_path Saving a debug log to {path}, please check it for sensitive information before sharing it.
-msg.debug.unable_to_write_file Unable to write to our debug log file ({path}): {error}
-
-msg.panel.graphing.prepopulation_successful Bandwidth graph has information for the last {duration}
-msg.panel.graphing.bw_event_cache_malformed Tor's 'GETINFO bw-event-cache' provided malformed output: {response}
-msg.panel.header.fd_used_at_sixty_percent Tor's file descriptor usage is at {percentage}%.
-msg.panel.header.fd_used_at_ninety_percent Tor's file descriptor usage is at {percentage}%. If you run out Tor will be unable to continue functioning.
-msg.panel.log.read_from_log_file Read {count} entries from tor's log file: {path} (read limit: {read_limit}, runtime: {runtime})
-
-msg.setup.nyx_is_running_as_root Nyx is currently running with root permissions. This isn't a good idea, nor should it be necessary.
-msg.setup.chroot_doesnt_exist The chroot path set in your config ({path}) doesn't exist.
-msg.setup.set_freebsd_chroot Adjusting paths to account for Tor running in a FreeBSD jail at: {path}
-msg.setup.tor_is_running_as_root Tor is currently running with root permissions. This isn't a good idea, nor should it be necessary. See the 'User UID' option on Tor's man page for an easy method of reducing its permissions after startup.
-msg.setup.unable_to_determine_pid Unable to determine Tor's pid. Some information, like its resource usage will be unavailable.
-msg.setup.unknown_event_types nyx doesn't recognize the following event types: {event_types} (log 'UNKNOWN' events to see them)
-msg.setup.color_support_available Terminal color support detected and enabled
-msg.setup.color_support_unavailable Terminal color support unavailable
-
-msg.tracker.abort_getting_resources Failed three attempts to get process resource usage from {resolver}, {response} ({exc})
-msg.tracker.abort_getting_port_usage Failed three attempts to determine the process using active ports ({exc})
-msg.tracker.lookup_rate_increased connection lookup time increasing to {seconds} seconds per call
-msg.tracker.unable_to_get_port_usages Unable to query the processes using ports usage lsof ({exc})
-msg.tracker.unable_to_get_resources Unable to query process resource usage from {resolver} ({exc})
-msg.tracker.unable_to_use_all_resolvers We were unable to use any of your system's resolvers to get tor's connections. This is fine, but means that the connections page will be empty. This is usually permissions related so if you would like to fix this then run nyx with the same user as tor (ie, "sudo -u <tor user> nyx").
-msg.tracker.unable_to_use_resolver Unable to query connections with {old_resolver}, trying {new_resolver}
-
-msg.usage.invalid_arguments {error} (for usage provide --help)
-msg.usage.not_a_valid_address '{address_input}' isn't a valid IPv4 address
-msg.usage.not_a_valid_port '{port_input}' isn't a valid port number
-msg.usage.unrecognized_log_flags Unrecognized event flags: {flags}
-msg.usage.unable_to_set_color_override "{color}" isn't a valid color
-
-msg.debug.header
-|Nyx {nyx_version} Debug Dump
-|Stem Version: {stem_version}
-|Python Version: {python_version}
-|Platform: {system} ({platform})
-|--------------------------------------------------------------------------------
-|Nyx Configuration ({nyxrc_path}):
-|{nyxrc_content}
-|--------------------------------------------------------------------------------
-
-msg.misc.event_types
-| d DEBUG a ADDRMAP r CLIENTS_SEEN C SIGNAL
-| i INFO f AUTHDIR_NEWDESCS u DESCCHANGED F STREAM_BW
-| n NOTICE j BUILDTIMEOUT_SET g GUARD G STATUS_CLIENT
-| w WARN b BW h HS_DESC H STATUS_GENERAL
-| e ERR k CELL_STATS v HS_DESC_CONTENT I STATUS_SERVER
-| c CIRC x NETWORK_LIVENESS s STREAM
-| l CIRC_BW y NEWCONSENSUS J TB_EMPTY
-| m CIRC_MINOR z NEWDESC t TRANSPORT_LAUNCHED
-| p CONF_CHANGED B NS
-| q CONN_BW o ORCONN
-|
-| DINWE tor runlevel+ A All Events
-| 12345 nyx runlevel+ X No Events
-| U Unknown Events
-
-msg.setup.unknown_term
-|Unknown $TERM: ({term})
-|Either update your terminfo database or run nyx using "TERM=xterm nyx".
-|
-
-msg.usage.help_output
-|Usage nyx [OPTION]
-|Terminal status monitor for Tor relays.
-|
-| -i, --interface [ADDRESS:]PORT change control interface from {address}:{port}
-| -s, --socket SOCKET_PATH attach using unix domain socket if present,
-| SOCKET_PATH defaults to: {socket}
-| -c, --config CONFIG_PATH loaded configuration options, CONFIG_PATH
-| defaults to: {config_path}
-| -d, --debug LOG_PATH writes all nyx logs to the given location
-| -l, --log EVENT_FLAGS event types to be logged (default: {events})
-|
-|{event_flags}
-|
-| -v, --version provides version information
-| -h, --help presents this help
-|
-|Example:
-|nyx -i 1643 attach to control port 1643
-|nyx -l we -c /tmp/cfg use this configuration file with 'WARN'/'ERR' events
-
-msg.usage.version_output
-|nyx version {version} (released {date})
-|
-
diff --git a/nyx/config/torrc.cfg b/nyx/config/torrc.cfg
deleted file mode 100644
index 71d4608..0000000
--- a/nyx/config/torrc.cfg
+++ /dev/null
@@ -1,53 +0,0 @@
-################################################################################
-#
-# Information related to tor configuration options. This has two sections...
-#
-# * torrc.alias Aliases for configuration options tor will accept.
-# * torrc.units Labels accepted by tor for various units.
-#
-################################################################################
-
-# Torrc aliases from the _option_abbrevs struct of 'src/or/config.c'. These
-# couldn't be requested via GETCONF as of 0.2.1.19, but this might have been
-# fixed. Discussion is in...
-#
-# https://trac.torproject.org/projects/tor/ticket/1802
-#
-# TODO: Check if this workaround can be dropped later.
-
-torrc.alias l => Log
-torrc.alias AllowUnverifiedNodes => AllowInvalidNodes
-torrc.alias AutomapHostSuffixes => AutomapHostsSuffixes
-torrc.alias AutomapHostOnResolve => AutomapHostsOnResolve
-torrc.alias BandwidthRateBytes => BandwidthRate
-torrc.alias BandwidthBurstBytes => BandwidthBurst
-torrc.alias DirFetchPostPeriod => StatusFetchPeriod
-torrc.alias MaxConn => ConnLimit
-torrc.alias ORBindAddress => ORListenAddress
-torrc.alias DirBindAddress => DirListenAddress
-torrc.alias SocksBindAddress => SocksListenAddress
-torrc.alias UseHelperNodes => UseEntryGuards
-torrc.alias NumHelperNodes => NumEntryGuards
-torrc.alias UseEntryNodes => UseEntryGuards
-torrc.alias NumEntryNodes => NumEntryGuards
-torrc.alias ResolvConf => ServerDNSResolvConfFile
-torrc.alias SearchDomains => ServerDNSSearchDomains
-torrc.alias ServerDNSAllowBrokenResolvConf => ServerDNSAllowBrokenConfig
-torrc.alias PreferTunnelledDirConns => PreferTunneledDirConns
-torrc.alias BridgeAuthoritativeDirectory => BridgeAuthoritativeDir
-torrc.alias StrictEntryNodes => StrictNodes
-torrc.alias StrictExitNodes => StrictNodes
-
-# Size and time modifiers allowed by 'src/or/config.c'.
-
-torrc.units.size.b b, byte, bytes
-torrc.units.size.kb kb, kbyte, kbytes, kilobyte, kilobytes
-torrc.units.size.mb m, mb, mbyte, mbytes, megabyte, megabytes
-torrc.units.size.gb gb, gbyte, gbytes, gigabyte, gigabytes
-torrc.units.size.tb tb, terabyte, terabytes
-
-torrc.units.time.sec second, seconds
-torrc.units.time.min minute, minutes
-torrc.units.time.hour hour, hours
-torrc.units.time.day day, days
-torrc.units.time.week week, weeks
diff --git a/nyx/settings/attributes.cfg b/nyx/settings/attributes.cfg
new file mode 100644
index 0000000..1942de9
--- /dev/null
+++ b/nyx/settings/attributes.cfg
@@ -0,0 +1,94 @@
+# General configuration data used by nyx.
+
+attr.flag_colors Authority => white
+attr.flag_colors BadExit => red
+attr.flag_colors BadDirectory => red
+attr.flag_colors Exit => cyan
+attr.flag_colors Fast => yellow
+attr.flag_colors Guard => green
+attr.flag_colors HSDir => magenta
+attr.flag_colors Named => blue
+attr.flag_colors Stable => blue
+attr.flag_colors Running => yellow
+attr.flag_colors Unnamed => magenta
+attr.flag_colors Valid => green
+attr.flag_colors V2Dir => cyan
+attr.flag_colors V3Dir => white
+
+attr.version_status_colors new => blue
+attr.version_status_colors new in series => blue
+attr.version_status_colors obsolete => red
+attr.version_status_colors recommended => green
+attr.version_status_colors old => red
+attr.version_status_colors unrecommended => red
+attr.version_status_colors unknown => cyan
+
+attr.hibernate_color awake => green
+attr.hibernate_color soft => yellow
+attr.hibernate_color hard => red
+
+attr.graph.title bandwidth => Bandwidth
+attr.graph.title connections => Connection Count
+attr.graph.title resources => System Resources
+
+attr.graph.header.primary bandwidth => Download
+attr.graph.header.primary connections => Inbound
+attr.graph.header.primary resources => CPU
+
+attr.graph.header.secondary bandwidth => Upload
+attr.graph.header.secondary connections => Outbound
+attr.graph.header.secondary resources => Memory
+
+attr.log_color DEBUG => magenta
+attr.log_color INFO => blue
+attr.log_color NOTICE => green
+attr.log_color WARN => yellow
+attr.log_color ERR => red
+
+attr.log_color NYX_DEBUG => magenta
+attr.log_color NYX_INFO => blue
+attr.log_color NYX_NOTICE => green
+attr.log_color NYX_WARN => yellow
+attr.log_color NYX_ERR => red
+
+attr.log_color CIRC => yellow
+attr.log_color BW => cyan
+attr.log_color NS => blue
+attr.log_color NEWCONSENSUS => blue
+attr.log_color GUARD => yellow
+
+attr.connection.category_color Inbound => green
+attr.connection.category_color Outbound => blue
+attr.connection.category_color Exit => red
+attr.connection.category_color Hidden => magenta
+attr.connection.category_color Socks => yellow
+attr.connection.category_color Circuit => cyan
+attr.connection.category_color Directory => magenta
+attr.connection.category_color Control => red
+
+attr.connection.sort_color Category => red
+attr.connection.sort_color Uptime => yellow
+attr.connection.sort_color Listing => green
+attr.connection.sort_color Ip Address => blue
+attr.connection.sort_color Port => blue
+attr.connection.sort_color Fingerprint => cyan
+attr.connection.sort_color Nickname => cyan
+attr.connection.sort_color Country => blue
+
+attr.config.category_color General => green
+attr.config.category_color Client => blue
+attr.config.category_color Relay => yellow
+attr.config.category_color Directory => magenta
+attr.config.category_color Authority => red
+attr.config.category_color Hidden Service => cyan
+attr.config.category_color Testing => white
+attr.config.category_color Unknown => white
+
+attr.config.sort_color Name => blue
+attr.config.sort_color Value => cyan
+attr.config.sort_color Value Type => green
+attr.config.sort_color Category => red
+attr.config.sort_color Usage => yellow
+attr.config.sort_color Summary => green
+attr.config.sort_color Description => white
+attr.config.sort_color Man Page Entry => blue
diff --git a/nyx/settings/dedup.cfg b/nyx/settings/dedup.cfg
new file mode 100644
index 0000000..42d8102
--- /dev/null
+++ b/nyx/settings/dedup.cfg
@@ -0,0 +1,91 @@
+################################################################################
+#
+# Snippets from common log messages. These are used to determine when entries
+# with dynamic content (hostnames, numbers, etc) are the same. If this matches
+# the start of both messages then the entries are flagged as duplicates. If the
+# entry begins with an asterisk (*) then it checks if the substrings exist
+# anywhere in the messages.
+#
+# Examples for the complete messages:
+#
+# [BW] READ: 0, WRITTEN: 0
+# [DEBUG] connection_handle_write(): After TLS write of 512: 0 read, 586 written
+# [DEBUG] flush_chunk_tls(): flushed 512 bytes, 0 ready to flush, 0 remain.
+# [DEBUG] conn_read_callback(): socket 7 wants to read.
+# [DEBUG] conn_write_callback(): socket 51 wants to write.
+# [DEBUG] connection_remove(): removing socket -1 (type OR), n_conns now 50
+# [DEBUG] connection_or_process_cells_from_inbuf(): 7: starting, inbuf_datalen
+# 0 (0 pending in tls object).
+# [DEBUG] connection_read_to_buf(): 38: starting, inbuf_datalen 0 (0 pending in
+# tls object). at_most 12800.
+# [DEBUG] connection_read_to_buf(): TLS connection closed on read. Closing.
+# (Nickname moria1, address 128.31.0.34)
+# [INFO] run_connection_housekeeping(): Expiring non-open OR connection to fd
+# 16 (79.193.61.171:443).
+# [INFO] rep_hist_downrate_old_runs(): Discounting all old stability info by a
+# factor of 0.950000
+# [NOTICE] Circuit build timeout of 96803ms is beyond the maximum build time we
+# have ever observed. Capping it to 96107ms.
+# The above NOTICE changes to an INFO message in maint-0.2.2
+# [NOTICE] Based on 1000 circuit times, it looks like we don't need to wait so
+# long for circuits to finish. We will now assume a circuit is too slow
+# to use after waiting 65 seconds.
+# [NOTICE] We stalled too much while trying to write 150 bytes to address
+# [scrubbed]. If this happens a lot, either something is wrong with
+# your network connection, or something is wrong with theirs. (fd 238,
+# type Directory, state 1, marked at main.c:702).
+# [NOTICE] I learned some more directory information, but not enough to build a
+# circuit: We have only 469/2027 usable descriptors.
+# [NOTICE] Attempt by %s to open a stream from unknown relay. Closing.
+# [NOTICE] Average packaged cell fullness: 70.976%. TLS write overhead: 11%
+# [NOTICE] Heartbeat: Tor's uptime is 8 days 6:00 hours, with 0 circuits open.
+# I've sent 3.53 MB and received 90.61 MB.
+# [WARN] You specified a server "Amunet8" by name, but this name is not
+# registered
+# [WARN] I have no descriptor for the router named "Amunet8" in my declared
+# family; I'll use the nickname as is, but this may confuse clients.
+# [WARN] Controller gave us config lines that didn't validate: Value
+# 'BandwidthRate ' is malformed or out of bounds.
+# [WARN] Problem bootstrapping. Stuck at 80%: Connecting to the Tor network.
+# (Network is unreachable; NOROUTE; count 47; recommendation warn)
+# [WARN] 4 unknown, 1 missing key, 3 good, 0 bad, 1 no signature, 4 required
+# [NYX_DEBUG] refresh rate: 0.001 seconds
+# [NYX_DEBUG] proc call (process connections): /proc/net/[tcp|udp] (runtime: 0.0018)
+# [NYX_DEBUG] system call: ps -p 2354 -o %cpu,rss,%mem,etime (runtime: 0.02)
+# [NYX_DEBUG] system call: netstat -npt | grep 2354/tor (runtime: 0.02)
+# [NYX_DEBUG] recreating panel 'graph' with the dimensions of 14/124
+# [NYX_DEBUG] redrawing the log panel with the corrected content height (estimat was off by 4)
+# [NYX_DEBUG] GETINFO accounting/bytes-left (runtime: 0.0006)
+# [NYX_DEBUG] GETINFO traffic/read (runtime: 0.0004)
+# [NYX_DEBUG] GETINFO traffic/written (runtime: 0.0002)
+# [NYX_DEBUG] GETCONF MyFamily (runtime: 0.0007)
+# [NYX_DEBUG] Unable to query process resource usage from ps, waiting 6.25 seconds (unrecognized output from ps: ...)
+#
+################################################################################
+
+dedup.BW READ:
+dedup.DEBUG connection_handle_write(): After TLS write of
+dedup.DEBUG flush_chunk_tls(): flushed
+dedup.DEBUG conn_read_callback(): socket
+dedup.DEBUG conn_write_callback(): socket
+dedup.DEBUG connection_remove(): removing socket
+dedup.DEBUG connection_or_process_cells_from_inbuf():
+dedup.DEBUG *pending in tls object). at_most
+dedup.DEBUG connection_read_to_buf(): TLS connection closed on read. Closing.
+dedup.INFO run_connection_housekeeping(): Expiring
+dedup.INFO rep_hist_downrate_old_runs(): Discounting all old stability info by a factor of
+dedup.INFO *build time we have ever observed. Capping it to
+dedup.NOTICE *build time we have ever observed. Capping it to
+dedup.NOTICE *We will now assume a circuit is too slow to use after waiting
+dedup.NOTICE We stalled too much while trying to write
+dedup.NOTICE I learned some more directory information, but not enough to build a circuit
+dedup.NOTICE Attempt by
+dedup.NOTICE *Loading relay descriptors.
+dedup.NOTICE Average packaged cell fullness:
+dedup.NOTICE Heartbeat: Tor's uptime is
+dedup.WARN You specified a server
+dedup.WARN I have no descriptor for the router named
+dedup.WARN Controller gave us config lines that didn't validate
+dedup.WARN Problem bootstrapping. Stuck at
+dedup.WARN *missing key,
+
diff --git a/nyx/settings/strings.cfg b/nyx/settings/strings.cfg
new file mode 100644
index 0000000..85b4f8d
--- /dev/null
+++ b/nyx/settings/strings.cfg
@@ -0,0 +1,107 @@
+################################################################################
+#
+# User facing strings. These are sorted into the following namespaces...
+#
+# * config parsing or handling configuration options
+# * debug concerns the --debug argument
+# * misc anything that doesn't fit into a present namespace
+# * panel used after startup by our curses panels
+# * setup notificaitons or issues arising while starting nyx
+# * tracker related to tracking resource usage or connections
+# * usage usage information about starting and running nyx
+#
+################################################################################
+
+msg.wrap {text}
+
+msg.config.unable_to_read_file Failed to load configuration (using defaults): "{error}"
+msg.config.nothing_loaded No nyxrc loaded, using defaults. You can customize nyx by placing a configuration file at {path} (see the nyxrc.sample for its options).
+
+msg.debug.saving_to_path Saving a debug log to {path}, please check it for sensitive information before sharing it.
+msg.debug.unable_to_write_file Unable to write to our debug log file ({path}): {error}
+
+msg.panel.graphing.prepopulation_successful Bandwidth graph has information for the last {duration}
+msg.panel.graphing.bw_event_cache_malformed Tor's 'GETINFO bw-event-cache' provided malformed output: {response}
+msg.panel.header.fd_used_at_sixty_percent Tor's file descriptor usage is at {percentage}%.
+msg.panel.header.fd_used_at_ninety_percent Tor's file descriptor usage is at {percentage}%. If you run out Tor will be unable to continue functioning.
+msg.panel.log.read_from_log_file Read {count} entries from tor's log file: {path} (read limit: {read_limit}, runtime: {runtime})
+
+msg.setup.nyx_is_running_as_root Nyx is currently running with root permissions. This isn't a good idea, nor should it be necessary.
+msg.setup.chroot_doesnt_exist The chroot path set in your config ({path}) doesn't exist.
+msg.setup.set_freebsd_chroot Adjusting paths to account for Tor running in a FreeBSD jail at: {path}
+msg.setup.tor_is_running_as_root Tor is currently running with root permissions. This isn't a good idea, nor should it be necessary. See the 'User UID' option on Tor's man page for an easy method of reducing its permissions after startup.
+msg.setup.unable_to_determine_pid Unable to determine Tor's pid. Some information, like its resource usage will be unavailable.
+msg.setup.unknown_event_types nyx doesn't recognize the following event types: {event_types} (log 'UNKNOWN' events to see them)
+msg.setup.color_support_available Terminal color support detected and enabled
+msg.setup.color_support_unavailable Terminal color support unavailable
+
+msg.tracker.abort_getting_resources Failed three attempts to get process resource usage from {resolver}, {response} ({exc})
+msg.tracker.abort_getting_port_usage Failed three attempts to determine the process using active ports ({exc})
+msg.tracker.lookup_rate_increased connection lookup time increasing to {seconds} seconds per call
+msg.tracker.unable_to_get_port_usages Unable to query the processes using ports usage lsof ({exc})
+msg.tracker.unable_to_get_resources Unable to query process resource usage from {resolver} ({exc})
+msg.tracker.unable_to_use_all_resolvers We were unable to use any of your system's resolvers to get tor's connections. This is fine, but means that the connections page will be empty. This is usually permissions related so if you would like to fix this then run nyx with the same user as tor (ie, "sudo -u <tor user> nyx").
+msg.tracker.unable_to_use_resolver Unable to query connections with {old_resolver}, trying {new_resolver}
+
+msg.usage.invalid_arguments {error} (for usage provide --help)
+msg.usage.not_a_valid_address '{address_input}' isn't a valid IPv4 address
+msg.usage.not_a_valid_port '{port_input}' isn't a valid port number
+msg.usage.unrecognized_log_flags Unrecognized event flags: {flags}
+msg.usage.unable_to_set_color_override "{color}" isn't a valid color
+
+msg.debug.header
+|Nyx {nyx_version} Debug Dump
+|Stem Version: {stem_version}
+|Python Version: {python_version}
+|Platform: {system} ({platform})
+|--------------------------------------------------------------------------------
+|Nyx Configuration ({nyxrc_path}):
+|{nyxrc_content}
+|--------------------------------------------------------------------------------
+
+msg.misc.event_types
+| d DEBUG a ADDRMAP r CLIENTS_SEEN C SIGNAL
+| i INFO f AUTHDIR_NEWDESCS u DESCCHANGED F STREAM_BW
+| n NOTICE j BUILDTIMEOUT_SET g GUARD G STATUS_CLIENT
+| w WARN b BW h HS_DESC H STATUS_GENERAL
+| e ERR k CELL_STATS v HS_DESC_CONTENT I STATUS_SERVER
+| c CIRC x NETWORK_LIVENESS s STREAM
+| l CIRC_BW y NEWCONSENSUS J TB_EMPTY
+| m CIRC_MINOR z NEWDESC t TRANSPORT_LAUNCHED
+| p CONF_CHANGED B NS
+| q CONN_BW o ORCONN
+|
+| DINWE tor runlevel+ A All Events
+| 12345 nyx runlevel+ X No Events
+| U Unknown Events
+
+msg.setup.unknown_term
+|Unknown $TERM: ({term})
+|Either update your terminfo database or run nyx using "TERM=xterm nyx".
+|
+
+msg.usage.help_output
+|Usage nyx [OPTION]
+|Terminal status monitor for Tor relays.
+|
+| -i, --interface [ADDRESS:]PORT change control interface from {address}:{port}
+| -s, --socket SOCKET_PATH attach using unix domain socket if present,
+| SOCKET_PATH defaults to: {socket}
+| -c, --config CONFIG_PATH loaded configuration options, CONFIG_PATH
+| defaults to: {config_path}
+| -d, --debug LOG_PATH writes all nyx logs to the given location
+| -l, --log EVENT_FLAGS event types to be logged (default: {events})
+|
+|{event_flags}
+|
+| -v, --version provides version information
+| -h, --help presents this help
+|
+|Example:
+|nyx -i 1643 attach to control port 1643
+|nyx -l we -c /tmp/cfg use this configuration file with 'WARN'/'ERR' events
+
+msg.usage.version_output
+|nyx version {version} (released {date})
+|
+
diff --git a/nyx/settings/torrc.cfg b/nyx/settings/torrc.cfg
new file mode 100644
index 0000000..71d4608
--- /dev/null
+++ b/nyx/settings/torrc.cfg
@@ -0,0 +1,53 @@
+################################################################################
+#
+# Information related to tor configuration options. This has two sections...
+#
+# * torrc.alias Aliases for configuration options tor will accept.
+# * torrc.units Labels accepted by tor for various units.
+#
+################################################################################
+
+# Torrc aliases from the _option_abbrevs struct of 'src/or/config.c'. These
+# couldn't be requested via GETCONF as of 0.2.1.19, but this might have been
+# fixed. Discussion is in...
+#
+# https://trac.torproject.org/projects/tor/ticket/1802
+#
+# TODO: Check if this workaround can be dropped later.
+
+torrc.alias l => Log
+torrc.alias AllowUnverifiedNodes => AllowInvalidNodes
+torrc.alias AutomapHostSuffixes => AutomapHostsSuffixes
+torrc.alias AutomapHostOnResolve => AutomapHostsOnResolve
+torrc.alias BandwidthRateBytes => BandwidthRate
+torrc.alias BandwidthBurstBytes => BandwidthBurst
+torrc.alias DirFetchPostPeriod => StatusFetchPeriod
+torrc.alias MaxConn => ConnLimit
+torrc.alias ORBindAddress => ORListenAddress
+torrc.alias DirBindAddress => DirListenAddress
+torrc.alias SocksBindAddress => SocksListenAddress
+torrc.alias UseHelperNodes => UseEntryGuards
+torrc.alias NumHelperNodes => NumEntryGuards
+torrc.alias UseEntryNodes => UseEntryGuards
+torrc.alias NumEntryNodes => NumEntryGuards
+torrc.alias ResolvConf => ServerDNSResolvConfFile
+torrc.alias SearchDomains => ServerDNSSearchDomains
+torrc.alias ServerDNSAllowBrokenResolvConf => ServerDNSAllowBrokenConfig
+torrc.alias PreferTunnelledDirConns => PreferTunneledDirConns
+torrc.alias BridgeAuthoritativeDirectory => BridgeAuthoritativeDir
+torrc.alias StrictEntryNodes => StrictNodes
+torrc.alias StrictExitNodes => StrictNodes
+
+# Size and time modifiers allowed by 'src/or/config.c'.
+
+torrc.units.size.b b, byte, bytes
+torrc.units.size.kb kb, kbyte, kbytes, kilobyte, kilobytes
+torrc.units.size.mb m, mb, mbyte, mbytes, megabyte, megabytes
+torrc.units.size.gb gb, gbyte, gbytes, gigabyte, gigabytes
+torrc.units.size.tb tb, terabyte, terabytes
+
+torrc.units.time.sec second, seconds
+torrc.units.time.min minute, minutes
+torrc.units.time.hour hour, hours
+torrc.units.time.day day, days
+torrc.units.time.week week, weeks
diff --git a/nyx/util/__init__.py b/nyx/util/__init__.py
index 350e96e..e32a816 100644
--- a/nyx/util/__init__.py
+++ b/nyx/util/__init__.py
@@ -37,7 +37,7 @@ stem.control.CACHEABLE_GETINFO_PARAMS = list(stem.control.CACHEABLE_GETINFO_PARA
stem.control.LOG_CACHE_FETCHES = False
try:
- uses_settings = stem.util.conf.uses_settings('nyx', os.path.join(BASE_DIR, 'config'), lazy_load = False)
+ uses_settings = stem.util.conf.uses_settings('nyx', os.path.join(BASE_DIR, 'settings'), lazy_load = False)
except IOError as exc:
print("Unable to load nyx's internal configurations: %s" % exc)
sys.exit(1)
1
0
[nyx/master] Have validate() provide a 'line => (type, msg)' dict
by atagar@torproject.org 13 Feb '16
by atagar@torproject.org 13 Feb '16
13 Feb '16
commit bf2b27c2e034ad0f7d9eb758ea79505f16e2aac2
Author: Damian Johnson <atagar(a)torproject.org>
Date: Sat Feb 6 13:24:31 2016 -0800
Have validate() provide a 'line => (type, msg)' dict
We only have one caller of validate() so might as well provide what it wants.
---
nyx/torrc_panel.py | 2 +-
nyx/util/tor_config.py | 8 ++++----
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/nyx/torrc_panel.py b/nyx/torrc_panel.py
index 01d12fc..e37c9b5 100644
--- a/nyx/torrc_panel.py
+++ b/nyx/torrc_panel.py
@@ -142,7 +142,7 @@ class TorrcPanel(panel.Panel):
if line and '#' in line:
rendered_contents[i] = line[:line.find('#')].strip()
- corrections = dict((line_number, (issue, msg)) for line_number, issue, msg in tor_config.validate(self.torrc_content))
+ corrections = tor_config.validate(self.torrc_content)
# offset to make room for the line numbers
diff --git a/nyx/util/tor_config.py b/nyx/util/tor_config.py
index 22e7938..ed8c88e 100644
--- a/nyx/util/tor_config.py
+++ b/nyx/util/tor_config.py
@@ -95,7 +95,7 @@ def validate(contents):
config_lines = config_text.splitlines() if config_text else []
custom_options = list(set([line.split(' ')[0] for line in config_lines]))
- issues_found, seen_options = [], []
+ issues_found, seen_options = {}, []
# Strips comments and collapses multiline multi-line entries, for more
# information see:
@@ -152,7 +152,7 @@ def validate(contents):
# most parameters are overwritten if defined multiple times
if option in seen_options and option not in get_multiline_parameters():
- issues_found.append((line_number, ValidationError.DUPLICATE, option))
+ issues_found[line_number] = (ValidationError.DUPLICATE, option)
continue
else:
seen_options.append(option)
@@ -160,7 +160,7 @@ def validate(contents):
# checks if the value isn't necessary due to matching the defaults
if option not in custom_options:
- issues_found.append((line_number, ValidationError.IS_DEFAULT, option))
+ issues_found[line_number] = (ValidationError.IS_DEFAULT, option)
# replace aliases with their recognized representation
@@ -210,7 +210,7 @@ def validate(contents):
elif value_type == ValueType.TIME:
display_values = [str_tools.time_label(int(val)) for val in tor_values]
- issues_found.append((line_number, ValidationError.MISMATCH, ', '.join(display_values)))
+ issues_found[line_number] = (ValidationError.MISMATCH, ', '.join(display_values))
return issues_found
1
0
commit 80178f6e0504c719f30e1f12694a1a8dcfed4631
Author: Damian Johnson <atagar(a)torproject.org>
Date: Sat Feb 6 13:29:25 2016 -0800
Merge _strip_comments() into caller
Merging another helper that doesn't add much.
---
nyx/util/tor_config.py | 26 ++++++--------------------
1 file changed, 6 insertions(+), 20 deletions(-)
diff --git a/nyx/util/tor_config.py b/nyx/util/tor_config.py
index ed8c88e..e8b82b3 100644
--- a/nyx/util/tor_config.py
+++ b/nyx/util/tor_config.py
@@ -103,7 +103,12 @@ def validate(contents):
stripped_contents, multiline_buffer = [], ''
- for line in _strip_comments(contents):
+ for line in contents:
+ if '#' in line:
+ line = line[:line.find('#')]
+
+ line = line.strip()
+
if not line:
stripped_contents.append('')
else:
@@ -238,22 +243,3 @@ def _parse_conf_value(conf_arg):
return str(int(val) * TIME_MULT[label]), ValueType.TIME
return conf_arg, ValueType.UNRECOGNIZED
-
-
-def _strip_comments(contents):
- """
- Removes comments and extra whitespace from the given torrc contents.
-
- Arguments:
- contents - torrc contents
- """
-
- stripped_contents = []
-
- for line in contents:
- if line and '#' in line:
- line = line[:line.find('#')]
-
- stripped_contents.append(line.strip())
-
- return stripped_contents
1
0
commit 302d4d56676503bda6d4d3bfb92b2f8e425bedfa
Author: Damian Johnson <atagar(a)torproject.org>
Date: Sat Feb 6 13:58:13 2016 -0800
Drop all torrc validations
Ok, screw it. Hours now I've been staring at this code to figure out if it
should be salvaged or not. Final conclusion: no.
1. This is a feature nobody wants. I've spent a silly amount of time making
it work while honestly our users would be happier if Nyx simply didn't.
2. Tor makes this hard to do reliably. There's torrc aliases, multi-line
entries, unit conversions, etc. Way too much headache for its negligible
value.
---
nyx/settings/torrc.cfg | 53 -----------
nyx/torrc_panel.py | 23 +----
nyx/util/tor_config.py | 245 -------------------------------------------------
3 files changed, 1 insertion(+), 320 deletions(-)
diff --git a/nyx/settings/torrc.cfg b/nyx/settings/torrc.cfg
deleted file mode 100644
index 71d4608..0000000
--- a/nyx/settings/torrc.cfg
+++ /dev/null
@@ -1,53 +0,0 @@
-################################################################################
-#
-# Information related to tor configuration options. This has two sections...
-#
-# * torrc.alias Aliases for configuration options tor will accept.
-# * torrc.units Labels accepted by tor for various units.
-#
-################################################################################
-
-# Torrc aliases from the _option_abbrevs struct of 'src/or/config.c'. These
-# couldn't be requested via GETCONF as of 0.2.1.19, but this might have been
-# fixed. Discussion is in...
-#
-# https://trac.torproject.org/projects/tor/ticket/1802
-#
-# TODO: Check if this workaround can be dropped later.
-
-torrc.alias l => Log
-torrc.alias AllowUnverifiedNodes => AllowInvalidNodes
-torrc.alias AutomapHostSuffixes => AutomapHostsSuffixes
-torrc.alias AutomapHostOnResolve => AutomapHostsOnResolve
-torrc.alias BandwidthRateBytes => BandwidthRate
-torrc.alias BandwidthBurstBytes => BandwidthBurst
-torrc.alias DirFetchPostPeriod => StatusFetchPeriod
-torrc.alias MaxConn => ConnLimit
-torrc.alias ORBindAddress => ORListenAddress
-torrc.alias DirBindAddress => DirListenAddress
-torrc.alias SocksBindAddress => SocksListenAddress
-torrc.alias UseHelperNodes => UseEntryGuards
-torrc.alias NumHelperNodes => NumEntryGuards
-torrc.alias UseEntryNodes => UseEntryGuards
-torrc.alias NumEntryNodes => NumEntryGuards
-torrc.alias ResolvConf => ServerDNSResolvConfFile
-torrc.alias SearchDomains => ServerDNSSearchDomains
-torrc.alias ServerDNSAllowBrokenResolvConf => ServerDNSAllowBrokenConfig
-torrc.alias PreferTunnelledDirConns => PreferTunneledDirConns
-torrc.alias BridgeAuthoritativeDirectory => BridgeAuthoritativeDir
-torrc.alias StrictEntryNodes => StrictNodes
-torrc.alias StrictExitNodes => StrictNodes
-
-# Size and time modifiers allowed by 'src/or/config.c'.
-
-torrc.units.size.b b, byte, bytes
-torrc.units.size.kb kb, kbyte, kbytes, kilobyte, kilobytes
-torrc.units.size.mb m, mb, mbyte, mbytes, megabyte, megabytes
-torrc.units.size.gb gb, gbyte, gbytes, gigabyte, gigabytes
-torrc.units.size.tb tb, terabyte, terabytes
-
-torrc.units.time.sec second, seconds
-torrc.units.time.min minute, minutes
-torrc.units.time.hour hour, hours
-torrc.units.time.day day, days
-torrc.units.time.week week, weeks
diff --git a/nyx/torrc_panel.py b/nyx/torrc_panel.py
index e37c9b5..0b456d8 100644
--- a/nyx/torrc_panel.py
+++ b/nyx/torrc_panel.py
@@ -5,7 +5,7 @@ Panel displaying the torrc or nyxrc with the validation done against it.
import math
import curses
-from nyx.util import expand_path, panel, tor_config, tor_controller, ui_tools
+from nyx.util import expand_path, panel, tor_controller, ui_tools
from stem.control import State
from stem.util import log, str_tools
@@ -131,7 +131,6 @@ class TorrcPanel(panel.Panel):
if self.torrc_content is None:
rendered_contents = ['### Unable to load the torrc ###']
- corrections = {}
else:
rendered_contents = [ui_tools.get_printable(line.replace('\t', ' ')) for line in self.torrc_content]
@@ -142,8 +141,6 @@ class TorrcPanel(panel.Panel):
if line and '#' in line:
rendered_contents[i] = line[:line.find('#')].strip()
- corrections = tor_config.validate(self.torrc_content)
-
# offset to make room for the line numbers
line_number_offset = 0
@@ -222,24 +219,6 @@ class TorrcPanel(panel.Panel):
if stripped_line:
is_multiline = stripped_line.endswith('\\')
- # gets the correction
-
- if line_number in corrections:
- line_issue, line_issue_msg = corrections[line_number]
-
- if line_issue in (tor_config.ValidationError.DUPLICATE, tor_config.ValidationError.IS_DEFAULT):
- line_comp['option'][1] = (curses.A_BOLD, 'blue')
- line_comp['argument'][1] = (curses.A_BOLD, 'blue')
- elif line_issue == tor_config.ValidationError.MISMATCH:
- line_comp['argument'][1] = (curses.A_BOLD, 'red')
- line_comp['correction'][0] = ' (%s)' % line_issue_msg
- else:
- # For some types of configs the correction field is simply used to
- # provide extra data (for instance, the type for tor state fields).
-
- line_comp['correction'][0] = ' (%s)' % line_issue_msg
- line_comp['correction'][1] = (curses.A_BOLD, 'magenta')
-
# draws the line number
if self.show_line_num and display_line < height and display_line >= 1:
diff --git a/nyx/util/tor_config.py b/nyx/util/tor_config.py
deleted file mode 100644
index e8b82b3..0000000
--- a/nyx/util/tor_config.py
+++ /dev/null
@@ -1,245 +0,0 @@
-"""
-Helper functions for working with tor's configuration file.
-"""
-
-from nyx.util import tor_controller
-
-from stem.util import conf, enum, str_tools
-
-CONFIG = conf.config_dict('nyx', {
- 'torrc.alias': {},
- 'torrc.units.size.b': [],
- 'torrc.units.size.kb': [],
- 'torrc.units.size.mb': [],
- 'torrc.units.size.gb': [],
- 'torrc.units.size.tb': [],
- 'torrc.units.time.sec': [],
- 'torrc.units.time.min': [],
- 'torrc.units.time.hour': [],
- 'torrc.units.time.day': [],
- 'torrc.units.time.week': [],
- 'tor.chroot': '',
-})
-
-
-def general_conf_handler(config, key):
- value = config.get(key)
-
- if key.startswith('torrc.units.') and value:
- # all the torrc.units.* values are comma separated lists
- return [entry.strip() for entry in value[0].split(',')]
-
-
-conf.get_config('nyx').add_listener(general_conf_handler, backfill = True)
-
-# enums and values for numeric torrc entries
-
-ValueType = enum.Enum('UNRECOGNIZED', 'SIZE', 'TIME')
-SIZE_MULT = {'b': 1, 'kb': 1024, 'mb': 1048576, 'gb': 1073741824, 'tb': 1099511627776}
-TIME_MULT = {'sec': 1, 'min': 60, 'hour': 3600, 'day': 86400, 'week': 604800}
-
-# enums for issues found during torrc validation:
-# DUPLICATE - entry is ignored due to being a duplicate
-# MISMATCH - the value doesn't match tor's current state
-# IS_DEFAULT - the configuration option matches tor's default
-
-ValidationError = enum.Enum('DUPLICATE', 'MISMATCH', 'IS_DEFAULT')
-
-MULTILINE_PARAM = None # cached multiline parameters (lazily loaded)
-
-
-def get_multiline_parameters():
- """
- Provides parameters that can be defined multiple times in the torrc without
- overwriting the value.
- """
-
- # fetches config options with the LINELIST (aka 'LineList'), LINELIST_S (aka
- # 'Dependent'), and LINELIST_V (aka 'Virtual') types
-
- global MULTILINE_PARAM
-
- if MULTILINE_PARAM is None:
- controller, multiline_entries = tor_controller(), []
-
- config_option_query = controller.get_info('config/names', None)
-
- if config_option_query:
- for line in config_option_query.strip().split('\n'):
- conf_option, conf_type = line.strip().split(' ', 1)
-
- if conf_type in ('LineList', 'Dependant', 'Virtual'):
- multiline_entries.append(conf_option)
- else:
- # unable to query tor connection, so not caching results
- return ()
-
- MULTILINE_PARAM = multiline_entries
-
- return tuple(MULTILINE_PARAM)
-
-
-def validate(contents):
- """
- Performs validation on the given torrc contents, providing back a listing of
- (line number, issue, msg) tuples for issues found. If the issue occures on a
- multiline torrc entry then the line number is for the last line of the entry.
-
- Arguments:
- contents - torrc contents
- """
-
- controller = tor_controller()
-
- config_text = controller.get_info('config-text', None)
- config_lines = config_text.splitlines() if config_text else []
- custom_options = list(set([line.split(' ')[0] for line in config_lines]))
-
- issues_found, seen_options = {}, []
-
- # Strips comments and collapses multiline multi-line entries, for more
- # information see:
- # https://trac.torproject.org/projects/tor/ticket/1929
-
- stripped_contents, multiline_buffer = [], ''
-
- for line in contents:
- if '#' in line:
- line = line[:line.find('#')]
-
- line = line.strip()
-
- if not line:
- stripped_contents.append('')
- else:
- line = multiline_buffer + line
- multiline_buffer = ''
-
- if line.endswith('\\'):
- multiline_buffer = line[:-1]
- stripped_contents.append('')
- else:
- stripped_contents.append(line.strip())
-
- for line_number in range(len(stripped_contents) - 1, -1, -1):
- line_text = stripped_contents[line_number]
-
- if not line_text:
- continue
-
- line_comp = line_text.split(None, 1)
-
- if len(line_comp) == 2:
- option, value = line_comp
- else:
- option, value = line_text, ''
-
- # Tor is case insensetive when parsing its torrc. This poses a bit of an
- # issue for us because we want all of our checks to be case insensetive
- # too but also want messages to match the normal camel-case conventions.
- #
- # Using the custom_options to account for this. It contains the tor reported
- # options (camel case) and is either a matching set or the following defaut
- # value check will fail. Hence using that hash to correct the case.
- #
- # TODO: when refactoring for stem make this less confusing...
-
- for custom_opt in custom_options:
- if custom_opt.lower() == option.lower():
- option = custom_opt
- break
-
- # if an aliased option then use its real name
-
- if option in CONFIG['torrc.alias']:
- option = CONFIG['torrc.alias'][option]
-
- # most parameters are overwritten if defined multiple times
-
- if option in seen_options and option not in get_multiline_parameters():
- issues_found[line_number] = (ValidationError.DUPLICATE, option)
- continue
- else:
- seen_options.append(option)
-
- # checks if the value isn't necessary due to matching the defaults
-
- if option not in custom_options:
- issues_found[line_number] = (ValidationError.IS_DEFAULT, option)
-
- # replace aliases with their recognized representation
-
- if option in CONFIG['torrc.alias']:
- option = CONFIG['torrc.alias'][option]
-
- # tor appears to replace tabs with a space, for instance:
- # "accept\t*:563" is read back as "accept *:563"
-
- value = value.replace('\t', ' ')
-
- # parse value if it's a size or time, expanding the units
-
- value, value_type = _parse_conf_value(value)
-
- # issues GETCONF to get the values tor's currently configured to use
-
- tor_values = controller.get_conf(option, [], True)
-
- # multiline entries can be comma separated values (for both tor and conf)
-
- value_list = [value]
-
- if option in get_multiline_parameters():
- value_list = [val.strip() for val in value.split(',')]
-
- fetched_values, tor_values = tor_values, []
- for fetched_value in fetched_values:
- for fetched_entry in fetched_value.split(','):
- fetched_entry = fetched_entry.strip()
-
- if fetched_entry not in tor_values:
- tor_values.append(fetched_entry)
-
- for val in value_list:
- # checks if both the argument and tor's value are empty
-
- is_blank_match = not val and not tor_values
-
- if not is_blank_match and val not in tor_values:
- # converts corrections to reader friedly size values
-
- display_values = tor_values
-
- if value_type == ValueType.SIZE:
- display_values = [str_tools.size_label(int(val)) for val in tor_values]
- elif value_type == ValueType.TIME:
- display_values = [str_tools.time_label(int(val)) for val in tor_values]
-
- issues_found[line_number] = (ValidationError.MISMATCH, ', '.join(display_values))
-
- return issues_found
-
-
-def _parse_conf_value(conf_arg):
- """
- Converts size or time values to their lowest units (bytes or seconds) which
- is what GETCONF calls provide. The returned is a tuple of the value and unit
- type.
-
- Arguments:
- conf_arg - torrc argument
- """
-
- if conf_arg.count(' ') == 1:
- val, unit = conf_arg.lower().split(' ', 1)
-
- if val.isdigit():
- for label in SIZE_MULT:
- if unit in CONFIG['torrc.units.size.' + label]:
- return str(int(val) * SIZE_MULT[label]), ValueType.SIZE
-
- for label in TIME_MULT:
- if unit in CONFIG['torrc.units.time.' + label]:
- return str(int(val) * TIME_MULT[label]), ValueType.TIME
-
- return conf_arg, ValueType.UNRECOGNIZED
1
0