@@ -17,6 +17,7 @@ package sip
17
17
import (
18
18
"context"
19
19
"fmt"
20
+ "github.com/livekit/protocol/rpc"
20
21
"math"
21
22
"net/netip"
22
23
"slices"
@@ -184,7 +185,7 @@ func (s *Server) processInvite(req *sip.Request, tx sip.ServerTransaction) (retE
184
185
185
186
from , to := cc .From (), cc .To ()
186
187
187
- cmon := s .mon .NewCall (stats .Inbound , from .Host , cc . To () .Host )
188
+ cmon := s .mon .NewCall (stats .Inbound , from .Host , to .Host )
188
189
cmon .InviteReq ()
189
190
defer cmon .SessionDur ()()
190
191
joinDur := cmon .JoinDur ()
@@ -193,7 +194,25 @@ func (s *Server) processInvite(req *sip.Request, tx sip.ServerTransaction) (retE
193
194
cc .Processing ()
194
195
}
195
196
196
- r , err := s .handler .GetAuthCredentials (ctx , callID , from .User , to .User , to .Host , src .Addr ())
197
+ callInfo := & rpc.SIPCall {
198
+ LkCallId : callID ,
199
+ SourceIp : src .Addr ().String (),
200
+ Address : ToSIPUri ("" , cc .Address ()),
201
+ From : ToSIPUri ("" , from ),
202
+ To : ToSIPUri ("" , to ),
203
+ }
204
+ for _ , h := range cc .RemoteHeaders () {
205
+ switch h := h .(type ) {
206
+ case * sip.ViaHeader :
207
+ callInfo .Via = append (callInfo .Via , & livekit.SIPUri {
208
+ Host : h .Host ,
209
+ Port : uint32 (h .Port ),
210
+ Transport : SIPTransportFrom (Transport (h .Transport )),
211
+ })
212
+ }
213
+ }
214
+
215
+ r , err := s .handler .GetAuthCredentials (ctx , callInfo )
197
216
if err != nil {
198
217
cmon .InviteErrorShort ("auth-error" )
199
218
log .Warnw ("Rejecting inbound, auth check failed" , err )
@@ -245,7 +264,7 @@ func (s *Server) processInvite(req *sip.Request, tx sip.ServerTransaction) (retE
245
264
// ok
246
265
}
247
266
248
- call = s .newInboundCall (log , cmon , cc , src , state , nil )
267
+ call = s .newInboundCall (log , cmon , cc , callInfo , state , nil )
249
268
call .joinDur = joinDur
250
269
return call .handleInvite (call .ctx , req , r .TrunkID , s .conf )
251
270
}
@@ -316,7 +335,7 @@ type inboundCall struct {
316
335
attrsToHdr map [string ]string
317
336
ctx context.Context
318
337
cancel func ()
319
- src netip. AddrPort
338
+ call * rpc. SIPCall
320
339
media * MediaPort
321
340
dtmf chan dtmf.Event // buffered
322
341
lkRoom * Room // LiveKit room; only active after correct pin is entered
@@ -331,7 +350,7 @@ func (s *Server) newInboundCall(
331
350
log logger.Logger ,
332
351
mon * stats.CallMonitor ,
333
352
cc * sipInbound ,
334
- src netip. AddrPort ,
353
+ call * rpc. SIPCall ,
335
354
state * CallState ,
336
355
extra map [string ]string ,
337
356
) * inboundCall {
@@ -342,7 +361,7 @@ func (s *Server) newInboundCall(
342
361
log : log ,
343
362
mon : mon ,
344
363
cc : cc ,
345
- src : src ,
364
+ call : call ,
346
365
state : state ,
347
366
extraAttrs : extra ,
348
367
dtmf : make (chan dtmf.Event , 10 ),
@@ -366,14 +385,10 @@ func (c *inboundCall) handleInvite(ctx context.Context, req *sip.Request, trunkI
366
385
// Send initial request. In the best case scenario, we will immediately get a room name to join.
367
386
// Otherwise, we could even learn that this number is not allowed and reject the call, or ask for pin if required.
368
387
disp := c .s .handler .DispatchCall (ctx , & CallInfo {
369
- TrunkID : trunkID ,
370
- ID : string (c .cc .ID ()),
371
- FromUser : c .cc .From ().User ,
372
- ToUser : c .cc .To ().User ,
373
- ToHost : c .cc .To ().Host ,
374
- SrcAddress : c .src .Addr (),
375
- Pin : "" ,
376
- NoPin : false ,
388
+ TrunkID : trunkID ,
389
+ Call : c .call ,
390
+ Pin : "" ,
391
+ NoPin : false ,
377
392
})
378
393
if disp .ProjectID != "" {
379
394
c .log = c .log .WithValues ("projectID" , disp .ProjectID )
@@ -659,14 +674,10 @@ func (c *inboundCall) pinPrompt(ctx context.Context, trunkID string) (disp CallD
659
674
660
675
c .log .Infow ("Checking Pin for SIP call" , "pin" , pin , "noPin" , noPin )
661
676
disp = c .s .handler .DispatchCall (ctx , & CallInfo {
662
- TrunkID : trunkID ,
663
- ID : string (c .cc .ID ()),
664
- FromUser : c .cc .From ().User ,
665
- ToUser : c .cc .To ().User ,
666
- ToHost : c .cc .To ().Host ,
667
- SrcAddress : c .src .Addr (),
668
- Pin : pin ,
669
- NoPin : noPin ,
677
+ TrunkID : trunkID ,
678
+ Call : c .call ,
679
+ Pin : pin ,
680
+ NoPin : noPin ,
670
681
})
671
682
if disp .ProjectID != "" {
672
683
c .log = c .log .WithValues ("projectID" , disp .ProjectID )
@@ -1008,6 +1019,13 @@ func (c *sipInbound) RespondAndDrop(status sip.StatusCode, reason string) {
1008
1019
c .drop ()
1009
1020
}
1010
1021
1022
+ func (c * sipInbound ) Address () sip.Uri {
1023
+ if c .invite == nil {
1024
+ return sip.Uri {}
1025
+ }
1026
+ return c .invite .Recipient
1027
+ }
1028
+
1011
1029
func (c * sipInbound ) From () sip.Uri {
1012
1030
if c .from == nil {
1013
1031
return sip.Uri {}
0 commit comments