commit 45b111e14c4d3f60b62d864c0459a7ee9dcf5908
parent 1b4f26195b70c248648b4e6ebfa735984af43643
Author: ThomasV <thomasv@gitorious>
Date: Sat, 5 Oct 2013 13:48:02 +0200
enable changes of protocol, proxy at runtime
Diffstat:
3 files changed, 20 insertions(+), 18 deletions(-)
diff --git a/gui/qt/network_dialog.py b/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*)'),
diff --git a/lib/__init__.py b/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
diff --git a/lib/network.py b/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')