slightly more robust connection procedure
This commit is contained in:
parent
94cc6aa93a
commit
c5d42f3614
1
electrum
1
electrum
|
@ -98,7 +98,6 @@ if __name__ == '__main__':
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
if not found: exit(1)
|
if not found: exit(1)
|
||||||
|
|
||||||
gui.main(url)
|
gui.main(url)
|
||||||
wallet.save()
|
wallet.save()
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
|
@ -1140,7 +1140,7 @@ class ElectrumWindow:
|
||||||
interface = self.wallet.interface
|
interface = self.wallet.interface
|
||||||
if self.funds_error:
|
if self.funds_error:
|
||||||
text = "Not enough funds"
|
text = "Not enough funds"
|
||||||
elif interface.is_connected:
|
elif interface and interface.is_connected:
|
||||||
self.network_button.set_tooltip_text("Connected to %s:%d.\n%d blocks"%(interface.host, interface.port, self.wallet.blocks))
|
self.network_button.set_tooltip_text("Connected to %s:%d.\n%d blocks"%(interface.host, interface.port, self.wallet.blocks))
|
||||||
if self.wallet.blocks == -1:
|
if self.wallet.blocks == -1:
|
||||||
self.status_image.set_from_stock(gtk.STOCK_NO, gtk.ICON_SIZE_MENU)
|
self.status_image.set_from_stock(gtk.STOCK_NO, gtk.ICON_SIZE_MENU)
|
||||||
|
@ -1159,7 +1159,7 @@ class ElectrumWindow:
|
||||||
if u: text += "[%s unconfirmed]"%( format_satoshis(u,True,self.wallet.num_zeros).strip() )
|
if u: text += "[%s unconfirmed]"%( format_satoshis(u,True,self.wallet.num_zeros).strip() )
|
||||||
else:
|
else:
|
||||||
self.status_image.set_from_stock(gtk.STOCK_NO, gtk.ICON_SIZE_MENU)
|
self.status_image.set_from_stock(gtk.STOCK_NO, gtk.ICON_SIZE_MENU)
|
||||||
self.network_button.set_tooltip_text("Trying to contact %s.\n%d blocks"%(interface.host, self.wallet.blocks))
|
self.network_button.set_tooltip_text("Trying to contact %s.\n%d blocks"%(self.wallet.server, self.wallet.blocks))
|
||||||
text = "Not connected"
|
text = "Not connected"
|
||||||
|
|
||||||
self.status_bar.pop(self.context_id)
|
self.status_bar.pop(self.context_id)
|
||||||
|
|
|
@ -206,7 +206,7 @@ class ElectrumWindow(QMainWindow):
|
||||||
self.emit(QtCore.SIGNAL('updatesignal'))
|
self.emit(QtCore.SIGNAL('updatesignal'))
|
||||||
|
|
||||||
def update_wallet(self):
|
def update_wallet(self):
|
||||||
if self.wallet.interface.is_connected:
|
if self.wallet.interface and self.wallet.interface.is_connected:
|
||||||
if self.wallet.blocks == -1:
|
if self.wallet.blocks == -1:
|
||||||
text = "Connecting..."
|
text = "Connecting..."
|
||||||
icon = QIcon(":icons/status_disconnected.png")
|
icon = QIcon(":icons/status_disconnected.png")
|
||||||
|
|
|
@ -211,6 +211,8 @@ class TcpStratumInterface(Interface):
|
||||||
|
|
||||||
def __init__(self, host, port):
|
def __init__(self, host, port):
|
||||||
Interface.__init__(self, host, port)
|
Interface.__init__(self, host, port)
|
||||||
|
|
||||||
|
def init_socket(self):
|
||||||
self.s = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
|
self.s = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
|
||||||
self.s.settimeout(5*60)
|
self.s.settimeout(5*60)
|
||||||
self.s.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
|
self.s.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
|
||||||
|
@ -277,7 +279,28 @@ class WalletSynchronizer(threading.Thread):
|
||||||
self.daemon = True
|
self.daemon = True
|
||||||
self.wallet = wallet
|
self.wallet = wallet
|
||||||
self.loop = loop
|
self.loop = loop
|
||||||
self.start_interface()
|
self.init_interface()
|
||||||
|
|
||||||
|
def init_interface(self):
|
||||||
|
try:
|
||||||
|
host, port, protocol = self.wallet.server.split(':')
|
||||||
|
port = int(port)
|
||||||
|
except:
|
||||||
|
self.wallet.pick_random_server()
|
||||||
|
host, port, protocol = self.wallet.server.split(':')
|
||||||
|
port = int(port)
|
||||||
|
|
||||||
|
#print protocol, host, port
|
||||||
|
if protocol == 't':
|
||||||
|
InterfaceClass = TcpStratumInterface
|
||||||
|
elif protocol == 'h':
|
||||||
|
InterfaceClass = HttpStratumInterface
|
||||||
|
else:
|
||||||
|
print "unknown protocol"
|
||||||
|
InterfaceClass = TcpStratumInterface
|
||||||
|
|
||||||
|
self.interface = InterfaceClass(host, port)
|
||||||
|
self.wallet.interface = self.interface
|
||||||
|
|
||||||
|
|
||||||
def handle_response(self, r):
|
def handle_response(self, r):
|
||||||
|
@ -330,27 +353,8 @@ class WalletSynchronizer(threading.Thread):
|
||||||
|
|
||||||
|
|
||||||
def start_interface(self):
|
def start_interface(self):
|
||||||
try:
|
self.interface.init_socket()
|
||||||
host, port, protocol = self.wallet.server.split(':')
|
|
||||||
port = int(port)
|
|
||||||
except:
|
|
||||||
self.wallet.pick_random_server()
|
|
||||||
host, port, protocol = self.wallet.server.split(':')
|
|
||||||
port = int(port)
|
|
||||||
|
|
||||||
#print protocol, host, port
|
|
||||||
if protocol == 't':
|
|
||||||
InterfaceClass = TcpStratumInterface
|
|
||||||
elif protocol == 'h':
|
|
||||||
InterfaceClass = HttpStratumInterface
|
|
||||||
else:
|
|
||||||
print "unknown protocol"
|
|
||||||
InterfaceClass = TcpStratumInterface
|
|
||||||
|
|
||||||
self.interface = InterfaceClass(host, port)
|
|
||||||
self.interface.start()
|
self.interface.start()
|
||||||
self.wallet.interface = self.interface
|
|
||||||
|
|
||||||
if self.interface.is_connected:
|
if self.interface.is_connected:
|
||||||
self.wallet.start_session(self.interface)
|
self.wallet.start_session(self.interface)
|
||||||
|
|
||||||
|
@ -358,6 +362,7 @@ class WalletSynchronizer(threading.Thread):
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
import socket, time
|
import socket, time
|
||||||
|
self.start_interface()
|
||||||
while True:
|
while True:
|
||||||
while self.interface.is_connected:
|
while self.interface.is_connected:
|
||||||
new_addresses = self.wallet.synchronize()
|
new_addresses = self.wallet.synchronize()
|
||||||
|
@ -384,6 +389,7 @@ class WalletSynchronizer(threading.Thread):
|
||||||
self.wallet.gui_callback()
|
self.wallet.gui_callback()
|
||||||
if self.loop:
|
if self.loop:
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
self.init_interface()
|
||||||
self.start_interface()
|
self.start_interface()
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue