mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-11 16:00:57 +00:00
python: ensure client session counter is never negative
This commit is contained in:
parent
3f9b0b7f4f
commit
598e828844
@ -132,9 +132,9 @@ class TrezorClient:
|
|||||||
self.session_counter += 1
|
self.session_counter += 1
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
if self.session_counter == 1:
|
self.session_counter = max(self.session_counter - 1, 0)
|
||||||
|
if self.session_counter == 0:
|
||||||
self.transport.end_session()
|
self.transport.end_session()
|
||||||
self.session_counter -= 1
|
|
||||||
|
|
||||||
def cancel(self):
|
def cancel(self):
|
||||||
self._raw_write(messages.Cancel())
|
self._raw_write(messages.Cancel())
|
||||||
|
@ -93,9 +93,9 @@ class Protocol:
|
|||||||
self.session_counter += 1
|
self.session_counter += 1
|
||||||
|
|
||||||
def end_session(self) -> None:
|
def end_session(self) -> None:
|
||||||
if self.session_counter == 1:
|
self.session_counter = max(self.session_counter - 1, 0)
|
||||||
|
if self.session_counter == 0:
|
||||||
self.handle.close()
|
self.handle.close()
|
||||||
self.session_counter -= 1
|
|
||||||
|
|
||||||
def read(self) -> protobuf.MessageType:
|
def read(self) -> protobuf.MessageType:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
Loading…
Reference in New Issue
Block a user