raise TypeError("self.shared not set in Processor")
while not self.shared.stopped():
session, request = self.pop_request()
-
- method = request['method']
- params = request.get('params',[])
-
- suffix = method.split('.')[-1]
- if suffix == 'subscribe':
- session.subscribe_to_service(method, params)
-
- # store session and id locally
- request['id'] = self.store_session_id(session, request['id'])
-
- # dispatch request to the relevant module..
- prefix = method.split('.')[0]
- try:
- func = self.processors[prefix]
- except:
- print "error: no processor for", prefix
- continue
-
- try:
- func(request,self.response_queue)
- except:
- traceback.print_exc(file=sys.stdout)
- continue
+ self.process(session, request)
self.stop()
def stop(self):
pass
- def process(self, request):
- print "New request", request
- # Do stuff...
- # response = request
- # When ready, you call
- # self.push_response(response)
+ def process(self, session, request):
+ method = request['method']
+ params = request.get('params',[])
+
+ suffix = method.split('.')[-1]
+ if suffix == 'subscribe':
+ session.subscribe_to_service(method, params)
+
+ # store session and id locally
+ request['id'] = self.store_session_id(session, request['id'])
+
+ # dispatch request to the relevant module..
+ prefix = request['method'].split('.')[0]
+ try:
+ func = self.processors[prefix]
+ except:
+ print "error: no processor for", prefix
+ return
+ try:
+ func(request,self.response_queue)
+ except:
+ traceback.print_exc(file=sys.stdout)
+
def add_session(self, session):
with self.lock:
from SocketServer import ThreadingMixIn
class StratumThreadedJSONRPCServer(ThreadingMixIn, StratumJSONRPCServer): pass
self.server = StratumThreadedJSONRPCServer(( self.host, self.port))
- for s in ['server.peers', 'server.banner', 'transaction.broadcast', \
- 'address.get_history','address.subscribe', 'numblocks.subscribe', 'client.version']:
+ for s in ['server.peers.subscribe', 'server.banner', 'blockchain.transaction.broadcast', \
+ 'blockchain.address.get_history','blockchain.address.subscribe', \
+ 'blockchain.numblocks.subscribe', 'client.version' ]:
self.server.register_function(self.process, s)
self.server.register_function(self.do_stop, 'stop')
#print session, request
session = self.server.sessions.get(session_id)
if session:
- #print "zz",session_id,session
- request['id'] = self.processor.store_session_id(session, request['id'])
- self.processor.process(request)
+ self.processor.process(session, request)
def do_stop(self, session, request):
self.shared.stop()