Browse Source

nodaemon

283
ThomasV 12 years ago
parent
commit
0ad7f72d3d
  1. 11
      electrum
  2. 16
      lib/verifier.py
  3. 21
      lib/wallet.py

11
electrum

@ -250,6 +250,9 @@ if __name__ == '__main__':
verifier.start()
gui.main(url)
wallet.save()
verifier.stop()
synchronizer.stop()
#interface.stop()
sys.exit(0)
if cmd not in known_commands:
@ -343,10 +346,11 @@ if __name__ == '__main__':
# open session
if cmd not in offline_commands and not options.offline:
interface = Interface(config)
interface.register_callback('connected', lambda: print_error("Connected to " + interface.connection_msg))
interface.register_callback('connected', lambda: sys.stderr.write("Connected to " + interface.connection_msg + "\n"))
interface.start()
wallet.interface = interface
WalletSynchronizer(wallet, config).start()
synchronizer = WalletSynchronizer(wallet, config)
synchronizer.start()
wallet.update()
wallet.save()
@ -643,3 +647,6 @@ if __name__ == '__main__':
addr = args[1]
print_msg(wallet.unprioritize(addr))
if cmd not in offline_commands and not options.offline:
synchronizer.stop()

16
lib/verifier.py

@ -29,7 +29,7 @@ class WalletVerifier(threading.Thread):
def __init__(self, interface, config):
threading.Thread.__init__(self)
self.daemon = True
#self.daemon = True
self.config = config
self.interface = interface
self.transactions = {} # requested verifications (with height sent by the requestor)
@ -45,6 +45,7 @@ class WalletVerifier(threading.Thread):
self.local_height = 0
self.init_headers_file()
self.set_local_height()
self.running = False
def get_confirmations(self, tx):
""" return the number of confirmations of a monitored transaction. """
@ -62,7 +63,15 @@ class WalletVerifier(threading.Thread):
if tx_hash not in self.transactions.keys():
self.transactions[tx_hash] = tx_height
def stop(self):
with self.lock: self.running = False
def is_running(self):
with self.lock: return self.running
def run(self):
with self.lock:
self.running = True
requested_merkle = []
requested_chunks = []
requested_headers = []
@ -71,7 +80,7 @@ class WalletVerifier(threading.Thread):
# subscribe to block headers
self.interface.send([ ('blockchain.headers.subscribe',[])], 'verifier')
while True:
while self.is_running():
# request missing chunks
if not all_chunks and self.height and not requested_chunks:
@ -117,9 +126,8 @@ class WalletVerifier(threading.Thread):
self.pending_headers.remove(header)
try:
r = self.interface.get_response('verifier',timeout=1)
r = self.interface.get_response('verifier',timeout=0.1)
except Queue.Empty:
time.sleep(1)
continue
# 3. handle response

21
lib/wallet.py

@ -1153,13 +1153,21 @@ class WalletSynchronizer(threading.Thread):
def __init__(self, wallet, config):
threading.Thread.__init__(self)
self.daemon = True
# self.daemon = True
self.wallet = wallet
self.interface = self.wallet.interface
self.interface.register_channel('synchronizer')
self.wallet.interface.register_callback('connected', lambda: self.wallet.set_up_to_date(False))
self.wallet.interface.register_callback('connected', lambda: self.interface.send([('server.banner',[])],'synchronizer') )
self.was_updated = True
self.running = False
self.lock = threading.Lock()
def stop(self):
with self.lock: self.running = False
def is_running(self):
with self.lock: return self.running
def synchronize_wallet(self):
new_addresses = self.wallet.synchronize()
@ -1186,6 +1194,8 @@ class WalletSynchronizer(threading.Thread):
def run(self):
with self.lock: self.running = True
requested_tx = []
missing_tx = []
requested_histories = {}
@ -1208,7 +1218,7 @@ class WalletSynchronizer(threading.Thread):
# subscriptions
self.subscribe_to_addresses(self.wallet.all_addresses())
while True:
while self.is_running():
# 1. send new requests
self.synchronize_wallet()
@ -1223,7 +1233,12 @@ class WalletSynchronizer(threading.Thread):
self.was_updated = False
# 2. get a response
r = self.interface.get_response('synchronizer')
try:
r = self.interface.get_response('synchronizer', timeout=0.1)
except:
continue
# poke sends None. (check if still needed)
if not r:
continue

Loading…
Cancel
Save