Skip to content

Let the port shared on the network be chosen, not discovered - #74

Merged
DarkPoesidon merged 1 commit into
mainfrom
feat/lan-sharing-http-and-port
Aug 27, 2026
Merged

Let the port shared on the network be chosen, not discovered#74
DarkPoesidon merged 1 commit into
mainfrom
feat/lan-sharing-http-and-port

Conversation

@DarkPoesidon

Copy link
Copy Markdown
Collaborator

Addresses the LAN-sharing part of the user's request: HTTP alongside SOCKS5, and a way to set the port.

HTTP already worked

mihomo's mixed-port serves HTTP and SOCKS5 on the same listener — nothing to add there. The description already said so (settings.routing.port.description).

The actual gap: no way to fix the port outside proxy-only mode

The port field was hidden everywhere except proxy-only mode, on the reasoning that the number is an implementation detail nobody needs to see (see the comment it replaces). That holds until another device is told to connect to it.

Worse, the backend was already inconsistent about this. chooseProxyPort:

  • Proxy-only: a taken port is reported as an error — right, because it is what got typed into Telegram.
  • Everywhere else: a taken port is silently swapped for a random free one.

Once LAN sharing is on in system-proxy or tunnel mode, the second behaviour is wrong for the same reason the first is right: a phone that was told to connect to 192.168.1.x:2080 cannot follow a silent switch to a different port, and had no way to set one in the first place.

What changed

Backend (mihomo_connect.go): chooseProxyPort now treats a taken port as an error whenever AllowLAN is on, not only in proxy-only mode. The error wording adapts — it blames the system proxy only when proxy-only mode is what makes the port matter; sharing gets its own message, because the system proxy isn't on trial there.

Frontend: the port field is shown whenever routingMode === "proxyOnly" || allowLan — so turning on sharing in any mode reveals the field to set it. No i18n changes needed; the existing description already covers "accepts both HTTP and SOCKS5" and the taken-port behaviour.

Testing

Two new tests: a taken port is reported once sharing is on, in both system-proxy and tunnel mode; the existing silent-fallback behaviour is confirmed unchanged when sharing is off. Confirmed the new test fails against the prior behaviour before the fix.

Full suite green, tsc --noEmit clean, frontend builds.

🤖 Generated with Claude Code

HTTP has worked all along — mihomo's mixed-port serves HTTP and SOCKS5
on the same listener, and the local-proxy description already said so.
What did not exist was a way to fix the port when sharing the connection
on the LAN outside proxy-only mode: the field was hidden everywhere else,
on the reasoning that the number is an implementation detail nobody needs
to see.

That reasoning holds until another device is told to connect to it. A
phone configured to point at this machine's address cannot follow a
silent change to the port any more than a program in proxy-only mode
could — and chooseProxyPort was treating them differently: proxy-only
reported a taken port as an error, everywhere else it quietly picked a
random free one instead. Sharing was already exposed to this, just
without anyone knowing until they went looking for why the address had
stopped working.

Both sides of that are fixed. The setting is now shown whenever it is
someone else's business — proxy-only, or LAN sharing turned on in any
mode — and chooseProxyPort now reports a taken port there too rather than
substituting one nobody asked for. The error blames the system proxy only
when proxy-only mode is what makes the port matter; sharing gets its own
wording, because the system proxy is not what is on trial there.

Two tests cover the failure mode directly: a taken port is reported once
sharing is on, in both system-proxy and tunnel mode, and the existing
silent-fallback behaviour is confirmed unchanged when sharing is off.
@DarkPoesidon
DarkPoesidon merged commit 1ec777f into main Aug 27, 2026
7 checks passed
@DarkPoesidon
DarkPoesidon deleted the feat/lan-sharing-http-and-port branch August 27, 2026 06:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant