electrum

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

commit 291038a5862d601d5056580b0b058b4738bac418
parent 606f1cd3f8c257d55934290ac10d7b2b2104a624
Author: ThomasV <thomasv@gitorious>
Date:   Tue,  5 Aug 2014 12:36:26 +0200

update peers script

Diffstat:
Mscripts/peers | 26+++++++++++++++++---------
1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/scripts/peers b/scripts/peers @@ -5,19 +5,24 @@ from electrum import Interface, SimpleConfig from electrum.network import filter_protocol, parse_servers from collections import defaultdict +#electrum.util.set_verbosity(1) + # 1. start interface and wait for connection interface = electrum.Interface('ecdsa.net:50002:s') -interface.start(wait = True) +q = Queue.Queue() +interface.start(q) + +i, r = q.get(timeout=10000) if not interface.is_connected: print "not connected" - exit() + exit(1) # 2. get list of peers -q = Queue.Queue() -interface.send([('server.peers.subscribe',[])], lambda i,x: q.put(x)) -r = q.get(timeout=10000) +interface.send_request({'id':0, 'method':'server.peers.subscribe','params':[]}) +i, r = q.get(timeout=10000) peers = parse_servers(r.get('result')) peers = filter_protocol(peers,'s') +i.stop() print "Contacting %d servers"%len(peers) # start interfaces @@ -25,21 +30,23 @@ config = SimpleConfig() interfaces = map ( lambda server: Interface(server, config), peers ) results_queue = Queue.Queue() reached_servers = [] -for i in interfaces: i.start(q) +for i in interfaces: + i.start(q) t0 = time.time() while peers: try: - i = q.get(timeout=1) + i, r = q.get(timeout=1) except: if time.time() - t0 > 10: print "timeout" break else: continue - peers.remove(i.server) + if i.server in peers: + peers.remove(i.server) if i.is_connected: - i.send([('blockchain.headers.subscribe',[])], lambda i,x: results_queue.put((i,x))) + i.send_request({'method':'blockchain.headers.subscribe','params':[]}, results_queue) reached_servers.append(i.server) else: print "Connection failed:", i.server @@ -81,6 +88,7 @@ while reached_servers: i, r = results_queue.get(timeout=10000) results[i.server] = r.get('result') reached_servers.remove(i.server) + i.stop() errors = analyze(results).keys()