diff options
author | Magnus Ahltorp <map@kth.se> | 2015-04-07 14:17:51 +0200 |
---|---|---|
committer | Magnus Ahltorp <map@kth.se> | 2015-04-07 14:17:51 +0200 |
commit | 71a95b89f9e7c51fd97d79ab73a2c1213ab1c641 (patch) | |
tree | 715e060044454e9a473a395b303682b37b1d6031 /tools/merge.py | |
parent | 3d7c2403f16d85222c52ca092f6732671d8af768 (diff) |
Only spawn one verifycert processmergeverify
Diffstat (limited to 'tools/merge.py')
-rwxr-xr-x | tools/merge.py | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/tools/merge.py b/tools/merge.py index a016b35..ce3bf0b 100755 --- a/tools/merge.py +++ b/tools/merge.py @@ -219,16 +219,19 @@ def unpack_entry(entry): import subprocess -def verify_entry(entry, hash): +def verify_entry(verifycert, entry, hash): unpacked = unpack_entry(entry) mtl = unpacked[0] assert hash == get_leaf_hash(mtl) - p = subprocess.Popen( - ["../verifycert.erl"], - stdin=subprocess.PIPE, stdout=subprocess.PIPE) - (verify_result, _) = p.communicate(entry) - if verify_result != "ok\n": - print >>sys.stderr, verify_result + s = struct.pack(">I", len(entry)) + entry + verifycert.stdin.write(s) + result_length_packed = verifycert.stdout.read(4) + (result_length,) = struct.unpack(">I", result_length_packed) + result = verifycert.stdout.read(result_length) + assert len(result) == result_length + (error_code,) = struct.unpack("B", result[0:1]) + if error_code != 0: + print >>sys.stderr, result[1:] sys.exit(1) timing_point(timing, "get new entries") @@ -246,6 +249,8 @@ for hash in new_entries: entries_to_fetch[storagenode["name"]].append(hash) break +verifycert = subprocess.Popen(["../verifycert.erl"], + stdin=subprocess.PIPE, stdout=subprocess.PIPE) added_entries = 0 for storagenode in storagenodes: @@ -254,7 +259,7 @@ for storagenode in storagenodes: entries = get_entries(storagenode["name"], "https://%s/" % storagenode["address"], chunk) for hash in chunk: entry = entries[hash] - verify_entry(entry, hash) + verify_entry(verifycert, entry, hash) write_chain(hash, entry) add_to_logorder(hash) logorder.append(hash) @@ -263,6 +268,8 @@ for storagenode in storagenodes: timing_point(timing, "add entries") print "added", added_entries, "entries" +verifycert.communicate(struct.pack("I", 0)) + tree = build_merkle_tree(logorder) tree_size = len(logorder) root_hash = tree[-1][0] |