def pop_request(self):
return self.request_queue.get()
+ def get_session_by_address(self, address):
+ for x in self.sessions:
+ if x.address == address:
+ return x
+
def get_session_id(self, internal_id):
with self.lock:
return self.internal_ids.pop(internal_id)
if method in ['server.version']:
session.version = params[0]
+ def get_sessions(self):
+ with self.lock:
+ r = self.sessions[:]
+ return r
def add_session(self, session):
with self.lock:
self.subscriptions = []
self.address = ''
self.name = ''
+ self.version = 'unknown'
+ self.time = time.time()
threading.Timer(2, self.info).start()
# Debugging method. Doesn't need to be threadsafe.
#print sub
method = sub[0]
if method == 'blockchain.address.subscribe':
- params = sub[1]
- addr = params[0]
+ addr = sub[1]
break
else:
addr = None
- print timestr(), self.name, self.address, addr,\
- len(self.subscriptions), self.version
+
+ if self.subscriptions:
+ print timestr(), self.name, self.address, addr,\
+ len(self.subscriptions), self.version
def stopped(self):
with self.lock:
def build_subdesc(method, params):
if method == "blockchain.numblocks.subscribe":
return method,
- elif method == "blockchain.address.get_history":
+ elif method == "blockchain.address.subscribe":
if not params:
return None
else:
def send_response(self, internal_id, response):
session, message_id = self.processor.get_session_id(internal_id)
- response['id'] = message_id
- session.send_response(response)
+ if session:
+ response['id'] = message_id
+ session.send_response(response)
+ else:
+ print "send_response: no session", message_id, internal_id, response