Improve logging of client version requests
This commit is contained in:
parent
8630c9136c
commit
382fc5ed44
@ -305,6 +305,15 @@ def version_string(ptuple):
|
|||||||
|
|
||||||
|
|
||||||
def protocol_version(client_req, server_min, server_max):
|
def protocol_version(client_req, server_min, server_max):
|
||||||
|
'''Given a client's protocol version string, return a pair of
|
||||||
|
protocol tuples:
|
||||||
|
|
||||||
|
(negotiated version, client min request)
|
||||||
|
|
||||||
|
If the request is unsupported, the negotiated protocol tuple is
|
||||||
|
None.
|
||||||
|
|
||||||
|
'''
|
||||||
'''Given a client protocol request, return the protocol version
|
'''Given a client protocol request, return the protocol version
|
||||||
to use as a tuple.
|
to use as a tuple.
|
||||||
|
|
||||||
@ -326,7 +335,7 @@ def protocol_version(client_req, server_min, server_max):
|
|||||||
if result < max(client_min, server_min) or result == (0, ):
|
if result < max(client_min, server_min) or result == (0, ):
|
||||||
result = None
|
result = None
|
||||||
|
|
||||||
return result
|
return result, client_min
|
||||||
|
|
||||||
|
|
||||||
unpack_int32_from = Struct('<i').unpack_from
|
unpack_int32_from = Struct('<i').unpack_from
|
||||||
|
|||||||
@ -122,12 +122,17 @@ class Controller(ServerBase):
|
|||||||
'''The arguments to a server.version RPC call to a peer.'''
|
'''The arguments to a server.version RPC call to a peer.'''
|
||||||
return [electrumx.version, [self.PROTOCOL_MIN, self.PROTOCOL_MAX]]
|
return [electrumx.version, [self.PROTOCOL_MIN, self.PROTOCOL_MAX]]
|
||||||
|
|
||||||
def protocol_tuple(self, client_protocol_str):
|
def protocol_tuple(self, request):
|
||||||
'''Given a client's protocol version string, return the negotiated
|
'''Given a client's protocol version request, return the negotiated
|
||||||
protocol version tuple, or None if unsupported.
|
protocol tuple. If the request is unsupported return None.
|
||||||
'''
|
'''
|
||||||
return util.protocol_version(client_protocol_str,
|
ptuple, client_min = util.protocol_version(request, self.PROTOCOL_MIN,
|
||||||
self.PROTOCOL_MIN, self.PROTOCOL_MAX)
|
self.PROTOCOL_MAX)
|
||||||
|
if not ptuple and client_min > util.protocol_tuple(self.PROTOCOL_MIN):
|
||||||
|
version = version_string(client_min)
|
||||||
|
self.logger.info(f'client requested future protocol version '
|
||||||
|
f'{version} - is your software out of date?')
|
||||||
|
return ptuple
|
||||||
|
|
||||||
async def start_servers(self):
|
async def start_servers(self):
|
||||||
'''Start the RPC server and schedule the external servers to be
|
'''Start the RPC server and schedule the external servers to be
|
||||||
|
|||||||
@ -440,8 +440,6 @@ class ElectrumX(SessionBase):
|
|||||||
ptuple = self.controller.protocol_tuple(protocol_version)
|
ptuple = self.controller.protocol_tuple(protocol_version)
|
||||||
|
|
||||||
if ptuple is None:
|
if ptuple is None:
|
||||||
self.logger.info('unsupported protocol version request {}'
|
|
||||||
.format(protocol_version))
|
|
||||||
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}')
|
||||||
|
|||||||
@ -183,21 +183,27 @@ def test_version_string():
|
|||||||
assert util.version_string((1, 3, 2)) == "1.3.2"
|
assert util.version_string((1, 3, 2)) == "1.3.2"
|
||||||
|
|
||||||
def test_protocol_version():
|
def test_protocol_version():
|
||||||
assert util.protocol_version(None, "1.0", "1.0") == (1, 0)
|
assert util.protocol_version(None, "1.0", "1.0") == ((1, 0), (1, 0))
|
||||||
assert util.protocol_version("0.10", "0.10", "1.1") == (0, 10)
|
assert util.protocol_version("0.10", "0.10", "1.1") == ((0, 10), (0, 10))
|
||||||
|
|
||||||
assert util.protocol_version("1.0", "1.0", "1.0") == (1, 0)
|
assert util.protocol_version("1.0", "1.0", "1.0") == ((1, 0), (1, 0))
|
||||||
assert util.protocol_version("1.0", "1.0", "1.1") == (1, 0)
|
assert util.protocol_version("1.0", "1.0", "1.1") == ((1, 0), (1, 0))
|
||||||
assert util.protocol_version("1.1", "1.0", "1.1") == (1, 1)
|
assert util.protocol_version("1.1", "1.0", "1.1") == ((1, 1), (1, 1))
|
||||||
assert util.protocol_version("1.2", "1.0", "1.1") is None
|
assert util.protocol_version("1.2", "1.0", "1.1") == (None, (1, 2))
|
||||||
assert util.protocol_version("0.9", "1.0", "1.1") is None
|
assert util.protocol_version("0.9", "1.0", "1.1") == (None, (0, 9))
|
||||||
|
|
||||||
assert util.protocol_version(["0.9", "1.0"], "1.0", "1.1") == (1, 0)
|
assert util.protocol_version(["0.9", "1.0"], "1.0", "1.1") \
|
||||||
assert util.protocol_version(["0.9", "1.1"], "1.0", "1.1") == (1, 1)
|
== ((1, 0), (0, 9))
|
||||||
assert util.protocol_version(["1.1", "0.9"], "1.0", "1.1") is None
|
assert util.protocol_version(["0.9", "1.1"], "1.0", "1.1") \
|
||||||
assert util.protocol_version(["0.8", "0.9"], "1.0", "1.1") is None
|
== ((1, 1), (0,9))
|
||||||
assert util.protocol_version(["1.1", "1.2"], "1.0", "1.1") == (1, 1)
|
assert util.protocol_version(["1.1", "0.9"], "1.0", "1.1") \
|
||||||
assert util.protocol_version(["1.2", "1.3"], "1.0", "1.1") is None
|
== (None, (1, 1))
|
||||||
|
assert util.protocol_version(["0.8", "0.9"], "1.0", "1.1") \
|
||||||
|
== (None, (0, 8))
|
||||||
|
assert util.protocol_version(["1.1", "1.2"], "1.0", "1.1") \
|
||||||
|
== ((1, 1), (1, 1))
|
||||||
|
assert util.protocol_version(["1.2", "1.3"], "1.0", "1.1") \
|
||||||
|
== (None, (1, 2))
|
||||||
|
|
||||||
|
|
||||||
def test_unpackers():
|
def test_unpackers():
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user