feat: multi-node device limit, optimize rate limiter
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user