|
|
@ -5,45 +5,24 @@ from electrum.network import DEFAULT_SERVERS, filter_protocol |
|
|
|
import time, Queue |
|
|
|
from collections import defaultdict |
|
|
|
|
|
|
|
import util, json |
|
|
|
set_verbosity(False) |
|
|
|
|
|
|
|
config = SimpleConfig() |
|
|
|
servers = filter_protocol(DEFAULT_SERVERS,'t') |
|
|
|
interfaces = map ( lambda server: Interface(server, config), servers ) |
|
|
|
results = util.send_request(servers, {'method':'blockchain.headers.subscribe', 'params':[]}) |
|
|
|
|
|
|
|
q = Queue.Queue() |
|
|
|
results_queue = Queue.Queue() |
|
|
|
|
|
|
|
for i in interfaces: i.start(q) |
|
|
|
d = defaultdict(int) |
|
|
|
|
|
|
|
reached_servers = [] |
|
|
|
for k, r in results.items(): |
|
|
|
blocks = r.get('block_height') |
|
|
|
d[blocks] += 1 |
|
|
|
|
|
|
|
while servers: |
|
|
|
i = q.get(timeout=1000) |
|
|
|
servers.remove(i.server) |
|
|
|
if i.is_connected: |
|
|
|
i.send([('blockchain.headers.subscribe',[])], lambda i,x: results_queue.put((i,x))) |
|
|
|
reached_servers.append(i.server) |
|
|
|
i.status = "ok" |
|
|
|
else: |
|
|
|
i.status = "unreachable" |
|
|
|
|
|
|
|
d = defaultdict(int) |
|
|
|
|
|
|
|
while reached_servers: |
|
|
|
i, r = results_queue.get(timeout=1000) |
|
|
|
i.blocks = r.get('result').get('block_height') |
|
|
|
d[i.blocks] += 1 |
|
|
|
reached_servers.remove(i.server) |
|
|
|
for k, v in results.items(): |
|
|
|
print k, v.get('block_height') |
|
|
|
|
|
|
|
v = d.values() |
|
|
|
numblocks = d.keys()[v.index(max(v))] |
|
|
|
|
|
|
|
for i in interfaces: |
|
|
|
if i.status == "ok": |
|
|
|
if abs(i.blocks-numblocks)>1: i.status = "lagging" |
|
|
|
else: |
|
|
|
i.blocks = 0 |
|
|
|
|
|
|
|
print "%30s %d %s "%(i.host, i.blocks, i.status) |
|
|
|
|
|
|
|
print "blocks:",numblocks |
|
|
|