Skip to content

Commit

Permalink
Implement Via headers for requests for outbound calls (#218)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Denys Smirnov <[email protected]>
  • Loading branch information
biglittlebigben and dennwc authored Nov 18, 2024
1 parent 44fe89c commit f7fecf7
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pkg/sip/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -1145,12 +1145,31 @@ func (c *sipInbound) swapSrcDst(req *sip.Request) {
req.AppendHeader((*sip.FromHeader)(c.to))
req.RemoveHeader("To")
req.AppendHeader((*sip.ToHeader)(c.from))
// Remove all Via headers
for req.RemoveHeader("Via") {
}
req.PrependHeader(c.generateViaHeader(req))
if route := req.RecordRoute(); route != nil {
req.RemoveHeader("Record-Route")
req.AppendHeader(&sip.RouteHeader{Address: route.Address})
}
}

func (c *sipInbound) generateViaHeader(req *sip.Request) *sip.ViaHeader {
newvia := &sip.ViaHeader{
ProtocolName: "SIP",
ProtocolVersion: "2.0",
Transport: req.Transport(),
Host: c.s.sconf.SignalingIP.String(), // This can be rewritten by transport layer
Port: c.s.conf.SIPPort, // This can be rewritten by transport layer
Params: sip.NewParams(),
}
// NOTE: Consider lenght of branch configurable
newvia.Params.Add("branch", sip.GenerateBranchN(16))

return newvia
}

func (c *sipInbound) setCSeq(req *sip.Request) {
setCSeq(req, c.nextRequestCSeq)

Expand Down

0 comments on commit f7fecf7

Please sign in to comment.