electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 33db7a0c43fbf17cd1ca34528d2d39a0270f854d
parent 66f224eab4e2ff4bf630db9cc1355c5b446ae934
Author: ThomasV <thomasv@gitorious>
Date:   Sun,  6 Oct 2013 14:13:20 +0200

fix servers script

Diffstat:
Mscripts/servers | 55+++++++++++++++++++++++++++++--------------------------
1 file changed, 29 insertions(+), 26 deletions(-)

diff --git a/scripts/servers b/scripts/servers @@ -1,46 +1,49 @@ #!/usr/bin/env python -from electrum import interface, Interface, DEFAULT_SERVERS +from electrum import Interface, SimpleConfig, set_verbosity +from electrum.network import DEFAULT_SERVERS, filter_protocol import time, Queue +from collections import defaultdict -servers = interface.filter_protocol(DEFAULT_SERVERS,'s') -interfaces = map ( lambda server: Interface({'server':server} ), servers ) -for i in interfaces: i.start() +set_verbosity(False) -for i in interfaces: +config = SimpleConfig() +servers = filter_protocol(DEFAULT_SERVERS,'t') +interfaces = map ( lambda server: Interface(server, config), servers ) + +q = Queue.Queue() +results_queue = Queue.Queue() + +for i in interfaces: i.start(q) + +reached_servers = [] + +while servers: + i = q.get(timeout=1000) + servers.remove(i.server) if i.is_connected: - i.send([('blockchain.numblocks.subscribe',[])]) - i.status = "timed out" + i.send([('blockchain.numblocks.subscribe',[])], lambda i,x: results_queue.put((i,x))) + reached_servers.append(i.server) + i.status = "ok" else: - servers.remove(i.server) i.status = "unreachable" -for i in interfaces: - while True: - try: - r = i.get_response(timeout=1) - except Queue.Empty: - break - - if r.get('method') == 'blockchain.numblocks.subscribe': - servers.remove(i.server) - i.status = "ok" - i.blocks = r.get('result') - break +d = defaultdict(int) +while reached_servers: + i, r = results_queue.get(timeout=1000) + i.blocks = r.get('result') + d[i.blocks] += 1 + reached_servers.remove(i.server) -from collections import defaultdict -d = defaultdict(int) -for i in interfaces: - if i.status == 'ok': - d[i.blocks] += 1 v = d.values() numblocks = d.keys()[v.index(max(v))] for i in interfaces: - if i.status == 'ok': + 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)