Skip to content

Commit fafb175

Browse files
committed
Finally got around to adressing review comments
1 parent 05264ed commit fafb175

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"
@@ -135,18 +134,17 @@ type dialogKey struct {
135134
}
136135

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

151149
closing core.Fuse
152150
cmu sync.RWMutex
@@ -167,9 +165,10 @@ type Server struct {
167165
}
168166

169167
type inProgressInvite struct {
170-
sipCallID string
171-
challenge digest.Challenge
172-
lkCallID string // SCL_* LiveKit call ID assigned to this dialog
168+
sipCallID string
169+
challenge digest.Challenge
170+
lkCallID string // SCL_* LiveKit call ID assigned to this dialog
171+
timeoutLink utils.TimeoutQueueItem[dialogKey]
173172
}
174173

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

0 commit comments

Comments
 (0)