mirror of
https://gitcode.com/JianFeeeee/webui4frpc.git
synced 2026-09-20 17:07:57 +00:00
feat: Phase C 完成 — ModelRouter 风格 UI 重设计 + 模拟 frps 测试 + lastSync 修复 + 集群作坊搭建
- 主题: sakura×frost 玻璃拟态 (theme.css) + SCSS 变量重映射 - 侧栏: 玻璃侧栏 246px + 渐变品牌区 + 面包屑导航 - 状态页: 玻璃 KPI 卡 + 远程节点/本地服务卡片网格 - 集群页: 英雄玻璃卡 + 横向环拓扑链 + 待办命令/活跃拓扑/日志区 - 令牌环: 新增 lastSync 上次同步时间替代周期计数 - 模拟 frps: frps2/frps3 容器 + test-forward.sh 全链路验证脚本 - 修复: BinaryPath 空导致 worker 不启动, 撤销仅撤第一个 link, 任务复活风暴 (published 追踪)
This commit is contained in:
@ -53,6 +53,9 @@ type Task struct {
|
||||
// owning node cancels it (stop worker, drop from topology). Reuses the
|
||||
// same publish channel as creation (round-1 inject, round-2 apply).
|
||||
Revoke bool `json:"revoke,omitempty"`
|
||||
// RemoveNode: node ID to remove from the ring; the node self-removes when
|
||||
// the command reaches it via the token.
|
||||
RemoveNode string `json:"removeNode,omitempty"`
|
||||
}
|
||||
|
||||
// TopoEntry is an ESTABLISHED forward in the cluster topology: who (OwnerID)
|
||||
@ -72,7 +75,11 @@ type State struct {
|
||||
LeaderID string `json:"leaderId"`
|
||||
Nodes []Node `json:"nodes"`
|
||||
Cycle int64 `json:"cycle"`
|
||||
RoundDelay time.Duration `json:"-"`
|
||||
// RoundDelay rides the token so every node converges on the same ring
|
||||
// cadence (serialized as nanoseconds; the leader refreshes it each round
|
||||
// via tkDelaySince). MUST be serialized — otherwise a token round-trip
|
||||
// zeroed it and LossTimeout collapsed to the floor.
|
||||
RoundDelay time.Duration `json:"roundDelay,omitempty"`
|
||||
// PendingTasks: not yet claimed (disappear when claimed).
|
||||
PendingTasks map[string]*Task `json:"pendingTasks,omitempty"`
|
||||
// Topology: active forwards owned by members (full cluster view).
|
||||
@ -80,13 +87,12 @@ type State struct {
|
||||
Seq int64 `json:"seq"`
|
||||
}
|
||||
|
||||
// Token is the circulating message: one physical token, two phases per cycle.
|
||||
// Token is the circulating message: one physical token per cycle (single
|
||||
// round — adopt + append + execute in one pass, no phase split).
|
||||
type Token struct {
|
||||
Cycle int64 `json:"cycle"`
|
||||
Phase int `json:"phase"`
|
||||
State State `json:"state"`
|
||||
Log []LogEntry `json:"logDelta,omitempty"`
|
||||
Passed []string `json:"passed,omitempty"`
|
||||
SentAt int64 `json:"sentAt,omitempty"`
|
||||
}
|
||||
|
||||
@ -205,6 +211,20 @@ func (s *State) NextTaskID() string {
|
||||
return fmt.Sprintf("t%d", s.Seq)
|
||||
}
|
||||
|
||||
// AddRemoveNode publishes a node-removal command via the token; the target
|
||||
// node self-removes when it receives the command (re-queue forwards, drop
|
||||
// ring position, pass token to former successor).
|
||||
func (s *State) AddRemoveNode(nodeID string) *Task {
|
||||
t := &Task{
|
||||
ID: s.NextTaskID(), Created: time.Now().Unix(), RemoveNode: nodeID,
|
||||
}
|
||||
if s.PendingTasks == nil {
|
||||
s.PendingTasks = map[string]*Task{}
|
||||
}
|
||||
s.PendingTasks[t.ID] = t
|
||||
return t
|
||||
}
|
||||
|
||||
// AddRevoke publishes a REVOCATION task (same channel as creation): when a
|
||||
// node wants to cancel an established forward, it injects a Revoke task;
|
||||
// the owning node cancels the worker and drops it from topology.
|
||||
@ -280,6 +300,21 @@ func (s *State) AddTopology(t *Task, ownerID string) *TopoEntry {
|
||||
return e
|
||||
}
|
||||
|
||||
// SelfRemove removes this node from the ring: re-queues its own forwards
|
||||
// as pending (so another member claims them), drops its topology entries
|
||||
// and removes its ring position. Returns the re-queued task ids.
|
||||
func (s *State) SelfRemove(nodeID string) []string {
|
||||
reattached := s.OfflineReassign(nodeID)
|
||||
i := s.Find(nodeID)
|
||||
if i >= 0 {
|
||||
s.Nodes = append(s.Nodes[:i], s.Nodes[i+1:]...)
|
||||
}
|
||||
if s.LeaderID == nodeID {
|
||||
s.LeaderID = ""
|
||||
}
|
||||
return reattached
|
||||
}
|
||||
|
||||
// RemoveTopology drops the active forward for the given local/remote/port
|
||||
// (returns true if removed — the owning node revokes it).
|
||||
func (s *State) RemoveTopology(local, remote string, port int) bool {
|
||||
@ -292,6 +327,19 @@ func (s *State) RemoveTopology(local, remote string, port int) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// TopologyOwner returns the node that owns the active forward matching the
|
||||
// given task (by local/remote/port), or "" if no such entry exists. Used to
|
||||
// route a revocation to the OWNING node (plan §任务撤销: "持有该转发的节点
|
||||
// 收到撤销任务后取消") instead of letting any lowest-load node claim it.
|
||||
func (s *State) TopologyOwner(t *Task) string {
|
||||
for _, e := range s.Topology {
|
||||
if e.Local.Name == t.Local.Name && e.Remote.Name == t.Remote.Name && e.Link.RemotePort == t.Link.RemotePort {
|
||||
return e.OwnerID
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// TopologyList returns active forwards, stable by task id.
|
||||
func (s *State) TopologyList() []*TopoEntry {
|
||||
out := make([]*TopoEntry, 0, len(s.Topology))
|
||||
|
||||
Reference in New Issue
Block a user