1
0
Fork 0
forked from External/ergo

change "last signoff" tracking to "last seen"

Explicit quit and ping timeout behave the same way,
but reattach after abandoning/losing the previous session
(without the break being detected server-side) is more aggressive
about replaying missed messages, at the cost of potential duplication.
This commit is contained in:
Shivaram Lingamneni 2020-02-27 02:13:31 -05:00
parent e575b6a29f
commit db39608bcb
7 changed files with 78 additions and 91 deletions

View file

@ -52,7 +52,6 @@ type IdleTimer struct {
quitTimeout time.Duration
state TimerState
timer *time.Timer
lastTouch time.Time
}
// Initialize sets up an IdleTimer and starts counting idle time;
@ -62,11 +61,9 @@ func (it *IdleTimer) Initialize(session *Session) {
it.registerTimeout = RegisterTimeout
it.idleTimeout, it.quitTimeout = it.recomputeDurations()
registered := session.client.Registered()
now := time.Now().UTC()
it.Lock()
defer it.Unlock()
it.lastTouch = now
if registered {
it.state = TimerActive
} else {
@ -95,12 +92,10 @@ func (it *IdleTimer) recomputeDurations() (idleTimeout, quitTimeout time.Duratio
func (it *IdleTimer) Touch() {
idleTimeout, quitTimeout := it.recomputeDurations()
now := time.Now().UTC()
it.Lock()
defer it.Unlock()
it.idleTimeout, it.quitTimeout = idleTimeout, quitTimeout
it.lastTouch = now
// a touch transitions TimerUnregistered or TimerIdle into TimerActive
if it.state != TimerDead {
it.state = TimerActive
@ -108,13 +103,6 @@ func (it *IdleTimer) Touch() {
}
}
func (it *IdleTimer) LastTouch() (result time.Time) {
it.Lock()
result = it.lastTouch
it.Unlock()
return
}
func (it *IdleTimer) processTimeout() {
idleTimeout, quitTimeout := it.recomputeDurations()