From 47896f50e354259a92bea77efc08d363fdba3c11 Mon Sep 17 00:00:00 2001 From: Denys Smirnov Date: Fri, 7 Mar 2025 21:49:42 +0200 Subject: [PATCH] Update protocol and IO service. (#3499) --- go.mod | 2 +- go.sum | 4 ++-- pkg/service/ioservice_sip.go | 30 ++++++++++++++++-------------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/go.mod b/go.mod index 8467d1c27..e261ece61 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,7 @@ require ( github.com/jxskiss/base62 v1.1.0 github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1 github.com/livekit/mediatransportutil v0.0.0-20241220010243-a2bdee945564 - github.com/livekit/protocol v1.34.0 + github.com/livekit/protocol v1.34.1-0.20250307181533-e586a23f4e56 github.com/livekit/psrpc v0.6.1-0.20250205181828-a0beed2e4126 github.com/mackerelio/go-osstat v0.2.5 github.com/magefile/mage v1.15.0 diff --git a/go.sum b/go.sum index a35c47cd2..10c63efa1 100644 --- a/go.sum +++ b/go.sum @@ -170,8 +170,8 @@ github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1 h1:jm09419p0lqTkD github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1/go.mod h1:Rs3MhFwutWhGwmY1VQsygw28z5bWcnEYmS1OG9OxjOQ= github.com/livekit/mediatransportutil v0.0.0-20241220010243-a2bdee945564 h1:GX7KF/V9ExmcfT/2Bdia8aROjkxrgx7WpyH7w9MB4J4= github.com/livekit/mediatransportutil v0.0.0-20241220010243-a2bdee945564/go.mod h1:36s+wwmU3O40IAhE+MjBWP3W71QRiEE9SfooSBvtBqY= -github.com/livekit/protocol v1.34.0 h1:hbIXgNW+JPiTcGjzNg1XgQg3Wqa2R5dBhzuy+LLEIS4= -github.com/livekit/protocol v1.34.0/go.mod h1:yXuQ7ucrLj91nbxL6/AHgtxdha1DGzLj1LkgvnT90So= +github.com/livekit/protocol v1.34.1-0.20250307181533-e586a23f4e56 h1:8D8AVKGc/y9FwCkZKgFyA8UJ1Wpm5Os5eo2N7ArEYK8= +github.com/livekit/protocol v1.34.1-0.20250307181533-e586a23f4e56/go.mod h1:WrT/CYRxtMNOVUjnIPm5OjWtEkmreffTeE1PRZwlRg4= github.com/livekit/psrpc v0.6.1-0.20250205181828-a0beed2e4126 h1:fzuYpAQbCid7ySPpQWWePfQOWUrs8x6dJ0T3Wl07n+Y= github.com/livekit/psrpc v0.6.1-0.20250205181828-a0beed2e4126/go.mod h1:X5WtEZ7OnEs72Fi5/J+i0on3964F1aynQpCalcgMqRo= github.com/mackerelio/go-osstat v0.2.5 h1:+MqTbZUhoIt4m8qzkVoXUJg1EuifwlAJSk4Yl2GXh+o= diff --git a/pkg/service/ioservice_sip.go b/pkg/service/ioservice_sip.go index cadb69aec..5892a4c47 100644 --- a/pkg/service/ioservice_sip.go +++ b/pkg/service/ioservice_sip.go @@ -30,21 +30,21 @@ import ( // matchSIPTrunk finds a SIP Trunk definition matching the request. // Returns nil if no rules matched or an error if there are conflicting definitions. -func (s *IOInfoService) matchSIPTrunk(ctx context.Context, trunkID, calling, called string, srcIP netip.Addr) (*livekit.SIPInboundTrunkInfo, error) { +func (s *IOInfoService) matchSIPTrunk(ctx context.Context, trunkID string, call *rpc.SIPCall) (*livekit.SIPInboundTrunkInfo, error) { if s.ss == nil { return nil, ErrSIPNotConnected } if trunkID != "" { // This is a best-effort optimization. Fallthrough to listing trunks if it doesn't work. if tr, err := s.ss.LoadSIPInboundTrunk(ctx, trunkID); err == nil { - tr, err = sip.MatchTrunkIter(iters.Slice([]*livekit.SIPInboundTrunkInfo{tr}), srcIP, calling, called) + tr, err = sip.MatchTrunkIter(iters.Slice([]*livekit.SIPInboundTrunkInfo{tr}), call) if err == nil { return tr, nil } } } - it := s.SelectSIPInboundTrunk(ctx, called) - return sip.MatchTrunkIter(it, srcIP, calling, called) + it := s.SelectSIPInboundTrunk(ctx, call.To.User) + return sip.MatchTrunkIter(it, call) } func (s *IOInfoService) SelectSIPInboundTrunk(ctx context.Context, called string) iters.Iter[*livekit.SIPInboundTrunkInfo] { @@ -82,18 +82,19 @@ func (s *IOInfoService) SelectSIPDispatchRule(ctx context.Context, trunkID strin } func (s *IOInfoService) EvaluateSIPDispatchRules(ctx context.Context, req *rpc.EvaluateSIPDispatchRulesRequest) (*rpc.EvaluateSIPDispatchRulesResponse, error) { + call := req.SIPCall() log := logger.GetLogger() - log = log.WithValues("toUser", req.CalledNumber, "fromUser", req.CallingNumber, "src", req.SrcAddress) - if req.SrcAddress == "" { + log = log.WithValues("toUser", call.To.User, "fromUser", call.From.User, "src", call.SourceIp) + if call.SourceIp == "" { log.Warnw("source address is not set", nil) // TODO: return error in the next release } - srcIP, err := netip.ParseAddr(req.SrcAddress) - if req.SrcAddress != "" && err != nil { + _, err := netip.ParseAddr(call.SourceIp) + if call.SourceIp != "" && err != nil { log.Errorw("cannot parse source IP", err) return nil, twirp.WrapError(twirp.NewError(twirp.InvalidArgument, err.Error()), err) } - trunk, err := s.matchSIPTrunk(ctx, req.SipTrunkId, req.CallingNumber, req.CalledNumber, srcIP) + trunk, err := s.matchSIPTrunk(ctx, req.SipTrunkId, call) if err != nil { return nil, err } @@ -127,18 +128,19 @@ func (s *IOInfoService) EvaluateSIPDispatchRules(ctx context.Context, req *rpc.E } func (s *IOInfoService) GetSIPTrunkAuthentication(ctx context.Context, req *rpc.GetSIPTrunkAuthenticationRequest) (*rpc.GetSIPTrunkAuthenticationResponse, error) { + call := req.SIPCall() log := logger.GetLogger() - log = log.WithValues("toUser", req.To, "fromUser", req.From, "src", req.SrcAddress) - if req.SrcAddress == "" { + log = log.WithValues("toUser", call.To.User, "fromUser", call.From.User, "src", call.SourceIp) + if call.SourceIp == "" { log.Warnw("source address is not set", nil) // TODO: return error in the next release } - srcIP, err := netip.ParseAddr(req.SrcAddress) - if req.SrcAddress != "" && err != nil { + _, err := netip.ParseAddr(call.SourceIp) + if call.SourceIp != "" && err != nil { log.Errorw("cannot parse source IP", err) return nil, twirp.WrapError(twirp.NewError(twirp.InvalidArgument, err.Error()), err) } - trunk, err := s.matchSIPTrunk(ctx, "", req.From, req.To, srcIP) + trunk, err := s.matchSIPTrunk(ctx, "", call) if err != nil { return nil, err }