diff options
-rwxr-xr-x | monitor/josef_experimental.py | 22 | ||||
-rw-r--r-- | monitor/josef_lib.py | 6 | ||||
-rwxr-xr-x | monitor/josef_monitor.py | 16 |
3 files changed, 38 insertions, 6 deletions
diff --git a/monitor/josef_experimental.py b/monitor/josef_experimental.py index 40695c4..579331b 100755 --- a/monitor/josef_experimental.py +++ b/monitor/josef_experimental.py @@ -9,7 +9,7 @@ import argparse import json from josef_leveldb import * from datetime import datetime as dt -from josef_monitor import verify_inclusion_by_hash +# from josef_monitor import verify_inclusion_by_hash from monitor_conf import * @@ -70,9 +70,23 @@ def update_roots(log): if __name__ == '__main__': - entry = get_entries(ctlogs[0]["url"], 1,1)["entries"] - print extract_original_entry(entry[0]) - + # entry = get_entries(ctlogs[0]["url"], 1,1)["entries"] + # print extract_original_entry(entry[0]) + for url in [CTLOGS[0]["url"],CTLOGS[5]["url"],CTLOGS[6]["url"]]: + # for log in CTLOGS: + # url = log["url"] + # url = CTLOGS[1]["url"] + # result = urlopen(url + "ct/v1/get-sth").info() + # print get_sth(url) + import urllib2, socket, urlparse + # set up your request as before, then: + data = urllib2.urlopen(url+ "ct/v1/get-sth") + addr = socket.gethostbyname(urlparse.urlparse(data.geturl()).hostname) + print addr, data.fp._sock.fp._sock.getpeername()[0] + + # data = urllib2.urlopen(request) + + # print addr diff --git a/monitor/josef_lib.py b/monitor/josef_lib.py index afb066b..0f64ef6 100644 --- a/monitor/josef_lib.py +++ b/monitor/josef_lib.py @@ -273,6 +273,12 @@ def get_sth(baseurl): result = urlopen(baseurl + "ct/v1/get-sth").read() return json.loads(result) +def get_sth_and_ip(baseurl): + data = urlopen(baseurl + "ct/v1/get-sth") + ip = data.fp._sock.fp._sock.getpeername()[0] + result = data.read() + return json.loads(result), ip + def get_proof_by_hash(baseurl, hash, tree_size): # try: params = urllib.urlencode({"hash":base64.b64encode(hash), diff --git a/monitor/josef_monitor.py b/monitor/josef_monitor.py index d97ba02..8b29443 100755 --- a/monitor/josef_monitor.py +++ b/monitor/josef_monitor.py @@ -46,6 +46,7 @@ class ctlog: self.logfile = CONFIG.OUTPUT_DIR + name + ".log" self.savefile = CONFIG.OUTPUT_DIR + name + "-state-info.json" self.subtree = [[]] + self.fe_ips = {} self.sth = None self.entries = 0 self.root_hash = None @@ -141,6 +142,7 @@ class ctlog: d["entries"] = self.entries d["subtree"] = encode_tree(self.subtree) d["sth"] = self.sth + d["fe_ips"] = self.fe_ips return d def save(self): @@ -156,11 +158,18 @@ class ctlog: self.subtree = decode_tree(d["subtree"]) self.sth = d["sth"] self.entries = d["entries"] + + if "fe_ips" in d: + self.fe_ips = d["fe_ips"] + else: + self.fe_ips = {} + except IOError, e: if e.errno == errno.ENOENT: return None raise e + def log(self, string): s = time.strftime('%Y-%m-%d %H:%M:%S') + " " + string s = datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S') + " " + string @@ -170,9 +179,12 @@ class ctlog: def update_sth(self): try: - new_sth = get_sth(self.url) + new_sth, ip = get_sth_and_ip(self.url) + if not ip in self.fe_ips: + self.fe_ips[ip] = new_sth["timestamp"] + self.log("New Front end IP: " + ip) except Exception, e: - self.log(ERROR_STR + "Failed to fetch STH. " +str(e)) + self.log(ERROR_STR + "Failed to fetch STH and IP. " +str(e)) return try: |