@@ -28,8 +28,6 @@ import (
2828 "sync/atomic"
2929 "time"
3030
31- uuid "github.com/satori/go.uuid"
32-
3331 "github.com/frostbyte73/core"
3432 "github.com/icholy/digest"
3533 "github.com/pkg/errors"
@@ -42,6 +40,7 @@ import (
4240 "github.com/livekit/protocol/livekit"
4341 "github.com/livekit/protocol/logger"
4442 "github.com/livekit/protocol/rpc"
43+ "github.com/livekit/protocol/utils"
4544 lksip "github.com/livekit/protocol/sip"
4645 "github.com/livekit/protocol/tracer"
4746 "github.com/livekit/protocol/utils/traceid"
@@ -139,7 +138,11 @@ func (s *Server) getCallInfo(id string) *inboundCallInfo {
139138}
140139
141140func (s * Server ) getInvite (sipCallID , toTag , fromTag string ) * inProgressInvite {
142- key := fmt .Sprintf ("%s:%s:%s" , sipCallID , toTag , fromTag )
141+ key := dialogKey {
142+ sipCallID : sipCallID ,
143+ toTag : toTag ,
144+ fromTag : fromTag ,
145+ }
143146 s .imu .Lock ()
144147 defer s .imu .Unlock ()
145148 is , ok := s .inProgressInvites [key ]
@@ -338,6 +341,7 @@ func (s *Server) processInvite(req *sip.Request, tx sip.ServerTransaction) (retE
338341 log = LoggerWithHeaders (log , cc )
339342
340343 if err := cc .ValidateInvite (); err != nil {
344+ log .Errorw ("invalid invite" , err )
341345 if s .conf .HideInboundPort {
342346 cc .Drop ()
343347 } else {
@@ -348,13 +352,16 @@ func (s *Server) processInvite(req *sip.Request, tx sip.ServerTransaction) (retE
348352
349353 // Establish ID
350354 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
355+ toParams := req .To ().Params // To() always exists, via ValidateInvite() check
356+ if toParams == nil {
357+ toParams = sip .NewParams ()
358+ req .To ().Params = toParams
359+ }
360+ toTag , ok := toParams .Get ("tag" )
352361 if ! ok {
353362 // No to-tag on the invite means we need to generate one per RFC 3261 section 12.
354363 // 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 )
364+ toParams .Add ("tag" , utils .NewGuid ("" ))
358365 }
359366 inviteProgress := s .getInvite (sipCallID , toTag , fromTag )
360367 callID := inviteProgress .lkCallID
0 commit comments