Browse Source

implement oneserver option for kivy

closes #4826
3.3.3.1
SomberNight 6 years ago
parent
commit
160bc93e26
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 9
      electrum/gui/kivy/main_window.py
  2. 7
      electrum/gui/kivy/uix/ui_screens/network.kv
  3. 16
      electrum/network.py
  4. 2
      setup.py

9
electrum/gui/kivy/main_window.py

@ -101,6 +101,14 @@ class ElectrumWindow(App):
def toggle_auto_connect(self, x): def toggle_auto_connect(self, x):
self.auto_connect = not self.auto_connect self.auto_connect = not self.auto_connect
oneserver = BooleanProperty(False)
def on_oneserver(self, instance, x):
net_params = self.network.get_parameters()
net_params = net_params._replace(oneserver=self.oneserver)
self.network.run_from_another_thread(self.network.set_parameters(net_params))
def toggle_oneserver(self, x):
self.oneserver = not self.oneserver
def choose_server_dialog(self, popup): def choose_server_dialog(self, popup):
from .uix.dialogs.choice_dialog import ChoiceDialog from .uix.dialogs.choice_dialog import ChoiceDialog
protocol = 's' protocol = 's'
@ -275,6 +283,7 @@ class ElectrumWindow(App):
self.server_host = net_params.host self.server_host = net_params.host
self.server_port = net_params.port self.server_port = net_params.port
self.auto_connect = net_params.auto_connect self.auto_connect = net_params.auto_connect
self.oneserver = net_params.oneserver
self.proxy_config = net_params.proxy if net_params.proxy else {} self.proxy_config = net_params.proxy if net_params.proxy else {}
self.plugins = kwargs.get('plugins', []) self.plugins = kwargs.get('plugins', [])

7
electrum/gui/kivy/uix/ui_screens/network.kv

@ -37,6 +37,13 @@ Popup:
description: _("Select your server automatically") description: _("Select your server automatically")
action: app.toggle_auto_connect action: app.toggle_auto_connect
CardSeparator
SettingsItem:
title: _("One-server mode") + ': ' + ('ON' if app.oneserver else 'OFF')
description: _("Only connect to a single server")
action: app.toggle_oneserver
disabled: app.auto_connect and not app.oneserver
CardSeparator CardSeparator
SettingsItem: SettingsItem:
value: "%d blocks" % app.num_blocks value: "%d blocks" % app.num_blocks

16
electrum/network.py

@ -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():

2
setup.py

@ -12,7 +12,7 @@ import subprocess
from setuptools import setup, find_packages from setuptools import setup, find_packages
from setuptools.command.install import install from setuptools.command.install import install
MIN_PYTHON_VERSION = "3.6" MIN_PYTHON_VERSION = "3.6.1"
_min_python_version_tuple = tuple(map(int, (MIN_PYTHON_VERSION.split(".")))) _min_python_version_tuple = tuple(map(int, (MIN_PYTHON_VERSION.split("."))))

Loading…
Cancel
Save