Skip to content

Commit 4f76b36

Browse files
committed
Finally got around to adressing review comments
1 parent de0faf0 commit 4f76b36

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

pkg/sip/inbound.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func (s *Server) cleanupInvites() {
148148
s.imu.Lock()
149149
for it := s.inviteTimeoutQueue.IterateRemoveAfter(inviteCredentialValidity); it.Next(); {
150150
key := it.Item().Value
151-
delete(s.inProgressInvites, *key)
151+
delete(s.inProgressInvites, key)
152152
}
153153
s.imu.Unlock()
154154
}
@@ -161,16 +161,22 @@ func (s *Server) getInvite(sipCallID, toTag, fromTag string) *inProgressInvite {
161161
toTag: toTag,
162162
fromTag: fromTag,
163163
}
164+
164165
s.imu.Lock()
165-
defer s.imu.Unlock()
166-
is, ok := s.inProgressInvites[key]
167-
if ok {
168-
return is
166+
is, exists := s.inProgressInvites[key]
167+
s.imu.Unlock()
168+
if !exists {
169+
s.imu.Lock()
170+
is, exists = s.inProgressInvites[key]
171+
if !exists {
172+
is = &inProgressInvite{sipCallID: sipCallID, timeoutLink: utils.TimeoutQueueItem[dialogKey]{Value: key}}
173+
s.inProgressInvites[key] = is
174+
}
175+
s.imu.Unlock()
169176
}
170-
is = &inProgressInvite{sipCallID: sipCallID}
171-
s.inProgressInvites[key] = is
172-
s.inviteTimeoutQueue.Reset(&utils.TimeoutQueueItem[*dialogKey]{Value: &key})
173177

178+
// Always reset the timeout link, whether just created or not
179+
s.inviteTimeoutQueue.Reset(&is.timeoutLink)
174180
return is
175181
}
176182

pkg/sip/server.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"net"
2525
"net/netip"
2626
"sync"
27-
"sync/atomic"
2827
"time"
2928

3029
"github.com/frostbyte73/core"
@@ -131,18 +130,17 @@ type dialogKey struct {
131130
}
132131

133132
type Server struct {
134-
log logger.Logger
135-
mon *stats.Monitor
136-
region string
137-
sipSrv *sipgo.Server
138-
getIOClient GetIOInfoClient
139-
sipListeners []io.Closer
140-
sipUnhandled RequestHandler
141-
142-
imu sync.Mutex
143-
inProgressInvites map[dialogKey]*inProgressInvite
144-
inviteTimeoutQueue utils.TimeoutQueue[*dialogKey]
145-
isCleanupTaskRunning atomic.Bool
133+
log logger.Logger
134+
mon *stats.Monitor
135+
region string
136+
sipSrv *sipgo.Server
137+
getIOClient GetIOInfoClient
138+
sipListeners []io.Closer
139+
sipUnhandled RequestHandler
140+
inviteTimeoutQueue utils.TimeoutQueue[dialogKey]
141+
142+
imu sync.Mutex
143+
inProgressInvites map[dialogKey]*inProgressInvite
146144

147145
closing core.Fuse
148146
cmu sync.RWMutex
@@ -162,9 +160,10 @@ type Server struct {
162160
}
163161

164162
type inProgressInvite struct {
165-
sipCallID string
166-
challenge digest.Challenge
167-
lkCallID string // SCL_* LiveKit call ID assigned to this dialog
163+
sipCallID string
164+
challenge digest.Challenge
165+
lkCallID string // SCL_* LiveKit call ID assigned to this dialog
166+
timeoutLink utils.TimeoutQueueItem[dialogKey]
168167
}
169168

170169
func NewServer(region string, conf *config.Config, log logger.Logger, mon *stats.Monitor, getIOClient GetIOInfoClient) *Server {

0 commit comments

Comments
 (0)