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, 单条转发故障不再波及兄弟
38 lines
892 B
Go
38 lines
892 B
Go
package process
|
|
|
|
import "testing"
|
|
|
|
func TestWorkerKeyRoundTrip(t *testing.T) {
|
|
cases := []struct {
|
|
local, remote string
|
|
port int
|
|
}{
|
|
{"web", "frps1", 18080},
|
|
{"db", "aliyun-frps", 5432},
|
|
{"svc-1", "node.a.example", 80},
|
|
}
|
|
for _, c := range cases {
|
|
key := WorkerKey(c.local, c.remote, c.port)
|
|
l, r, p, ok := ParseWorkerKey(key)
|
|
if !ok || l != c.local || r != c.remote || p != c.port {
|
|
t.Fatalf("roundtrip %q -> (%q,%q,%d,%v)", key, l, r, p, ok)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestParseWorkerKeyRejectsBad(t *testing.T) {
|
|
bad := []string{
|
|
"", "srv-a", // legacy per-remote names / empty
|
|
"a~b", // missing port
|
|
"a~b~x", // non-numeric port
|
|
"a~b~0", // port out of range
|
|
"~b~1", // empty local
|
|
"a~~1", // empty remote
|
|
}
|
|
for _, key := range bad {
|
|
if _, _, _, ok := ParseWorkerKey(key); ok {
|
|
t.Fatalf("ParseWorkerKey(%q) accepted, want reject", key)
|
|
}
|
|
}
|
|
}
|