feat(reverse): reverse proxy — bridge + portal (Mux.cool over VLESS-Rvs) - #3095
Draft
LOVECHEN wants to merge 3 commits into
Draft
feat(reverse): reverse proxy — bridge + portal (Mux.cool over VLESS-Rvs)#3095LOVECHEN wants to merge 3 commits into
LOVECHEN wants to merge 3 commits into
Conversation
Self-contained transport/muxcool package implementing Xray's Mux.cool multiplexing wire protocol: frame codec, server/client workers, UDP (full-cone) and a buffered pipe, with unit tests. mihomo's sing-mux is a different, wire-incompatible protocol; a real Mux.cool implementation is required for interop with Xray mux-based features (reverse proxy in the following commits). Standalone package, no wiring.
Add VLESS Rvs command (0x04, address-less like Mux) to the client encoder and DstAddr.Rvs; add a DialReverse outbound method that opens a VLESS-Rvs stream reusing the full transport chain (REALITY/TLS/ws/grpc/Vision). This is the capability a reverse-proxy bridge uses to dial a portal. No user-facing config on its own.
Xray-compatible reverse proxy, both roles, over Mux.cool + VLESS-Rvs: - reverse-bridge listener: dials a referenced VLESS outbound to the portal, runs a Mux.cool ServerWorker, feeds substreams into tunnel (UDP via dialer.DialContext). - reverse-portal listener (+tls): accepts VLESS-Rvs (REALITY / plain TLS / Vision auto-detected), runs a Mux.cool ClientWorker + heartbeat. - reverse portal runtime registry + round-robin picker; reverse-portal outbound. - register the two listener types and the outbound. Supports TCP/REALITY/Vision/UDP(full-cone). Addresses MetaCubeX#190.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an Xray-compatible reverse proxy to mihomo — both roles: bridge (NAT side; dials out and lands traffic to its local network) and portal (public side; accepts reverse connections and serves user traffic), without an external tunnel. New listener types
reverse-bridge/reverse-portaland areverse-portaloutbound. Supports TCP / REALITY / Vision / UDP (full-cone).Addresses #190 (currently
not_planned) — opening for discussion.Why
mihomo can currently only be a client to Xray's reverse proxy via an external tunnel. This lets mihomo interoperate with Xray's reverse proxy in both roles, and run a pure mihomo↔mihomo reverse stack. Verified against Xray-core 26.7.28 in every role-swap combination (bridge ∈ {mihomo, Xray} × portal ∈ {mihomo, Xray}).
Suggested commit structure
transport/muxcool— Xray Mux.cool wire protocol (frame codec + server/client workers + UDP full-cone + buffered pipe), stdlib-only, with unit tests. mihomo's sing-mux is a different, wire-incompatible protocol, so a real Mux.cool impl is required. Standalone package, no wiring.Rvscommand +DialReverse—CommandRvs (0x04)(address-less, likeMux) in the client encoder +DstAddr.Rvs;DialReverseoutbound method that opens a VLESS-Rvs stream reusing the full transport chain (REALITY/TLS/ws/grpc/Vision). This is the capability a bridge uses to dial a portal.listener/inbound/reverse_bridge.go:reverse-bridgelistener (no port); resolves a referenced VLESS outbound,DialReverseto the portal, runs a Mux.coolServerWorker, feeds each substream intotunnel.HandleTCPConn(UDP lands viadialer.DialContext); reconnects on drop.listener/inbound/reverse_portal.go(+reverse_portal_tls.go):reverse-portallistener; accepts VLESS-Rvs (optional REALITY / plain TLS 1.3 / Vision auto-detected from client flow); runs a Mux.coolClientWorker+ heartbeat.listener/reverse/portal.go: runtime registry (tag → active tunnels) with a round-robin,IsActive-filtered picker.adapter/outbound/reverse_portal.go:reverse-portaloutbound; routes user traffic to an active tunnel by tag (TCPDialContext+ UDPListenPacketContext).adapter/outbound/base.go: expose the auto-close wrapper's inner adapter (so the bridge can get the concrete*Vless).listener/parse.go,adapter/parser.go: register the two listener types + the outbound.Configuration reference
reverse-bridgelistener (no port; dials out):name,type: reverse-bridge,portal(aproxies:VLESS outbound name used to dial the portal).reverse-portallistener (accepts reverse connections):name,type: reverse-portal,listen/port,uuid,tag(links to the outbound), plus one security layer —reality-config: {dest, private-key, short-id: [], server-names: []}ortls: true(+certificate/private-key, PEM path or inline; empty → self-signed) or none. Precedence: reality > tls > none.flowis auto-detected (empty orxtls-rprx-vision; Vision needs TLS/REALITY underneath).reverse-portaloutbound:name,type: reverse-portal,tag(matches the listener's tag).Testing
End-to-end against real Xray-core 26.7.28 — all four quadrants for TCP and REALITY; UDP full-cone (single/multi-target) both directions; Vision (
xtls-rprx-vision); plusgo test -racefortransport/muxcool.Notes for maintainers
Sizeable feature for a
not_plannedissue — happy to split (bridge-only first, or gate behind a build tag) or adjust the config surface. UDP lands via direct dial (no XUDP GlobalID; Xray's reverse path doesn't use it either). Reverse accounts require empty or Vision flow.