From 6f89ead3dd153e1cd095136220dc0b03a49db258 Mon Sep 17 00:00:00 2001 From: Nishad Musthafa Date: Thu, 3 Jul 2025 11:13:02 -0700 Subject: [PATCH] Revert "Fixing the check to include checking for trunks pre filtering" This reverts commit af8cac038fe3704cb7c57c7e70627124dcbc1de5. --- pkg/service/ioservice_sip.go | 39 +++++++++--------------------------- 1 file changed, 10 insertions(+), 29 deletions(-) diff --git a/pkg/service/ioservice_sip.go b/pkg/service/ioservice_sip.go index 772ffde65..b1c0cded9 100644 --- a/pkg/service/ioservice_sip.go +++ b/pkg/service/ioservice_sip.go @@ -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) }