Repository navigation
feat(remote): 主机侧与反向端口转发:远端服务监听端口,Core 新增两个转发命令与反向开关 (Refs 1lck/Lithe-IDEA#2231) - #159
Merged
Merged
Conversation
…r (Refs 1lck/Lithe-IDEA#2231) The server can now listen on a host port for a forwarding rule the user added (listener.open/adopt/close/list, listener.accepted, feature "listener"). Host rules relay every accepted connection on the host; reverse rules hand each connection to the client as a tunnel that reaches this machine's loopback interface. Core adds remote.startHostForward and remote.startReverseForward. Host forwards listen on the host's loopback interface unless the request asks for every interface; reverse forwards bind loopback only and start only when the new remote preference allowReverseForwarding is on (off by default). All kinds share the 64-forward limit, report kind and failedConnections, and are never reopened after a reconnect. New error codes: forward_host_port_in_use, forward_host_port_denied, forward_host_unsupported, reverse_forward_disabled.
xiaoyumuxi
marked this pull request as ready for review
November 21, 2026 17:21
33 of 40 tasks
xiaoyumuxi
added a commit
to 1lck/Lithe-IDEA
that referenced
this pull request
Nov 22, 2026
- 端口窗口标题栏“+”打开“添加转发规则”:主机端口 → 另一台服务器(T3), 主机端口 → 本机(T4 反向转发,只在设置允许时提供);默认只监听主机回环地址, 监听全部网卡每次都询问、不记住,目标不是主机回环地址时先询问(S28) - 端口窗口新增“转发规则”一节:监听地址(全部网卡用警告色)、目标、连接数和状态, 可逐条停止,全部停止也停止规则;规则随会话结束,重连后不自动恢复 - 设置 › 工具 › 远程工作区新增“端口转发 › 反向转发”,默认自动(不允许) - Core 客户端接上 remote.startHostForward / remote.startReverseForward 和四个新错误码 - 固定 Core main 62d44ce(Lithe-IDEA/Lithe-core-rust#159) - 中英词条、无头截图、功能矩阵和远程开发 Note 同步更新
1 task done
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.
关联 Issue
1lck/Lithe-IDEA#2231(远程开发完整设计)D10 转发规则 T3、T4:让 Linux 主机自己监听端口并转到另一台服务器(主机侧转发),以及让主机回环端口连回本机(反向转发)。本 PR 是 Core 部分,桌面端端口页的“添加转发规则…”和设置开关另开 PR。
类型
listener.*监听方法组(featurelistener);Core 新增remote.startHostForward、remote.startReverseForward,远程工作区设置新增“允许反向转发”,新增四个错误码改动说明
远端服务:监听(新文件
crates/remote/src/server/listener.rs,接线在connection.rs、session.rs、tunnel.rs、protocol/methods.rs)listener.open { listenerId, host, port, relay? }返回{ port }。host只接受 IP,不解析主机名,所以主机不会去解析客户端发来的地址:relay(一个tunnel.open目标)是主机侧规则:主机自己连目标、在主机上复制字节,数据不经过连接;host是回环地址,或在用户确认监听全部网卡时为0.0.0.0/::。relay是反向规则:host必须是回环地址;每个接入的连接先挂起,发listener.accepted { listenerId, acceptId },客户端订阅一条新隧道后用listener.adopt { listenerId, acceptId, tunnelId }接管,之后和客户端自己开的隧道一样。listener.close返回最终状态并关闭端口,以及它转发或挂起的所有连接;最多等 1 秒让端口释放,规则改到同一端口能马上重新绑定。listener.list列出listenerId、port、connections、failedConnections。ADDRESS_IN_USE,系统拒绝(如普通用户绑 1024 以下)是PERMISSION_DENIED,主机名或不允许的地址是INVALID_REQUEST,接管一个已不在等待的连接是UNKNOWN_RESOURCE。客户端:主机侧与反向转发(新文件
crates/remote/src/client/host_forward.rs,改forward_set.rs、forward.rs、api.rs)HostForward对应主机侧规则;ReverseForward收到listener.accepted后在本机只连127.0.0.1、再试::1,主机上的用户无法借它访问本机所在的局域网。本机连接失败计入failedConnections。ForwardSet统一管理三种转发:64 个的上限三种合计;先占位、不持锁启动、提交时去重,重复点击不会开第二个端口:本地按目标,主机侧按主机端口(未指定时任意端口)+ 网卡 + 目标,反向按主机端口 + 本机端口。allowNonLoopbackTarget),否则返回forward_target_not_confirmed。kind(local/host/reverse)、hostListenHost、hostListenPort、requestedHostPort、allInterfaces、failedConnections;不适用于该种类的字段不出现。remote.forward.host_started、remote.forward.host_removed两个事件(logging/events/remote.json,已重新生成),只记录种类、端口、是否全部网卡和计数,不记录地址、网址或进程名。设置(
client/preferences.rs、workspace/preferences.rs)allowReverseForwarding,默认false(自动 = 不允许),因为反向转发打开的本机端口主机上的所有用户都能访问。remote.preferences新增reverseForwarding { source, allowed };remote.editPreferences新增reverseForwarding: { allowed: boolean|null }。一次只能改一个值,一个都不给或给多个都按{ field: "operation" }拒绝。命令(
workspace/forwards.rs,接线在command.rs、dispatcher/remote.rs、request_trace.rs)remote.startHostForward { sessionId, targetHost, targetPort, listenPort?, allInterfaces?, allowNonLoopbackTarget? }→{ forward, created }。默认只监听主机回环地址;allInterfaces由桌面端每次询问用户,Core 不记住。remote.startReverseForward { sessionId, localPort, listenPort?, preferences }→{ forward, created }。请求带上当前设置文档(和remote.connect带 SSH 程序的方式一样),Core 判断不允许时返回reverse_forward_disabled,所有客户端执行同一条规则。localPort为 0 是invalid_request,details.field为localPort。protocol/error.rs,诊断目录已重新生成),一码一义:forward_host_port_in_use、forward_host_port_denied、forward_host_unsupported(远端服务没有listener功能)、reverse_forward_disabled。其他远端错误沿用sessions::request_error的映射。request_trace的非高频测试列表。契约文档
contracts/remote-workspace-protocol-v1.md:方法表加四行、事件表加listener.accepted;新增“Listeners”一节;“服务器从不监听网络端口”改为只为用户添加的规则监听;错误码列表加ADDRESS_IN_USE;“连接结束即结束”的资源加上监听。contracts/rust-core-api.md:命令表两行;设置一节改为三个值;转发一节重写:三种转发、种类对照表、主机端口规则与错误、反向默认关闭、按规则去重、合计上限、重连后不恢复。contracts/application-boundary.md:错误码列表加四项。验证
cargo fmt --allcargo clippy -p lithe-remote -p lithe-workspace -p lithe-core -p lithe-protocol --all-targets --all-features -- -D warnings:无警告cargo test -p lithe-remote --features server:全部通过(tests/tunnels.rs17 个,含主机侧转发、反向转发接管、端口占用、超时记失败、会话结束关闭监听)cargo test -p lithe-workspace:59 个通过(新增反向开关往返与reverse_forwarding_allowed,多字段编辑被拒)cargo test -p lithe-core:889 个通过;新增remote_host_and_reverse_forwards_follow_their_own_rules,经过分发器验证主机侧转发回显、非回环目标需确认、端口占用、未开启时拒绝反向、开启后反向回显与去重、localPort为 0、列表种类和停止cargo test -p lithe-diagnostics -p lithe-protocol:通过node scripts/logging/generate-log-events.mjs --check:148 个事件,生成结果一致node shared/plugins/scripts/verify-docs.mjs:通过