From 25d558479978d60d39be02b5b9d76454e8529c96 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Thu, 16 Aug 2012 15:55:43 +0300 Subject: [PATCH] tested maxdebit with linphone and corrected a few issues --- cmd/cgr-rater/cgr-rater.go | 1 + conf/session_manager.config | 2 +- sessionmanager/sessiondelegate.go | 7 ++++++- timespans/calldesc.go | 3 ++- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/cmd/cgr-rater/cgr-rater.go b/cmd/cgr-rater/cgr-rater.go index bc6eaffef..d4e1fd7e5 100644 --- a/cmd/cgr-rater/cgr-rater.go +++ b/cmd/cgr-rater/cgr-rater.go @@ -227,6 +227,7 @@ func startSessionManager(responder *timespans.Responder, loggerDb timespans.Stor sm.Connect(&sessionmanager.SessionDelegate{connector, dp}, freeswitch_server, freeswitch_pass) default: timespans.Logger.Err(fmt.Sprintf("Cannot start session manger of type: %s!", sm_switch_type)) + exitChan <- true } } diff --git a/conf/session_manager.config b/conf/session_manager.config index 3eea88a6e..45cb9e9f4 100644 --- a/conf/session_manager.config +++ b/conf/session_manager.config @@ -23,7 +23,7 @@ logdb_name = cgrates # The name of the database to connect to. [session_manager] enabled = true -type = freeswitch +switch_type = freeswitch debit_period = 10 rater = internal #address where to access rater. Can be internal, direct rater address or the address of a balancer rpc_encoding = gob diff --git a/sessionmanager/sessiondelegate.go b/sessionmanager/sessiondelegate.go index 7aefc095d..5c6c0a546 100644 --- a/sessionmanager/sessiondelegate.go +++ b/sessionmanager/sessiondelegate.go @@ -150,6 +150,7 @@ func (rsd *SessionDelegate) OnChannelHangupComplete(ev Event, s *Session) { func (rsd *SessionDelegate) LoopAction(s *Session, cd *timespans.CallDescriptor) { cc := ×pans.CallCost{} + cd.Amount = rsd.DebitPeriod.Seconds() err := rsd.Connector.MaxDebit(*cd, cc) if err != nil { timespans.Logger.Err(fmt.Sprintf("Could not complete debit opperation: %v", err)) @@ -157,7 +158,11 @@ func (rsd *SessionDelegate) LoopAction(s *Session, cd *timespans.CallDescriptor) s.sessionManager.DisconnectSession(s) } nbts := len(cc.Timespans) - remainingSeconds := cc.Timespans[nbts-1].TimeEnd.Sub(cc.Timespans[0].TimeStart).Seconds() + remainingSeconds := 0.0 + timespans.Logger.Debug(fmt.Sprintf("MaxDebited and got this: %v", cc)) + if nbts > 0 { + remainingSeconds = cc.Timespans[nbts-1].TimeEnd.Sub(cc.Timespans[0].TimeStart).Seconds() + } if remainingSeconds == 0 || err != nil { timespans.Logger.Info(fmt.Sprintf("No credit left: Disconnect %v", s)) s.Disconnect() diff --git a/timespans/calldesc.go b/timespans/calldesc.go index 6bd1d9abe..cb95ea905 100644 --- a/timespans/calldesc.go +++ b/timespans/calldesc.go @@ -410,8 +410,9 @@ func (cd *CallDescriptor) Debit() (cc *CallCost, err error) { // by the GetMaxSessionTime method. The amount filed has to be filled in call descriptor. func (cd *CallDescriptor) MaxDebit() (cc *CallCost, err error) { remainingSeconds, err := cd.GetMaxSessionTime() + Logger.Debug(fmt.Sprintf("In MaxDebitd remaining seconds: %v", remainingSeconds)) if err != nil || remainingSeconds == 0 { - return nil, errors.New("no more credit") + return new(CallCost), errors.New("no more credit") } if remainingSeconds > 0 { // for postpaying client returns -1 rs, _ := time.ParseDuration(fmt.Sprintf("%vs", remainingSeconds))