Skip to content

Commit 1f96454

Browse files
committed
PR comments, except one
1 parent 65c3096 commit 1f96454

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,5 @@ require (
142142
google.golang.org/grpc v1.76.0 // indirect
143143
gopkg.in/yaml.v2 v2.4.0 // indirect
144144
)
145+
146+
replace github.com/livekit/psrpc => ../psrpc

pkg/sip/inbound.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

141140
func (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

pkg/sip/server.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ type Handler interface {
126126
OnSessionEnd(ctx context.Context, callIdentifier *CallIdentifier, callInfo *livekit.SIPCallInfo, reason string)
127127
}
128128

129+
type dialogKey struct {
130+
sipCallID string
131+
toTag string
132+
fromTag string
133+
}
134+
129135
type Server struct {
130136
log logger.Logger
131137
mon *stats.Monitor
@@ -136,7 +142,7 @@ type Server struct {
136142
sipUnhandled RequestHandler
137143

138144
imu sync.Mutex
139-
inProgressInvites map[string]*inProgressInvite
145+
inProgressInvites map[dialogKey]*inProgressInvite
140146

141147
closing core.Fuse
142148
cmu sync.RWMutex
@@ -172,7 +178,7 @@ func NewServer(region string, conf *config.Config, log logger.Logger, mon *stats
172178
region: region,
173179
mon: mon,
174180
getIOClient: getIOClient,
175-
inProgressInvites: make(map[string]*inProgressInvite),
181+
inProgressInvites: make(map[dialogKey]*inProgressInvite),
176182
byRemoteTag: make(map[RemoteTag]*inboundCall),
177183
byLocalTag: make(map[LocalTag]*inboundCall),
178184
byCallID: make(map[string]*inboundCall),

0 commit comments

Comments
 (0)