mirror of
https://gitcode.com/JianFeeeee/webui4frpc.git
synced 2026-09-20 17:07:57 +00:00
核心改动(ring 协议不变,Task 本来就是 {Local,Remote,Link} 三元组):
- process.WorkerKey: worker 键改为 'local~remote~port' 三元组
- renderForward: 每条 forward 渲染只含 1 个 proxy 的独立 frpc 配置
(替代 renderRemote 把该 remote 全部 forwards 塞进一个进程)
- ClaimFn/RevokeFn: 认领/撤销只操作这一条 forward 自己的进程
- SyncWorkers/auto-start: 只拉起 localOnly 转发的独立进程,
集群转发由 ring 认领节点拉起 (消除三台争抢 proxy already exists)
- RemoteStatus/StartRemote/StopRemote/RestartRemote: remote 级聚合辅助,
保持 /profiles API 形状不变, 前端零改动
- handleStatus/logs: 按 worker key 解析真实 remote 名
效果: 三台节点的 frpc 各自只注册自己拥有的 proxy, 单条转发故障不再波及兄弟
40 lines
1.4 KiB
Go
40 lines
1.4 KiB
Go
package process
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// WorkerKey is the unique identity of ONE forward's worker process:
|
|
//
|
|
// "<local>~<remote>~<port>"
|
|
//
|
|
// The per-forward worker model gives every link its own frpc process, config
|
|
// file and log file. This fixes the multi-node proxy-name fight of the old
|
|
// per-remote model (every node rendered the SAME proxy list and raced to
|
|
// register them on frps -> "proxy already exists"), and isolates faults: one
|
|
// crashing forward can no longer take its siblings down.
|
|
//
|
|
// '~' is a legal filename character on every supported OS (including Windows,
|
|
// unlike ':') and is rare in user-chosen node names. ParseWorkerKey rejects
|
|
// malformed keys so callers fail loudly instead of silently mis-rendering.
|
|
func WorkerKey(local, remote string, port int) string {
|
|
return fmt.Sprintf("%s~%s~%d", local, remote, port)
|
|
}
|
|
|
|
// ParseWorkerKey splits a worker key back into its (local, remote, port)
|
|
// forward triple. ok=false for anything that is not a well-formed key
|
|
// (e.g. legacy per-remote worker names).
|
|
func ParseWorkerKey(key string) (local, remote string, port int, ok bool) {
|
|
parts := strings.Split(key, "~")
|
|
if len(parts) != 3 {
|
|
return "", "", 0, false
|
|
}
|
|
p, err := strconv.Atoi(parts[2])
|
|
if err != nil || parts[0] == "" || parts[1] == "" || p <= 0 {
|
|
return "", "", 0, false
|
|
}
|
|
return parts[0], parts[1], p, true
|
|
}
|