From 37c15f7018a0bf942c3ba7c8aaf3a711934eee2e Mon Sep 17 00:00:00 2001 From: Neil Booth Date: Wed, 6 Sep 2017 18:14:52 +0900 Subject: [PATCH] Show protocol version in sessions RPC call --- server/controller.py | 10 ++++++---- server/session.py | 13 +++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/server/controller.py b/server/controller.py index d78a082..2f17773 100644 --- a/server/controller.py +++ b/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(), diff --git a/server/session.py b/server/session.py index 5a45de4..a1c6ef6 100644 --- a/server/session.py +++ b/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.'''