1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-02-21 12:02:19 +00:00

TEMP: try fix mailbox issue

This commit is contained in:
M1nd3r 2025-01-06 16:06:50 +01:00
parent 811eb3840c
commit 5bd51bc6b7
3 changed files with 20 additions and 14 deletions

View File

@ -269,7 +269,8 @@ if utils.USE_THP:
)
channel.sessions[new_session.session_id] = new_session
loop.schedule(new_session.handle())
new_session.handle_spawn = loop.spawn(new_session.handle())
loop.schedule(new_session.handle_spawn)
return Success(message="New session created.")

View File

@ -382,7 +382,8 @@ async def _handle_state_ENCRYPTED_TRANSPORT(ctx: Channel, message_length: int) -
s = SeedlessSessionContext(ctx, session_id)
ctx.sessions[session_id] = s
loop.schedule(s.handle())
s.handle_spawn = loop.spawn(s.handle())
loop.schedule(s.handle_spawn)
elif ctx.sessions[session_id].get_session_state() is SessionState.UNALLOCATED:
raise ThpUnallocatedSessionError(session_id)
@ -390,18 +391,20 @@ async def _handle_state_ENCRYPTED_TRANSPORT(ctx: Channel, message_length: int) -
s = ctx.sessions[session_id]
update_session_last_used(s.channel_id, (s.session_id).to_bytes(1, "big"))
s.incoming_message.put(
Message(
message_type,
buffer[
INIT_HEADER_LENGTH
+ MESSAGE_TYPE_LENGTH
+ SESSION_ID_LENGTH : message_length
- CHECKSUM_LENGTH
- TAG_LENGTH
],
)
message = Message(
message_type,
buffer[
INIT_HEADER_LENGTH
+ MESSAGE_TYPE_LENGTH
+ SESSION_ID_LENGTH : message_length
- CHECKSUM_LENGTH
- TAG_LENGTH
],
)
if not s.incoming_message.is_empty():
await s.handle_spawn
s.incoming_message.clear()
s.incoming_message.put(message)
async def _handle_pairing(ctx: Channel, message_length: int) -> None:

View File

@ -34,6 +34,7 @@ class GenericSessionContext(Context):
self.channel: Channel = channel
self.session_id: int = session_id
self.incoming_message = loop.mailbox()
self.handle_spawn: loop.spawn | None = None
async def handle(self) -> None:
if __debug__ and utils.ALLOW_DEBUG_MESSAGES:
@ -51,7 +52,8 @@ class GenericSessionContext(Context):
next_message = None
try:
if await self._handle_message(message):
loop.schedule(self.handle())
self.handle_spawn = loop.spawn(self.handle())
loop.schedule(self.handle_spawn)
return
except UnexpectedMessageException as unexpected:
# The workflow was interrupted by an unexpected message. We need to