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`,
|
||||
only raw headers can be subscribed to.
|
||||
* Only the first :func:`server.version` message is accepted.
|
||||
* Optional *cp_height* argument added to
|
||||
: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
|
||||
Use :func:`server.ping` rather than sending version requests as a
|
||||
ping mechanism.
|
||||
.. versionchanged:: 1.4
|
||||
Only the first :func:`server.version` message is accepted.
|
||||
|
||||
* *client_name*
|
||||
|
||||
|
||||
@ -59,7 +59,6 @@ class SessionBase(ServerSession):
|
||||
self.env = controller.env
|
||||
self.daemon = self.bp.daemon
|
||||
self.client = 'unknown'
|
||||
self.client_version = (1, )
|
||||
self.anon_logs = self.env.anon_logs
|
||||
self.txs_sent = 0
|
||||
self.log_me = False
|
||||
@ -142,6 +141,7 @@ class ElectrumX(SessionBase):
|
||||
self.max_response_size = self.env.max_send
|
||||
self.max_subs = self.env.max_session_subs
|
||||
self.hashX_subs = {}
|
||||
self.sv_seen = False
|
||||
self.mempool_statuses = {}
|
||||
self.protocol_version = None
|
||||
self.set_protocol_handlers((1, 1))
|
||||
@ -416,24 +416,24 @@ class ElectrumX(SessionBase):
|
||||
'''
|
||||
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.
|
||||
|
||||
client_name: a string identifying 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:
|
||||
client_name = str(client_name)
|
||||
if self.env.drop_client is not None and \
|
||||
self.env.drop_client.match(client_name):
|
||||
self.close_after_send = True
|
||||
raise RPCError(BAD_REQUEST,
|
||||
f'unsupported client: {client_name}')
|
||||
self.client = str(client_name)[:17]
|
||||
try:
|
||||
self.client_version = tuple(int(part) for part
|
||||
in self.client.split('.'))
|
||||
except Exception:
|
||||
pass
|
||||
self.client = client_name[:17]
|
||||
|
||||
# Find the highest common protocol version. Disconnect if
|
||||
# that protocol version in unsupported.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user