Browse Source

update script

283
ThomasV 11 years ago
parent
commit
c3419eb7bb
  1. 39
      scripts/servers

39
scripts/servers

@ -5,45 +5,24 @@ from electrum.network import DEFAULT_SERVERS, filter_protocol
import time, Queue import time, Queue
from collections import defaultdict from collections import defaultdict
import util, json
set_verbosity(False) set_verbosity(False)
config = SimpleConfig() config = SimpleConfig()
servers = filter_protocol(DEFAULT_SERVERS,'t') 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() d = defaultdict(int)
results_queue = Queue.Queue()
for i in interfaces: i.start(q)
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: for k, v in results.items():
i, r = results_queue.get(timeout=1000) print k, v.get('block_height')
i.blocks = r.get('result').get('block_height')
d[i.blocks] += 1
reached_servers.remove(i.server)
v = d.values() v = d.values()
numblocks = d.keys()[v.index(max(v))] numblocks = d.keys()[v.index(max(v))]
print "blocks:",numblocks
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)

Loading…
Cancel
Save