|
@ -50,9 +50,13 @@ class Network(threading.Thread): |
|
|
self.interfaces = {} |
|
|
self.interfaces = {} |
|
|
self.queue = Queue.Queue() |
|
|
self.queue = Queue.Queue() |
|
|
self.default_server = self.config.get('server') |
|
|
self.default_server = self.config.get('server') |
|
|
self.disconnected_servers = [] |
|
|
|
|
|
self.callbacks = {} |
|
|
self.callbacks = {} |
|
|
self.servers = [] |
|
|
|
|
|
|
|
|
self.protocol = 's' |
|
|
|
|
|
self.irc_servers = [] # returned by interface (list from irc) |
|
|
|
|
|
self.disconnected_servers = [] |
|
|
|
|
|
self.recent_servers = self.config.get('recent_servers',[]) # successful connections |
|
|
|
|
|
|
|
|
self.banner = '' |
|
|
self.banner = '' |
|
|
self.interface = None |
|
|
self.interface = None |
|
|
self.proxy = self.config.get('proxy') |
|
|
self.proxy = self.config.get('proxy') |
|
@ -105,7 +109,7 @@ class Network(threading.Thread): |
|
|
|
|
|
|
|
|
def random_server(self): |
|
|
def random_server(self): |
|
|
choice_list = [] |
|
|
choice_list = [] |
|
|
l = filter_protocol(self.get_servers(), 's') |
|
|
l = filter_protocol(self.get_servers(), self.protocol) |
|
|
for s in l: |
|
|
for s in l: |
|
|
if s in self.disconnected_servers or s in self.interfaces.keys(): |
|
|
if s in self.disconnected_servers or s in self.interfaces.keys(): |
|
|
continue |
|
|
continue |
|
@ -123,11 +127,12 @@ class Network(threading.Thread): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_servers(self): |
|
|
def get_servers(self): |
|
|
if not self.servers: |
|
|
out = self.irc_servers if self.irc_servers else DEFAULT_SERVERS |
|
|
return DEFAULT_SERVERS |
|
|
for s in self.recent_servers: |
|
|
else: |
|
|
host, port, protocol = s.split(':') |
|
|
return self.servers |
|
|
if host not in out: |
|
|
|
|
|
out[host] = { protocol:port } |
|
|
|
|
|
return out |
|
|
|
|
|
|
|
|
def start_interface(self, server): |
|
|
def start_interface(self, server): |
|
|
if server in self.interfaces.keys(): |
|
|
if server in self.interfaces.keys(): |
|
@ -184,6 +189,14 @@ class Network(threading.Thread): |
|
|
self.interface = self.interfaces[server] |
|
|
self.interface = self.interfaces[server] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def add_recent_server(self, i): |
|
|
|
|
|
# list is ordered |
|
|
|
|
|
s = i.server |
|
|
|
|
|
if s in self.recent_servers: |
|
|
|
|
|
self.recent_servers.remove(s) |
|
|
|
|
|
self.recent_servers.insert(0,s) |
|
|
|
|
|
self.recent_servers = self.recent_servers[0:20] |
|
|
|
|
|
self.config.set_key('recent_servers', self.recent_servers) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -202,6 +215,7 @@ class Network(threading.Thread): |
|
|
continue |
|
|
continue |
|
|
|
|
|
|
|
|
if i.is_connected: |
|
|
if i.is_connected: |
|
|
|
|
|
self.add_recent_server(i) |
|
|
i.send([ ('blockchain.headers.subscribe',[])], self.on_header) |
|
|
i.send([ ('blockchain.headers.subscribe',[])], self.on_header) |
|
|
if i == self.interface: |
|
|
if i == self.interface: |
|
|
print_error('sending subscriptions to', self.interface.server) |
|
|
print_error('sending subscriptions to', self.interface.server) |
|
@ -230,7 +244,7 @@ class Network(threading.Thread): |
|
|
|
|
|
|
|
|
def on_peers(self, i, r): |
|
|
def on_peers(self, i, r): |
|
|
if not r: return |
|
|
if not r: return |
|
|
self.servers = self.parse_servers(r.get('result')) |
|
|
self.irc_servers = self.parse_servers(r.get('result')) |
|
|
self.trigger_callback('peers') |
|
|
self.trigger_callback('peers') |
|
|
|
|
|
|
|
|
def on_banner(self, i, r): |
|
|
def on_banner(self, i, r): |
|
|