From c7b49738a0a7eb7bd67e7e08c2fb265556ce5d20 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Tue, 20 Nov 2012 14:21:35 +0400 Subject: [PATCH] password protect unsubscribe --- backends/bitcoind/blockchain_processor.py | 14 ++++++++++---- processor.py | 18 ++++++++++-------- server.py | 2 +- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/backends/bitcoind/blockchain_processor.py b/backends/bitcoind/blockchain_processor.py index e6dcd57..5e7901a 100644 --- a/backends/bitcoind/blockchain_processor.py +++ b/backends/bitcoind/blockchain_processor.py @@ -16,6 +16,7 @@ class BlockchainProcessor(Processor): Processor.__init__(self) self.shared = shared + self.config = config self.up_to_date = False self.watched_addresses = [] self.history_cache = {} @@ -539,10 +540,15 @@ class BlockchainProcessor(Processor): elif method == 'blockchain.address.unsubscribe': try: - address = params[0] - self.watched_addresses.remove(address) - print_log('unsubscribed', address) - result = "ok" + password = params[0] + address = params[1] + if password == self.config.get('server','password'): + self.watched_addresses.remove(address) + print_log('unsubscribed', address) + result = "ok" + else: + print_log('incorrect password') + result = "authentication error" except BaseException, e: error = str(e) + ': ' + address print_log( "error:", error ) diff --git a/processor.py b/processor.py index 82124e0..8d1788d 100644 --- a/processor.py +++ b/processor.py @@ -24,9 +24,10 @@ def print_log(*args): class Shared: - def __init__(self): + def __init__(self, config): self.lock = threading.Lock() self._stopped = False + self.config = config def stop(self): print_log( "Stopping Stratum" ) @@ -70,8 +71,8 @@ class Processor(threading.Thread): class Dispatcher: - def __init__(self): - self.shared = Shared() + def __init__(self, config): + self.shared = Shared(config) self.request_dispatcher = RequestDispatcher(self.shared) self.request_dispatcher.start() self.response_dispatcher = \ @@ -281,8 +282,9 @@ class ResponseDispatcher(threading.Thread): if internal_id is None: # and method is not None and params is not None: found = self.notification(method, params, response) if not found and method == 'blockchain.address.subscribe': - self.request_dispatcher.push_request(None,{'method':method.replace('.subscribe', '.unsubscribe'), 'params':params, 'id':None}) - pass + params2 = [self.shared.config.get('server','password')] + params + self.request_dispatcher.push_request(None,{'method':method.replace('.subscribe', '.unsubscribe'), 'params':params2, 'id':None}) + # A response elif internal_id is not None: self.send_response(internal_id, response) @@ -298,7 +300,7 @@ class ResponseDispatcher(threading.Thread): if session.contains_subscription(subdesc): session.send_response(response) found = True - if not found: print "no subscriber for", subdesc + # if not found: print_log( "no subscriber for", subdesc) return found def send_response(self, internal_id, response): @@ -306,6 +308,6 @@ class ResponseDispatcher(threading.Thread): if session: response['id'] = message_id session.send_response(response) - else: - print_log( "send_response: no session", message_id, internal_id, response ) + #else: + # print_log( "send_response: no session", message_id, internal_id, response ) diff --git a/server.py b/server.py index 99fbee1..f874cfe 100755 --- a/server.py +++ b/server.py @@ -132,7 +132,7 @@ if __name__ == '__main__': print_log( "Starting Electrum server on", host) # Create hub - dispatcher = Dispatcher() + dispatcher = Dispatcher(config) shared = dispatcher.shared # Create and register processors -- 1.7.1