|
@ -116,6 +116,7 @@ class NetworkParameters(NamedTuple): |
|
|
protocol: str |
|
|
protocol: str |
|
|
proxy: Optional[dict] |
|
|
proxy: Optional[dict] |
|
|
auto_connect: bool |
|
|
auto_connect: bool |
|
|
|
|
|
oneserver: bool = False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proxy_modes = ['socks4', 'socks5'] |
|
|
proxy_modes = ['socks4', 'socks5'] |
|
@ -176,7 +177,6 @@ class Network(PrintError): |
|
|
if config is None: |
|
|
if config is None: |
|
|
config = {} # Do not use mutables as default values! |
|
|
config = {} # Do not use mutables as default values! |
|
|
self.config = SimpleConfig(config) if isinstance(config, dict) else config # type: SimpleConfig |
|
|
self.config = SimpleConfig(config) if isinstance(config, dict) else config # type: SimpleConfig |
|
|
self.num_server = 10 if not self.config.get('oneserver') else 0 |
|
|
|
|
|
blockchain.blockchains = blockchain.read_blockchains(self.config) |
|
|
blockchain.blockchains = blockchain.read_blockchains(self.config) |
|
|
self.print_error("blockchains", list(blockchain.blockchains)) |
|
|
self.print_error("blockchains", list(blockchain.blockchains)) |
|
|
self._blockchain_preferred_block = self.config.get('blockchain_preferred_block', None) # type: Optional[Dict] |
|
|
self._blockchain_preferred_block = self.config.get('blockchain_preferred_block', None) # type: Optional[Dict] |
|
@ -386,7 +386,8 @@ class Network(PrintError): |
|
|
port=port, |
|
|
port=port, |
|
|
protocol=protocol, |
|
|
protocol=protocol, |
|
|
proxy=self.proxy, |
|
|
proxy=self.proxy, |
|
|
auto_connect=self.auto_connect) |
|
|
auto_connect=self.auto_connect, |
|
|
|
|
|
oneserver=self.oneserver) |
|
|
|
|
|
|
|
|
def get_donation_address(self): |
|
|
def get_donation_address(self): |
|
|
if self.is_connected(): |
|
|
if self.is_connected(): |
|
@ -496,16 +497,18 @@ class Network(PrintError): |
|
|
except: |
|
|
except: |
|
|
return |
|
|
return |
|
|
self.config.set_key('auto_connect', net_params.auto_connect, False) |
|
|
self.config.set_key('auto_connect', net_params.auto_connect, False) |
|
|
|
|
|
self.config.set_key('oneserver', net_params.oneserver, False) |
|
|
self.config.set_key('proxy', proxy_str, False) |
|
|
self.config.set_key('proxy', proxy_str, False) |
|
|
self.config.set_key('server', server_str, True) |
|
|
self.config.set_key('server', server_str, True) |
|
|
# abort if changes were not allowed by config |
|
|
# abort if changes were not allowed by config |
|
|
if self.config.get('server') != server_str \ |
|
|
if self.config.get('server') != server_str \ |
|
|
or self.config.get('proxy') != proxy_str: |
|
|
or self.config.get('proxy') != proxy_str \ |
|
|
|
|
|
or self.config.get('oneserver') != net_params.oneserver: |
|
|
return |
|
|
return |
|
|
|
|
|
|
|
|
async with self.restart_lock: |
|
|
async with self.restart_lock: |
|
|
self.auto_connect = net_params.auto_connect |
|
|
self.auto_connect = net_params.auto_connect |
|
|
if self.proxy != proxy or self.protocol != protocol: |
|
|
if self.proxy != proxy or self.protocol != protocol or self.oneserver != net_params.oneserver: |
|
|
# Restart the network defaulting to the given server |
|
|
# Restart the network defaulting to the given server |
|
|
await self._stop() |
|
|
await self._stop() |
|
|
self.default_server = server_str |
|
|
self.default_server = server_str |
|
@ -515,6 +518,10 @@ class Network(PrintError): |
|
|
else: |
|
|
else: |
|
|
await self.switch_lagging_interface() |
|
|
await self.switch_lagging_interface() |
|
|
|
|
|
|
|
|
|
|
|
def _set_oneserver(self, oneserver: bool): |
|
|
|
|
|
self.num_server = 10 if not oneserver else 0 |
|
|
|
|
|
self.oneserver = oneserver |
|
|
|
|
|
|
|
|
async def _switch_to_random_interface(self): |
|
|
async def _switch_to_random_interface(self): |
|
|
'''Switch to a random connected server other than the current one''' |
|
|
'''Switch to a random connected server other than the current one''' |
|
|
servers = self.get_interfaces() # Those in connected state |
|
|
servers = self.get_interfaces() # Those in connected state |
|
@ -808,6 +815,7 @@ class Network(PrintError): |
|
|
self.protocol = deserialize_server(self.default_server)[2] |
|
|
self.protocol = deserialize_server(self.default_server)[2] |
|
|
self.server_queue = queue.Queue() |
|
|
self.server_queue = queue.Queue() |
|
|
self._set_proxy(deserialize_proxy(self.config.get('proxy'))) |
|
|
self._set_proxy(deserialize_proxy(self.config.get('proxy'))) |
|
|
|
|
|
self._set_oneserver(self.config.get('oneserver')) |
|
|
self._start_interface(self.default_server) |
|
|
self._start_interface(self.default_server) |
|
|
|
|
|
|
|
|
async def main(): |
|
|
async def main(): |
|
|