From 5306a8b55e698bb7f7d849c91ea0e4d6cdb54396 Mon Sep 17 00:00:00 2001 From: M1nd3r Date: Wed, 3 Apr 2024 17:31:24 +0200 Subject: [PATCH] chore(core): improve logging of channel state, reduce logging of sessions --- core/src/storage/cache_thp.py | 3 --- core/src/trezor/wire/thp/channel.py | 28 +++++----------------------- 2 files changed, 5 insertions(+), 26 deletions(-) diff --git a/core/src/storage/cache_thp.py b/core/src/storage/cache_thp.py index cf228b6f0..b81147a4e 100644 --- a/core/src/storage/cache_thp.py +++ b/core/src/storage/cache_thp.py @@ -180,7 +180,6 @@ def set_channel_host_ephemeral_key(channel: ChannelCache, key: bytearray) -> Non def get_new_session(channel: ChannelCache): - print("---------------get new session") new_sid = get_next_session_id(channel) index = _get_next_session_index() @@ -194,8 +193,6 @@ def get_new_session(channel: ChannelCache): _SESSIONS[index].state[:] = bytearray( _UNALLOCATED_STATE.to_bytes(_SESSION_STATE_LENGTH, "big") ) - for s in _SESSIONS: - print(s) return _SESSIONS[index] diff --git a/core/src/trezor/wire/thp/channel.py b/core/src/trezor/wire/thp/channel.py index 191998d1a..bf006059f 100644 --- a/core/src/trezor/wire/thp/channel.py +++ b/core/src/trezor/wire/thp/channel.py @@ -71,11 +71,11 @@ class Channel(Context): def get_channel_state(self) -> int: state = int.from_bytes(self.channel_cache.state, "big") - print("channel.get_ch_state:", state) + print("channel.get_ch_state:", _state_to_str(state)) return state def set_channel_state(self, state: ChannelState) -> None: - print("channel.set_ch_state:", int.from_bytes(state.to_bytes(1, "big"), "big")) + print("channel.set_ch_state:", _state_to_str(state)) self.channel_cache.state = bytearray(state.to_bytes(1, "big")) def set_buffer(self, buffer: utils.BufferType) -> None: @@ -194,7 +194,7 @@ class Channel(Context): ) -> None: state = self.get_channel_state() if __debug__: - log.debug(__name__, _state_to_str(state)) + log.debug(__name__, "state: " + _state_to_str(state)) if state is ChannelState.TH1: await self._handle_state_TH1(payload_length, message_length, sync_bit) @@ -600,26 +600,8 @@ def is_channel_state_pairing(state: int) -> bool: def _state_to_str(state: int) -> str: - if state == ChannelState.ENCRYPTED_TRANSPORT: - return "state: encrypted transport" - elif state == ChannelState.TH1: - return "state: th1" - elif state == ChannelState.TH2: - return "state: th2" - elif state == ChannelState.TP1: - return "state: tp1" - elif state == ChannelState.TP2: - return "state: tp2" - elif state == ChannelState.TP3: - return "state: tp3" - elif state == ChannelState.TP4: - return "state: tp4" - elif state == ChannelState.TP5: - return "state: tp5" - elif state == ChannelState.UNALLOCATED: - return "state: unallocated" - else: - return "state: " + names = {v: k for k, v in ChannelState.__dict__.items() if not k.startswith("__")} + return names.get(state) def printBytes(a):