@@ -138,21 +138,22 @@ func (s *Server) getCallInfo(id string) *inboundCallInfo {
138138 return c
139139}
140140
141- func (s * Server ) getInvite (sipCallID string ) * inProgressInvite {
141+ func (s * Server ) getInvite (sipCallID , toTag , fromTag string ) * inProgressInvite {
142+ key := fmt .Sprintf ("%s:%s:%s" , sipCallID , toTag , fromTag )
142143 s .imu .Lock ()
143144 defer s .imu .Unlock ()
144- is , ok := s .inProgressInvites [sipCallID ]
145+ is , ok := s .inProgressInvites [key ]
145146 if ok {
146147 return is
147148 }
148149 is = & inProgressInvite {sipCallID : sipCallID }
149- s .inProgressInvites [sipCallID ] = is
150+ s .inProgressInvites [key ] = is
150151
151152 go func () {
152153 time .Sleep (inviteCredentialValidity )
153154 s .imu .Lock ()
154155 defer s .imu .Unlock ()
155- delete (s .inProgressInvites , sipCallID )
156+ delete (s .inProgressInvites , key )
156157 }()
157158 return is
158159}
@@ -322,7 +323,7 @@ func (s *Server) processInvite(req *sip.Request, tx sip.ServerTransaction) (retE
322323 )
323324
324325 var call * inboundCall
325- cc := s .newInbound (log , "unassigned" , s .ContactURI (legTr ), req , tx , func (headers map [string ]string ) map [string ]string {
326+ cc := s .newInbound (log , s .ContactURI (legTr ), req , tx , func (headers map [string ]string ) map [string ]string {
326327 c := call
327328 if c == nil || len (c .attrsToHdr ) == 0 {
328329 return headers
@@ -346,21 +347,22 @@ func (s *Server) processInvite(req *sip.Request, tx sip.ServerTransaction) (retE
346347 }
347348
348349 // Establish ID
349- if _ , ok := req .To ().Params .Get ("tag" ); ! ok {
350+ fromTag , _ := req .From ().Params .Get ("tag" ) // always exists, via ValidateInvite() check
351+ toTag , ok := req .To ().Params .Get ("tag" ) // To() always exists, via ValidateInvite() check
352+ if ! ok {
350353 // No to-tag on the invite means we need to generate one per RFC 3261 section 12.
351- if ! inviteHasAuth (req ) {
352- // No auth = a 407 response and another INVITE+auth.
353- // Generate a new to-tag early, to make sure both INVITES have the same ID.
354- uuid , _ := uuid .NewV4 () // Same as NewResponseFromRequest in sipgo
355- req .To ().Params .Add ("tag" , uuid .String ())
356- }
354+ // Generate a new to-tag early, to make sure both INVITES have the same ID.
355+ uuid , _ := uuid .NewV4 () // Same as NewResponseFromRequest in sipgo
356+ toTag = uuid .String ()
357+ req .To ().Params .Add ("tag" , toTag )
357358 }
358- inviteProgress := s .getInvite (req . CallID (). Value () )
359+ inviteProgress := s .getInvite (sipCallID , toTag , fromTag )
359360 callID := inviteProgress .lkCallID
360361 if callID == "" {
361362 callID = lksip .NewCallID ()
362363 inviteProgress .lkCallID = callID
363364 }
365+ cc .id = LocalTag (callID )
364366
365367 log = log .WithValues ("callID" , callID )
366368 cc .log = log
@@ -1390,11 +1392,11 @@ func (c *inboundCall) transferCall(ctx context.Context, transferTo string, heade
13901392
13911393}
13921394
1393- func (s * Server ) newInbound (log logger.Logger , id LocalTag , contact URI , invite * sip.Request , inviteTx sip.ServerTransaction , getHeaders setHeadersFunc ) * sipInbound {
1395+ func (s * Server ) newInbound (log logger.Logger , contact URI , invite * sip.Request , inviteTx sip.ServerTransaction , getHeaders setHeadersFunc ) * sipInbound {
13941396 c := & sipInbound {
13951397 log : log ,
13961398 s : s ,
1397- id : id ,
1399+ id : "unassigned" ,
13981400 invite : invite ,
13991401 inviteTx : inviteTx ,
14001402 legTr : legTransportFromReq (invite ),
0 commit comments