refactor network constants
This commit is contained in:
@@ -37,6 +37,7 @@ import socks
|
||||
from . import util
|
||||
from . import bitcoin
|
||||
from .bitcoin import *
|
||||
from . import constants
|
||||
from .interface import Connection, Interface
|
||||
from . import blockchain
|
||||
from .version import ELECTRUM_VERSION, PROTOCOL_VERSION
|
||||
@@ -60,7 +61,7 @@ def parse_servers(result):
|
||||
for v in item[2]:
|
||||
if re.match("[st]\d*", v):
|
||||
protocol, port = v[0], v[1:]
|
||||
if port == '': port = bitcoin.NetworkConstants.DEFAULT_PORTS[protocol]
|
||||
if port == '': port = constants.net.DEFAULT_PORTS[protocol]
|
||||
out[protocol] = port
|
||||
elif re.match("v(.?)+", v):
|
||||
version = v[1:]
|
||||
@@ -94,7 +95,7 @@ def filter_protocol(hostmap, protocol = 's'):
|
||||
|
||||
def pick_random_server(hostmap = None, protocol = 's', exclude_set = set()):
|
||||
if hostmap is None:
|
||||
hostmap = bitcoin.NetworkConstants.DEFAULT_SERVERS
|
||||
hostmap = constants.net.DEFAULT_SERVERS
|
||||
eligible = list(set(filter_protocol(hostmap, protocol)) - exclude_set)
|
||||
return random.choice(eligible) if eligible else None
|
||||
|
||||
@@ -364,7 +365,7 @@ class Network(util.DaemonThread):
|
||||
return list(self.interfaces.keys())
|
||||
|
||||
def get_servers(self):
|
||||
out = bitcoin.NetworkConstants.DEFAULT_SERVERS
|
||||
out = constants.net.DEFAULT_SERVERS
|
||||
if self.irc_servers:
|
||||
out.update(filter_version(self.irc_servers.copy()))
|
||||
else:
|
||||
@@ -967,7 +968,7 @@ class Network(util.DaemonThread):
|
||||
def init_headers_file(self):
|
||||
b = self.blockchains[0]
|
||||
filename = b.path()
|
||||
length = 80 * len(bitcoin.NetworkConstants.CHECKPOINTS) * 2016
|
||||
length = 80 * len(constants.net.CHECKPOINTS) * 2016
|
||||
if not os.path.exists(filename) or os.path.getsize(filename) < length:
|
||||
with open(filename, 'wb') as f:
|
||||
if length>0:
|
||||
@@ -1092,4 +1093,4 @@ class Network(util.DaemonThread):
|
||||
f.write(json.dumps(cp, indent=4))
|
||||
|
||||
def max_checkpoint(self):
|
||||
return max(0, len(bitcoin.NetworkConstants.CHECKPOINTS) * 2016 - 1)
|
||||
return max(0, len(constants.net.CHECKPOINTS) * 2016 - 1)
|
||||
|
||||
Reference in New Issue
Block a user