summaryrefslogtreecommitdiff
path: root/tools/mergestatus.py
blob: 9dbbb7bc4cdc06fdb9a01a227efbde635dca34b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2017, NORDUnet A/S.
# See LICENSE for licensing information.
#
import sys
import json
import urllib2
import time
import requests
import base64
import errno
from base64 import b64encode
from mergetools import parse_args, get_nfetched, hexencode, hexdecode, \
     get_logorder, get_sth
from certtools import create_ssl_context, get_public_key_from_file, \
     timing_point, create_sth_signature, write_file, check_sth_signature, \
     build_merkle_tree

def main():
    args, config, localconfig = parse_args()
    paths = localconfig["paths"]
    mergenodes = config.get("mergenodes", [])
    mergedb = paths["db"]
    sthfile = mergedb + "/sth"
    currentsizefile = mergedb + "/fetched"

    currentsize = json.loads(open(currentsizefile, "r").read())
    
    print currentsize["index"]+1,
    
    for mergenode in mergenodes:
        if mergenode["name"] == config["primarymergenode"]:
            continue
        verifiedfile = mergedb + "/verified." + mergenode["name"]
        try:
            tree = json.loads(open(verifiedfile, "r").read())
            print tree["tree_size"],
        except (IOError, ValueError):
            pass
    try:
        sth = json.loads(open(sthfile, "r").read())
        print sth["tree_size"],
    except IOError, e:
        print ".",
        if e.errno != errno.ENOENT:
            raise
    print

if __name__ == '__main__':
    sys.exit(main())