pass
def push_response(self, response):
- print "response", response
+ #print "response", response
self.dispatcher.request_dispatcher.push_response(response)
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)
self.subscriptions = []
self.address = ''
self.name = ''
- #threading.Timer(2, self.info).start()
+ self.version = 'unknown'
+ self.time = time.time()
+ threading.Timer(2, self.info).start()
# Debugging method. Doesn't need to be threadsafe.
def info(self):
for sub in self.subscriptions:
- print sub
- method, params = sub
+ #print sub
+ method = sub[0]
if method == 'blockchain.address.subscribe':
- 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 subscribe_to_service(self, method, params):
subdesc = self.build_subdesc(method, params)
with self.lock:
- self.subscriptions.append(subdesc)
+ if subdesc is not None:
+ self.subscriptions.append(subdesc)
# subdesc = A subscription description
- def build_subdesc(self, method, params):
+ @staticmethod
+ 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:
#print "pop response", response
internal_id = response.get('id')
method = response.get('method')
- params = response.get('params', [])
+ params = response.get('params')
# A notification
- if internal_id is None and method is None:
- self.notification(response)
- elif internal_id is not None:
+ if internal_id is None: # and method is not None and params is not None:
+ self.notification(method, params, response)
+ # A response
+ elif internal_id is not None: # and method is None and params is None:
self.send_response(internal_id, response)
else:
print "no method", response
- def notification(self, response):
- subdesc = self.build_subdesc(method, params)
+ def notification(self, method, params, response):
+ subdesc = Session.build_subdesc(method, params)
for session in self.processor.sessions:
if session.stopped():
continue
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