2013-04-28 04:47:19 -07:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# Electrum - lightweight Bitcoin client
|
|
|
|
# Copyright (C) 2012 thomasv@gitorious
|
|
|
|
#
|
2016-02-23 02:36:42 -08:00
|
|
|
# Permission is hereby granted, free of charge, to any person
|
|
|
|
# obtaining a copy of this software and associated documentation files
|
|
|
|
# (the "Software"), to deal in the Software without restriction,
|
|
|
|
# including without limitation the rights to use, copy, modify, merge,
|
|
|
|
# publish, distribute, sublicense, and/or sell copies of the Software,
|
|
|
|
# and to permit persons to whom the Software is furnished to do so,
|
|
|
|
# subject to the following conditions:
|
2013-04-28 04:47:19 -07:00
|
|
|
#
|
2016-02-23 02:36:42 -08:00
|
|
|
# The above copyright notice and this permission notice shall be
|
|
|
|
# included in all copies or substantial portions of the Software.
|
2013-04-28 04:47:19 -07:00
|
|
|
#
|
2016-02-23 02:36:42 -08:00
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
# SOFTWARE.
|
2017-02-17 04:56:23 -08:00
|
|
|
import socket
|
2013-04-28 04:47:19 -07:00
|
|
|
|
|
|
|
from PyQt4.QtGui import *
|
|
|
|
from PyQt4.QtCore import *
|
2015-10-28 04:10:43 -07:00
|
|
|
|
|
|
|
from electrum.i18n import _
|
2017-01-07 08:25:09 -08:00
|
|
|
from electrum.network import DEFAULT_PORTS
|
2015-10-28 04:10:43 -07:00
|
|
|
from electrum.network import serialize_server, deserialize_server
|
2013-04-28 04:47:19 -07:00
|
|
|
|
2013-09-24 01:06:03 -07:00
|
|
|
from util import *
|
2013-04-28 04:47:19 -07:00
|
|
|
|
2014-09-19 01:46:18 -07:00
|
|
|
protocol_names = ['TCP', 'SSL']
|
|
|
|
protocol_letters = 'ts'
|
2013-04-28 04:47:19 -07:00
|
|
|
|
2015-12-22 05:23:51 -08:00
|
|
|
class NetworkDialog(WindowModalDialog):
|
2013-09-10 09:27:32 -07:00
|
|
|
def __init__(self, network, config, parent):
|
2015-12-22 05:23:51 -08:00
|
|
|
WindowModalDialog.__init__(self, parent, _('Network'))
|
2017-02-17 04:56:23 -08:00
|
|
|
self.setMinimumSize(400, 20)
|
2016-01-13 03:34:42 -08:00
|
|
|
self.nlayout = NetworkChoiceLayout(network, config)
|
|
|
|
vbox = QVBoxLayout(self)
|
2016-01-13 04:25:48 -08:00
|
|
|
vbox.addLayout(self.nlayout.layout())
|
2016-01-13 03:34:42 -08:00
|
|
|
vbox.addLayout(Buttons(CancelButton(self), OkButton(self)))
|
|
|
|
|
|
|
|
def do_exec(self):
|
|
|
|
result = self.exec_()
|
|
|
|
if result:
|
|
|
|
self.nlayout.accept()
|
|
|
|
return result
|
2013-04-28 04:47:19 -07:00
|
|
|
|
2016-01-13 03:34:42 -08:00
|
|
|
|
|
|
|
class NetworkChoiceLayout(object):
|
|
|
|
def __init__(self, network, config, wizard=False):
|
2013-09-10 09:27:32 -07:00
|
|
|
self.network = network
|
2013-04-28 04:47:19 -07:00
|
|
|
self.config = config
|
|
|
|
self.protocol = None
|
2017-02-17 04:56:23 -08:00
|
|
|
self.tor_proxy = None
|
2013-04-28 04:47:19 -07:00
|
|
|
|
2014-07-25 00:11:56 -07:00
|
|
|
self.servers = network.get_servers()
|
|
|
|
host, port, protocol, proxy_config, auto_connect = network.get_parameters()
|
|
|
|
if not proxy_config:
|
2015-03-12 10:12:34 -07:00
|
|
|
proxy_config = { "mode":"none", "host":"localhost", "port":"9050"}
|
2014-07-25 00:11:56 -07:00
|
|
|
|
2016-01-13 03:34:42 -08:00
|
|
|
if not wizard:
|
2013-10-04 10:27:50 -07:00
|
|
|
if network.is_connected():
|
2017-03-23 13:53:03 -07:00
|
|
|
status = _("Server") + ": %s"%(host)
|
2013-09-10 10:59:58 -07:00
|
|
|
else:
|
2017-03-23 13:53:03 -07:00
|
|
|
status = _("Disconnected from server")
|
2013-04-28 04:47:19 -07:00
|
|
|
else:
|
2016-10-14 05:05:24 -07:00
|
|
|
status = _("Please choose a server.") + "\n" + _("Press 'Next' if you are offline.")
|
2013-04-28 04:47:19 -07:00
|
|
|
|
2017-03-23 13:53:03 -07:00
|
|
|
tabs = QTabWidget()
|
|
|
|
server_tab = QWidget()
|
2017-03-23 22:25:03 -07:00
|
|
|
proxy_tab = QWidget()
|
2017-03-23 13:53:03 -07:00
|
|
|
blockchain_tab = QWidget()
|
|
|
|
tabs.addTab(server_tab, _('Server'))
|
2017-03-23 22:25:03 -07:00
|
|
|
tabs.addTab(proxy_tab, _('Proxy'))
|
2017-03-23 13:53:03 -07:00
|
|
|
tabs.addTab(blockchain_tab, _('Blockchain'))
|
|
|
|
|
|
|
|
# server tab
|
|
|
|
grid = QGridLayout(server_tab)
|
2013-04-28 04:47:19 -07:00
|
|
|
grid.setSpacing(8)
|
|
|
|
|
2015-03-23 03:11:51 -07:00
|
|
|
# server
|
2013-04-28 04:47:19 -07:00
|
|
|
self.server_host = QLineEdit()
|
|
|
|
self.server_host.setFixedWidth(200)
|
|
|
|
self.server_port = QLineEdit()
|
|
|
|
self.server_port.setFixedWidth(60)
|
2016-01-03 08:47:02 -08:00
|
|
|
|
2017-03-23 22:25:03 -07:00
|
|
|
# use SSL
|
|
|
|
self.ssl_cb = QCheckBox(_('Use SSL'))
|
|
|
|
self.ssl_cb.setChecked(auto_connect)
|
|
|
|
self.ssl_cb.stateChanged.connect(self.change_protocol)
|
|
|
|
|
2013-10-05 02:49:36 -07:00
|
|
|
# auto connect
|
2016-01-03 08:47:02 -08:00
|
|
|
self.autoconnect_cb = QCheckBox(_('Select server automatically'))
|
2015-05-25 00:18:52 -07:00
|
|
|
self.autoconnect_cb.setChecked(auto_connect)
|
|
|
|
self.autoconnect_cb.setEnabled(self.config.is_modifiable('auto_connect'))
|
2017-03-23 13:53:03 -07:00
|
|
|
|
|
|
|
msg = _("Electrum sends your wallet addresses to a single server, in order to receive your transaction history.") + "\n\n" \
|
|
|
|
+ _("In addition, Electrum connects to several nodes in order to download block headers and find out the longest blockchain.") + " " \
|
|
|
|
+ _("This blockchain is used to verify the transactions sent by the address server.")
|
2017-03-23 22:25:03 -07:00
|
|
|
msg2 = _("If auto-connect is enabled, Electrum will always use a server that is on the longest blockchain.") + " " \
|
|
|
|
+ _("If it is disabled, you have to choose a server you want to use. Electrum will warn you if your server is lagging.")
|
2017-03-23 13:53:03 -07:00
|
|
|
|
|
|
|
grid.addWidget(QLabel(_('Server') + ':'), 0, 0)
|
|
|
|
grid.addWidget(self.server_host, 0, 1, 1, 2)
|
|
|
|
grid.addWidget(self.server_port, 0, 3)
|
|
|
|
grid.addWidget(HelpButton(msg), 0, 4)
|
2017-03-23 22:25:03 -07:00
|
|
|
grid.addWidget(self.ssl_cb, 1, 1, 1, 3)
|
|
|
|
grid.addWidget(self.autoconnect_cb, 2, 1, 1, 3)
|
|
|
|
grid.addWidget(HelpButton(msg2), 2, 4)
|
2014-07-28 00:28:02 -07:00
|
|
|
label = _('Active Servers') if network.is_connected() else _('Default Servers')
|
2016-01-13 03:34:42 -08:00
|
|
|
self.servers_list_widget = QTreeWidget()
|
2013-04-28 04:47:19 -07:00
|
|
|
self.servers_list_widget.setHeaderLabels( [ label, _('Limit') ] )
|
|
|
|
self.servers_list_widget.setMaximumHeight(150)
|
|
|
|
self.servers_list_widget.setColumnWidth(0, 240)
|
2017-03-23 22:25:03 -07:00
|
|
|
grid.addWidget(self.servers_list_widget, 3, 0, 1, 5)
|
2013-04-28 04:47:19 -07:00
|
|
|
|
2013-10-05 01:14:33 -07:00
|
|
|
def enable_set_server():
|
2015-01-29 04:35:19 -08:00
|
|
|
if config.is_modifiable('server'):
|
2015-05-25 00:18:52 -07:00
|
|
|
enabled = not self.autoconnect_cb.isChecked()
|
2015-01-29 04:35:19 -08:00
|
|
|
self.server_host.setEnabled(enabled)
|
|
|
|
self.server_port.setEnabled(enabled)
|
|
|
|
self.servers_list_widget.setEnabled(enabled)
|
|
|
|
else:
|
2015-05-25 00:18:52 -07:00
|
|
|
for w in [self.autoconnect_cb, self.server_host, self.server_port, self.ssl_cb, self.servers_list_widget]:
|
2015-01-29 04:35:19 -08:00
|
|
|
w.setEnabled(False)
|
2013-10-05 01:14:33 -07:00
|
|
|
|
2015-05-25 00:18:52 -07:00
|
|
|
self.autoconnect_cb.clicked.connect(enable_set_server)
|
2013-10-05 01:14:33 -07:00
|
|
|
enable_set_server()
|
2013-04-28 04:47:19 -07:00
|
|
|
|
2017-03-23 22:25:03 -07:00
|
|
|
# Proxy tab
|
|
|
|
grid = QGridLayout(proxy_tab)
|
2017-03-23 13:53:03 -07:00
|
|
|
grid.setSpacing(8)
|
|
|
|
|
2013-04-28 04:47:19 -07:00
|
|
|
# proxy setting
|
|
|
|
self.proxy_mode = QComboBox()
|
|
|
|
self.proxy_host = QLineEdit()
|
|
|
|
self.proxy_host.setFixedWidth(200)
|
|
|
|
self.proxy_port = QLineEdit()
|
|
|
|
self.proxy_port.setFixedWidth(60)
|
|
|
|
self.proxy_mode.addItems(['NONE', 'SOCKS4', 'SOCKS5', 'HTTP'])
|
2017-02-23 13:35:41 -08:00
|
|
|
self.proxy_user = QLineEdit()
|
|
|
|
self.proxy_user.setPlaceholderText(_("Proxy user"))
|
|
|
|
self.proxy_password = QLineEdit()
|
|
|
|
self.proxy_password.setPlaceholderText(_("Password"))
|
|
|
|
self.proxy_password.setEchoMode(QLineEdit.Password)
|
|
|
|
self.proxy_password.setFixedWidth(60)
|
2013-04-28 04:47:19 -07:00
|
|
|
|
|
|
|
def check_for_disable(index = False):
|
2015-01-29 02:06:46 -08:00
|
|
|
if self.config.is_modifiable('proxy'):
|
2017-02-23 13:35:41 -08:00
|
|
|
for w in [self.proxy_host, self.proxy_port, self.proxy_user, self.proxy_password]:
|
|
|
|
w.setEnabled(self.proxy_mode.currentText() != 'NONE')
|
2013-04-28 04:47:19 -07:00
|
|
|
else:
|
2015-01-29 02:06:46 -08:00
|
|
|
for w in [self.proxy_host, self.proxy_port, self.proxy_mode]: w.setEnabled(False)
|
2013-04-28 04:47:19 -07:00
|
|
|
|
|
|
|
check_for_disable()
|
|
|
|
self.proxy_mode.connect(self.proxy_mode, SIGNAL('currentIndexChanged(int)'), check_for_disable)
|
2017-02-17 06:12:28 -08:00
|
|
|
|
2013-04-28 04:47:19 -07:00
|
|
|
self.proxy_mode.setCurrentIndex(self.proxy_mode.findText(str(proxy_config.get("mode").upper())))
|
|
|
|
self.proxy_host.setText(proxy_config.get("host"))
|
|
|
|
self.proxy_port.setText(proxy_config.get("port"))
|
2017-02-23 13:35:41 -08:00
|
|
|
self.proxy_user.setText(proxy_config.get("user", ""))
|
|
|
|
self.proxy_password.setText(proxy_config.get("password", ""))
|
2013-04-28 04:47:19 -07:00
|
|
|
|
2017-02-17 06:12:28 -08:00
|
|
|
self.proxy_mode.connect(self.proxy_mode, SIGNAL('currentIndexChanged(int)'), self.proxy_settings_changed)
|
|
|
|
self.proxy_host.connect(self.proxy_host, SIGNAL('textEdited(QString)'), self.proxy_settings_changed)
|
|
|
|
self.proxy_port.connect(self.proxy_port, SIGNAL('textEdited(QString)'), self.proxy_settings_changed)
|
2017-02-23 13:35:41 -08:00
|
|
|
self.proxy_user.connect(self.proxy_user, SIGNAL('textEdited(QString)'), self.proxy_settings_changed)
|
|
|
|
self.proxy_password.connect(self.proxy_password, SIGNAL('textEdited(QString)'), self.proxy_settings_changed)
|
2017-02-17 06:12:28 -08:00
|
|
|
|
2017-03-23 13:53:03 -07:00
|
|
|
self.tor_cb = QCheckBox(_("Use Tor Proxy"))
|
|
|
|
self.tor_cb.setIcon(QIcon(":icons/tor_logo.png"))
|
|
|
|
self.tor_cb.hide()
|
|
|
|
self.tor_cb.clicked.connect(self.use_tor_proxy)
|
|
|
|
|
|
|
|
grid.addWidget(self.tor_cb, 1, 0, 1, 3)
|
2013-10-05 02:49:36 -07:00
|
|
|
grid.addWidget(self.proxy_mode, 4, 1)
|
|
|
|
grid.addWidget(self.proxy_host, 4, 2)
|
|
|
|
grid.addWidget(self.proxy_port, 4, 3)
|
2017-02-23 13:35:41 -08:00
|
|
|
grid.addWidget(self.proxy_user, 5, 2)
|
|
|
|
grid.addWidget(self.proxy_password, 5, 3)
|
2017-03-23 13:53:03 -07:00
|
|
|
grid.setRowStretch(6, 1)
|
|
|
|
|
|
|
|
# Blockchain Tab
|
|
|
|
from electrum import bitcoin
|
|
|
|
from amountedit import AmountEdit
|
|
|
|
grid = QGridLayout(blockchain_tab)
|
|
|
|
n = len(network.get_interfaces())
|
|
|
|
status = _("Connected to %d nodes.")%n if n else _("Not connected")
|
|
|
|
height_str = "%d "%(network.get_local_height()) + _("blocks")
|
|
|
|
self.checkpoint_height = self.config.get('checkpoint_height', 0)
|
|
|
|
self.checkpoint_value = self.config.get('checkpoint_value', bitcoin.GENESIS)
|
|
|
|
grid.addWidget(QLabel(_("Height") + ':'), 0, 0)
|
|
|
|
grid.addWidget(QLabel(height_str), 0, 1)
|
|
|
|
grid.addWidget(QLabel(_('Status') + ':'), 1, 0)
|
|
|
|
grid.addWidget(QLabel(status), 1, 1, 1, 3)
|
|
|
|
|
|
|
|
self.cph_label = QLabel(_('Height'))
|
|
|
|
self.cph = QLineEdit("%d"%self.checkpoint_height)
|
|
|
|
self.cph.setFixedWidth(80)
|
|
|
|
self.cpv_label = QLabel(_('Hash'))
|
|
|
|
self.cpv = QLineEdit(self.checkpoint_value)
|
|
|
|
self.cpv.setCursorPosition(0)
|
|
|
|
self.cpv.setFocusPolicy(Qt.NoFocus)
|
|
|
|
self.cpv.setReadOnly(True)
|
|
|
|
def on_cph():
|
|
|
|
try:
|
|
|
|
height = int(self.cph.text())
|
|
|
|
except:
|
|
|
|
height = 0
|
|
|
|
self.cph.setText('%d'%height)
|
2017-03-23 13:57:01 -07:00
|
|
|
if height == self.checkpoint_height:
|
2017-03-23 13:53:03 -07:00
|
|
|
return
|
|
|
|
try:
|
|
|
|
self.network.print_error("fetching header")
|
|
|
|
header = self.network.synchronous_get(('blockchain.block.get_header', [height]), 5)
|
|
|
|
_hash = self.network.blockchain.hash_header(header)
|
|
|
|
except BaseException as e:
|
|
|
|
self.network.print_error(str(e))
|
|
|
|
_hash = ''
|
|
|
|
self.cpv.setText(_hash)
|
|
|
|
self.cpv.setCursorPosition(0)
|
|
|
|
if _hash:
|
|
|
|
self.checkpoint_height = height
|
|
|
|
self.checkpoint_value = _hash
|
|
|
|
self.cph.editingFinished.connect(on_cph)
|
|
|
|
grid.addWidget(QLabel(_('Checkpoint') +':'), 3, 0, 1, 2)
|
|
|
|
grid.addWidget(self.cph_label, 4, 0)
|
|
|
|
grid.addWidget(self.cph, 4, 1)
|
|
|
|
grid.addWidget(self.cpv_label, 5, 0)
|
|
|
|
grid.addWidget(self.cpv, 5, 1)
|
|
|
|
grid.setRowStretch(7, 1)
|
2017-03-23 22:25:03 -07:00
|
|
|
vbox = QVBoxLayout()
|
2017-03-23 13:53:03 -07:00
|
|
|
vbox.addWidget(tabs)
|
2016-01-13 03:34:42 -08:00
|
|
|
self.layout_ = vbox
|
2017-03-23 22:25:03 -07:00
|
|
|
# tor detector
|
2017-02-17 05:43:30 -08:00
|
|
|
self.td = td = TorDetector()
|
2017-02-17 04:56:23 -08:00
|
|
|
td.found_proxy.connect(self.suggest_proxy)
|
|
|
|
td.start()
|
2017-03-23 13:53:03 -07:00
|
|
|
self.change_server(host, protocol)
|
|
|
|
self.set_protocol(protocol)
|
|
|
|
self.servers_list_widget.connect(
|
|
|
|
self.servers_list_widget,
|
|
|
|
SIGNAL('currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)'),
|
|
|
|
lambda x,y: self.server_changed(x))
|
2013-04-28 04:47:19 -07:00
|
|
|
|
2016-01-13 03:34:42 -08:00
|
|
|
def layout(self):
|
|
|
|
return self.layout_
|
2013-04-28 04:47:19 -07:00
|
|
|
|
|
|
|
def init_servers_list(self):
|
|
|
|
self.servers_list_widget.clear()
|
2015-03-14 08:03:22 -07:00
|
|
|
for _host, d in sorted(self.servers.items()):
|
2013-04-28 04:47:19 -07:00
|
|
|
if d.get(self.protocol):
|
|
|
|
pruning_level = d.get('pruning','')
|
|
|
|
self.servers_list_widget.addTopLevelItem(QTreeWidgetItem( [ _host, pruning_level ] ))
|
|
|
|
|
|
|
|
def set_protocol(self, protocol):
|
|
|
|
if protocol != self.protocol:
|
|
|
|
self.protocol = protocol
|
|
|
|
self.init_servers_list()
|
2014-10-21 10:05:51 -07:00
|
|
|
|
2015-03-23 03:11:51 -07:00
|
|
|
def change_protocol(self, use_ssl):
|
|
|
|
p = 's' if use_ssl else 't'
|
2013-04-28 04:47:19 -07:00
|
|
|
host = unicode(self.server_host.text())
|
2013-10-04 23:51:53 -07:00
|
|
|
pp = self.servers.get(host, DEFAULT_PORTS)
|
2013-04-28 04:47:19 -07:00
|
|
|
if p not in pp.keys():
|
|
|
|
p = pp.keys()[0]
|
|
|
|
port = pp[p]
|
|
|
|
self.server_host.setText( host )
|
|
|
|
self.server_port.setText( port )
|
|
|
|
self.set_protocol(p)
|
|
|
|
|
|
|
|
def server_changed(self, x):
|
2014-10-21 10:05:51 -07:00
|
|
|
if x:
|
2013-04-28 04:47:19 -07:00
|
|
|
self.change_server(str(x.text(0)), self.protocol)
|
|
|
|
|
|
|
|
def change_server(self, host, protocol):
|
|
|
|
|
|
|
|
pp = self.servers.get(host, DEFAULT_PORTS)
|
2015-02-05 22:37:09 -08:00
|
|
|
if protocol and protocol not in protocol_letters:
|
|
|
|
protocol = None
|
2013-04-28 04:47:19 -07:00
|
|
|
if protocol:
|
|
|
|
port = pp.get(protocol)
|
2015-02-05 22:37:09 -08:00
|
|
|
if port is None:
|
|
|
|
protocol = None
|
2014-10-21 10:05:51 -07:00
|
|
|
|
2013-04-28 04:47:19 -07:00
|
|
|
if not protocol:
|
|
|
|
if 's' in pp.keys():
|
|
|
|
protocol = 's'
|
|
|
|
port = pp.get(protocol)
|
|
|
|
else:
|
|
|
|
protocol = pp.keys()[0]
|
|
|
|
port = pp.get(protocol)
|
2014-10-21 10:05:51 -07:00
|
|
|
|
2013-04-28 04:47:19 -07:00
|
|
|
self.server_host.setText( host )
|
|
|
|
self.server_port.setText( port )
|
2015-03-23 03:11:51 -07:00
|
|
|
self.ssl_cb.setChecked(protocol=='s')
|
2013-04-28 04:47:19 -07:00
|
|
|
|
2016-01-13 03:34:42 -08:00
|
|
|
def accept(self):
|
2015-10-28 04:07:45 -07:00
|
|
|
host = str(self.server_host.text())
|
|
|
|
port = str(self.server_port.text())
|
2015-03-23 03:11:51 -07:00
|
|
|
protocol = 's' if self.ssl_cb.isChecked() else 't'
|
2015-10-28 04:07:45 -07:00
|
|
|
# sanitize
|
|
|
|
try:
|
|
|
|
deserialize_server(serialize_server(host, port, protocol))
|
|
|
|
except:
|
|
|
|
return
|
2013-04-28 04:47:19 -07:00
|
|
|
|
|
|
|
if self.proxy_mode.currentText() != 'NONE':
|
2014-10-21 10:05:51 -07:00
|
|
|
proxy = { 'mode':str(self.proxy_mode.currentText()).lower(),
|
|
|
|
'host':str(self.proxy_host.text()),
|
2017-02-23 13:35:41 -08:00
|
|
|
'port':str(self.proxy_port.text()),
|
|
|
|
'user':str(self.proxy_user.text()),
|
|
|
|
'password':str(self.proxy_password.text())}
|
2013-04-28 04:47:19 -07:00
|
|
|
else:
|
|
|
|
proxy = None
|
|
|
|
|
2015-05-25 00:18:52 -07:00
|
|
|
auto_connect = self.autoconnect_cb.isChecked()
|
2013-09-12 05:58:42 -07:00
|
|
|
|
2013-10-05 02:16:09 -07:00
|
|
|
self.network.set_parameters(host, port, protocol, proxy, auto_connect)
|
2017-03-23 13:53:03 -07:00
|
|
|
self.config.set_key('checkpoint_height', self.checkpoint_height)
|
|
|
|
self.config.set_key('checkpoint_value', self.checkpoint_value)
|
2017-02-17 04:56:23 -08:00
|
|
|
|
|
|
|
def suggest_proxy(self, found_proxy):
|
|
|
|
self.tor_proxy = found_proxy
|
2017-03-23 13:53:03 -07:00
|
|
|
self.tor_cb.setText("Use Tor proxy at port " + str(found_proxy[1]))
|
2017-02-17 06:12:28 -08:00
|
|
|
if self.proxy_mode.currentIndex() == 2 \
|
|
|
|
and self.proxy_host.text() == "127.0.0.1" \
|
|
|
|
and self.proxy_port.text() == str(found_proxy[1]):
|
2017-03-23 13:53:03 -07:00
|
|
|
self.tor_cb.setChecked(True)
|
|
|
|
self.tor_cb.show()
|
2017-02-17 04:56:23 -08:00
|
|
|
|
2017-02-17 06:12:28 -08:00
|
|
|
def use_tor_proxy(self, use_it):
|
2017-02-17 04:56:23 -08:00
|
|
|
# 2 = SOCKS5
|
2017-02-17 06:12:28 -08:00
|
|
|
if not use_it:
|
|
|
|
self.proxy_mode.setCurrentIndex(0)
|
2017-03-23 13:53:03 -07:00
|
|
|
self.tor_cb.setChecked(False)
|
2017-02-17 06:12:28 -08:00
|
|
|
else:
|
|
|
|
self.proxy_mode.setCurrentIndex(2)
|
|
|
|
self.proxy_host.setText("127.0.0.1")
|
|
|
|
self.proxy_port.setText(str(self.tor_proxy[1]))
|
2017-02-23 13:35:41 -08:00
|
|
|
self.proxy_user.setText("")
|
|
|
|
self.proxy_password.setText("")
|
2017-03-23 13:53:03 -07:00
|
|
|
self.tor_cb.setChecked(True)
|
2017-02-17 06:12:28 -08:00
|
|
|
|
|
|
|
def proxy_settings_changed(self):
|
2017-03-23 13:53:03 -07:00
|
|
|
self.tor_cb.setChecked(False)
|
2017-02-17 04:56:23 -08:00
|
|
|
|
|
|
|
|
|
|
|
class TorDetector(QThread):
|
|
|
|
found_proxy = pyqtSignal(object)
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
QThread.__init__(self)
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
# Probable ports for Tor to listen at
|
|
|
|
ports = [9050, 9150]
|
|
|
|
for p in ports:
|
|
|
|
if TorDetector.is_tor_port(p):
|
|
|
|
self.found_proxy.emit(("127.0.0.1", p))
|
|
|
|
return
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def is_tor_port(port):
|
|
|
|
try:
|
2017-02-17 06:12:28 -08:00
|
|
|
s = socket._socketobject(socket.AF_INET, socket.SOCK_STREAM)
|
2017-02-17 04:56:23 -08:00
|
|
|
s.settimeout(0.1)
|
|
|
|
s.connect(("127.0.0.1", port))
|
|
|
|
# Tor responds uniquely to HTTP-like requests
|
|
|
|
s.send("GET\n")
|
|
|
|
if "Tor is not an HTTP Proxy" in s.recv(1024):
|
|
|
|
return True
|
|
|
|
except socket.error:
|
|
|
|
pass
|
|
|
|
return False
|