Protocol 1.4: only accept a single server.version message
- remove unused self.client_version - coerce client_name to a str
This commit is contained in:
parent
382fc5ed44
commit
5ba5d05add
@ -129,6 +129,7 @@ Changes
|
|||||||
|
|
||||||
* The argument *raw* removed from :func:`blockchain.headers.subscribe`,
|
* The argument *raw* removed from :func:`blockchain.headers.subscribe`,
|
||||||
only raw headers can be subscribed to.
|
only raw headers can be subscribed to.
|
||||||
|
* Only the first :func:`server.version` message is accepted.
|
||||||
* Optional *cp_height* argument added to
|
* Optional *cp_height* argument added to
|
||||||
:func:`blockchain.block.header` and :func:`blockchain.block.headers`
|
:func:`blockchain.block.header` and :func:`blockchain.block.headers`
|
||||||
|
|
||||||
|
|||||||
@ -907,6 +907,8 @@ Identify the client to the server and negotiate the protocol version.
|
|||||||
.. versionchanged:: 1.2
|
.. versionchanged:: 1.2
|
||||||
Use :func:`server.ping` rather than sending version requests as a
|
Use :func:`server.ping` rather than sending version requests as a
|
||||||
ping mechanism.
|
ping mechanism.
|
||||||
|
.. versionchanged:: 1.4
|
||||||
|
Only the first :func:`server.version` message is accepted.
|
||||||
|
|
||||||
* *client_name*
|
* *client_name*
|
||||||
|
|
||||||
|
|||||||
@ -59,7 +59,6 @@ class SessionBase(ServerSession):
|
|||||||
self.env = controller.env
|
self.env = controller.env
|
||||||
self.daemon = self.bp.daemon
|
self.daemon = self.bp.daemon
|
||||||
self.client = 'unknown'
|
self.client = 'unknown'
|
||||||
self.client_version = (1, )
|
|
||||||
self.anon_logs = self.env.anon_logs
|
self.anon_logs = self.env.anon_logs
|
||||||
self.txs_sent = 0
|
self.txs_sent = 0
|
||||||
self.log_me = False
|
self.log_me = False
|
||||||
@ -142,6 +141,7 @@ class ElectrumX(SessionBase):
|
|||||||
self.max_response_size = self.env.max_send
|
self.max_response_size = self.env.max_send
|
||||||
self.max_subs = self.env.max_session_subs
|
self.max_subs = self.env.max_session_subs
|
||||||
self.hashX_subs = {}
|
self.hashX_subs = {}
|
||||||
|
self.sv_seen = False
|
||||||
self.mempool_statuses = {}
|
self.mempool_statuses = {}
|
||||||
self.protocol_version = None
|
self.protocol_version = None
|
||||||
self.set_protocol_handlers((1, 1))
|
self.set_protocol_handlers((1, 1))
|
||||||
@ -416,24 +416,24 @@ class ElectrumX(SessionBase):
|
|||||||
'''
|
'''
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def server_version(self, client_name=None, protocol_version=None):
|
def server_version(self, client_name='', protocol_version=None):
|
||||||
'''Returns the server version as a string.
|
'''Returns the server version as a string.
|
||||||
|
|
||||||
client_name: a string identifying the client
|
client_name: a string identifying the client
|
||||||
protocol_version: the protocol version spoken by the client
|
protocol_version: the protocol version spoken by the client
|
||||||
'''
|
'''
|
||||||
|
if self.sv_seen and self.protocol_tuple >= (1, 4):
|
||||||
|
raise RPCError(BAD_REQUEST, f'server.version already sent')
|
||||||
|
self.sv_seen = True
|
||||||
|
|
||||||
if client_name:
|
if client_name:
|
||||||
|
client_name = str(client_name)
|
||||||
if self.env.drop_client is not None and \
|
if self.env.drop_client is not None and \
|
||||||
self.env.drop_client.match(client_name):
|
self.env.drop_client.match(client_name):
|
||||||
self.close_after_send = True
|
self.close_after_send = True
|
||||||
raise RPCError(BAD_REQUEST,
|
raise RPCError(BAD_REQUEST,
|
||||||
f'unsupported client: {client_name}')
|
f'unsupported client: {client_name}')
|
||||||
self.client = str(client_name)[:17]
|
self.client = client_name[:17]
|
||||||
try:
|
|
||||||
self.client_version = tuple(int(part) for part
|
|
||||||
in self.client.split('.'))
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# 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.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user