[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r15482: use fingerprint, not name, as the primary key for routers (blossom/trunk)
Author: goodell
Date: 2008-06-27 02:52:11 -0400 (Fri, 27 Jun 2008)
New Revision: 15482
Modified:
blossom/trunk/blossom.py
Log:
use fingerprint, not name, as the primary key for routers
Modified: blossom/trunk/blossom.py
===================================================================
--- blossom/trunk/blossom.py 2008-06-26 23:11:20 UTC (rev 15481)
+++ blossom/trunk/blossom.py 2008-06-27 06:52:11 UTC (rev 15482)
@@ -138,19 +138,17 @@
PERSIST = 0
META_LOCAL = [__version__]
-addr = {}
+allrtrs = {}
attempted = {}
-bw = {}
-cc = {}
cc_name = {}
+network = {}
circuits = {}
closed_streams = {}
counted_streams = {}
detached_streams = {}
failed_streams = {}
-fingerprint = {}
+fpmap = {}
local = {}
-network = {}
path = {}
pending_streams = {}
policy = {}
@@ -590,7 +588,6 @@
threading.Thread.join(self, timeout)
class TorEventHandler(EventHandler):
-# def circ_status(self, eventtype, circID, status, path):
def circ_status_event(self, c):
"""Called when a circuit status changes if listening to CIRCSTATUS
events. 'status' is a member of CIRC_STATUS; circID is a numeric
@@ -632,7 +629,6 @@
if query_streams.has_key(streamID):
self.stream_status_event("STREAM", "DETACHED", streamID, query_streams[streamID])
-# def stream_status(self, eventtype, status, streamID, target, circID="0"):
def stream_status_event(self, s):
"""Called when a stream status changes if listening to STREAMSTATUS
events. 'status' is a member of STREAM_STATUS; streamID is a
@@ -695,36 +691,33 @@
if k == "i":
isp = v
- allrtrs = {}
+ selectedrtrs = allrtrs
- for rtr in cc.keys():
- allrtrs[rtr] = 1
-
if country:
log_msg(2, "*** requested country: %s" % country)
for rtr in allrtrs.keys():
- if cc[rtr] != country:
- del allrtrs[rtr]
+ if allrtrs[rtr]["cc"] != country:
+ del selectedrtrs[rtr]
if isp:
log_msg(2, "*** requested ISP: %s" % isp)
for rtr in allrtrs.keys():
- if network[rtr].lower() != isp:
- del allrtrs[rtr]
+ if allrtrs[rtr]["network"].lower() != isp:
+ del selectedrtrs[rtr]
- log_msg(3, "--- allrtrs.keys(): %s" % allrtrs.keys())
+ log_msg(3, "--- selectedrtrs.keys(): %s" % selectedrtrs.keys())
if status != "DETACHED":
for c_circID in circuits.keys():
if len(circuits[c_circID][PATH]):
last_hop = circuits[c_circID][PATH][-1].lower()
log_msg(3, "--- last_hop: %s" % last_hop)
- if allrtrs.has_key(last_hop):
+ if selectedrtrs.has_key(last_hop):
circID = c_circID
dest = last_hop
break
if status == "DETACHED" or not dest:
- dest = select_random(streamID, allrtrs.keys(), q_port)
+ dest = select_random(streamID, selectedrtrs.keys(), q_port)
interesting_ports.append(q_port)
if dest:
@@ -799,8 +792,8 @@
try:
if m.group(1) and cur_addr:
conn.redirect_stream(streamID, cur_addr[:-1])
- elif addr.has_key(cur_exit):
- conn.redirect_stream(streamID, addr[cur_exit])
+ elif fpmap.has_key(cur_exit):
+ conn.redirect_stream(streamID, fpmap[cur_exit].addr)
except ErrorReply:
log_msg(1, "cannot redirect stream %s" % streamID)
attach_stream(streamID, circID)
@@ -863,82 +856,82 @@
done = 0
output = ""
- try:
- if self.path[-4:] == ".css" or self.path[-4:] == ".gif":
- try:
- f = open("%s%s" % (F_ROOT, self.path))
- data = f.read()
- self.send_response(200)
- if self.path[-4:] == ".css":
- self.send_header("Content-type", "text/css")
- else:
- self.send_header("ETag", "0-0-0-0")
- self.send_header("Content-type", "image/gif")
- except:
- log_msg(1, "secondary do_GET A unexpected: %s" % sys.exc_info()[0])
- data = "404 File Not Found"
- self.send_response(404)
- self.send_header("Content-type", "text/plain")
-
- elif self.path == "/":
- AUTOREFRESH = 0
- data = generate_output(AUTOREFRESH)
+ # try:
+ if self.path[-4:] == ".css" or self.path[-4:] == ".gif":
+ try:
+ f = open("%s%s" % (F_ROOT, self.path))
+ data = f.read()
self.send_response(200)
- self.send_header("Content-type", "text/html")
+ if self.path[-4:] == ".css":
+ self.send_header("Content-type", "text/css")
+ else:
+ self.send_header("ETag", "0-0-0-0")
+ self.send_header("Content-type", "image/gif")
+ except:
+ log_msg(1, "secondary do_GET A unexpected: %s" % sys.exc_info()[0])
+ data = "404 File Not Found"
+ self.send_response(404)
+ self.send_header("Content-type", "text/plain")
- elif self.path == "/autorefresh":
- AUTOREFRESH = -1
- data = generate_output(AUTOREFRESH)
- self.send_response(200)
- self.send_header("Content-type", "text/html")
+ elif self.path == "/":
+ AUTOREFRESH = 0
+ data = generate_output(AUTOREFRESH)
+ self.send_response(200)
+ self.send_header("Content-type", "text/html")
- elif self.path == "/network-status":
- data = generate_network_status()
- self.send_response(200)
- self.send_header("Content-type", "text/html")
+ elif self.path == "/autorefresh":
+ AUTOREFRESH = -1
+ data = generate_output(AUTOREFRESH)
+ self.send_response(200)
+ self.send_header("Content-type", "text/html")
- elif len(self.path) > 9 and self.path[:10] == "/attach?q=":
- data = generate_output(int(self.path[10:]))
- self.send_response(200)
- self.send_header("Content-type", "text/html")
+ elif self.path == "/network-status":
+ data = generate_network_status()
+ self.send_response(200)
+ self.send_header("Content-type", "text/html")
- elif len(self.path) > 8 and self.path[:9] == "/connect?":
- vals = {}
- args = self.path[9:].split("&")
- for arg in args:
- k, v = arg.split("=")
- vals[k] = v
+ elif len(self.path) > 9 and self.path[:10] == "/attach?q=":
+ data = generate_output(int(self.path[10:]))
+ self.send_response(200)
+ self.send_header("Content-type", "text/html")
- if vals["c"] and vals["s"]:
- try:
- sh, sp = parseHostAndPort(TORCONTROL)
- attach_stream(int(vals["s"]), int(vals["c"]))
- except:
- log_msg(1, "secondary do_GET B unexpected: %s" % sys.exc_info()[0])
- log_msg(2, "*** attach %s to %s unsuccessful" % (vals["s"], vals["c"]))
+ elif len(self.path) > 8 and self.path[:9] == "/connect?":
+ vals = {}
+ args = self.path[9:].split("&")
+ for arg in args:
+ k, v = arg.split("=")
+ vals[k] = v
- time.sleep(TIME_ACTION)
+ if vals["c"] and vals["s"]:
+ try:
+ sh, sp = parseHostAndPort(TORCONTROL)
+ attach_stream(int(vals["s"]), int(vals["c"]))
+ except:
+ log_msg(1, "secondary do_GET B unexpected: %s" % sys.exc_info()[0])
+ log_msg(2, "*** attach %s to %s unsuccessful" % (vals["s"], vals["c"]))
- data = generate_output(AUTOREFRESH)
- self.send_response(200)
- self.send_header("Content-type", "text/html")
+ time.sleep(TIME_ACTION)
- elif not done:
- data = "404 File Not Found"
- self.send_response(404)
- self.send_header("Content-type", "text/plain")
+ data = generate_output(AUTOREFRESH)
+ self.send_response(200)
+ self.send_header("Content-type", "text/html")
- if not done:
- self.send_header("Content-Length", len(data))
- self.end_headers()
- self.wfile.write(data)
+ elif not done:
+ data = "404 File Not Found"
+ self.send_response(404)
+ self.send_header("Content-type", "text/plain")
+ if not done:
+ self.send_header("Content-Length", len(data))
+ self.end_headers()
+ self.wfile.write(data)
+ '''
except KeyboardInterrupt:
log_msg(1, "exiting on ^C [%s]\n" % get_curr_time())
sys.exit(0)
except:
log_msg(1, "secondary do_GET C unexpected: %s" % sys.exc_info()[0])
-
+ '''
def do_POST(self):
global conn
@@ -1171,8 +1164,8 @@
for rtr in path:
ccs = "~~"
- if cc.has_key(rtr.lower()):
- ccs = cc[rtr.lower()]
+ if allrtrs.has_key(rtr):
+ ccs = allrtrs[rtr]["cc"]
icon = "<img %s src=\"%s/%s.gif\"> " % (IMG_SIZE, URL_FLAGS, ccs)
else:
icon = "<img %s src=\"%s\"> " % (IMG_SIZE, ICON_BUILT_1)
@@ -1186,8 +1179,8 @@
a = ""
min = 1<<16
for rtr in path:
- if bw.has_key(rtr) and bw[rtr] < min:
- min = bw[rtr]
+ if allrtrs.has_key(rtr) and allrtrs[rtr]["bw"] < min:
+ min = allrtrs[rtr]["bw"]
if min >= 400:
r = "<img %s src=\"%s\">" % (IMG_SIZE, ICON_V3)
elif min >= 60:
@@ -1464,6 +1457,12 @@
return content
+def fprevmap(x):
+ if allrtrs.has_key(x):
+ return allrtrs[x]["name"]
+ else:
+ return x
+
def generate_output(arg):
global circuits
global counted_streams
@@ -1494,6 +1493,7 @@
if circuits.has_key(circID) and circuits[circID][BUILT]:
td_class = "leftentry"
+ namelist = ",".join(map(lambda x: fprevmap(x), circuits[circID][PATH]))
content += """
<tr>
<td class="%s"><tt> %s %s %s</tt></td>
@@ -1507,7 +1507,7 @@
td_class,
circID,
td_class,
- attach_link(select_stream, circID, ",".join(circuits[circID][PATH]))
+ attach_link(select_stream, circID, namelist)
)
# report streams associated with this circuit
@@ -1768,10 +1768,18 @@
log_msg(2, "*** external processing complete for stream %s" % streamID)
return
+def fingerprint(name):
+ if fpmap.has_key(name):
+ return fpmap[name]
+ else:
+ return name
+
def process_line(line):
+ global allrtrs
global circuits
global closed_streams
global counted_streams
+ global fpmap
global semaphore
global streams
@@ -1799,10 +1807,12 @@
circuits[circID] = [[], 0, {}]
elif status == "EXTENDED":
- circuits[circID] = [c_path.split(","), 0, {}]
+ cp = map(lambda x: fingerprint(x), c_path.split(","))
+ circuits[circID] = [cp, 0, {}]
elif status == "BUILT":
- circuits[circID] = [c_path.split(","), 1, {}]
+ cp = map(lambda x: fingerprint(x), c_path.split(","))
+ circuits[circID] = [cp, 1, {}]
elif status == "FAILED" or status == "CLOSED":
if circuits.has_key(circID):
@@ -1826,7 +1836,6 @@
if status in ("SENTCONNECT", "REMAP", "SUCCEEDED"):
if circuits.has_key(circID):
- log_msg(2, "circID %s streamID %s" % (circID, streamID))
if not circuits[circID][STREAMS].has_key(streamID):
for circ in circuits:
if circuits[circ][STREAMS].has_key(streamID):
@@ -1845,19 +1854,20 @@
failed_streams[streamID] = int(time)
elif code in ["DATA", "DATA+"]:
- if len(args) > 3:
+ if len(args) > 6: # should always be true
name = re.sub(r"^\*", "", args[1])
- cc[name] = args[0].lower()
+ fp = args[6][:-1]
+ allrtrs[fp] = {
+ "cc" : args[0].lower(),
+ "name" : name,
+ "bw" : int(int(args[2])/1000),
+ "addr" : args[4],
+ "network" : args[5]
+ }
+ fpmap[name] = fp
+ fpmap["$%s" % fp] = fp
if code == "DATA":
- tor_nodes[name] = 1
- if re.match(r'[0-9]+', args[2]):
- bw[name] = int(int(args[2])/1000)
- else:
- bw[name] = 0
- if len(args) > 6:
- addr[name] = args[4]
- network[name] = args[5]
- fingerprint[args[6]] = name
+ tor_nodes[args[6]] = 1
elif code == "POLICY":
if len(args) > 6: