From 4a86c34316df27508c18e2590e65898dfcf34bd7 Mon Sep 17 00:00:00 2001 From: Sean DuBois Date: Mon, 4 Dec 2023 11:49:30 -0500 Subject: [PATCH] Include Host in Trunk+DispatchHandler processing --- go.mod | 2 +- go.sum | 2 ++ pkg/service/service.go | 6 ++++-- pkg/sip/inbound.go | 10 +++++----- pkg/sip/server.go | 4 ++-- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index 0e469b80..2d7e69b5 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/icholy/digest v0.1.22 github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1 github.com/livekit/mediatransportutil v0.0.0-20231017082622-43f077b4e60e - github.com/livekit/protocol v1.9.2-0.20231121183749-0cb26043c3cd + github.com/livekit/protocol v1.9.4-0.20231204164031-5ffa9f0c6545 github.com/livekit/psrpc v0.5.2 github.com/livekit/server-sdk-go v1.1.1 github.com/pion/interceptor v0.1.25 diff --git a/go.sum b/go.sum index 2f50d8b2..48698938 100644 --- a/go.sum +++ b/go.sum @@ -92,6 +92,8 @@ github.com/livekit/mediatransportutil v0.0.0-20231017082622-43f077b4e60e h1:yNeI github.com/livekit/mediatransportutil v0.0.0-20231017082622-43f077b4e60e/go.mod h1:+WIOYwiBMive5T81V8B2wdAc2zQNRjNQiJIcPxMTILY= github.com/livekit/protocol v1.9.2-0.20231121183749-0cb26043c3cd h1:DlyhqC/Ge176SQFNCP/VgSabh3Gwf0cjEKqooznbO1E= github.com/livekit/protocol v1.9.2-0.20231121183749-0cb26043c3cd/go.mod h1:8f342d5nvfNp9YAEfJokSR+zbNFpaivgU0h6vwaYhes= +github.com/livekit/protocol v1.9.4-0.20231204164031-5ffa9f0c6545 h1:PvGxeNAXwNvZY/x4akBKA1SN3sjmcoyMy56/reSWjho= +github.com/livekit/protocol v1.9.4-0.20231204164031-5ffa9f0c6545/go.mod h1:8f342d5nvfNp9YAEfJokSR+zbNFpaivgU0h6vwaYhes= github.com/livekit/psrpc v0.5.2 h1:+MvG8Otm/J6MTg2MP/uuMbrkxOWsrj2hDhu/I1VIU1U= github.com/livekit/psrpc v0.5.2/go.mod h1:cQjxg1oCxYHhxxv6KJH1gSvdtCHQoRZCHgPdm5N8v2g= github.com/livekit/server-sdk-go v1.1.1 h1:TkDD/Ecyh7XNuxgxhpsDQ1uzbTlDWwwJrbkyUjQmcbY= diff --git a/pkg/service/service.go b/pkg/service/service.go index 094fee5b..f7b22345 100644 --- a/pkg/service/service.go +++ b/pkg/service/service.go @@ -73,10 +73,11 @@ func (s *Service) Run() error { } } -func (s *Service) HandleTrunkAuthentication(from, to, srcAddress string) (username, password string, err error) { +func (s *Service) HandleTrunkAuthentication(from, to, toHost, srcAddress string) (username, password string, err error) { resp, err := s.psrpcClient.GetSIPTrunkAuthentication(context.TODO(), &rpc.GetSIPTrunkAuthenticationRequest{ From: from, To: to, + ToHost: toHost, SrcAddress: srcAddress, }) @@ -87,10 +88,11 @@ func (s *Service) HandleTrunkAuthentication(from, to, srcAddress string) (userna return resp.Username, resp.Password, nil } -func (s *Service) HandleDispatchRules(callingNumber, calledNumber, srcAddress string, pin string, noPin bool) (joinRoom, identity string, requestPin, rejectInvite bool) { +func (s *Service) HandleDispatchRules(callingNumber, calledNumber, calledHost, srcAddress string, pin string, noPin bool) (joinRoom, identity string, requestPin, rejectInvite bool) { resp, err := s.psrpcClient.EvaluateSIPDispatchRules(context.TODO(), &rpc.EvaluateSIPDispatchRulesRequest{ CallingNumber: callingNumber, CalledNumber: calledNumber, + CalledHost: calledHost, SrcAddress: srcAddress, Pin: pin, NoPin: noPin, diff --git a/pkg/sip/inbound.go b/pkg/sip/inbound.go index 74442881..3689c77e 100644 --- a/pkg/sip/inbound.go +++ b/pkg/sip/inbound.go @@ -111,9 +111,9 @@ func (s *Server) onInvite(req *sip.Request, tx sip.ServerTransaction) { } src := req.Source() - username, password, err := s.authHandler(from.Address.User, to.Address.User, src) + username, password, err := s.authHandler(from.Address.User, to.Address.User, to.Address.Host, src) if err != nil { - log.Printf("Rejecting inbound call, doesn't match any Trunks %q %q %q\n", from.Address.User, to.Address.User, src) + log.Printf("Rejecting inbound call, doesn't match any Trunks %q %q %q %q\n", from.Address.User, to.Address.User, to.Address.Host, src) sipErrorResponse(tx, req) return } @@ -154,9 +154,9 @@ func (s *Server) newInboundCall(tag string, from *sip.FromHeader, to *sip.ToHead func (c *inboundCall) handleInvite(req *sip.Request, tx sip.ServerTransaction, conf *config.Config) { // Send initial request. In the best case scenario, we will immediately get a room name to join. // Otherwise, we could even learn that this number is not allowed and reject the call, or ask for pin if required. - roomName, identity, requirePin, rejectInvite := c.s.dispatchRuleHandler(c.from.Address.User, c.to.Address.User, c.src, "", false) + roomName, identity, requirePin, rejectInvite := c.s.dispatchRuleHandler(c.from.Address.User, c.to.Address.User, c.to.Address.Host, c.src, "", false) if rejectInvite { - log.Printf("Rejecting inbound call, doesn't match any Dispatch Rules %q %q %q\n", c.from.Address.User, c.to.Address.User, c.src) + log.Printf("Rejecting inbound call, doesn't match any Dispatch Rules %q %q %q %q\n", c.from.Address.User, c.to.Address.User, c.to.Address.Host, c.src) sipErrorResponse(tx, req) return } @@ -229,7 +229,7 @@ func (c *inboundCall) pinPrompt() { noPin = pin == "" log.Printf("Checking Pin for SIP call %q -> %q = %q (noPin = %v)\n", c.from.Address.User, c.to.Address.User, pin, noPin) - roomName, identity, requirePin, reject := c.s.dispatchRuleHandler(c.from.Address.User, c.to.Address.User, c.src, pin, noPin) + roomName, identity, requirePin, reject := c.s.dispatchRuleHandler(c.from.Address.User, c.to.Address.User, c.to.Address.Host, c.src, pin, noPin) if reject || requirePin || roomName == "" { c.playAudio(c.s.res.wrongPin) c.Close() diff --git a/pkg/sip/server.go b/pkg/sip/server.go index 04ac6dc9..a60c8032 100644 --- a/pkg/sip/server.go +++ b/pkg/sip/server.go @@ -38,8 +38,8 @@ var ( ) type ( - AuthHandlerFunc func(from, to, srcAddress string) (username, password string, err error) - DispatchRuleHandlerFunc func(callingNumber, calledNumber, srcAddress string, pin string, noPin bool) (joinRoom, identity string, requestPin, rejectInvite bool) + AuthHandlerFunc func(fromUser, toUser, toHost, srcAddress string) (username, password string, err error) + DispatchRuleHandlerFunc func(fromUser, toUser, toHost, srcAddress string, pin string, noPin bool) (joinRoom, identity string, requestPin, rejectInvite bool) Server struct { sipSrv *sipgo.Server signalingIp string