|
|
@ -78,6 +78,7 @@ def parse_servers(result): |
|
|
|
servers[host] = out |
|
|
|
return servers |
|
|
|
|
|
|
|
|
|
|
|
def filter_version(servers): |
|
|
|
def is_recent(version): |
|
|
|
try: |
|
|
@ -87,7 +88,7 @@ def filter_version(servers): |
|
|
|
return {k: v for k, v in servers.items() if is_recent(v.get('version'))} |
|
|
|
|
|
|
|
|
|
|
|
def filter_protocol(hostmap, protocol = 's'): |
|
|
|
def filter_protocol(hostmap, protocol='s'): |
|
|
|
'''Filters the hostmap for those implementing protocol. |
|
|
|
The result is a list in serialized form.''' |
|
|
|
eligible = [] |
|
|
@ -97,12 +98,14 @@ def filter_protocol(hostmap, protocol = 's'): |
|
|
|
eligible.append(serialize_server(host, port, protocol)) |
|
|
|
return eligible |
|
|
|
|
|
|
|
|
|
|
|
def pick_random_server(hostmap = None, protocol = 's', exclude_set = set()): |
|
|
|
if hostmap is None: |
|
|
|
hostmap = constants.net.DEFAULT_SERVERS |
|
|
|
eligible = list(set(filter_protocol(hostmap, protocol)) - exclude_set) |
|
|
|
return random.choice(eligible) if eligible else None |
|
|
|
|
|
|
|
|
|
|
|
from .simple_config import SimpleConfig |
|
|
|
|
|
|
|
proxy_modes = ['socks4', 'socks5', 'http'] |
|
|
@ -201,7 +204,7 @@ class Network(util.DaemonThread): |
|
|
|
self.pending_sends = [] |
|
|
|
self.message_id = 0 |
|
|
|
self.debug = False |
|
|
|
self.irc_servers = {} # returned by interface (list from irc) |
|
|
|
self.irc_servers = {} # returned by interface (list from irc) |
|
|
|
self.recent_servers = self.read_recent_servers() # note: needs self.recent_servers_lock |
|
|
|
|
|
|
|
self.banner = '' |
|
|
@ -213,7 +216,7 @@ class Network(util.DaemonThread): |
|
|
|
# callbacks set by the GUI |
|
|
|
self.callbacks = defaultdict(list) # note: needs self.callback_lock |
|
|
|
|
|
|
|
dir_path = os.path.join( self.config.path, 'certs') |
|
|
|
dir_path = os.path.join(self.config.path, 'certs') |
|
|
|
util.make_dir(dir_path) |
|
|
|
|
|
|
|
# subscriptions and requests |
|
|
@ -312,9 +315,6 @@ class Network(util.DaemonThread): |
|
|
|
def is_connecting(self): |
|
|
|
return self.connection_status == 'connecting' |
|
|
|
|
|
|
|
def is_up_to_date(self): |
|
|
|
return self.unanswered_requests == {} |
|
|
|
|
|
|
|
@with_interface_lock |
|
|
|
def queue_request(self, method, params, interface=None): |
|
|
|
# If you want to queue a request on any interface it must go |
|
|
@ -406,7 +406,7 @@ class Network(util.DaemonThread): |
|
|
|
except: |
|
|
|
continue |
|
|
|
if host not in out: |
|
|
|
out[host] = { protocol:port } |
|
|
|
out[host] = {protocol: port} |
|
|
|
return out |
|
|
|
|
|
|
|
@with_interface_lock |
|
|
@ -416,7 +416,7 @@ class Network(util.DaemonThread): |
|
|
|
self.print_error("connecting to %s as new interface" % server) |
|
|
|
self.set_status('connecting') |
|
|
|
self.connecting.add(server) |
|
|
|
c = Connection(server, self.socket_queue, self.config.path) |
|
|
|
Connection(server, self.socket_queue, self.config.path) |
|
|
|
|
|
|
|
def start_random_interface(self): |
|
|
|
with self.interface_lock: |
|
|
@ -553,7 +553,7 @@ class Network(util.DaemonThread): |
|
|
|
if self.server_is_lagging() and self.auto_connect: |
|
|
|
# switch to one that has the correct header (not height) |
|
|
|
header = self.blockchain().read_header(self.get_local_height()) |
|
|
|
filtered = list(map(lambda x:x[0], filter(lambda x: x[1].tip_header==header, self.interfaces.items()))) |
|
|
|
filtered = list(map(lambda x: x[0], filter(lambda x: x[1].tip_header == header, self.interfaces.items()))) |
|
|
|
if filtered: |
|
|
|
choice = random.choice(filtered) |
|
|
|
self.switch_to_interface(choice) |
|
|
@ -569,6 +569,7 @@ class Network(util.DaemonThread): |
|
|
|
self.interface = None |
|
|
|
self.start_interface(server) |
|
|
|
return |
|
|
|
|
|
|
|
i = self.interfaces[server] |
|
|
|
if self.interface != i: |
|
|
|
self.print_error("switching to", server) |
|
|
@ -601,7 +602,7 @@ class Network(util.DaemonThread): |
|
|
|
|
|
|
|
def process_response(self, interface, response, callbacks): |
|
|
|
if self.debug: |
|
|
|
self.print_error("<--", response) |
|
|
|
self.print_error(interface.host, "<--", response) |
|
|
|
error = response.get('error') |
|
|
|
result = response.get('result') |
|
|
|
method = response.get('method') |
|
|
@ -798,6 +799,7 @@ class Network(util.DaemonThread): |
|
|
|
server, socket = self.socket_queue.get() |
|
|
|
if server in self.connecting: |
|
|
|
self.connecting.remove(server) |
|
|
|
|
|
|
|
if socket: |
|
|
|
self.new_interface(server, socket) |
|
|
|
else: |
|
|
@ -1008,6 +1010,7 @@ class Network(util.DaemonThread): |
|
|
|
interface.mode = 'default' |
|
|
|
interface.request = None |
|
|
|
self.notify('updated') |
|
|
|
|
|
|
|
# refresh network dialog |
|
|
|
self.notify('interfaces') |
|
|
|
|
|
|
|