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:
parent
e575b6a29f
commit
db39608bcb
7 changed files with 78 additions and 91 deletions
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue