From 377b0d57492c320012b91dd792cc632b8d64a4cf Mon Sep 17 00:00:00 2001 From: DanB Date: Wed, 16 Mar 2016 18:34:50 +0100 Subject: [PATCH] SMG.debit - store lazy the lastUsed --- sessionmanager/smg_session.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sessionmanager/smg_session.go b/sessionmanager/smg_session.go index 35447f2b0..47f7e3132 100644 --- a/sessionmanager/smg_session.go +++ b/sessionmanager/smg_session.go @@ -77,7 +77,6 @@ func (self *SMGSession) debitLoop(debitInterval time.Duration) { // Attempts to debit a duration, returns maximum duration which can be debitted or error func (self *SMGSession) debit(dur time.Duration, lastUsed time.Duration) (time.Duration, error) { - self.lastUsage = dur // Reset the lastUsage for later reference lastUsedCorrection := time.Duration(0) // Used if lastUsed influences the debit if self.cd.DurationIndex != 0 && lastUsed != 0 { if self.lastUsage > lastUsed { // We have debitted more than we have used, refund in the duration debitted @@ -98,6 +97,7 @@ func (self *SMGSession) debit(dur time.Duration, lastUsed time.Duration) (time.D self.cd.DurationIndex += dur cc := &engine.CallCost{} if err := self.rater.MaxDebit(self.cd, cc); err != nil { + self.lastUsage = 0 return 0, err } // cd corrections @@ -117,6 +117,7 @@ func (self *SMGSession) debit(dur time.Duration, lastUsed time.Duration) (time.D if ccDuration < 0 { // if correction has pushed ccDuration bellow 0 ccDuration = 0 } + self.lastUsage = ccDuration // Reset the lastUsage for later reference return ccDuration, nil }