Browse Source

enable changes of protocol, proxy at runtime

283
ThomasV 11 years ago
parent
commit
45b111e14c
  1. 5
      gui/qt/network_dialog.py
  2. 2
      lib/__init__.py
  3. 31
      lib/network.py

5
gui/qt/network_dialog.py

@ -121,10 +121,9 @@ class NetworkDialog(QDialog):
if server:
host, port, protocol = server.split(':')
self.set_protocol(protocol)
self.change_server(host, protocol)
else:
self.set_protocol('s')
self.set_protocol(self.network.protocol)
self.servers_list_widget.connect(self.servers_list_widget,
SIGNAL('currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)'),

2
lib/__init__.py

@ -3,7 +3,7 @@ from util import format_satoshis, print_msg, print_json, print_error, set_verbos
from wallet import WalletSynchronizer, WalletStorage
from wallet_factory import WalletFactory as Wallet
from verifier import TxVerifier
from network import Network, DEFAULT_SERVERS, DEFAULT_PORTS, pick_random_server
from network import Network, DEFAULT_SERVERS, DEFAULT_PORTS
from interface import Interface
from simple_config import SimpleConfig
import bitcoin

31
lib/network.py

@ -35,8 +35,8 @@ def filter_protocol(servers, p):
return l
def pick_random_server():
return random.choice( filter_protocol(DEFAULT_SERVERS,'s') )
#def pick_random_server():
# return random.choice( filter_protocol(DEFAULT_SERVERS,'s') )
class Network(threading.Thread):
@ -175,18 +175,21 @@ class Network(threading.Thread):
def set_parameters(self, host, port, protocol, proxy, auto_connect):
self.config.set_key('auto_cycle', auto_connect, True)
self.config.set_key("proxy", proxy, True)
self.proxy = proxy
self.config.set_key("protocol", protocol, True)
self.protocol = protocol
self.config.set_key('auto_cycle', auto_connect, True)
server = ':'.join([ host, port, protocol ])
self.config.set_key("server", server, True)
if self.proxy != proxy or self.protocol != protocol:
self.proxy = proxy
self.protocol = protocol
for i in self.interfaces.values(): i.stop()
if auto_connect:
self.interface = None
self.default_server = None
return
if auto_connect:
if not self.interface:
self.switch_to_random_interface()
@ -202,12 +205,14 @@ class Network(threading.Thread):
self.switch_to_interface(random.choice(self.interfaces.values()))
def switch_to_interface(self, interface):
print_error("switching to", interface.server)
server = interface.server
print_error("switching to", server)
self.interface = interface
h = self.heights.get(self.interface.server)
h = self.heights.get(server)
if h:
self.server_lag = self.blockchain.height - h
self.config.set_key('server', self.interface.server, False)
self.config.set_key('server', server, False)
self.default_server = server
self.send_subscriptions()
self.trigger_callback('connected')
@ -298,8 +303,6 @@ class Network(threading.Thread):
if i == self.interface:
self.server_lag = self.blockchain.height - self.heights[i.server]
if self.server_lag:
print "on_header: lag", self.server_lag
self.trigger_callback('updated')

Loading…
Cancel
Save