[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r19572: {torctl} Add config file support to TorUtil. Also implement part 8 of (torctl/trunk/python/TorCtl)
Author: mikeperry
Date: 2009-05-27 07:32:48 -0400 (Wed, 27 May 2009)
New Revision: 19572
Modified:
torctl/trunk/python/TorCtl/PathSupport.py
torctl/trunk/python/TorCtl/SQLSupport.py
torctl/trunk/python/TorCtl/TorUtil.py
Log:
Add config file support to TorUtil. Also implement part 8 of
proposal 161 in SQLSupport.
Modified: torctl/trunk/python/TorCtl/PathSupport.py
===================================================================
--- torctl/trunk/python/TorCtl/PathSupport.py 2009-05-27 11:30:09 UTC (rev 19571)
+++ torctl/trunk/python/TorCtl/PathSupport.py 2009-05-27 11:32:48 UTC (rev 19572)
@@ -1373,6 +1373,7 @@
for circ in self.circuit_list():
if circ.built and not circ.requested_closed and not circ.dirty \
and circ.circ_id not in badcircs:
+ # XXX: Fails for 'tor-resolve 530.19.6.80' -> NEWRESOLVE
if circ.exit.will_exit_to(stream.host, stream.port):
try:
self.c.attach_stream(stream.strm_id, circ.circ_id)
Modified: torctl/trunk/python/TorCtl/SQLSupport.py
===================================================================
--- torctl/trunk/python/TorCtl/SQLSupport.py 2009-05-27 11:30:09 UTC (rev 19571)
+++ torctl/trunk/python/TorCtl/SQLSupport.py 2009-05-27 11:32:48 UTC (rev 19572)
@@ -565,6 +565,36 @@
f.flush()
write_stats = Callable(write_stats)
+
+
+ def write_bws(f, pct_low=0, pct_high=100, order_by=None, recompute=False, stat_clause=None, filter_clause=None):
+ if not order_by:
+ order_by=RouterStats.avg_first_ext
+
+ if recompute:
+ RouterStats.compute(pct_low, pct_high, stat_clause, filter_clause)
+
+ pct_clause = and_(RouterStats.percentile >= pct_low,
+ RouterStats.percentile < pct_high)
+
+ # This is Fail City and sqlalchemy is running for mayor.
+ if sqlalchemy.__version__ < "0.5.0":
+ sbw = RouterStats.query.filter(pct_clause).filter(stat_clause).avg(RouterStats.sbw)
+ filt_sbw = RouterStats.query.filter(pct_clause).filter(stat_clause).avg(RouterStats.filt_sbw)
+ else:
+ sbw = tc_session.query(func.avg(RouterStats.sbw)).filter(pct_clause).filter(stat_clause).scalar()
+ filt_sbw = tc_session.query(func.avg(RouterStats.filt_sbw)).filter(pct_clause).filter(stat_clause).scalar()
+
+ f.write(str(int(time.time()))+"\n")
+
+ for s in RouterStats.query.filter(pct_clause).filter(stat_clause).\
+ order_by(order_by).all():
+ f.write("node_id=$"+s.router.idhex+" nick="+s.router.nickname)
+ f.write(" strm_bw="+str(s.sbw))
+ f.write(" filt_bw="+str(s.filt_sbw)+"\n")
+
+ f.flush()
+ write_bws = Callable(write_bws)
##################### End Model ####################
Modified: torctl/trunk/python/TorCtl/TorUtil.py
===================================================================
--- torctl/trunk/python/TorCtl/TorUtil.py 2009-05-27 11:30:09 UTC (rev 19571)
+++ torctl/trunk/python/TorCtl/TorUtil.py 2009-05-27 11:32:48 UTC (rev 19572)
@@ -15,13 +15,13 @@
import sha
import math
import time
+import ConfigParser
__all__ = ["Enum", "Enum2", "Callable", "sort_list", "quote", "escape_dots", "unescape_dots",
"BufSock", "secret_to_key", "urandom_rng", "s2k_gen", "s2k_check", "plog",
"ListenSocket", "zprob", "logfile", "loglevel"]
-# TODO: Make functions to read these from a config file. This isn't
-# the right place for them either.. But at least it's unified.
+# TODO: This isn't the right place for these.. But at least it's unified.
tor_port = 9060
tor_host = '127.0.0.1'
@@ -32,6 +32,24 @@
meta_port = 9052
meta_host = '127.0.0.1'
+def read_config(filename):
+ config = ConfigParser.SafeConfigParser()
+ config.read(filename)
+ global tor_port, tor_host, control_port, control_pass, control_host
+ global meta_port, meta_host
+ global loglevel
+
+ tor_port = config.getint('TorCtl', 'tor_port')
+ meta_port = config.getint('TorCtl', 'meta_port')
+ control_port = config.getint('TorCtl', 'control_port')
+
+ tor_host = config.get('TorCtl', 'tor_host')
+ control_host = config.get('TorCtl', 'control_host')
+ meta_host = config.get('TorCtl', 'meta_host')
+ control_pass = config.get('TorCtl', 'control_pass')
+ loglevel = config.get('TorCtl', 'loglevel')
+
+
class Enum:
""" Defines an ordered dense name-to-number 1-1 mapping """
def __init__(self, start, names):
@@ -205,7 +223,6 @@
k = binascii.a2b_hex(k[3:])
return secret_to_key(secret, k[:9]) == k[9:]
-
## XXX: Make this a class?
loglevel = "DEBUG"
loglevels = {"DEBUG" : 0, "INFO" : 1, "NOTICE" : 2, "WARN" : 3, "ERROR" : 4}