@@ -137,21 +137,22 @@ func (s *Server) getCallInfo(id string) *inboundCallInfo {
137137 return c
138138}
139139
140- func (s * Server ) getInvite (sipCallID string ) * inProgressInvite {
140+ func (s * Server ) getInvite (sipCallID , toTag , fromTag string ) * inProgressInvite {
141+ key := fmt .Sprintf ("%s:%s:%s" , sipCallID , toTag , fromTag )
141142 s .imu .Lock ()
142143 defer s .imu .Unlock ()
143- is , ok := s .inProgressInvites [sipCallID ]
144+ is , ok := s .inProgressInvites [key ]
144145 if ok {
145146 return is
146147 }
147148 is = & inProgressInvite {sipCallID : sipCallID }
148- s .inProgressInvites [sipCallID ] = is
149+ s .inProgressInvites [key ] = is
149150
150151 go func () {
151152 time .Sleep (inviteCredentialValidity )
152153 s .imu .Lock ()
153154 defer s .imu .Unlock ()
154- delete (s .inProgressInvites , sipCallID )
155+ delete (s .inProgressInvites , key )
155156 }()
156157 return is
157158}
@@ -309,7 +310,7 @@ func (s *Server) processInvite(req *sip.Request, tx sip.ServerTransaction) (retE
309310 )
310311
311312 var call * inboundCall
312- cc := s .newInbound (log , "unassigned" , s .ContactURI (legTr ), req , tx , func (headers map [string ]string ) map [string ]string {
313+ cc := s .newInbound (log , s .ContactURI (legTr ), req , tx , func (headers map [string ]string ) map [string ]string {
313314 c := call
314315 if c == nil || len (c .attrsToHdr ) == 0 {
315316 return headers
@@ -333,21 +334,22 @@ func (s *Server) processInvite(req *sip.Request, tx sip.ServerTransaction) (retE
333334 }
334335
335336 // Establish ID
336- if _ , ok := req .To ().Params .Get ("tag" ); ! ok {
337+ fromTag , _ := req .From ().Params .Get ("tag" ) // always exists, via ValidateInvite() check
338+ toTag , ok := req .To ().Params .Get ("tag" ) // To() always exists, via ValidateInvite() check
339+ if ! ok {
337340 // No to-tag on the invite means we need to generate one per RFC 3261 section 12.
338- if ! inviteHasAuth (req ) {
339- // No auth = a 407 response and another INVITE+auth.
340- // Generate a new to-tag early, to make sure both INVITES have the same ID.
341- uuid , _ := uuid .NewV4 () // Same as NewResponseFromRequest in sipgo
342- req .To ().Params .Add ("tag" , uuid .String ())
343- }
341+ // Generate a new to-tag early, to make sure both INVITES have the same ID.
342+ uuid , _ := uuid .NewV4 () // Same as NewResponseFromRequest in sipgo
343+ toTag = uuid .String ()
344+ req .To ().Params .Add ("tag" , toTag )
344345 }
345- inviteProgress := s .getInvite (req . CallID (). Value () )
346+ inviteProgress := s .getInvite (sipCallID , toTag , fromTag )
346347 callID := inviteProgress .lkCallID
347348 if callID == "" {
348349 callID = lksip .NewCallID ()
349350 inviteProgress .lkCallID = callID
350351 }
352+ cc .id = LocalTag (callID )
351353
352354 log = log .WithValues ("callID" , callID )
353355 cc .log = log
@@ -1310,11 +1312,11 @@ func (c *inboundCall) transferCall(ctx context.Context, transferTo string, heade
13101312
13111313}
13121314
1313- func (s * Server ) newInbound (log logger.Logger , id LocalTag , contact URI , invite * sip.Request , inviteTx sip.ServerTransaction , getHeaders setHeadersFunc ) * sipInbound {
1315+ func (s * Server ) newInbound (log logger.Logger , contact URI , invite * sip.Request , inviteTx sip.ServerTransaction , getHeaders setHeadersFunc ) * sipInbound {
13141316 c := & sipInbound {
13151317 log : log ,
13161318 s : s ,
1317- id : id ,
1319+ id : "unassigned" ,
13181320 invite : invite ,
13191321 inviteTx : inviteTx ,
13201322 legTr : legTransportFromReq (invite ),
0 commit comments