From 2aa7b932bba7813f85062d557c96f8ba6e58cbfa Mon Sep 17 00:00:00 2001 From: JeremyRand Date: Fri, 20 Sep 2019 18:57:53 +0000 Subject: [PATCH] Use SOCKSRandomAuth for stream isolation Cherry-picked from e20dd76d5b6550f495c63d209d876cdb37031236 --- electrum/gui/qt/network_dialog.py | 11 +++++++++-- electrum/interface.py | 6 ++++-- electrum/network.py | 14 +++++++++++++- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/electrum/gui/qt/network_dialog.py b/electrum/gui/qt/network_dialog.py index 92e3733d561e..4ab12a348ff0 100644 --- a/electrum/gui/qt/network_dialog.py +++ b/electrum/gui/qt/network_dialog.py @@ -271,18 +271,21 @@ def __init__(self, network: Network, config, wizard=False): self.proxy_password.setPlaceholderText(_("Password")) self.proxy_password.setEchoMode(QLineEdit.Password) self.proxy_password.setFixedWidth(fixed_width_port) + self.proxy_isolate = QCheckBox(_("Use stream isolation")) self.proxy_mode.currentIndexChanged.connect(self.set_proxy) self.proxy_host.editingFinished.connect(self.set_proxy) self.proxy_port.editingFinished.connect(self.set_proxy) self.proxy_user.editingFinished.connect(self.set_proxy) self.proxy_password.editingFinished.connect(self.set_proxy) + self.proxy_isolate.clicked.connect(self.set_proxy) self.proxy_mode.currentIndexChanged.connect(self.proxy_settings_changed) self.proxy_host.textEdited.connect(self.proxy_settings_changed) self.proxy_port.textEdited.connect(self.proxy_settings_changed) self.proxy_user.textEdited.connect(self.proxy_settings_changed) self.proxy_password.textEdited.connect(self.proxy_settings_changed) + self.proxy_isolate.clicked.connect(self.proxy_settings_changed) self.tor_cb = QCheckBox(_("Use Tor Proxy")) self.tor_cb.setIcon(read_QIcon("tor_logo.png")) @@ -297,6 +300,7 @@ def __init__(self, network: Network, config, wizard=False): grid.addWidget(self.proxy_port, 4, 3) grid.addWidget(self.proxy_user, 5, 2) grid.addWidget(self.proxy_password, 5, 3) + grid.addWidget(self.proxy_isolate, 6, 2) grid.setRowStretch(7, 1) # Blockchain Tab @@ -342,7 +346,7 @@ def __init__(self, network: Network, config, wizard=False): def check_disable_proxy(self, b): if not self.config.is_modifiable('proxy'): b = False - for w in [self.proxy_mode, self.proxy_host, self.proxy_port, self.proxy_user, self.proxy_password]: + for w in [self.proxy_mode, self.proxy_host, self.proxy_port, self.proxy_user, self.proxy_password, self.proxy_isolate]: w.setEnabled(b) def enable_set_server(self): @@ -407,6 +411,7 @@ def fill_in_proxy_settings(self): self.proxy_port.setText(proxy_config.get("port")) self.proxy_user.setText(proxy_config.get("user", "")) self.proxy_password.setText(proxy_config.get("password", "")) + self.proxy_isolate.setChecked(proxy_config.get("isolate", True)) def layout(self): return self.layout_ @@ -474,7 +479,8 @@ def set_proxy(self): 'host':str(self.proxy_host.text()), 'port':str(self.proxy_port.text()), 'user':str(self.proxy_user.text()), - 'password':str(self.proxy_password.text())} + 'password':str(self.proxy_password.text()), + 'isolate':self.proxy_isolate.isChecked()} else: proxy = None self.tor_cb.setChecked(False) @@ -507,6 +513,7 @@ def use_tor_proxy(self, use_it): self.proxy_port.setText(str(self.tor_proxy[1])) self.proxy_user.setText("") self.proxy_password.setText("") + self.proxy_isolate.setChecked(True) self.tor_cb.setChecked(True) self.proxy_cb.setChecked(True) self.check_disable_proxy(use_it) diff --git a/electrum/interface.py b/electrum/interface.py index 0f4129f39e9a..9cf0d5a0b5b4 100644 --- a/electrum/interface.py +++ b/electrum/interface.py @@ -250,8 +250,10 @@ def diagnostic_name(self): def _set_proxy(self, proxy: dict): if proxy: - username, pw = proxy.get('user'), proxy.get('password') - if not username or not pw: + username, pw, isolate = proxy.get('user'), proxy.get('password'), proxy.get('isolate') + if isolate: + auth = aiorpcx.socks.SOCKSRandomAuth() + elif not username or not pw: auth = None else: auth = aiorpcx.socks.SOCKSUserAuth(username, pw) diff --git a/electrum/network.py b/electrum/network.py index dd66209f4315..ef2f6ae4637d 100644 --- a/electrum/network.py +++ b/electrum/network.py @@ -149,7 +149,8 @@ def serialize_proxy(p): if not isinstance(p, dict): return None return ':'.join([p.get('mode'), p.get('host'), p.get('port'), - p.get('user', ''), p.get('password', '')]) + p.get('user', ''), p.get('password', ''), + ('1' if p.get('isolate', True) else '0')]) def deserialize_proxy(s: str) -> Optional[dict]: @@ -177,6 +178,17 @@ def deserialize_proxy(s: str) -> Optional[dict]: n += 1 if len(args) > n: proxy["password"] = args[n] + n += 1 + if len(args) > n: + isolate = args[n] + if isolate == "0": + proxy["isolate"] = False + elif isolate == "1": + proxy["isolate"] = True + else: + raise Exception("Couldn't parse proxy isolation setting: " + isolate) + else: + proxy["isolate"] = True return proxy