Skip to content

fix(v2ray): use dynamic port for SOCKS5 inbound instead of hardcoded 1080#86

Open
Sentinel-Bluebuilder wants to merge 2 commits into
sentinel-official:developmentfrom
Sentinel-Bluebuilder:fix/v2ray-dynamic-socks-port
Open

fix(v2ray): use dynamic port for SOCKS5 inbound instead of hardcoded 1080#86
Sentinel-Bluebuilder wants to merge 2 commits into
sentinel-official:developmentfrom
Sentinel-Bluebuilder:fix/v2ray-dynamic-socks-port

Conversation

@Sentinel-Bluebuilder

Copy link
Copy Markdown

Rebased onto current development (replaces #72, auto-closed after retarget from maindevelopment due to base divergence). Single commit, same fix, cleanly rebased onto development HEAD 732bf85.

…1080

Port 1080 is commonly used by other proxy software. If already in use,
V2Ray fails to start with 'address already in use' after the session
payment is already made, wasting tokens.

Now uses find-free-ports (already a dependency) for both API and SOCKS
inbound ports. The assigned SOCKS port is exposed via the socksPort
property so callers know where to connect.

Fixes sentinel-official#36

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…te by default

Per maintainer feedback: instead of always auto-picking the SOCKS port,
accept an optional port in the V2Ray constructor. Default (0) preserves the
auto-allocate behavior; an explicit port forces a fixed, predictable SOCKS
inbound. apiPort (internal stats inbound) stays auto-allocated.

findFreePorts(2) -> findFreePorts(needSocks ? 2 : 1).
@Sentinel-Bluebuilder

Copy link
Copy Markdown
Author

Revised per your feedback. The SOCKS port is now customizable instead of always auto-allocated:

  • constructor(socksPort?: number) — pass an explicit port (e.g. 1080) to force a fixed, predictable SOCKS inbound; omit it (default 0) to keep the auto-allocate behavior.
  • In parseConfig, findFreePorts(2) is now findFreePorts(needSocks ? 2 : 1) — when an explicit SOCKS port was requested we only allocate the apiPort.
  • apiPort (internal stats inbound) stays auto-allocated either way.

One design note: I kept the requested port on the instance (this.socksPort) set in the constructor, and resolve the effective port in parseConfig. The alternative was a parseConfig(handshakeData, nodeAddrs, socksPort?) param. I went with the constructor because the SOCKS port is a property of how this client exposes its proxy, not of the per-handshake node data — it's known at construction time, whereas the WireGuard listenPort (in the sibling PR) only becomes relevant after the handshake. Happy to move it to the parseConfig signature if you'd prefer the two PRs to be symmetric.

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