Browse Source

more robust connection procedure: let the user start with proxy

283
thomasv 12 years ago
parent
commit
c735fcd228
  1. 26
      lib/interface.py
  2. 8
      lib/wallet.py

26
lib/interface.py

@ -64,12 +64,6 @@ class Interface(threading.Thread):
self.port = port self.port = port
self.proxy = proxy self.proxy = proxy
self.use_ssl = use_ssl 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 self.poll_interval = 1
#json #json
@ -136,7 +130,7 @@ class Interface(threading.Thread):
self.init_server(host, port, proxy, use_ssl) self.init_server(host, port, proxy, use_ssl)
self.session_id = None self.session_id = None
self.connection_msg = ('https' if self.use_ssl else 'http') + '://%s:%d'%( self.host, self.port ) self.connection_msg = ('https' if self.use_ssl else 'http') + '://%s:%d'%( self.host, self.port )
self.is_connected = True
def run_http(self): def run_http(self):
self.is_connected = True self.is_connected = True
@ -326,6 +320,10 @@ class Interface(threading.Thread):
self.callbacks = {} self.callbacks = {}
self.lock = threading.Lock() self.lock = threading.Lock()
self.servers = [] # actual list from IRC
self.rtime = 0
self.bytes_received = 0
def init_interface(self): def init_interface(self):
@ -342,7 +340,12 @@ class Interface(threading.Thread):
if self.is_connected: break if self.is_connected: break
if not servers: 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() self.connect_event.set()
if self.is_connected: if self.is_connected:
@ -483,12 +486,13 @@ class Interface(threading.Thread):
def run(self): def run(self):
while True: while True:
self.init_interface() 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') self.trigger_callback('disconnected')
if not self.loop: break
if not self.loop: break
time.sleep(5) time.sleep(5)

8
lib/wallet.py

@ -29,6 +29,7 @@ import random
import aes import aes
import ecdsa import ecdsa
import Queue import Queue
import time
from ecdsa.util import string_to_number, number_to_string from ecdsa.util import string_to_number, number_to_string
from util import print_error, user_dir, format_satoshis from util import print_error, user_dir, format_satoshis
@ -858,7 +859,12 @@ class WalletSynchronizer(threading.Thread):
def run(self): 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') self.interface.send([('server.banner',[])],'synchronizer')
# subscriptions # subscriptions

Loading…
Cancel
Save