electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit c735fcd228e745d315362b02fbdcf3489c9489fa
parent af0d8d664b3abaff8a02320fef8a023502885e12
Author: thomasv <thomasv@gitorious>
Date:   Mon, 22 Oct 2012 17:18:07 +0200

more robust connection procedure: let the user start with proxy

Diffstat:
Mlib/interface.py | 26+++++++++++++++-----------
Mlib/wallet.py | 8+++++++-
2 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/lib/interface.py b/lib/interface.py @@ -64,12 +64,6 @@ class Interface(threading.Thread): self.port = port self.proxy = proxy self.use_ssl = use_ssl - - self.servers = [] # actual list from IRC - self.rtime = 0 - self.bytes_received = 0 - - self.is_connected = True self.poll_interval = 1 #json @@ -136,7 +130,7 @@ class Interface(threading.Thread): self.init_server(host, port, proxy, use_ssl) self.session_id = None self.connection_msg = ('https' if self.use_ssl else 'http') + '://%s:%d'%( self.host, self.port ) - + self.is_connected = True def run_http(self): self.is_connected = True @@ -326,6 +320,10 @@ class Interface(threading.Thread): self.callbacks = {} self.lock = threading.Lock() + self.servers = [] # actual list from IRC + self.rtime = 0 + self.bytes_received = 0 + def init_interface(self): @@ -342,7 +340,12 @@ class Interface(threading.Thread): if self.is_connected: break if not servers: - raise BaseException('no server available') + print 'no server available' + self.is_connected = False + self.connect_event.set() # to finish start + self.server = 'ecdsa.org:50001:t' + self.proxy = None + return self.connect_event.set() if self.is_connected: @@ -483,12 +486,13 @@ class Interface(threading.Thread): def run(self): while True: self.init_interface() - self.resend_subscriptions() + if self.is_connected: + self.resend_subscriptions() + self.run_tcp() if self.protocol in 'st' else self.run_http() - self.run_tcp() if self.protocol in 'st' else self.run_http() self.trigger_callback('disconnected') - if not self.loop: break + if not self.loop: break time.sleep(5) diff --git a/lib/wallet.py b/lib/wallet.py @@ -29,6 +29,7 @@ import random import aes import ecdsa import Queue +import time from ecdsa.util import string_to_number, number_to_string from util import print_error, user_dir, format_satoshis @@ -858,7 +859,12 @@ class WalletSynchronizer(threading.Thread): def run(self): - # request banner, because 'connected' event happends before this thread is started + + # wait until we are connected, in case the user is not connected + while not self.interface.is_connected: + time.sleep(1) + + # request banner, because 'connected' event happens before this thread is started self.interface.send([('server.banner',[])],'synchronizer') # subscriptions