commit c5b122a779dc2c085739c97609cbe13b403db1b6
parent 8d88b0702da6102f2f2aeae801ab679382506367
Author: ThomasV <thomasv@gitorious>
Date: Mon, 19 Mar 2012 21:19:50 +0300
Merge branch 'master' of gitorious.org:electrum/electrum
Diffstat:
2 files changed, 48 insertions(+), 46 deletions(-)
diff --git a/client/gui_qt.py b/client/gui_qt.py
@@ -854,8 +854,9 @@ class ElectrumWindow(QMainWindow):
hbox = QHBoxLayout()
l = QLabel()
l.setPixmap(QPixmap(":icons/network.png"))
- hbox.addWidget(l)
+ hbox.addWidget(l)
hbox.addWidget(QLabel(status))
+
vbox.addLayout(hbox)
hbox = QHBoxLayout()
@@ -865,13 +866,20 @@ class ElectrumWindow(QMainWindow):
hbox.addWidget(host_line)
vbox.addLayout(hbox)
- servers_list = QTreeWidget(parent)
- servers_list.setHeaderLabels( [ 'Active servers'] )
- servers_list.setMaximumHeight(150)
- for item in wallet.interface.servers:
- servers_list.addTopLevelItem(QTreeWidgetItem( [ item ] ))
- servers_list.connect(servers_list, SIGNAL('itemClicked(QTreeWidgetItem*, int)'), lambda x:host_line.setText( x.text(0) + ':%d'%wallet.port ))
- vbox.addWidget(servers_list)
+ if wallet.interface.servers:
+ servers_list = QTreeWidget(parent)
+ servers_list.setHeaderLabels( [ 'Active servers'] )
+ servers_list.setMaximumHeight(150)
+ for item in wallet.interface.servers:
+ servers_list.addTopLevelItem(QTreeWidgetItem( [ item ] ))
+ servers_list.connect(servers_list, SIGNAL('itemClicked(QTreeWidgetItem*, int)'), lambda x:host_line.setText( x.text(0) + ':%d'%wallet.port ))
+ vbox.addWidget(servers_list)
+ else:
+ hbox = QHBoxLayout()
+ hbox.addWidget(QLabel('No nodes available'))
+ b = EnterButton("Find nodes", lambda: wallet.interface.get_servers(wallet) )
+ hbox.addWidget(b)
+ vbox.addLayout(hbox)
vbox.addLayout(ok_cancel_buttons(d))
d.setLayout(vbox)
diff --git a/client/interface.py b/client/interface.py
@@ -21,7 +21,7 @@ import random, socket, ast
import thread, threading, traceback, sys, time, json
DEFAULT_TIMEOUT = 5
-DEFAULT_SERVERS = ['ecdsa.org','electrum.novit.ro'] # list of default servers
+DEFAULT_SERVERS = ['electrum.bitcoins.sk','ecdsa.org','electrum.novit.ro'] # list of default servers
class Interface:
@@ -32,7 +32,7 @@ class Interface:
self.history_callback = history_callback
self.newblock_callback = newblock_callback
- self.servers = DEFAULT_SERVERS # actual list from IRC
+ self.servers = [] # actual list from IRC
self.rtime = 0
self.blocks = 0
self.message = ''
@@ -60,8 +60,6 @@ class Interface:
self.tx_event.wait()
return self.tx_result
- def get_servers(self):
- pass
def start_session(self, addresses, version):
pass
@@ -113,6 +111,7 @@ class Interface:
self.is_up_to_date = True
elif method == 'server.peers':
+ print "Received server list: ", result
self.servers = map( lambda x:x[1], result )
elif method == 'address.subscribe':
@@ -148,11 +147,36 @@ class Interface:
self.send(messages)
+ def get_servers(self, wallet):
+ # loop over default servers
+ # requesting servers could be an independent process
+ addresses = wallet.all_addresses()
+ version = wallet.electrum_version
+
+ for server in DEFAULT_SERVERS:
+ print "connecting to", server
+ try:
+ self.host = server
+ self.start_session(addresses, version)
+ wallet.host = self.host
+ break
+ except socket.timeout:
+ continue
+ except socket.error:
+ continue
+ except:
+ traceback.print_exc(file=sys.stdout)
+
+
+
+
+
class PollingInterface(Interface):
""" non-persistent connection. synchronous calls"""
def start_session(self, addresses, version):
self.send([('session.new', [ version, addresses ])] )
+ self.send([('server.peers',[])])
thread.start_new_thread(self.poll_thread, (5,))
def get_history(self, address):
@@ -189,31 +213,6 @@ class PollingInterface(Interface):
self.disconnected_event.set()
- def get_servers(self):
- #thread.start_new_thread(self.update_servers_thread, ())
- pass
-
- def update_servers_thread(self):
- # if my server is not reachable, I should get the list from one of the default servers
- # requesting servers could be an independent process
- while True:
- for server in DEFAULT_SERVERS:
- try:
- self.peers_server = server
-
- self.send([('server.peers',[])])
-
- # print "Received server list from %s" % self.peers_server, out
- break
- except socket.timeout:
- continue
- except socket.error:
- continue
- except:
- traceback.print_exc(file=sys.stdout)
-
- time.sleep(5*60)
-
@@ -247,7 +246,7 @@ class NativeInterface(PollingInterface):
request = repr ( (cmd, str_params) ) + "#"
s = socket.socket( socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(DEFAULT_TIMEOUT)
- s.connect(( self.host if cmd!='peers' else self.peers_server, self.port) )
+ s.connect(( self.host, self.port) )
s.send( request )
out = ''
while 1:
@@ -277,7 +276,7 @@ class HttpInterface(PollingInterface):
def start_session(self, addresses, version):
self.session_id = None
- self.send([('client.version', [version]), ('server.banner',[]), ('numblocks.subscribe',[])])
+ self.send([('client.version', [version]), ('server.banner',[]), ('numblocks.subscribe',[]), ('server.peers',[])])
self.subscribe(addresses)
thread.start_new_thread(self.poll_thread, (15,))
@@ -373,9 +372,6 @@ class AsynchronousInterface(Interface):
out += request + '\n'
self.s.send( out )
- def get_servers(self):
- self.send([('server.peers',[])])
-
def get_history(self, addr):
self.send([('address.get_history', [addr])])
self.addresses_waiting_for_history.append(addr)
@@ -385,7 +381,7 @@ class AsynchronousInterface(Interface):
self.s.settimeout(1)
self.s.connect(( self.host, self.port))
thread.start_new_thread(self.listen_thread, ())
- self.send([('client.version', [version]), ('server.banner',[]), ('numblocks.subscribe',[])])
+ self.send([('client.version', [version]), ('server.banner',[]), ('numblocks.subscribe',[]), ('server.peers',[])])
self.subscribe(addresses)
@@ -414,7 +410,7 @@ def new_interface(wallet):
interface = InterfaceClass(host, port, address_cb, history_cb)
return interface
-
+
def loop_interfaces_thread(wallet):
while True:
@@ -422,7 +418,6 @@ def loop_interfaces_thread(wallet):
addresses = wallet.all_addresses()
version = wallet.electrum_version
wallet.interface.start_session(addresses, version)
- wallet.interface.get_servers()
wallet.interface.disconnected_event.wait()
print "Disconnected"
@@ -436,4 +431,3 @@ def loop_interfaces_thread(wallet):
print "Starting new session: %s:%d"%(wallet.host,wallet.port)
wallet.interface = new_interface(wallet)
-