From abba36ac6c3c56a235f9513eb75464c5abb1a585 Mon Sep 17 00:00:00 2001 From: Neil Booth Date: Sat, 1 Apr 2017 11:17:57 +0900 Subject: [PATCH] Relax the get_chunk restriction based on client Closes #162 --- server/session.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/server/session.py b/server/session.py index b7e4ddb..5236001 100644 --- a/server/session.py +++ b/server/session.py @@ -34,6 +34,7 @@ class SessionBase(JSONSession): self.env = controller.env self.daemon = self.bp.daemon self.client = 'unknown' + self.client_version = (1) self.protocol_version = '1.0' self.anon_logs = self.env.anon_logs self.last_delay = 0 @@ -262,14 +263,15 @@ class ElectrumX(SessionBase): index: the chunk index''' index = self.controller.non_negative_integer(index) - self.chunk_indices.append(index) - self.chunk_indices = self.chunk_indices[-5:] - # -2 allows backing up a single chunk but no more. - if index <= max(self.chunk_indices[:-2], default=-1): - msg = ('chunk indices not advancing (wrong network?): {}' - .format(self.chunk_indices)) - # INVALID_REQUEST triggers a disconnect - raise RPCError(msg, JSONRPC.INVALID_REQUEST) + if self.client_version < (2, 8, 3): + self.chunk_indices.append(index) + self.chunk_indices = self.chunk_indices[-5:] + # -2 allows backing up a single chunk but no more. + if index <= max(self.chunk_indices[:-2], default=-1): + msg = ('chunk indices not advancing (wrong network?): {}' + .format(self.chunk_indices)) + # use INVALID_REQUEST to trigger a disconnect + raise RPCError(msg, JSONRPC.INVALID_REQUEST) return self.controller.get_chunk(index) def is_tor(self): @@ -323,6 +325,11 @@ class ElectrumX(SessionBase): ''' if client_name: self.client = str(client_name)[:17] + try: + self.client_version = tuple(int(part) for part + in self.client.split('.')) + except Exception: + pass if protocol_version is not None: self.protocol_version = protocol_version return version.VERSION