Revert "Fixing the check to include checking for trunks pre filtering"

This reverts commit af8cac038f.
This commit is contained in:
Nishad Musthafa
2025-07-03 11:13:02 -07:00
parent af8cac038f
commit 6f89ead3dd
+10 -29
View File
@@ -44,37 +44,27 @@ func (s *IOInfoService) matchSIPTrunk(ctx context.Context, trunkID string, call
}
}
}
it, zeroTrunks := s.SelectSIPInboundTrunk(ctx, call.To.User)
it := s.SelectSIPInboundTrunk(ctx, call.To.User)
result, err := sip.MatchTrunkDetailed(it, call)
if err != nil {
return nil, err
}
// If trunks exist but none matched or there is atleast one trunk, return a specific error
if (result.MatchType == sip.TrunkMatchNone || result.MatchType == sip.TrunkMatchEmpty) && !zeroTrunks {
// If trunks exist but none matched, return a specific error
if result.MatchType == sip.TrunkMatchNone {
return nil, ErrSIPTrunkNotFound
}
// If no trunks were defined at all, return nil (this is different from TrunkMatchNone)
if zeroTrunks || result.MatchType == sip.TrunkMatchEmpty {
if result.MatchType == sip.TrunkMatchEmpty {
return nil, nil
}
return result.Trunk, nil
}
func (s *IOInfoService) SelectSIPInboundTrunk(ctx context.Context, called string) (iters.Iter[*livekit.SIPInboundTrunkInfo], bool) {
// Create a stats callback to log filtering statistics
var zeroTrunks bool
statsCallback := func(stats livekit.FilterStats) {
// Check if there are no trunks at all
if stats.TotalItemsBeforeFilter == 0 {
zeroTrunks = true
}
}
it := livekit.ListPageIterWithStats(s.ss.ListSIPInboundTrunk, &livekit.ListSIPInboundTrunkRequest{
func (s *IOInfoService) SelectSIPInboundTrunk(ctx context.Context, called string) iters.Iter[*livekit.SIPInboundTrunkInfo] {
it := livekit.ListPageIter(s.ss.ListSIPInboundTrunk, &livekit.ListSIPInboundTrunkRequest{
Numbers: []string{called},
}, statsCallback, false)
return iters.PagesAsIter(ctx, it), zeroTrunks
})
return iters.PagesAsIter(ctx, it)
}
// matchSIPDispatchRule finds the best dispatch rule matching the request parameters. Returns an error if no rule matched.
@@ -98,18 +88,9 @@ func (s *IOInfoService) SelectSIPDispatchRule(ctx context.Context, trunkID strin
if trunkID != "" {
trunkIDs = []string{trunkID}
}
// Create a stats callback to log filtering statistics
statsCallback := func(stats livekit.FilterStats) {
logger.Infow("SIP Dispatch Rule selection filtering stats",
"totalBeforeFilter", stats.TotalItemsBeforeFilter,
"totalAfterFilter", stats.TotalItemsAfterFilter,
"itemsInCurrentPage", stats.ItemsInCurrentPage,
"filteredInCurrentPage", stats.FilteredInCurrentPage,
"trunkID", trunkID)
}
it := livekit.ListPageIterWithStats(s.ss.ListSIPDispatchRule, &livekit.ListSIPDispatchRuleRequest{
it := livekit.ListPageIter(s.ss.ListSIPDispatchRule, &livekit.ListSIPDispatchRuleRequest{
TrunkIds: trunkIDs,
}, statsCallback, false)
})
return iters.PagesAsIter(ctx, it)
}