feat: multi-node device limit, optimize rate limiter

This commit is contained in:
xboard
2026-03-25 17:38:40 +08:00
parent 7e3ad7cb23
commit b51cecfe17
11 changed files with 616 additions and 151 deletions
+19 -1
View File
@@ -35,7 +35,7 @@ const drainTimeout = 5 * time.Second
type SingBox struct {
cfg config.KernelConfig
mu sync.Mutex
mu sync.RWMutex
box *box.Box
ctx context.Context
cancel context.CancelFunc
@@ -392,6 +392,24 @@ func (s *SingBox) SetDeviceLimitFunc(fn func(uuid string) (int, bool)) {
}
}
// UpdateGlobalDevices updates the global device state from panel (for multi-node).
func (s *SingBox) UpdateGlobalDevices(users map[int][]string) {
s.mu.RLock()
defer s.mu.RUnlock()
if s.connTracker != nil {
s.connTracker.UpdateGlobalDevices(users)
}
}
// ClearGlobalDevices clears the global device state (on WS disconnect).
func (s *SingBox) ClearGlobalDevices() {
s.mu.RLock()
defer s.mu.RUnlock()
if s.connTracker != nil {
s.connTracker.ClearGlobalDevices()
}
}
// ─── User management (non-disruptive) ───────────────────────────────────────
// AddUsers hot-swaps users into running inbounds. Zero connection disruption.