Skip to content

Commit 7e3a124

Browse files
committed
PR comments, except one
1 parent 13ecae4 commit 7e3a124

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030

3131
msdk "github.com/livekit/media-sdk"
3232
"github.com/livekit/protocol/rpc"
33-
uuid "github.com/satori/go.uuid"
33+
"github.com/livekit/protocol/utils"
3434

3535
"github.com/frostbyte73/core"
3636
"github.com/icholy/digest"
@@ -138,7 +138,11 @@ func (s *Server) getCallInfo(id string) *inboundCallInfo {
138138
}
139139

140140
func (s *Server) getInvite(sipCallID, toTag, fromTag string) *inProgressInvite {
141-
key := fmt.Sprintf("%s:%s:%s", sipCallID, toTag, fromTag)
141+
key := dialogKey{
142+
sipCallID: sipCallID,
143+
toTag: toTag,
144+
fromTag: fromTag,
145+
}
142146
s.imu.Lock()
143147
defer s.imu.Unlock()
144148
is, ok := s.inProgressInvites[key]
@@ -325,6 +329,7 @@ func (s *Server) processInvite(req *sip.Request, tx sip.ServerTransaction) (retE
325329
log = LoggerWithHeaders(log, cc)
326330

327331
if err := cc.ValidateInvite(); err != nil {
332+
log.Errorw("invalid invite", err)
328333
if s.conf.HideInboundPort {
329334
cc.Drop()
330335
} else {
@@ -335,13 +340,16 @@ func (s *Server) processInvite(req *sip.Request, tx sip.ServerTransaction) (retE
335340

336341
// Establish ID
337342
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
343+
toParams := req.To().Params // To() always exists, via ValidateInvite() check
344+
if toParams == nil {
345+
toParams = sip.NewParams()
346+
req.To().Params = toParams
347+
}
348+
toTag, ok := toParams.Get("tag")
339349
if !ok {
340350
// No to-tag on the invite means we need to generate one per RFC 3261 section 12.
341351
// 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)
352+
toParams.Add("tag", utils.NewGuid(""))
345353
}
346354
inviteProgress := s.getInvite(sipCallID, toTag, fromTag)
347355
callID := inviteProgress.lkCallID

pkg/sip/server.go

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

125+
type dialogKey struct {
126+
sipCallID string
127+
toTag string
128+
fromTag string
129+
}
130+
125131
type Server struct {
126132
log logger.Logger
127133
mon *stats.Monitor
@@ -132,7 +138,7 @@ type Server struct {
132138
sipUnhandled RequestHandler
133139

134140
imu sync.Mutex
135-
inProgressInvites map[string]*inProgressInvite
141+
inProgressInvites map[dialogKey]*inProgressInvite
136142

137143
closing core.Fuse
138144
cmu sync.RWMutex
@@ -167,7 +173,7 @@ func NewServer(region string, conf *config.Config, log logger.Logger, mon *stats
167173
region: region,
168174
mon: mon,
169175
getIOClient: getIOClient,
170-
inProgressInvites: make(map[string]*inProgressInvite),
176+
inProgressInvites: make(map[dialogKey]*inProgressInvite),
171177
activeCalls: make(map[RemoteTag]*inboundCall),
172178
byLocal: make(map[LocalTag]*inboundCall),
173179
}

0 commit comments

Comments
 (0)