1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-02-01 10:20:59 +00:00

refactor(trezorlib): improve transport protocol file structure

[no changelog]
This commit is contained in:
M1nd3r 2024-10-14 18:39:50 +02:00
parent 594ec26fa7
commit 7f503ce199
15 changed files with 18 additions and 19 deletions

View File

@ -29,7 +29,7 @@ from .. import exceptions, transport, ui
from ..client import TrezorClient
from ..messages import Capability
from ..transport import Transport
from ..transport.new import channel_database
from ..transport.thp import channel_database
LOG = logging.getLogger(__name__)

View File

@ -27,8 +27,8 @@ import click
from .. import __version__, log, messages, protobuf
from ..client import TrezorClient
from ..transport import DeviceIsBusy, enumerate_devices
from ..transport.new import channel_database
from ..transport.session import Session
from ..transport.thp import channel_database
from ..transport.udp import UdpTransport
from . import (
AliasedGroup,

View File

@ -23,10 +23,10 @@ from . import mapping, messages, models
from .mapping import ProtobufMapping
from .tools import parse_path
from .transport import Transport, get_transport
from .transport.new.channel_data import ChannelData
from .transport.new.protocol_and_channel import ProtocolAndChannel
from .transport.new.protocol_v1 import ProtocolV1
from .transport.new.protocol_v2 import ProtocolV2
from .transport.thp.channel_data import ChannelData
from .transport.thp.protocol_and_channel import ProtocolAndChannel
from .transport.thp.protocol_v1 import ProtocolV1
from .transport.thp.protocol_v2 import ProtocolV2
if t.TYPE_CHECKING:
from .transport.session import Session

View File

@ -37,8 +37,8 @@ from .exceptions import TrezorFailure
from .log import DUMP_BYTES
from .messages import DebugWaitType
from .tools import expect
from .transport.new.protocol_v1 import ProtocolV1
from .transport.session import Session
from .transport.thp.protocol_v1 import ProtocolV1
if t.TYPE_CHECKING:
from typing_extensions import Protocol

View File

@ -4,8 +4,8 @@ import logging
import typing as t
from .. import exceptions, messages, models
from .new.protocol_v1 import ProtocolV1
from .new.protocol_v2 import ProtocolV2
from .thp.protocol_v1 import ProtocolV1
from .thp.protocol_v2 import ProtocolV2
if t.TYPE_CHECKING:
from ..client import TrezorClient

View File

@ -3,7 +3,7 @@ import logging
import os
import typing as t
from .channel_data import ChannelData
from ..thp.channel_data import ChannelData
from .protocol_and_channel import ProtocolAndChannel
LOG = logging.getLogger(__name__)
@ -69,7 +69,7 @@ def save_channel(new_channel: ProtocolAndChannel):
channels = read_all_channels()
transport_path = new_channel.transport.get_path()
# If channel is modified: replace the old by the new
# If the channel is found in database: replace the old entry by the new
for i, channel in enumerate(channels):
if channel["transport_path"] == transport_path:
LOG.debug("Modified channel entry for %s", transport_path)
@ -77,7 +77,7 @@ def save_channel(new_channel: ProtocolAndChannel):
save_all_channels(channels)
return
# Else: add a new channel entry
# Channel was not found: add a new channel entry
LOG.debug("Created a new channel entry on path %s", transport_path)
channels.append(new_channel.get_channel_data().to_dict())
save_all_channels(channels)

View File

@ -5,7 +5,7 @@ import logging
from ... import messages
from ...mapping import ProtobufMapping
from .. import Transport
from .channel_data import ChannelData
from ..thp.channel_data import ChannelData
LOG = logging.getLogger(__name__)

View File

@ -15,10 +15,10 @@ from ... import exceptions, messages
from ...mapping import ProtobufMapping
from .. import Transport
from ..thp import checksum, curve25519, thp_io
from ..thp.channel_data import ChannelData
from ..thp.checksum import CHECKSUM_LENGTH
from ..thp.message_header import MessageHeader
from . import channel_database, control_byte
from .channel_data import ChannelData
from .protocol_and_channel import ProtocolAndChannel
LOG = logging.getLogger(__name__)
@ -365,7 +365,7 @@ class ProtocolV2(ProtocolAndChannel):
if not is_valid:
click.echo(
"Received a message with an invalid checksum:"
+ hexlify(header.to_bytes_init() + payload + chksum),
+ hexlify(header.to_bytes_init() + payload + chksum).decode(),
err=True,
)
header, payload, chksum = thp_io.read(self.transport)

View File

@ -24,8 +24,7 @@ from __future__ import annotations
from gevent import monkey
import trezorlib.transport.new
import trezorlib.transport.new.transport
import trezorlib.transport
monkey.patch_all()

View File

@ -33,7 +33,7 @@ from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.device import apply_settings
from trezorlib.device import wipe as wipe_device
from trezorlib.transport import enumerate_devices, get_transport
from trezorlib.transport.new.protocol_v1 import ProtocolV1
from trezorlib.transport.thp.protocol_v1 import ProtocolV1
# register rewrites before importing from local package
# so that we see details of failed asserts from this module
@ -310,7 +310,7 @@ def client(
wipe_device(session)
sleep(1) # Makes tests more stable (wait for wipe to finish)
from trezorlib.transport.new import channel_database
from trezorlib.transport.thp import channel_database
channel_database.clear_stored_channels()
_raw_client.protocol = None