|
|
@ -68,19 +68,19 @@ def parse_servers(result): |
|
|
|
|
|
|
|
return servers |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def filter_protocol(servers, p): |
|
|
|
l = [] |
|
|
|
for k, protocols in servers.items(): |
|
|
|
if p in protocols: |
|
|
|
s = serialize_server(k, protocols[p], p) |
|
|
|
l.append(s) |
|
|
|
return l |
|
|
|
|
|
|
|
|
|
|
|
def pick_random_server(p='s'): |
|
|
|
return random.choice( filter_protocol(DEFAULT_SERVERS,p) ) |
|
|
|
def filter_protocol(hostmap = DEFAULT_SERVERS, protocol = 's'): |
|
|
|
'''Filters the hostmap for those implementing protocol. |
|
|
|
The result is a list in serialized form.''' |
|
|
|
eligible = [] |
|
|
|
for host, portmap in hostmap.items(): |
|
|
|
port = portmap.get(protocol) |
|
|
|
if port: |
|
|
|
eligible.append(serialize_server(host, port, protocol)) |
|
|
|
return eligible |
|
|
|
|
|
|
|
def pick_random_server(hostmap = DEFAULT_SERVERS, protocol = 's', exclude_set = set()): |
|
|
|
eligible = list(set(filter_protocol(hostmap, protocol)) - exclude_set) |
|
|
|
return random.choice(eligible) if eligible else None |
|
|
|
|
|
|
|
from simple_config import SimpleConfig |
|
|
|
|
|
|
@ -149,7 +149,7 @@ class Network(util.DaemonThread): |
|
|
|
except: |
|
|
|
self.default_server = None |
|
|
|
if not self.default_server: |
|
|
|
self.default_server = pick_random_server('s') |
|
|
|
self.default_server = pick_random_server() |
|
|
|
|
|
|
|
self.irc_servers = {} # returned by interface (list from irc) |
|
|
|
self.recent_servers = self.read_recent_servers() |
|
|
@ -247,21 +247,6 @@ class Network(util.DaemonThread): |
|
|
|
value = self.get_status_value(key) |
|
|
|
self.response_queue.put({'method':'network.status', 'params':[key, value]}) |
|
|
|
|
|
|
|
def random_server(self): |
|
|
|
choice_list = [] |
|
|
|
l = filter_protocol(self.get_servers(), self.protocol) |
|
|
|
for s in l: |
|
|
|
if s in self.pending_servers or s in self.disconnected_servers or s in self.interfaces.keys(): |
|
|
|
continue |
|
|
|
else: |
|
|
|
choice_list.append(s) |
|
|
|
|
|
|
|
if not choice_list: |
|
|
|
return |
|
|
|
|
|
|
|
server = random.choice( choice_list ) |
|
|
|
return server |
|
|
|
|
|
|
|
def get_parameters(self): |
|
|
|
host, port, protocol = deserialize_server(self.default_server) |
|
|
|
auto_connect = self.config.get('auto_cycle', True) |
|
|
@ -293,7 +278,8 @@ class Network(util.DaemonThread): |
|
|
|
i.start() |
|
|
|
|
|
|
|
def start_random_interface(self): |
|
|
|
server = self.random_server() |
|
|
|
exclude_set = self.disconnected_servers.union(self.pending_servers).union(set(self.interfaces)) |
|
|
|
server = pick_random_server(self.get_servers(), self.protocol, exclude_set) |
|
|
|
if server: |
|
|
|
self.start_interface(server) |
|
|
|
|
|
|
|