Adjust loop clear

M1nd3r/thp5
M1nd3r 1 month ago
parent bb82bcafb1
commit 54661fb5f9

@ -5,7 +5,7 @@ from typing import TYPE_CHECKING # pyright:ignore[reportShadowedImports]
import usb
from storage import cache_thp
from storage.cache_thp import KEY_LENGTH, SESSION_ID_LENGTH, TAG_LENGTH, ChannelCache
from trezor import log, loop, protobuf, utils
from trezor import log, loop, protobuf, utils, workflow
from trezor.enums import FailureType, MessageType # , ThpPairingMethod
from trezor.messages import Failure
from trezor.wire import message_handler
@ -534,9 +534,18 @@ class Channel(Context):
try:
await self.waiting_for_ack_timeout
except loop.TaskClosed:
THP.sync_set_send_bit_to_opposite(self.channel_cache)
break
THP.sync_set_send_bit_to_opposite(self.channel_cache)
# Let the main loop be restarted and clear loop, if there is no other
# workflow and the state is ENCRYPTED_TRANSPORT
if (
not workflow.tasks
and self.get_channel_state() is ChannelState.ENCRYPTED_TRANSPORT
):
loop.clear()
async def _wait_for_ack(self) -> None:
await loop.sleep(1000)

@ -47,7 +47,7 @@ class SessionContext(Context):
async def handle(self, is_debug_session: bool = False) -> None:
if __debug__:
log.debug(__name__, "handle - start")
log.debug(__name__, "handle - start (session_id: %d)", self.session_id)
if is_debug_session:
import apps.debug
@ -98,8 +98,6 @@ class SessionContext(Context):
and message.type not in AVOID_RESTARTING_FOR
):
# Shut down the loop if there is no next message waiting.
# Let the session be restarted from `main`.
loop.clear()
return # pylint: disable=lost-exception
except Exception as exc:

Loading…
Cancel
Save