mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-25 09:08:45 +05:00
sipagent: add caps for concurrency limiting
This commit is contained in:
committed by
Dan Christian Bogos
parent
fc92654ad4
commit
c6318cb3f7
@@ -52,11 +52,12 @@ var (
|
||||
|
||||
// NewSIPAgent will construct a SIPAgent
|
||||
func NewSIPAgent(connMgr *engine.ConnManager, cfg *config.CGRConfig,
|
||||
filterS *engine.FilterS) (sa *SIPAgent, err error) {
|
||||
filterS *engine.FilterS, caps *engine.Caps) (sa *SIPAgent, err error) {
|
||||
sa = &SIPAgent{
|
||||
connMgr: connMgr,
|
||||
filterS: filterS,
|
||||
cfg: cfg,
|
||||
caps: caps,
|
||||
ackMap: make(map[string]chan struct{}),
|
||||
stopChan: make(chan struct{}),
|
||||
}
|
||||
@@ -82,6 +83,7 @@ type SIPAgent struct {
|
||||
connMgr *engine.ConnManager
|
||||
filterS *engine.FilterS
|
||||
cfg *config.CGRConfig
|
||||
caps *engine.Caps
|
||||
stopChan chan struct{}
|
||||
ackMap map[string]chan struct{}
|
||||
ackLocks sync.RWMutex
|
||||
@@ -296,6 +298,12 @@ func (sa *SIPAgent) answerMessage(messageStr, addr string, write func(ans []byte
|
||||
}
|
||||
|
||||
func (sa *SIPAgent) handleMessage(sipMessage sipingo.Message, remoteHost string) (sipAnswer sipingo.Message) {
|
||||
if sa.caps.IsLimited() {
|
||||
if err := sa.caps.Allocate(); err != nil {
|
||||
return bareSipErr(sipMessage, "SIP/2.0 503 Service Unavailable")
|
||||
}
|
||||
defer sa.caps.Deallocate()
|
||||
}
|
||||
if sipMessage[userAgentHeader] != "" {
|
||||
sipMessage[userAgentHeader] = fmt.Sprintf("%s@%s", utils.CGRateS, utils.Version)
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ func (sip *SIPAgent) Start(shutdown *utils.SyncedChan, registry *servmanager.Ser
|
||||
[]string{
|
||||
utils.ConnManager,
|
||||
utils.FilterS,
|
||||
utils.CapS,
|
||||
},
|
||||
registry, sip.cfg.GeneralCfg().ConnectTimeout)
|
||||
if err != nil {
|
||||
@@ -58,11 +59,12 @@ func (sip *SIPAgent) Start(shutdown *utils.SyncedChan, registry *servmanager.Ser
|
||||
}
|
||||
cm := srvDeps[utils.ConnManager].(*ConnManagerService).ConnManager()
|
||||
fs := srvDeps[utils.FilterS].(*FilterService).FilterS()
|
||||
caps := srvDeps[utils.CapS].(*CapService).Caps()
|
||||
|
||||
sip.mu.Lock()
|
||||
defer sip.mu.Unlock()
|
||||
sip.oldListen = sip.cfg.SIPAgentCfg().Listen
|
||||
sip.sip, err = agents.NewSIPAgent(cm, sip.cfg, fs)
|
||||
sip.sip, err = agents.NewSIPAgent(cm, sip.cfg, fs, caps)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user