[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] r24405: {arm} Updating TorCtl to the current git version. (in arm/resources: . TorCtl)
Author: atagar
Date: 2011-03-22 02:25:04 +0000 (Tue, 22 Mar 2011)
New Revision: 24405
Modified:
arm/resources/TorCtl/PathSupport.py
arm/resources/TorCtl/TorCtl.py
arm/resources/TorCtl/TorUtil.py
arm/resources/notes.txt
Log:
Updating TorCtl to the current git version.
Modified: arm/resources/TorCtl/PathSupport.py
===================================================================
--- arm/resources/TorCtl/PathSupport.py 2011-03-22 02:18:36 UTC (rev 24404)
+++ arm/resources/TorCtl/PathSupport.py 2011-03-22 02:25:04 UTC (rev 24405)
@@ -1318,6 +1318,12 @@
port_table = set()
_table_lock = threading.Lock()
+ def __init__(self, family=2, type=1, proto=0, _sock=None):
+ ret = super(SmartSocket, self).__init__(family, type, proto, _sock)
+ self.__local_addr = None
+ plog("DEBUG", "New socket constructor")
+ return ret
+
def connect(self, args):
ret = super(SmartSocket, self).connect(args)
myaddr = self.getsockname()
@@ -1341,10 +1347,13 @@
return ret
def __del__(self):
- SmartSocket._table_lock.acquire()
- SmartSocket.port_table.remove(self.__local_addr)
- SmartSocket._table_lock.release()
- plog("DEBUG", "Removed "+self.__local_addr+" from our local port list")
+ if self.__local_addr:
+ SmartSocket._table_lock.acquire()
+ SmartSocket.port_table.remove(self.__local_addr)
+ plog("DEBUG", "Removed "+self.__local_addr+" from our local port list")
+ SmartSocket._table_lock.release()
+ else:
+ plog("DEBUG", "Got a socket deletion with no address")
def table_size():
SmartSocket._table_lock.acquire()
Modified: arm/resources/TorCtl/TorCtl.py
===================================================================
--- arm/resources/TorCtl/TorCtl.py 2011-03-22 02:18:36 UTC (rev 24404)
+++ arm/resources/TorCtl/TorCtl.py 2011-03-22 02:25:04 UTC (rev 24405)
@@ -180,32 +180,33 @@
self.updated = datetime.datetime(*map(int, m.groups()))
class Event:
- def __init__(self, event_name):
+ def __init__(self, event_name, body=None):
+ self.body = body
self.event_name = event_name
self.arrived_at = 0
self.state = EVENT_STATE.PRISTINE
class TimerEvent(Event):
- def __init__(self, event_name, type):
- Event.__init__(self, event_name)
- self.type = type
+ def __init__(self, event_name, body):
+ Event.__init__(self, event_name, body)
+ self.type = body
class NetworkStatusEvent(Event):
- def __init__(self, event_name, nslist):
- Event.__init__(self, event_name)
+ def __init__(self, event_name, nslist, body):
+ Event.__init__(self, event_name, body)
self.nslist = nslist # List of NetworkStatus objects
class NewConsensusEvent(NetworkStatusEvent):
pass
class NewDescEvent(Event):
- def __init__(self, event_name, idlist):
- Event.__init__(self, event_name)
+ def __init__(self, event_name, idlist, body):
+ Event.__init__(self, event_name, body)
self.idlist = idlist
class GuardEvent(Event):
- def __init__(self, event_name, ev_type, guard, status):
- Event.__init__(self, event_name)
+ def __init__(self, event_name, ev_type, guard, status, body):
+ Event.__init__(self, event_name, body)
if "~" in guard:
(self.idhex, self.nick) = guard[1:].split("~")
elif "=" in guard:
@@ -216,8 +217,8 @@
class BuildTimeoutSetEvent(Event):
def __init__(self, event_name, set_type, total_times, timeout_ms, xm, alpha,
- quantile):
- Event.__init__(self, event_name)
+ quantile, body):
+ Event.__init__(self, event_name, body)
self.set_type = set_type
self.total_times = total_times
self.timeout_ms = timeout_ms
@@ -227,8 +228,8 @@
class CircuitEvent(Event):
def __init__(self, event_name, circ_id, status, path, purpose,
- reason, remote_reason):
- Event.__init__(self, event_name)
+ reason, remote_reason, body):
+ Event.__init__(self, event_name, body)
self.circ_id = circ_id
self.status = status
self.path = path
@@ -238,8 +239,9 @@
class StreamEvent(Event):
def __init__(self, event_name, strm_id, status, circ_id, target_host,
- target_port, reason, remote_reason, source, source_addr, purpose):
- Event.__init__(self, event_name)
+ target_port, reason, remote_reason, source, source_addr, purpose,
+ body):
+ Event.__init__(self, event_name, body)
self.strm_id = strm_id
self.status = status
self.circ_id = circ_id
@@ -253,8 +255,8 @@
class ORConnEvent(Event):
def __init__(self, event_name, status, endpoint, age, read_bytes,
- wrote_bytes, reason, ncircs):
- Event.__init__(self, event_name)
+ wrote_bytes, reason, ncircs, body):
+ Event.__init__(self, event_name, body)
self.status = status
self.endpoint = endpoint
self.age = age
@@ -264,21 +266,21 @@
self.ncircs = ncircs
class StreamBwEvent(Event):
- def __init__(self, event_name, strm_id, written, read):
- Event.__init__(self, event_name)
+ def __init__(self, event_name, saved_body, strm_id, written, read):
+ Event.__init__(self, event_name, saved_body)
self.strm_id = int(strm_id)
self.bytes_read = int(read)
self.bytes_written = int(written)
class LogEvent(Event):
def __init__(self, level, msg):
- Event.__init__(self, level)
+ Event.__init__(self, level, msg)
self.level = level
self.msg = msg
class AddrMapEvent(Event):
- def __init__(self, event_name, from_addr, to_addr, when):
- Event.__init__(self, event_name)
+ def __init__(self, event_name, from_addr, to_addr, when, body):
+ Event.__init__(self, event_name, body)
self.from_addr = from_addr
self.to_addr = to_addr
self.when = when
@@ -290,14 +292,14 @@
self.when = when
class BWEvent(Event):
- def __init__(self, event_name, read, written):
- Event.__init__(self, event_name)
+ def __init__(self, event_name, read, written, body):
+ Event.__init__(self, event_name, body)
self.read = read
self.written = written
class UnknownEvent(Event):
def __init__(self, event_name, event_string):
- Event.__init__(self, event_name)
+ Event.__init__(self, event_name, event_string)
self.event_string = event_string
ipaddress_re = re.compile(r"(\d{1,3}\.){3}\d{1,3}$")
@@ -374,6 +376,7 @@
desc_re = {
"router": r"(\S+) (\S+)",
"opt fingerprint": r"(.+).*on (\S+)",
+ "opt extra-info-digest": r"(\S+)",
"opt hibernating": r"1$",
"platform": r"Tor (\S+).*on ([\S\s]+)",
"accept": r"(\S+):([^-]+)(?:-(\d+))?",
@@ -410,7 +413,9 @@
self.__dict__[i] = copy.deepcopy(args[0].__dict__[i])
return
else:
- (idhex, name, bw, down, exitpolicy, flags, ip, version, os, uptime, published, contact, rate_limited, orhash, ns_bandwidth) = args
+ (idhex, name, bw, down, exitpolicy, flags, ip, version, os, uptime,
+ published, contact, rate_limited, orhash,
+ ns_bandwidth,extra_info_digest) = args
self.idhex = idhex
self.nickname = name
if ns_bandwidth != None:
@@ -432,6 +437,7 @@
self.contact = contact
self.rate_limited = rate_limited
self.orhash = orhash
+ self.extra_info_digest = extra_info_digest
self._generated = [] # For ExactUniformGenerator
def __str__(self):
@@ -456,6 +462,7 @@
router = "[none]"
published = "never"
contact = None
+ extra_info_digest = None
for line in desc:
# Pull off the keyword...
@@ -504,6 +511,8 @@
published = datetime.datetime(*t[0:6])
elif kw == "contact":
contact = g[0]
+ elif kw == "opt extra-info-digest":
+ extra_info_digest = g[0]
elif kw == "opt hibernating":
dead = True
if ("Running" in ns.flags):
@@ -519,7 +528,7 @@
plog("INFO", "No version and/or OS for router " + ns.nickname)
return Router(ns.idhex, ns.nickname, bw_observed, dead, exitpolicy,
ns.flags, ip, version, os, uptime, published, contact, rate_limited,
- ns.orhash, ns.bandwidth)
+ ns.orhash, ns.bandwidth, extra_info_digest)
build_from_desc = Callable(build_from_desc)
def update_to(self, new):
@@ -994,7 +1003,7 @@
def set_option(self, key, value):
"""Set the value of the configuration option 'key' to the value 'value'.
"""
- self.set_options([(key, value)])
+ return self.set_options([(key, value)])
def set_options(self, kvlist):
"""Given a list of (key,value) pairs, set them as configuration
@@ -1003,7 +1012,7 @@
if not kvlist:
return
msg = " ".join(["%s=\"%s\""%(k,quote(v)) for k,v in kvlist])
- self.sendAndRecv("SETCONF %s\r\n"%msg)
+ return self.sendAndRecv("SETCONF %s\r\n"%msg)
def reset_options(self, keylist):
"""Reset the options listed in 'keylist' to their default values.
@@ -1012,7 +1021,7 @@
previous versions wanted you to set configuration keys to "".
That no longer works.
"""
- self.sendAndRecv("RESETCONF %s\r\n"%(" ".join(keylist)))
+ return self.sendAndRecv("RESETCONF %s\r\n"%(" ".join(keylist)))
def get_consensus(self):
"""Get the pristine Tor Consensus. Returns a list of
@@ -1379,7 +1388,8 @@
if purpose: purpose = purpose[9:]
if reason: reason = reason[8:]
if remote: remote = remote[15:]
- event = CircuitEvent(evtype, ident, status, path, purpose, reason, remote)
+ event = CircuitEvent(evtype, ident, status, path, purpose, reason,
+ remote, body)
elif evtype == "STREAM":
#plog("DEBUG", "STREAM: "+body)
m = re.match(r"(\S+)\s+(\S+)\s+(\S+)\s+(\S+)?:(\d+)(\sREASON=\S+)?(\sREMOTE_REASON=\S+)?(\sSOURCE=\S+)?(\sSOURCE_ADDR=\S+)?(\s+PURPOSE=\S+)?", body)
@@ -1397,7 +1407,8 @@
purpose = purpose.lstrip()
purpose = purpose[8:]
event = StreamEvent(evtype, ident, status, circ, target_host,
- int(target_port), reason, remote, source, source_addr, purpose)
+ int(target_port), reason, remote, source, source_addr,
+ purpose, body)
elif evtype == "ORCONN":
m = re.match(r"(\S+)\s+(\S+)(\sAGE=\S+)?(\sREAD=\S+)?(\sWRITTEN=\S+)?(\sREASON=\S+)?(\sNCIRCS=\S+)?", body)
if not m:
@@ -1415,18 +1426,18 @@
if wrote: wrote = int(wrote[9:])
else: wrote = 0
event = ORConnEvent(evtype, status, target, age, read, wrote,
- reason, ncircs)
+ reason, ncircs, body)
elif evtype == "STREAM_BW":
m = re.match(r"(\d+)\s+(\d+)\s+(\d+)", body)
if not m:
raise ProtocolError("STREAM_BW event misformatted.")
- event = StreamBwEvent(evtype, *m.groups())
+ event = StreamBwEvent(evtype, body, *m.groups())
elif evtype == "BW":
m = re.match(r"(\d+)\s+(\d+)", body)
if not m:
raise ProtocolError("BANDWIDTH event misformatted.")
read, written = map(long, m.groups())
- event = BWEvent(evtype, read, written)
+ event = BWEvent(evtype, read, written, body)
elif evtype in ("DEBUG", "INFO", "NOTICE", "WARN", "ERR"):
event = LogEvent(evtype, body)
elif evtype == "NEWDESC":
@@ -1434,7 +1445,7 @@
ids = []
for i in ids_verb:
ids.append(i.replace("~", "=").split("=")[0].replace("$",""))
- event = NewDescEvent(evtype, ids)
+ event = NewDescEvent(evtype, ids, body)
elif evtype == "ADDRMAP":
# TODO: Also parse errors and GMTExpiry
m = re.match(r'(\S+)\s+(\S+)\s+(\"[^"]+\"|\w+)', body)
@@ -1445,11 +1456,11 @@
when = None
else:
when = time.strptime(when[1:-1], "%Y-%m-%d %H:%M:%S")
- event = AddrMapEvent(evtype, fromaddr, toaddr, when)
+ event = AddrMapEvent(evtype, fromaddr, toaddr, when, body)
elif evtype == "NS":
- event = NetworkStatusEvent(evtype, parse_ns_body(data))
+ event = NetworkStatusEvent(evtype, parse_ns_body(data), data)
elif evtype == "NEWCONSENSUS":
- event = NewConsensusEvent(evtype, parse_ns_body(data))
+ event = NewConsensusEvent(evtype, parse_ns_body(data), data)
elif evtype == "BUILDTIMEOUT_SET":
m = re.match(
r"(\S+)\sTOTAL_TIMES=(\d+)\sTIMEOUT_MS=(\d+)\sXM=(\d+)\sALPHA=(\S+)\sCUTOFF_QUANTILE=(\S+)",
@@ -1457,11 +1468,11 @@
set_type, total_times, timeout_ms, xm, alpha, quantile = m.groups()
event = BuildTimeoutSetEvent(evtype, set_type, int(total_times),
int(timeout_ms), int(xm), float(alpha),
- float(quantile))
+ float(quantile), body)
elif evtype == "GUARD":
m = re.match(r"(\S+)\s(\S+)\s(\S+)", body)
entry, guard, status = m.groups()
- event = GuardEvent(evtype, entry, guard, status)
+ event = GuardEvent(evtype, entry, guard, status, body)
elif evtype == "TORCTL_TIMER":
event = TimerEvent(evtype, data)
else:
Modified: arm/resources/TorCtl/TorUtil.py
===================================================================
--- arm/resources/TorCtl/TorUtil.py 2011-03-22 02:18:36 UTC (rev 24404)
+++ arm/resources/TorCtl/TorUtil.py 2011-03-22 02:25:04 UTC (rev 24405)
@@ -24,7 +24,7 @@
__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"]
+ "ListenSocket", "zprob", "logfile", "loglevel", "loglevels"]
# TODO: This isn't the right place for these.. But at least it's unified.
tor_port = 9060
@@ -339,7 +339,7 @@
if not logfile:
logfile = sys.stdout
# HACK: if logfile is a string, assume is it the desired filename.
- if type(logfile) is str:
+ if isinstance(logfile, basestring):
f = logging.FileHandler(logfile)
f.setFormatter(formatter)
logger.addHandler(f)
Modified: arm/resources/notes.txt
===================================================================
--- arm/resources/notes.txt 2011-03-22 02:18:36 UTC (rev 24404)
+++ arm/resources/notes.txt 2011-03-22 02:25:04 UTC (rev 24405)
@@ -8,7 +8,7 @@
- dump /release/ChangeLog into /resources/build/debian/changelog
TorCtl (dependency) -
- Last Updated: 11/18/10 (https://gitweb.torproject.org/pytorctl.git):
+ Last Updated: 3/21/11 (https://gitweb.torproject.org/pytorctl.git):
To update run the following:
git clone git://git.torproject.org/pytorctl.git
cd pytorctl
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits