refactor: перенос логики сессии в internal/session и обновление mobile-фасада

This commit is contained in:
samosvalishe committed 2026-08-01 03:05:14 +03:00
1 parent 68485cbee7
commit 1f86fda104
55 files changed
+5314 -1312

No files matched your search

+13
View File
@@ -33,10 +33,21 @@ type SessionPool struct {
counter atomic.Uint64
connCounter atomic.Uint64
// active - зеркало числа живых сессий для наблюдателей вне пакета
// (watchdog и счётчик стримов в UI). nil, если хост его не просил.
active *atomic.Int32
readyOnce sync.Once
ready chan struct{}
}
// publishActive обновляет внешнее зеркало. Вызывать под p.mu.
func (p *SessionPool) publishActive() {
if p.active != nil {
p.active.Store(int32(len(p.sessions))) //nolint:gosec // сессий десятки, int32 не переполнить
}
}
// Ready возвращает канал, закрытый при первом появлении сессии в пуле.
func (p *SessionPool) Ready() <-chan struct{} {
p.mu.Lock()
@@ -53,6 +64,7 @@ func (p *SessionPool) Add(id int, s *smux.Session) *PooledSession {
ps := &PooledSession{ID: id, Sess: s}
p.mu.Lock()
p.sessions = append(p.sessions, ps)
p.publishActive()
if p.ready == nil {
p.ready = make(chan struct{})
}
@@ -71,6 +83,7 @@ func (p *SessionPool) Remove(ps *PooledSession) {
break
}
}
p.publishActive()
p.mu.Unlock()
}