Browse Source

Revert "Revert "Added proxy options to network dialog""

This reverts commit 6e0b3620d2.
283
bkkcoins 12 years ago
parent
commit
09c90c0971
  1. 19
      lib/gui_qt.py
  2. 7
      lib/interface.py
  3. 2
      lib/simple_config.py
  4. 5
      lib/wallet.py

19
lib/gui_qt.py

@ -1380,6 +1380,22 @@ class ElectrumWindow(QMainWindow):
hbox.addWidget(radio2)
vbox.addLayout(hbox)
hbox = QHBoxLayout()
proxy_mode = QComboBox()
proxy_host = QLineEdit()
proxy_port = QLineEdit()
proxy_mode.addItems(['NONE', 'SOCKS4', 'SOCKS5', 'HTTP'])
proxy_mode.setCurrentIndex(proxy_mode.findText(str(interface.proxy["mode"]).upper()))
proxy_host.setText(interface.proxy["host"])
proxy_port.setText(interface.proxy["port"])
hbox.addWidget(QLabel(_('Proxy') + ':'))
hbox.addWidget(proxy_mode)
hbox.addWidget(proxy_host)
hbox.addWidget(proxy_port)
vbox.addLayout(hbox)
hbox = QHBoxLayout()
if wallet.interface.servers:
label = _('Active Servers')
@ -1413,7 +1429,8 @@ class ElectrumWindow(QMainWindow):
server = unicode( host_line.text() )
try:
wallet.set_server(server)
proxy = { u'mode':unicode(proxy_mode.currentText()).lower(), u'host':unicode(proxy_host.text()), u'port':unicode(proxy_port.text()) }
wallet.set_server(server, proxy)
except:
QMessageBox.information(None, _('Error'), 'error', _('OK'))
if parent == None:

7
lib/interface.py

@ -29,7 +29,7 @@ DEFAULT_SERVERS = [ 'ecdsa.org:50001:t',
'uncle-enzo.info:50001:t',
'electrum.bytesized-hosting.com:50001:t'] # list of default servers
proxy_modes = ['off', 'socks4', 'socks5', 'http' ]
proxy_modes = ['none', 'socks4', 'socks5', 'http' ]
def replace_keys(obj, old_key, new_key):
if isinstance(obj, dict):
@ -192,7 +192,7 @@ class HttpStratumInterface(PollingInterface):
def send(self, messages):
import urllib2, json, time, cookielib
if self.proxy["mode"] != "off":
if self.proxy["mode"] != "none":
import socks
socks.setdefaultproxy(proxy_modes.index(self.proxy["mode"]), self.proxy["host"], int(self.proxy["port"]) )
socks.wrapmodule(urllib2)
@ -260,7 +260,7 @@ class TcpStratumInterface(Interface):
def init_socket(self):
global proxy_modes
if self.proxy["mode"] == "off":
if self.proxy["mode"] == "none":
self.s = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
else:
import socks
@ -460,6 +460,7 @@ class WalletSynchronizer(threading.Thread):
if self.loop:
time.sleep(5)
# Server has been changed. Copy callback for new interface.
self.proxy = self.interface.proxy
self.init_interface()
self.start_interface()
continue

2
lib/simple_config.py

@ -3,7 +3,7 @@ import os
from util import user_dir
class SimpleConfig:
default_options = {"gui": "lite", "proxy": { "mode": "off", "host":"localhost", "port":"8080" } }
default_options = {"gui": "lite", "proxy": { "mode": "none", "host":"localhost", "port":"8080" } }
def set_key(self, key, value, save = True):
self.config[key] = value

5
lib/wallet.py

@ -347,15 +347,16 @@ class Wallet:
def is_up_to_date(self):
return self.interface.responses.empty() and not self.interface.unanswered_requests
def set_server(self, server):
def set_server(self, server, proxy):
# raise an error if the format isnt correct
a,b,c = server.split(':')
b = int(b)
assert c in ['t', 'h', 'n']
# set the server
if server != self.server:
if server != self.server or proxy != self.interface.proxy:
self.server = server
self.save()
self.interface.proxy = proxy
self.interface.is_connected = False # this exits the polling loop
self.interface.poke()

Loading…
Cancel
Save