Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use UDP with node bridge, non-UDP with old bridge when communicating with emulator #268

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ def is_running() -> bool:
return is_port_in_use(BRIDGE_PORT)


def is_node_bridge_running() -> bool:
if VERSION_RUNNING is None:
return False
return "node" in VERSION_RUNNING


def get_status() -> "StatusResponse":
if helpers.physical_trezor():
return {
Expand Down
15 changes: 8 additions & 7 deletions src/emulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ def wait_for_udp_device() -> Transport:


def get_device() -> Transport:
if bridge.is_running():
# Node bridges need UDP
if bridge.is_running() and not bridge.is_node_bridge_running():
return wait_for_bridge_device()

return wait_for_udp_device()
Expand Down Expand Up @@ -306,7 +307,7 @@ def get_current_screen() -> str:

@contextmanager
def connect_to_client(
needs_udp: bool = True,
needs_udp: bool = False,
) -> Generator[TrezorClientDebugLink, None, None]:
"""Connect to the emulator and yield a client instance.
Disconnect after the action is done.
Expand All @@ -328,7 +329,7 @@ def connect_to_client(

@contextmanager
def connect_to_debuglink(
needs_udp: bool = True,
needs_udp: bool = False,
) -> Generator[DebugLink, None, None]:
"""Connect to the emulator and yield a debuglink instance.
Disconnect after the action is done.
Expand Down Expand Up @@ -455,7 +456,7 @@ def read_and_confirm_mnemonic() -> None:


def read_and_confirm_mnemonic_t2t1() -> None:
with connect_to_debuglink() as debug:
with connect_to_debuglink(needs_udp=True) as debug:
debug.watch_layout(True)

preview_texts = [
Expand Down Expand Up @@ -514,7 +515,7 @@ def read_and_confirm_mnemonic_t2t1() -> None:


def read_and_confirm_mnemonic_t3t1() -> None:
with connect_to_debuglink() as debug:
with connect_to_debuglink(needs_udp=True) as debug:
debug.watch_layout(True)

# "backup contains XXX words"
Expand Down Expand Up @@ -904,7 +905,7 @@ def allow_unsafe() -> None:

def get_debug_state() -> Dict[str, Any]:
# We need to connect on UDP not to interrupt any bridge sessions
with connect_to_debuglink() as debug:
with connect_to_debuglink(needs_udp=True) as debug:
debug_state = debug.state()
debug_state_dict: Dict[str, Any] = {}
for key in dir(debug_state):
Expand All @@ -929,7 +930,7 @@ class ScreenContent(TypedDict):


def get_screen_content() -> ScreenContent:
with connect_to_debuglink() as debug:
with connect_to_debuglink(needs_udp=True) as debug:
layout = debug.read_layout()
title = layout.title()
body = layout.text_content()
Expand Down
Loading