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