commit 967f1a6a4290154977ab7c0cc2cbe0560d7246ce Author: Matthew Finkel Matthew.Finkel@gmail.com Date: Sun Feb 2 03:04:03 2014 +0000
Only add bridges for which their documents were verified by the BA --- lib/bridgedb/Bridges.py | 14 +++++----- lib/bridgedb/Main.py | 69 +++++++++++++++++++++-------------------------- 2 files changed, 37 insertions(+), 46 deletions(-)
diff --git a/lib/bridgedb/Bridges.py b/lib/bridgedb/Bridges.py index 1a2bdd6..a6ca14f 100644 --- a/lib/bridgedb/Bridges.py +++ b/lib/bridgedb/Bridges.py @@ -473,9 +473,7 @@ def parseDescFile(f, bridge_purpose='bridge'): elif line.startswith("router-signature"): purposeMatches = (purpose == bridge_purpose or bridge_purpose is None) if purposeMatches and nickname and ip and orport and fingerprint: - b = Bridge(nickname, ipaddr.IPAddress(ip), orport, fingerprint) - b.assertOK() - yield b + yield (nickname, ipaddr.IPAddress(ip), orport, fingerprint) nickname = ip = orport = fingerprint = purpose = None
@@ -637,9 +635,10 @@ def parseStatusFile(networkstatusFile): if line.startswith("r "): (nickname, ID, descDigest, timestamp, ORaddr, ORport, dirport) = networkstatus.parseRLine(line) + hexID = toHex(ID) logging.debug("Parsed networkstatus line:") logging.debug(" Nickname: %s" % nickname) - logging.debug(" Identity: %s" % toHex(ID)) + logging.debug(" Identity: %s" % hexID) if descDigest: logging.debug(" Descriptor: {0}".format(toHex(descDigest))) logging.debug(" Timestamp: {0}".format(timestamp)) @@ -667,14 +666,15 @@ def parseStatusFile(networkstatusFile): "yielding %s nickname=%s descDigest=%s " "running=%s stable=%s oraddr=%s orport=%s " "oraddrs=%s ts=%s" - % (toHex(ID), nickname, descDigest, running, + % (hexID, nickname, descDigest, running, stable, ORaddr, ORport, or_addresses, timestamp)) - yield (ID, nickname, descDigest, running, stable, ORaddr, ORport, + yield (ID, nickname, descDigest, running, stable, + ipaddr.IPAddress(ORaddr), ORport, or_addresses, timestamp)
(nickname, ID, descDigest, timestamp, ORaddr, ORport, dirport, - addr, portlist) = (None for x in xrange(9)) + addr, portlist, hexID) = (None for x in xrange(10)) running = stable = False or_addresses = {}
diff --git a/lib/bridgedb/Main.py b/lib/bridgedb/Main.py index c3a90ea..36e4e88 100644 --- a/lib/bridgedb/Main.py +++ b/lib/bridgedb/Main.py @@ -95,66 +95,57 @@ def load(state, splitter, clear=False): status = {} addresses = {} timestamps = {} + bridges = {} + desc_digests = {} + ei_digests = {}
logging.info("Opening network status file: %s" % state.STATUS_FILE) f = open(state.STATUS_FILE, 'r') - for (ID, nickname, descDigest, running, stable, + for (ID, nickname, desc_digest, running, stable, ORaddr, ORport, or_addresses, timestamp) in Bridges.parseStatusFile(f): - - status[ID] = running, stable - addresses[ID] = or_addresses + bridge = Bridges.Bridge(nickname, ORaddr, ORport, id_digest=ID, + or_addresses=or_addresses) + bridge.assertOK() + bridge.setStatus(running, stable) + bridge.setDescriptorDigest(desc_digest) + bridges[ID] = bridge
if ID in timestamps.keys(): timestamps[ID].append(timestamp) else: timestamps[ID] = [timestamp] - #transports[ID] = transports logging.debug("Closing network status file") f.close()
- bridges = {} db = bridgedb.Storage.getDB()
for fname in state.BRIDGE_FILES: logging.info("Opening bridge-server-descriptor file: '%s'" % fname) f = open(fname, 'r') - for bridge in Bridges.parseDescFile(f, state.BRIDGE_PURPOSE): - if bridge.getID() in bridges: - logging.warn("Parsed a duplicate bridge. Skipping.") - continue - else: - bridges[bridge.getID()] = bridge - s = status.get(bridge.getID()) - if s is not None: - running, stable = s - bridge.setStatus(running=running, stable=stable) - # XXX: what do we do with all these or_addresses? - # - # The bridge stability metrics are only concerned with a - # single ip:port So for now, we will only consider the bridges - # primary IP:port - bridge.or_addresses = addresses.get(bridge.getID()) - # We attempt to insert all bridges. If the bridge is not - # running, then it is skipped during the insertion process. Also, - # if we have a descriptor for the bridge but it was not in the - # ns, then we skip it there, too. - splitter.insert(bridge) - - if state.COLLECT_TIMESTAMPS: - if bridge.getID() in timestamps.keys(): - ts = timestamps[bridge.getID()][:] - ts.sort() - for timestamp in ts: - logging.debug( - "Updating BridgeHistory timestamps for %s: %s" - % (bridge.fingerprint, timestamp)) - bridgedb.Stability.addOrUpdateBridgeHistory( - bridge, timestamp) - + desc_digests.update(Bridges.getDescriptorDigests(f)) + if bridge.getID() in timestamps.keys(): + ts = timestamps[bridge.getID()][:] + ts.sort() + for timestamp in ts: + logging.debug( + "Adding/updating timestamps in BridgeHistory for "\ + "'%s' in database: %s" + % (bridge.fingerprint, timestamp)) + bridgedb.Stability.addOrUpdateBridgeHistory( + bridge, timestamp) logging.debug("Closing bridge-server-descriptor file: '%s'" % fname) f.close()
+ for ID in bridges.keys(): + bridge = bridges[ID] + if bridge.desc_digest in desc_digests: + bridge.setVerified() + bridge.setExtraInfoDigest(desc_digests[bridge.desc_digest]) + # We attempt to insert all bridges. If the bridge is not + # running, then it is skipped during the insertion process. + splitter.insert(bridge) + # read pluggable transports from extra-info document # XXX: should read from networkstatus after bridge-authority # does a reachability test