Store session's protocol version as a tuple, not string
This commit is contained in:
parent
5ba5d05add
commit
fdb34e7d25
@ -533,7 +533,7 @@ class Controller(ServerBase):
|
|||||||
session.flags(),
|
session.flags(),
|
||||||
session.peer_address_str(for_log=for_log),
|
session.peer_address_str(for_log=for_log),
|
||||||
session.client,
|
session.client,
|
||||||
session.protocol_version,
|
session.protocol_version_string(),
|
||||||
session.count_pending_items(),
|
session.count_pending_items(),
|
||||||
session.txs_sent,
|
session.txs_sent,
|
||||||
session.sub_count(),
|
session.sub_count(),
|
||||||
|
|||||||
@ -143,8 +143,11 @@ class ElectrumX(SessionBase):
|
|||||||
self.hashX_subs = {}
|
self.hashX_subs = {}
|
||||||
self.sv_seen = False
|
self.sv_seen = False
|
||||||
self.mempool_statuses = {}
|
self.mempool_statuses = {}
|
||||||
self.protocol_version = None
|
self.set_protocol_handlers(util.protocol_tuple(
|
||||||
self.set_protocol_handlers((1, 1))
|
self.controller.PROTOCOL_MIN))
|
||||||
|
|
||||||
|
def protocol_version_string(self):
|
||||||
|
return util.version_string(self.protocol_tuple)
|
||||||
|
|
||||||
def sub_count(self):
|
def sub_count(self):
|
||||||
return len(self.hashX_subs)
|
return len(self.hashX_subs)
|
||||||
@ -438,15 +441,13 @@ class ElectrumX(SessionBase):
|
|||||||
# Find the highest common protocol version. Disconnect if
|
# Find the highest common protocol version. Disconnect if
|
||||||
# that protocol version in unsupported.
|
# that protocol version in unsupported.
|
||||||
ptuple = self.controller.protocol_tuple(protocol_version)
|
ptuple = self.controller.protocol_tuple(protocol_version)
|
||||||
|
|
||||||
if ptuple is None:
|
if ptuple is None:
|
||||||
self.close_after_send = True
|
self.close_after_send = True
|
||||||
raise RPCError(BAD_REQUEST,
|
raise RPCError(BAD_REQUEST,
|
||||||
f'unsupported protocol version: {protocol_version}')
|
f'unsupported protocol version: {protocol_version}')
|
||||||
|
|
||||||
self.set_protocol_handlers(ptuple)
|
self.set_protocol_handlers(ptuple)
|
||||||
|
|
||||||
return (electrumx.version, self.protocol_version)
|
return (electrumx.version, self.protocol_version_string())
|
||||||
|
|
||||||
async def transaction_broadcast(self, raw_tx):
|
async def transaction_broadcast(self, raw_tx):
|
||||||
'''Broadcast a raw transaction to the network.
|
'''Broadcast a raw transaction to the network.
|
||||||
@ -467,10 +468,7 @@ class ElectrumX(SessionBase):
|
|||||||
f'network rules.\n\n{message}\n[{raw_tx}]')
|
f'network rules.\n\n{message}\n[{raw_tx}]')
|
||||||
|
|
||||||
def set_protocol_handlers(self, ptuple):
|
def set_protocol_handlers(self, ptuple):
|
||||||
protocol_version = '.'.join(str(part) for part in ptuple)
|
self.protocol_tuple = ptuple
|
||||||
if protocol_version == self.protocol_version:
|
|
||||||
return
|
|
||||||
self.protocol_version = protocol_version
|
|
||||||
|
|
||||||
controller = self.controller
|
controller = self.controller
|
||||||
handlers = {
|
handlers = {
|
||||||
@ -547,7 +545,9 @@ class LocalRPC(SessionBase):
|
|||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.client = 'RPC'
|
self.client = 'RPC'
|
||||||
self.max_response_size = 0
|
self.max_response_size = 0
|
||||||
self.protocol_version = 'RPC'
|
|
||||||
|
def protocol_version_string(self):
|
||||||
|
return 'RPC'
|
||||||
|
|
||||||
def request_handler(self, method):
|
def request_handler(self, method):
|
||||||
'''Return the async handler for the given request method.'''
|
'''Return the async handler for the given request method.'''
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user