Browse Source

Show protocol version in sessions RPC call

master
Neil Booth 7 years ago
parent
commit
37c15f7018
  1. 10
      server/controller.py
  2. 13
      server/session.py

10
server/controller.py

@ -542,13 +542,14 @@ class Controller(util.LoggedClass):
'''A generator returning lines for a list of sessions.
data is the return value of rpc_sessions().'''
fmt = ('{:<6} {:<5} {:>17} {:>5} {:>5} '
fmt = ('{:<6} {:<5} {:>17} {:>5} {:>5} {:>5} '
'{:>7} {:>7} {:>7} {:>7} {:>7} {:>9} {:>21}')
yield fmt.format('ID', 'Flags', 'Client', 'Reqs', 'Txs', 'Subs',
yield fmt.format('ID', 'Flags', 'Client', 'Proto',
'Reqs', 'Txs', 'Subs',
'Recv', 'Recv KB', 'Sent', 'Sent KB', 'Time', 'Peer')
for (id_, flags, peer, client, reqs, txs_sent, subs,
for (id_, flags, peer, client, proto, reqs, txs_sent, subs,
recv_count, recv_size, send_count, send_size, time) in data:
yield fmt.format(id_, flags, client,
yield fmt.format(id_, flags, client, proto,
'{:,d}'.format(reqs),
'{:,d}'.format(txs_sent),
'{:,d}'.format(subs),
@ -566,6 +567,7 @@ class Controller(util.LoggedClass):
session.flags(),
session.peername(for_log=for_log),
session.client,
session.protocol_version,
session.count_pending_items(),
session.txs_sent,
session.sub_count(),

13
server/session.py

@ -113,6 +113,7 @@ class ElectrumX(SessionBase):
self.hashX_subs = {}
self.mempool_statuses = {}
self.chunk_indices = []
self.protocol_version = None
self.set_protocol_handlers((1, 0))
def sub_count(self):
@ -322,8 +323,6 @@ class ElectrumX(SessionBase):
except Exception:
pass
self.log_info('protocol version {} requested'.format(protocol_version))
# Find the highest common protocol version. Disconnect if
# that protocol version in unsupported.
ptuple = util.protocol_version(protocol_version, version.PROTOCOL_MIN,
@ -336,10 +335,11 @@ class ElectrumX(SessionBase):
self.set_protocol_handlers(ptuple)
# The return value depends on the protocol version
if ptuple < (1, 1):
return version.VERSION
return (version.VERSION, '.'.join(str(part) for part in ptuple))
else:
return (version.VERSION, self.protocol_version)
async def transaction_broadcast(self, raw_tx):
'''Broadcast a raw transaction to the network.
@ -382,6 +382,10 @@ class ElectrumX(SessionBase):
return message
def set_protocol_handlers(self, ptuple):
protocol_version = '.'.join(str(part) for part in ptuple)
if protocol_version == self.protocol_version:
return
self.protocol_version = protocol_version
controller = self.controller
handlers = {
'blockchain.address.get_balance': controller.address_get_balance,
@ -438,6 +442,7 @@ class LocalRPC(SessionBase):
super().__init__(*args, **kwargs)
self.client = 'RPC'
self.max_send = 0
self.protocol_version = 'RPC'
def request_handler(self, method):
'''Return the async handler for the given request method.'''

Loading…
Cancel
Save