Skip to content

Commit

Permalink
fix: use UDP with node bridge, non-UDP with old bridge when communica…
Browse files Browse the repository at this point in the history
…ting with emulator
  • Loading branch information
grdddj committed Oct 7, 2024
1 parent 013b102 commit b881bdc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
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

0 comments on commit b881bdc

Please sign in to comment.