Skip to content

Commit 60757c5

Browse files
committed
chore: remove bridge proxy and use node-bridge as default
1 parent edd5c4c commit 60757c5

File tree

10 files changed

+40
-209
lines changed

10 files changed

+40
-209
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ Supported platforms are Linux and macOS (both Intel and Silicon).
4545
- Service running on *localhost:21325*
4646
- Connection between the trezor device (or running emulator) and the host
4747
- Used by applications needing to communicate with trezor device (for example Suite)
48-
- **Bridge proxy**
49-
- Proxies requests to the bridge
5048
- **Bitcoin regtest**
5149
- Bitcoind with [blockbook](https://github.com/trezor/blockbook) running in regtest mode
5250
- Default credentials for bitcoin backend

docker/compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ services:
2020
ports:
2121
- "9001:9001"
2222
- "9002:9002"
23-
- "21326:21326"
24-
- "127.0.0.1:21325:21326" # macos needs proxy to override the "origin" of the trezord request
23+
# 21325 is the legacy bridge port. It will not work on macOS (see bridge-proxy before this commit).
24+
- "21328:21328" # new bridge port
2525
environment:
2626
- DISPLAY=docker.for.mac.host.internal:0
2727
- REGTEST_RPC_URL=http://host.docker.internal:18021

src/binaries.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
IS_ARM = os.uname().machine.startswith(("aarch64", "arm"))
4444
ARM_IDENTIFIER = "-arm"
4545

46-
DEFAULT_BRIDGE = "2.0.33" if not IS_ARM else f"2.0.33{ARM_IDENTIFIER}"
46+
DEFAULT_BRIDGE = NODE_BRIDGE_ID
4747

4848

4949
def register_new_firmware(model: Model, version: str, location: str) -> None:

src/binaries/node-bridge/modify_node_bin_js.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,23 @@ else
1919
echo "Error: no line matching '$string_to_comment' found in '$1'."
2020
exit 1
2121
fi
22+
23+
# Replace if (isOriginAllowed) with if (true)
24+
if grep -q "if (isOriginAllowed)" "$1"; then
25+
sed -i 's/if (isOriginAllowed)/if (true)/g' "$1"
26+
echo "Success: replaced 'if (isOriginAllowed)' with 'if (true)'."
27+
else
28+
echo "Error: no line matching 'if (isOriginAllowed)' found in '$1'."
29+
exit 1
30+
fi
31+
32+
33+
# replace all occurrences of 127.0.0.1 with 0.0.0.0
34+
# TL;DR: macOS Docker's extra VM layer requires explicit binding to all interfaces (0.0.0.0) to be reachable from the host.
35+
if grep -q 'var ADDRESS = "http://127.0.0.1"' "$1"; then
36+
sed -i 's|var ADDRESS = "http://127.0.0.1"|var ADDRESS = "http://0.0.0.0"|g' "$1"
37+
echo "Success: replaced 'var ADDRESS = \"http://127.0.0.1\"' with 'var ADDRESS = \"http://0.0.0.0\"'."
38+
else
39+
echo "Error: no line matching 'var ADDRESS = \"http://127.0.0.1\"' found in '$1'."
40+
exit 1
41+
fi

src/bridge.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
from psutil import Popen
1111

1212
import binaries
13-
import bridge_proxy
1413
import helpers
15-
from bridge_proxy import PORT as BRIDGE_PROXY_PORT
1614

1715
if TYPE_CHECKING:
1816
from typing_extensions import TypedDict
@@ -61,13 +59,12 @@ def is_port_in_use(port: int) -> bool:
6159
return s.connect_ex(("0.0.0.0", port)) == 0
6260

6361

64-
def check_bridge_and_proxy_status() -> None:
65-
"""Reporting the status of bridge and proxy, for debugging purposes"""
62+
def check_bridge_status() -> None:
63+
"""Reporting the status of bridge, for debugging purposes"""
6664
log(f"Is bridge running - {is_port_in_use(BRIDGE_PORT)}")
67-
log(f"Is bridge proxy running - {is_port_in_use(BRIDGE_PROXY_PORT)}")
6865

6966

70-
def start(version: str, proxy: bool = False, output_to_logfile: bool = True) -> None:
67+
def start(version: str, output_to_logfile: bool = True) -> None:
7168
log("Starting")
7269
global BRIDGE
7370
global VERSION_RUNNING
@@ -87,7 +84,7 @@ def start(version: str, proxy: bool = False, output_to_logfile: bool = True) ->
8784
# not to still think the bridge is running
8885
if BRIDGE is not None and not is_running():
8986
log("Bridge was probably killed by user manually, resetting local state")
90-
stop(proxy=proxy)
87+
stop()
9188

9289
if BRIDGE is not None:
9390
log("WARNING: Bridge is already running, not spawning a new one", "red")
@@ -158,14 +155,11 @@ def get_command_list() -> list[str]:
158155

159156
VERSION_RUNNING = version
160157

161-
if proxy:
162-
bridge_proxy.start()
163-
164158
time.sleep(0.5)
165-
check_bridge_and_proxy_status()
159+
check_bridge_status()
166160

167161

168-
def stop(proxy: bool = True) -> None:
162+
def stop() -> None:
169163
log("Stopping")
170164
global BRIDGE
171165
global VERSION_RUNNING
@@ -190,8 +184,5 @@ def stop(proxy: bool = True) -> None:
190184
BRIDGE = None
191185
VERSION_RUNNING = None
192186

193-
if proxy:
194-
bridge_proxy.stop()
195-
196187
time.sleep(0.5)
197-
check_bridge_and_proxy_status()
188+
check_bridge_status()

src/bridge_proxy.py

Lines changed: 0 additions & 62 deletions
This file was deleted.

src/bridge_proxy_server.py

Lines changed: 0 additions & 105 deletions
This file was deleted.

src/controller.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class BackgroundCheckResponse(TypedDict):
4242
IP = "0.0.0.0"
4343
PORT = 9001
4444
LOG_COLOR = "blue"
45-
BRIDGE_PROXY = False # is being set in main.py (when not disabled, will be True)
4645
REGTEST_RPC = BTCJsonRPC(
4746
url=os.getenv("REGTEST_RPC_URL") or "http://0.0.0.0:18021",
4847
user="rpc",
@@ -147,18 +146,12 @@ def run_bridge_command(self) -> "ResponseType":
147146
if self.command == "bridge-start":
148147
version = self.request_dict.get("version", binaries.DEFAULT_BRIDGE)
149148
output_to_logfile = self.request_dict.get("output_to_logfile", True)
150-
bridge.start(
151-
version, proxy=BRIDGE_PROXY, output_to_logfile=output_to_logfile
152-
)
149+
bridge.start(version, output_to_logfile=output_to_logfile)
153150
response_text = f"Bridge version {version} started"
154-
if BRIDGE_PROXY:
155-
response_text += " with bridge proxy"
156151
return {"response": response_text}
157152
elif self.command == "bridge-stop":
158-
bridge.stop(proxy=BRIDGE_PROXY)
153+
bridge.stop()
159154
response_text = "Stopping bridge"
160-
if BRIDGE_PROXY:
161-
response_text += " + stopping bridge proxy"
162155
return {"response": response_text}
163156
else:
164157
return {

src/dashboard/js/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,14 @@ const app = createApp({
200200
this.emulators.versions[model].versions = options;
201201
this.emulators.versions[model].selected = options[0];
202202
}
203-
this.bridges.selected = dataObject.bridges[0];
204-
this.bridges.versions = dataObject.bridges;
203+
const nodebridge = [];
204+
const legacy = [];
205+
dataObject.bridges.forEach((b) =>
206+
b.startsWith("2.") ? legacy.push(b) : nodebridge.push(b)
207+
);
208+
this.bridges.versions = nodebridge.concat(legacy);
209+
this.bridges.selected = this.bridges.versions[0];
210+
205211
this.bridges.hasSuiteLocal = dataObject.bridges.includes(
206212
"local-suite-node-bridge"
207213
);

src/main.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ def log(text: str, color: str = LOG_COLOR) -> None:
3030
parser = argparse.ArgumentParser()
3131
parser.add_argument("-v", "--verbosity", action="count", default=0)
3232
parser.add_argument("--work-dir")
33-
parser.add_argument("--disable-bridge-proxy", action="store_true")
3433
args = parser.parse_args()
3534

3635
effective_work_dir = args.work_dir
@@ -49,15 +48,6 @@ def log(text: str, color: str = LOG_COLOR) -> None:
4948
binaries.explore(args)
5049
dashboard.start()
5150

52-
if args.disable_bridge_proxy:
53-
log(
54-
"Bridge proxy disabled. "
55-
"Communication with Bridge needs to be done directly."
56-
)
57-
else:
58-
log("Will create bridge proxy when spawning a bridge.")
59-
controller.BRIDGE_PROXY = True
60-
6151
if helpers.physical_trezor():
6252
log("Will support physical Trezor.")
6353
else:

0 commit comments

Comments
 (0)