Browse Source

update scripts/servers to display server version

seed_v14
ThomasV 7 years ago
parent
commit
70af22c9e4
  1. 21
      lib/network.py
  2. 34
      scripts/peers
  3. 16
      scripts/servers
  4. 3
      scripts/util.py

21
lib/network.py

@ -120,18 +120,21 @@ def parse_servers(result):
elif re.match("p\d*", v):
pruning_level = v[1:]
if pruning_level == '': pruning_level = '0'
try:
is_recent = util.normalize_version(version) >= util.normalize_version(PROTOCOL_VERSION)
except Exception as e:
print_error(e)
is_recent = False
if out and is_recent:
if out:
out['pruning'] = pruning_level
out['version'] = version
servers[host] = out
return servers
def filter_version(servers):
def is_recent(version):
try:
return util.normalize_version(version) >= util.normalize_version(PROTOCOL_VERSION)
except Exception as e:
return False
return {k: v for k, v in servers.items() if is_recent(v.get('version'))}
def filter_protocol(hostmap, protocol = 's'):
'''Filters the hostmap for those implementing protocol.
The result is a list in serialized form.'''
@ -574,7 +577,7 @@ class Network(util.DaemonThread):
self.on_notify_header(interface, result)
elif method == 'server.peers.subscribe':
if error is None:
self.irc_servers = parse_servers(result)
self.irc_servers = filter_version(parse_servers(result))
self.notify('servers')
elif method == 'server.banner':
if error is None:

34
scripts/peers

@ -3,37 +3,13 @@
import util, json
from collections import defaultdict
def analyze(results):
out = {}
dd = {}
for k, v in results.items():
height = v.get('block_height')
merkle = v.get('merkle_root')
utxo = v.get('utxo_root')
d = dd.get(merkle, defaultdict(int))
d[utxo] += 1
dd[merkle] = d
refs = {}
for merkle, d in dd.items():
v = list(d.values())
m = max(v)
dkeys = list(d.keys())
ref = dkeys[v.index(m)]
refs[merkle] = ref, m
for k, v in results.items():
height = v.get('block_height')
merkle = v.get('merkle_root')
utxo = v.get('utxo_root')
ref_utxo, num = refs.get(merkle)
if ref_utxo != utxo and num > 1:
out[k] = height, merkle, utxo
return out
from electrum.network import filter_protocol
from electrum.blockchain import hash_header
peers = util.get_peers()
peers = filter_protocol(peers, 's')
results = util.send_request(peers, 'blockchain.headers.subscribe', [])
errors = analyze(results).keys()
for n,v in sorted(results.items(), key=lambda x:x[1].get('block_height')):
print("%40s"%n, v.get('block_height'), v.get('utxo_root'), "error" if n in errors else "ok")
print("%60s"%n, v.get('block_height'), hash_header(v))

16
scripts/servers

@ -2,25 +2,13 @@
from electrum import set_verbosity
from electrum.network import filter_protocol
from collections import defaultdict
import util, json
set_verbosity(False)
servers = util.get_peers()
results = util.send_request(servers, 'blockchain.headers.subscribe', [])
d = defaultdict(int)
for k, v in sorted(servers.items(), key=lambda x:x[1].get('version')):
print("%40s"%k, v.get('version'))
for k, r in results.items():
blocks = r.get('block_height')
d[blocks] += 1
for k, v in results.items():
print(k, v.get('block_height'))
v = list(d.values())
k = list(d.keys())
numblocks = k[v.index(max(v))]
print("blocks:", numblocks)

3
scripts/util.py

@ -1,5 +1,6 @@
import select, time, electrum, queue
from electrum import Connection, Interface, SimpleConfig
from electrum.network import filter_protocol, parse_servers
from collections import defaultdict
@ -60,8 +61,6 @@ def get_peers():
if responses:
response = responses[0][1] # One response, (req, response) tuple
peers = parse_servers(response.get('result'))
peers = filter_protocol(peers,'s')
#print(response)
return peers

Loading…
Cancel
Save