Browse Source

Simplify sessions call

master
Neil Booth 8 years ago
parent
commit
3abddf4a51
  1. 14
      server/protocol.py

14
server/protocol.py

@ -163,8 +163,8 @@ class ServerManager(LoggedClass):
now = time.time() now = time.time()
return [(session.kind, return [(session.kind,
session.peername(for_log=False), session.peername(for_log=False),
len(session.hash168s), session.sub_count(),
'RPC' if isinstance(session, LocalRPC) else session.client, session.client,
session.recv_count, session.recv_size, session.recv_count, session.recv_size,
session.send_count, session.send_size, session.send_count, session.send_size,
session.error_count, session.error_count,
@ -197,9 +197,7 @@ class Session(JSONRPC):
self.daemon = bp.daemon self.daemon = bp.daemon
self.coin = bp.coin self.coin = bp.coin
self.kind = kind self.kind = kind
self.hash168s = set()
self.jobs = asyncio.Queue() self.jobs = asyncio.Queue()
self.current_task = None
self.client = 'unknown' self.client = 'unknown'
def connection_made(self, transport): def connection_made(self, transport):
@ -251,6 +249,9 @@ class Session(JSONRPC):
return 'xx.xx.xx.xx:xx' return 'xx.xx.xx.xx:xx'
return '{}:{}'.format(self.peer_info[0], self.peer_info[1]) return '{}:{}'.format(self.peer_info[0], self.peer_info[1])
def sub_count(self):
return 0
def tx_hash_from_param(self, param): def tx_hash_from_param(self, param):
'''Raise an RPCError if the parameter is not a valid transaction '''Raise an RPCError if the parameter is not a valid transaction
hash.''' hash.'''
@ -309,6 +310,7 @@ class ElectrumX(Session):
self.subscribe_headers = False self.subscribe_headers = False
self.subscribe_height = False self.subscribe_height = False
self.notified_height = None self.notified_height = None
self.hash168s = set()
rpcs = [ rpcs = [
('blockchain', ('blockchain',
'address.get_balance address.get_history address.get_mempool ' 'address.get_balance address.get_history address.get_mempool '
@ -324,6 +326,9 @@ class ElectrumX(Session):
for prefix, suffixes in rpcs for prefix, suffixes in rpcs
for suffix in suffixes.split()} for suffix in suffixes.split()}
def sub_count(self):
return len(self.hash168s)
async def notify(self, height, touched, cache): async def notify(self, height, touched, cache):
'''Notify the client about changes in height and touched addresses. '''Notify the client about changes in height and touched addresses.
@ -629,3 +634,4 @@ class LocalRPC(Session):
cmds = 'getinfo sessions numsessions peers numpeers'.split() cmds = 'getinfo sessions numsessions peers numpeers'.split()
self.handlers = {cmd: getattr(self.manager, 'rpc_{}'.format(cmd)) self.handlers = {cmd: getattr(self.manager, 'rpc_{}'.format(cmd))
for cmd in cmds} for cmd in cmds}
self.client = 'RPC'

Loading…
Cancel
Save