Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qml: show option for single server in ServerConfig #9243

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions electrum/gui/qml/components/ServerConfigDialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ ElDialog {
onClicked: {
Config.autoConnect = serverconfig.auto_connect
Network.server = serverconfig.address
Network.oneServer = serverconfig.auto_connect
? false
: serverconfig.one_server
rootItem.close()
}
}
Expand Down
20 changes: 19 additions & 1 deletion electrum/gui/qml/components/controls/ServerConfig.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Item {
property bool showAutoselectServer: true
property alias auto_connect: auto_server_cb.checked
property alias address: address_tf.text
property alias one_server: one_server_cb.checked

implicitHeight: rootLayout.height

Expand All @@ -26,7 +27,7 @@ Item {
id: auto_server_cb
visible: showAutoselectServer
text: qsTr('Select server automatically')
checked: true
checked: !showAutoselectServer
}

Label {
Expand All @@ -45,6 +46,22 @@ Item {
}
}

RowLayout {
Layout.fillWidth: true
visible: !auto_server_cb.checked && address_tf.text

CheckBox {
id: one_server_cb
Layout.fillWidth: true
text: qsTr('One server')
}

HelpButton {
heading: qsTr('One server')
helptext: qsTr('Connect only to a single Electrum Server. This can help with privacy, but at the cost of detecting lagging and forks')
}
}

ColumnLayout {
Heading {
text: qsTr('Servers')
Expand Down Expand Up @@ -96,6 +113,7 @@ Item {
Component.onCompleted: {
root.auto_connect = Config.autoConnectDefined ? Config.autoConnect : false
root.address = Network.server
one_server_cb.checked = Network.oneServer
// TODO: initial setup should not connect already, is Network.server defined?
}
}
1 change: 1 addition & 0 deletions electrum/gui/qml/components/wizard/WCServerConfig.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ WizardComponent {
function apply() {
wizard_data['autoconnect'] = sc.address.trim() == ""
wizard_data['server'] = sc.address
wizard_data['one_server'] = sc.one_server
}

ColumnLayout {
Expand Down
12 changes: 12 additions & 0 deletions electrum/gui/qml/qenetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,18 @@ def proxy(self, proxy_settings):
def isProxyTor(self):
return bool(self.network.is_proxy_tor)

@pyqtProperty(bool, notify=statusChanged)
def oneServer(self):
return self.network.oneserver

@oneServer.setter
def oneServer(self, one_server: bool):
if one_server != self.network.oneserver:
net_params = self.network.get_parameters()
net_params = net_params._replace(oneserver=one_server)
self.network.run_from_another_thread(self.network.set_parameters(net_params))
self.statusChanged.emit()

@pyqtProperty('QVariant', notify=feeHistogramUpdated)
def feeHistogram(self):
return self._fee_histogram
Expand Down
1 change: 1 addition & 0 deletions electrum/gui/qt/wizard/server_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,4 @@ def __init__(self, parent, wizard):
def apply(self):
self.wizard_data['autoconnect'] = self.sw.server_e.text().strip() == ''
self.wizard_data['server'] = self.sw.server_e.text()
self.wizard_data['one_server'] = self.wizard.config.NETWORK_ONESERVER
15 changes: 14 additions & 1 deletion electrum/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,13 @@ def get_parameters(self) -> NetworkParameters:
def _init_parameters_from_config(self) -> None:
dns_hacks.configure_dns_resolver()
self.auto_connect = self.config.NETWORK_AUTO_CONNECT
if self.auto_connect and self.config.NETWORK_ONESERVER:
# enabling both oneserver and auto_connect doesn't really make sense
# assume oneserver is enabled for privacy reasons, disable auto_connect and assume server is unpredictable
self.logger.warning(f'both "oneserver" and "auto_connect" options enabled, disabling "auto_connect" and resetting "server".')
self.config.NETWORK_SERVER = "" # let _set_default_server set harmless default (localhost)
self.auto_connect = False

self._set_default_server()
self._set_proxy(deserialize_proxy(self.config.NETWORK_PROXY, self.config.NETWORK_PROXY_USER,
self.config.NETWORK_PROXY_PASSWORD))
Expand Down Expand Up @@ -639,7 +646,12 @@ def _set_default_server(self) -> None:
self.logger.warning(f'failed to parse server-string ({server!r}); falling back to localhost:1:s.')
self.default_server = ServerAddr.from_str("localhost:1:s")
else:
self.default_server = pick_random_server(allowed_protocols=self._allowed_protocols)
# if oneserver is enabled but no server specified then don't pick a random server
if self.config.NETWORK_ONESERVER:
self.logger.warning(f'"oneserver" option enabled, but no "server" defined; falling back to localhost:1:s.')
self.default_server = ServerAddr.from_str("localhost:1:s")
else:
self.default_server = pick_random_server(allowed_protocols=self._allowed_protocols)
assert isinstance(self.default_server, ServerAddr), f"invalid type for default_server: {self.default_server!r}"

def _set_proxy(self, proxy: Optional[dict]):
Expand Down Expand Up @@ -684,6 +696,7 @@ async def set_parameters(self, net_params: NetworkParameters):
int(proxy['port'])
except Exception:
return

self.config.NETWORK_AUTO_CONNECT = net_params.auto_connect
self.config.NETWORK_ONESERVER = net_params.oneserver
self.config.NETWORK_PROXY = proxy_str
Expand Down
3 changes: 2 additions & 1 deletion electrum/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,14 +704,15 @@ def do_configure_server(self, wizard_data: dict):
self._logger.debug(f'configuring server: {wizard_data!r}')
net_params = self._daemon.network.get_parameters()
server = ''
oneserver = wizard_data.get('one_server', False)
if not wizard_data['autoconnect']:
try:
server = ServerAddr.from_str_with_inference(wizard_data['server'])
if not server:
raise Exception('failed to parse server %s' % wizard_data['server'])
except Exception:
return
net_params = net_params._replace(server=server, auto_connect=wizard_data['autoconnect'])
net_params = net_params._replace(server=server, auto_connect=wizard_data['autoconnect'], oneserver=oneserver)
self._daemon.network.run_from_another_thread(self._daemon.network.set_parameters(net_params))

def do_configure_autoconnect(self, wizard_data: dict):
Expand Down