[tor-commits] [arm/release] Moving torrc validation logging to the torConfig
atagar at torproject.org
atagar at torproject.org
Sun Jul 17 06:08:20 UTC 2011
commit ed7b9ec4f7d4ccc3e4a417f416b519b9a9865a11
Author: Damian Johnson <atagar at torproject.org>
Date: Fri May 13 19:21:52 2011 -0700
Moving torrc validation logging to the torConfig
---
src/cli/controller.py | 72 +++---------------------------------------------
src/util/torConfig.py | 69 ++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 73 insertions(+), 68 deletions(-)
diff --git a/src/cli/controller.py b/src/cli/controller.py
index d44b811..5696daa 100644
--- a/src/cli/controller.py
+++ b/src/cli/controller.py
@@ -103,9 +103,7 @@ CONFIG = {"features.graph.type": 1,
"log.startTime": log.INFO,
"log.refreshRate": log.DEBUG,
"log.highCpuUsage": log.WARN,
- "log.configEntryUndefined": log.NOTICE,
- "log.torrc.validation.torStateDiffers": log.WARN,
- "log.torrc.validation.unnecessaryTorrcEntries": log.NOTICE}
+ "log.configEntryUndefined": log.NOTICE}
class ControlPanel(panel.Panel):
""" Draws single line label for interface controls. """
@@ -282,72 +280,12 @@ def drawTorMonitor(stdscr, startTime, loggedEvents, isBlindMode):
# confLocation = ""
# loads the torrc and provides warnings in case of validation errors
- loadedTorrc = torConfig.getTorrc()
- loadedTorrc.getLock().acquire()
-
- try: loadedTorrc.load(True)
+ try:
+ loadedTorrc = torConfig.getTorrc()
+ loadedTorrc.load(True)
+ loadedTorrc.logValidationIssues()
except: pass
- if loadedTorrc.isLoaded():
- corrections = loadedTorrc.getCorrections()
- duplicateOptions, defaultOptions, mismatchLines, missingOptions = [], [], [], []
-
- for lineNum, issue, msg in corrections:
- if issue == torConfig.ValidationError.DUPLICATE:
- duplicateOptions.append("%s (line %i)" % (msg, lineNum + 1))
- elif issue == torConfig.ValidationError.IS_DEFAULT:
- defaultOptions.append("%s (line %i)" % (msg, lineNum + 1))
- elif issue == torConfig.ValidationError.MISMATCH: mismatchLines.append(lineNum + 1)
- elif issue == torConfig.ValidationError.MISSING: missingOptions.append(msg)
-
- if duplicateOptions or defaultOptions:
- msg = "Unneeded torrc entries found. They've been highlighted in blue on the torrc page."
-
- if duplicateOptions:
- if len(duplicateOptions) > 1:
- msg += "\n- entries ignored due to having duplicates: "
- else:
- msg += "\n- entry ignored due to having a duplicate: "
-
- duplicateOptions.sort()
- msg += ", ".join(duplicateOptions)
-
- if defaultOptions:
- if len(defaultOptions) > 1:
- msg += "\n- entries match their default values: "
- else:
- msg += "\n- entry matches its default value: "
-
- defaultOptions.sort()
- msg += ", ".join(defaultOptions)
-
- log.log(CONFIG["log.torrc.validation.unnecessaryTorrcEntries"], msg)
-
- if mismatchLines or missingOptions:
- msg = "The torrc differ from what tor's using. You can issue a sighup to reload the torrc values by pressing x."
-
- if mismatchLines:
- if len(mismatchLines) > 1:
- msg += "\n- torrc values differ on lines: "
- else:
- msg += "\n- torrc value differs on line: "
-
- mismatchLines.sort()
- msg += ", ".join([str(val + 1) for val in mismatchLines])
-
- if missingOptions:
- if len(missingOptions) > 1:
- msg += "\n- configuration values are missing from the torrc: "
- else:
- msg += "\n- configuration value is missing from the torrc: "
-
- missingOptions.sort()
- msg += ", ".join(missingOptions)
-
- log.log(CONFIG["log.torrc.validation.torStateDiffers"], msg)
-
- loadedTorrc.getLock().release()
-
# minor refinements for connection resolver
if not isBlindMode:
if torPid:
diff --git a/src/util/torConfig.py b/src/util/torConfig.py
index a083099..14ef4ce 100644
--- a/src/util/torConfig.py
+++ b/src/util/torConfig.py
@@ -23,7 +23,9 @@ CONFIG = {"features.torrc.validate": True,
"torrc.label.time.day": [],
"torrc.label.time.week": [],
"log.torrc.readFailed": log.WARN,
- "log.configDescriptions.unrecognizedCategory": log.NOTICE}
+ "log.configDescriptions.unrecognizedCategory": log.NOTICE,
+ "log.torrc.validation.unnecessaryTorrcEntries": log.NOTICE,
+ "log.torrc.validation.torStateDiffers": log.WARN}
# enums and values for numeric torrc entries
ValueType = enum.Enum("UNRECOGNIZED", "SIZE", "TIME")
@@ -753,6 +755,71 @@ class Torrc():
"""
return self.valsLock
+
+ def logValidationIssues(self):
+ """
+ Performs validation on the loaded contents, and logs warnings for issues
+ that are found.
+ """
+
+ corrections = self.getCorrections()
+
+ if corrections:
+ duplicateOptions, defaultOptions, mismatchLines, missingOptions = [], [], [], []
+
+ for lineNum, issue, msg in corrections:
+ if issue == ValidationError.DUPLICATE:
+ duplicateOptions.append("%s (line %i)" % (msg, lineNum + 1))
+ elif issue == ValidationError.IS_DEFAULT:
+ defaultOptions.append("%s (line %i)" % (msg, lineNum + 1))
+ elif issue == ValidationError.MISMATCH: mismatchLines.append(lineNum + 1)
+ elif issue == ValidationError.MISSING: missingOptions.append(msg)
+
+ if duplicateOptions or defaultOptions:
+ msg = "Unneeded torrc entries found. They've been highlighted in blue on the torrc page."
+
+ if duplicateOptions:
+ if len(duplicateOptions) > 1:
+ msg += "\n- entries ignored due to having duplicates: "
+ else:
+ msg += "\n- entry ignored due to having a duplicate: "
+
+ duplicateOptions.sort()
+ msg += ", ".join(duplicateOptions)
+
+ if defaultOptions:
+ if len(defaultOptions) > 1:
+ msg += "\n- entries match their default values: "
+ else:
+ msg += "\n- entry matches its default value: "
+
+ defaultOptions.sort()
+ msg += ", ".join(defaultOptions)
+
+ log.log(CONFIG["log.torrc.validation.unnecessaryTorrcEntries"], msg)
+
+ if mismatchLines or missingOptions:
+ msg = "The torrc differ from what tor's using. You can issue a sighup to reload the torrc values by pressing x."
+
+ if mismatchLines:
+ if len(mismatchLines) > 1:
+ msg += "\n- torrc values differ on lines: "
+ else:
+ msg += "\n- torrc value differs on line: "
+
+ mismatchLines.sort()
+ msg += ", ".join([str(val + 1) for val in mismatchLines])
+
+ if missingOptions:
+ if len(missingOptions) > 1:
+ msg += "\n- configuration values are missing from the torrc: "
+ else:
+ msg += "\n- configuration value is missing from the torrc: "
+
+ missingOptions.sort()
+ msg += ", ".join(missingOptions)
+
+ log.log(CONFIG["log.torrc.validation.torStateDiffers"], msg)
def _testConfigDescriptions():
"""
More information about the tor-commits
mailing list