Skip to content

Commit

Permalink
Include Host in Trunk+DispatchHandler processing
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean-Der committed Dec 4, 2023
1 parent e921a23 commit 4a86c34
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
6 changes: 4 additions & 2 deletions pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})

Expand All @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions pkg/sip/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions pkg/sip/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4a86c34

Please sign in to comment.