mirror of
https://github.com/v2fly/v2ray-core.git
synced 2026-01-01 15:05:35 -05:00
remove context in struct
This commit is contained in:
@@ -30,28 +30,34 @@ type sessionId struct {
|
||||
type SessionHistory struct {
|
||||
sync.RWMutex
|
||||
cache map[sessionId]time.Time
|
||||
token *signal.Semaphore
|
||||
timer *time.Timer
|
||||
task *signal.PeriodicTask
|
||||
}
|
||||
|
||||
func NewSessionHistory() *SessionHistory {
|
||||
h := &SessionHistory{
|
||||
cache: make(map[sessionId]time.Time, 128),
|
||||
token: signal.NewSemaphore(1),
|
||||
}
|
||||
h.task = &signal.PeriodicTask{
|
||||
Interval: time.Second * 30,
|
||||
Execute: func() error {
|
||||
h.removeExpiredEntries()
|
||||
return nil
|
||||
},
|
||||
}
|
||||
common.Must(h.task.Start())
|
||||
return h
|
||||
}
|
||||
|
||||
// Close implements common.Closable.
|
||||
func (h *SessionHistory) Close() error {
|
||||
return h.task.Close()
|
||||
}
|
||||
|
||||
func (h *SessionHistory) add(session sessionId) {
|
||||
h.Lock()
|
||||
defer h.Unlock()
|
||||
|
||||
h.cache[session] = time.Now().Add(time.Minute * 3)
|
||||
select {
|
||||
case <-h.token.Wait():
|
||||
h.timer = time.AfterFunc(time.Minute*3, h.removeExpiredEntries)
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
func (h *SessionHistory) has(session sessionId) bool {
|
||||
@@ -75,11 +81,6 @@ func (h *SessionHistory) removeExpiredEntries() {
|
||||
delete(h.cache, session)
|
||||
}
|
||||
}
|
||||
|
||||
if h.timer != nil {
|
||||
h.timer.Stop()
|
||||
h.timer = nil
|
||||
}
|
||||
}
|
||||
|
||||
type ServerSession struct {
|
||||
|
||||
Reference in New Issue
Block a user