Skip to content

Commit bb81ab3

Browse files
ralyodioclaude
andcommitted
fix(tor): make the toggle find + start the auto-installed Tor (v3.2.3)
Real-device test surfaced "Tor couldn't start" even though Tor installed and ran. Three bugs, all fixed: - Layout: ensure_tor put Tor in $APP_DIR/tor-bin, but the launcher/helper live in a tronbrowser/ subdir, so the helper's $DIR/tor-bin missed it. Now install Tor next to the launcher, AND the helper also searches the parent's tor-bin/. - Lib path: the Expert Bundle tor needs LD_LIBRARY_PATH; the old condition only matched when tor was under $DIR. Now detect a bundle by a sibling libevent and set LD_LIBRARY_PATH/DYLD_LIBRARY_PATH wherever tor was found (else it exits instantly → "tor-exited"). - Double-start: if Tor is already serving SOCKS (e.g. `tron tor` or a system service), reuse it instead of spawning a second tor that fails to bind 9050. Validated end-to-end against real Tor (in the misplaced-dir scenario): helper finds Tor, sets the lib path, bootstraps to 100%, and curl --socks5-hostname returns IsTor:true; reuse path confirmed ("reusing it"). `tron tor` resolver + LD path updated to match. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 6fed6d3 commit bb81ab3

28 files changed

Lines changed: 72 additions & 38 deletions

File tree

apps/desktop/extensions/ai-sidebar/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": 3,
33
"name": "TronBrowser",
4-
"version": "3.2.2",
4+
"version": "3.2.3",
55
"description": "TronBrowser — privacy-first, AI-native. Branded new tab, private search, CoinPay login, and a bring-your-own-keys AI sidebar.",
66
"icons": {
77
"16": "icons/icon-16.png",
1.32 KB
Binary file not shown.

apps/desktop/launcher/tron-tor-helper

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Endpoints (POST/GET on 127.0.0.1):
1818
Single-instance: binds a fixed loopback port; a second copy exits cleanly when
1919
the port is taken, so the launcher can fire-and-forget it every launch.
2020
"""
21+
import glob
2122
import json
2223
import os
2324
import shutil
@@ -46,21 +47,46 @@ def log(msg):
4647

4748
def tor_binary():
4849
"""Bundled `tor` next to the helper or under tor-bin/ (the auto-installed
49-
Tor Expert Bundle), else one on PATH (or None)."""
50+
Tor Expert Bundle), else one on PATH (or None). Checks the launcher dir, its
51+
tor-bin/, and the parent's tor-bin/ (the release extracts the shim into a
52+
subdir, so tor-bin can live a level up)."""
53+
cands = []
5054
if BUNDLED_DIR:
51-
for cand in (os.path.join(BUNDLED_DIR, "tor"),
52-
os.path.join(BUNDLED_DIR, "tor-bin", "tor")):
53-
if os.access(cand, os.X_OK):
54-
return cand
55+
parent = os.path.dirname(BUNDLED_DIR.rstrip("/"))
56+
cands += [os.path.join(BUNDLED_DIR, "tor"),
57+
os.path.join(BUNDLED_DIR, "tor-bin", "tor"),
58+
os.path.join(parent, "tor-bin", "tor")]
59+
for cand in cands:
60+
if os.access(cand, os.X_OK):
61+
return cand
5562
return shutil.which("tor")
5663

5764

65+
def socks_port_open():
66+
"""True if something already accepts connections on the SOCKS port — e.g.
67+
Tor started by `tron tor` or a system service. Then we reuse it instead of
68+
spawning a duplicate (a second tor would fail to bind the port)."""
69+
import socket
70+
try:
71+
with socket.create_connection((HOST, SOCKS_PORT), timeout=1.5):
72+
return True
73+
except OSError:
74+
return False
75+
76+
5877
def start_tor():
5978
"""Start tor and block until bootstrapped. Returns (ok, error)."""
6079
global _proc, _ready
6180
with _lock:
6281
if _proc is not None and _proc.poll() is None and _ready:
63-
return True, None # already up
82+
return True, None # already up (we started it)
83+
# Something already serving SOCKS on the port (tron tor / system tor)? Reuse
84+
# it — don't spawn a second tor that would fail to bind the port.
85+
if socks_port_open():
86+
_set_ready(True)
87+
log("tor already running on %s:%d — reusing it" % (HOST, SOCKS_PORT))
88+
return True, None
89+
with _lock:
6490
binary = tor_binary()
6591
if not binary:
6692
log("start requested but no tor binary found (bundled or on PATH)")
@@ -74,11 +100,12 @@ def start_tor():
74100

75101
_ready = False
76102
env = os.environ.copy()
77-
# The Tor Expert Bundle ships its own libs next to the binary with no
78-
# $ORIGIN rpath, so a bundled/auto-installed tor needs its dir on the
79-
# library path. (Harmless for a system tor, which we don't touch here.)
80-
if BUNDLED_DIR and os.path.dirname(binary).startswith(BUNDLED_DIR):
81-
bindir = os.path.dirname(binary)
103+
# The Tor Expert Bundle ships its own libs (libevent/libssl/…) next to
104+
# the binary with no $ORIGIN rpath, so it needs its dir on the library
105+
# path. Detect a bundle by a sibling libevent — works wherever tor was
106+
# found; a system tor (no sibling libs) is left untouched.
107+
bindir = os.path.dirname(binary)
108+
if glob.glob(os.path.join(bindir, "libevent*")):
82109
for var in ("LD_LIBRARY_PATH", "DYLD_LIBRARY_PATH"):
83110
env[var] = bindir + (os.pathsep + env[var] if env.get(var) else "")
84111
try:

apps/desktop/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tronbrowser/desktop",
3-
"version": "3.2.2",
3+
"version": "3.2.3",
44
"private": true,
55
"description": "Desktop shell for the TronBrowser Chromium fork",
66
"type": "module",

apps/docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tronbrowser/docs",
3-
"version": "3.2.2",
3+
"version": "3.2.3",
44
"private": true,
55
"description": "Documentation site",
66
"type": "module",

apps/extensions/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tronbrowser/extensions",
3-
"version": "3.2.2",
3+
"version": "3.2.3",
44
"private": true,
55
"description": "TronBrowser extension store — pay $1, list your MV3 extension (tronbrowser.dev/store)",
66
"type": "module",

apps/mobile/app.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"slug": "tronbrowserdev",
55
"owner": "profullstack",
66
"scheme": "tronbrowser",
7-
"version": "3.2.2",
7+
"version": "3.2.3",
88
"orientation": "portrait",
99
"userInterfaceStyle": "dark",
1010
"platforms": [

apps/mobile/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tronbrowser/mobile",
3-
"version": "3.2.2",
3+
"version": "3.2.3",
44
"private": true,
55
"description": "TronBrowser mobile (Expo / React Native) — Phase 2",
66
"type": "module",

apps/web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tronbrowser/web",
3-
"version": "3.2.2",
3+
"version": "3.2.3",
44
"private": true,
55
"description": "TronBrowser marketing site + web dashboard",
66
"type": "module",

apps/web/public/install.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ case "${1:-}" in
131131
# (any platform) if missing. (The `--tor` flag, handled by the launcher,
132132
# instead opens a dedicated Tor session.)
133133
resolve_tor() {
134-
if [ -x "$APP_DIR/tor-bin/tor" ]; then echo "$APP_DIR/tor-bin/tor"
134+
ldir="$(dirname "$(readlink -f "$CURRENT" 2>/dev/null || echo "$CURRENT")")"
135+
if [ -x "$ldir/tor-bin/tor" ]; then echo "$ldir/tor-bin/tor"
136+
elif [ -x "$APP_DIR/tor-bin/tor" ]; then echo "$APP_DIR/tor-bin/tor"
135137
else command -v tor 2>/dev/null || true; fi
136138
}
137139
TORBIN="$(resolve_tor)"
@@ -321,7 +323,12 @@ download_tor_expert_bundle() { # dest_dir
321323
ensure_tor() {
322324
[ "${TB_NO_TOR_INSTALL:-0}" = "1" ] && return 0
323325
command -v tor >/dev/null 2>&1 && return 0
324-
[ -x "$APP_DIR/tor-bin/tor" ] && return 0
326+
# Install Tor right next to the launcher shim so its dir ($DIR/tor-bin) resolves
327+
# it — the release tarball extracts the shim into a tronbrowser/ subdir.
328+
tordest="$APP_DIR/tor-bin"
329+
_ldir="$(find "$APP_DIR" -maxdepth 3 -type f -name tronbrowser 2>/dev/null | head -n1)"
330+
[ -n "$_ldir" ] && tordest="$(dirname "$_ldir")/tor-bin"
331+
[ -x "$tordest/tor" ] && return 0
325332

326333
info "Setting up Tor (for the in-browser Tor toggle)…"
327334
# 1) Homebrew (macOS/Linux) — no sudo.

0 commit comments

Comments
 (0)