Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to upstream sipgo parser #219

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ toolchain go1.23.1

require (
github.com/at-wat/ebml-go v0.17.1
github.com/emiago/sipgo v0.13.1
github.com/frostbyte73/core v0.0.12
github.com/gotranspile/g722 v0.0.0-20240123003956-384a1bb16a19
github.com/icholy/digest v0.1.23
Expand All @@ -16,6 +15,7 @@ require (
github.com/livekit/protocol v1.27.2-0.20241112203928-f558b991de7c
github.com/livekit/psrpc v0.6.1-0.20240924010758-9f0a4268a3b9
github.com/livekit/server-sdk-go/v2 v2.3.1-0.20241115175035-a3cf5f4c2d27
github.com/livekit/sipgo v0.13.2-0.20241021131531-e4db84deff2c
github.com/mjibson/go-dsp v0.0.0-20180508042940-11479a337f12
github.com/ory/dockertest/v3 v3.10.0
github.com/pion/interceptor v0.1.37
Expand Down Expand Up @@ -56,14 +56,15 @@ require (
github.com/docker/docker v25.0.5+incompatible // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/emiago/sipgo v0.24.1 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gammazero/deque v0.2.1 // indirect
github.com/go-jose/go-jose/v3 v3.0.3 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gobwas/httphead v0.1.0 // indirect
github.com/gobwas/pool v0.2.1 // indirect
github.com/gobwas/ws v1.2.1 // indirect
github.com/gobwas/ws v1.4.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/cel-go v0.21.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
Expand All @@ -76,6 +77,8 @@ require (
github.com/lithammer/shortuuid/v4 v4.0.0 // indirect
github.com/mackerelio/go-osstat v0.2.4 // indirect
github.com/magefile/mage v1.15.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/nats-io/nats.go v1.36.0 // indirect
Expand All @@ -102,6 +105,7 @@ require (
github.com/prometheus/procfs v0.12.0 // indirect
github.com/puzpuzpuz/xsync/v3 v3.4.0 // indirect
github.com/redis/go-redis/v9 v9.6.1 // indirect
github.com/rs/zerolog v1.33.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b // indirect
github.com/stoewer/go-strcase v1.3.0 // indirect
Expand All @@ -128,5 +132,3 @@ require (
google.golang.org/grpc v1.67.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)

replace github.com/emiago/sipgo => github.com/livekit/sipgo v0.13.2-0.20240820220653-befde351a575
23 changes: 19 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UF
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/containerd/continuity v0.4.3 h1:6HVkalIp+2u1ZLH1J/pYX2oBVXlJZvh1X1A7bEZ9Su8=
github.com/containerd/continuity v0.4.3/go.mod h1:F6PTNCKepoxEaXLQp3wDAjygEnImnZ/7o4JzpodfroQ=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY=
Expand All @@ -49,6 +50,8 @@ github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj
github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/emiago/sipgo v0.24.1 h1:RKy6NqVnvjgpLywo1sa4v+lwfEz5O5/0yk4Z8eek4XM=
github.com/emiago/sipgo v0.24.1/go.mod h1:UB0Ao5xk1b1TQisO29jmUDz0mXNINpHBR4YXsLbLXEs=
github.com/envoyproxy/protoc-gen-validate v1.1.0 h1:tntQDh69XqOCOZsDz0lVJQez/2L6Uu2PdjCQwWCJ3bM=
github.com/envoyproxy/protoc-gen-validate v1.1.0/go.mod h1:sXRDRVmzEbkM7CVcM06s9shE/m23dg3wzjl0UWqJ2q4=
github.com/frostbyte73/core v0.0.12 h1:kySA8+Os6eqnPFoExD2T7cehjSAY1MRyIViL0yTy2uc=
Expand All @@ -70,8 +73,9 @@ github.com/gobwas/httphead v0.1.0 h1:exrUm0f4YX0L7EBwZHuCF4GDp8aJfVeBrlLQrs6NqWU
github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM=
github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og=
github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
github.com/gobwas/ws v1.2.1 h1:F2aeBZrm2NDsc7vbovKrWSogd4wvfAxg0FQ89/iqOTk=
github.com/gobwas/ws v1.2.1/go.mod h1:hRKAFb8wOxFROYNsT1bqfWnhX+b5MFeJM9r2ZSwg/KY=
github.com/gobwas/ws v1.4.0 h1:CTaoG1tojrh4ucGPcoJFiAQUAsEWekEWvLy7GsVNqGs=
github.com/gobwas/ws v1.4.0/go.mod h1:G3gNqMNtPppf5XUz7O4shetPpcZ1VJ7zt18dlUeakrc=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/google/cel-go v0.21.0 h1:cl6uW/gxN+Hy50tNYvI691+sXxioCnstFzLp2WO4GCI=
Expand Down Expand Up @@ -124,12 +128,18 @@ github.com/livekit/psrpc v0.6.1-0.20240924010758-9f0a4268a3b9 h1:33oBjGpVD9tYkDX
github.com/livekit/psrpc v0.6.1-0.20240924010758-9f0a4268a3b9/go.mod h1:CQUBSPfYYAaevg1TNCc6/aYsa8DJH4jSRFdCeSZk5u0=
github.com/livekit/server-sdk-go/v2 v2.3.1-0.20241115175035-a3cf5f4c2d27 h1:ofp1nAfeoaLCbq1b23BSePp/ZyxD2LkiN2cIHU37+Ks=
github.com/livekit/server-sdk-go/v2 v2.3.1-0.20241115175035-a3cf5f4c2d27/go.mod h1:66ieZlHprXyHQLYEcFEJUkg8DS3DOsdpri9lXjNJmFk=
github.com/livekit/sipgo v0.13.2-0.20240820220653-befde351a575 h1:9On8gLpup6Hs9f679MO2jNtLZzpB901vSRKXzVmRP4w=
github.com/livekit/sipgo v0.13.2-0.20240820220653-befde351a575/go.mod h1:BY01/cjS7NQGCKAvgD+4FtIJ/8hPXwcDKnSan5uvklc=
github.com/livekit/sipgo v0.13.2-0.20241021131531-e4db84deff2c h1:KquO53e0/2HPNnYf91w0MW+AbFGVvXRMnbvsxZ7sk/Y=
github.com/livekit/sipgo v0.13.2-0.20241021131531-e4db84deff2c/go.mod h1:nbNi0IsYn4tyY2ab7Rafvifty07miHYvgedPMKWbaI4=
github.com/mackerelio/go-osstat v0.2.4 h1:qxGbdPkFo65PXOb/F/nhDKpF2nGmGaCFDLXoZjJTtUs=
github.com/mackerelio/go-osstat v0.2.4/go.mod h1:Zy+qzGdZs3A9cuIqmgbJvwbmLQH9dJvtio5ZjJTbdlQ=
github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg=
github.com/magefile/mage v1.15.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mjibson/go-dsp v0.0.0-20180508042940-11479a337f12 h1:dd7vnTDfjtwCETZDrRe+GPYNLA1jBtbZeyfyE8eZCyk=
Expand Down Expand Up @@ -210,6 +220,9 @@ github.com/redis/go-redis/v9 v9.6.1 h1:HHDteefn6ZkTtY5fGUE8tj8uy85AHk6zP7CpzIAM0
github.com/redis/go-redis/v9 v9.6.1/go.mod h1:0C0c6ycQsdpVNQpxb1njEQIqkx5UcsM8FJCQLgE9+RA=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b h1:gQZ0qzfKHQIybLANtM3mBXNUtOfsCFXeTsnBqCsx1KM=
Expand Down Expand Up @@ -313,12 +326,14 @@ golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
Expand Down
4 changes: 2 additions & 2 deletions pkg/sip/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ import (
"sync"
"time"

"github.com/emiago/sipgo"
"github.com/emiago/sipgo/sip"
"github.com/frostbyte73/core"
"golang.org/x/exp/maps"

"github.com/livekit/protocol/livekit"
"github.com/livekit/protocol/logger"
"github.com/livekit/protocol/rpc"
"github.com/livekit/protocol/tracer"
"github.com/livekit/sipgo"
"github.com/livekit/sipgo/sip"

"github.com/livekit/sip/pkg/config"
siperrors "github.com/livekit/sip/pkg/errors"
Expand Down
25 changes: 12 additions & 13 deletions pkg/sip/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"sync/atomic"
"time"

"github.com/emiago/sipgo/sip"
"github.com/frostbyte73/core"
"github.com/icholy/digest"
"github.com/pkg/errors"
Expand All @@ -36,6 +35,7 @@ import (
"github.com/livekit/protocol/tracer"
"github.com/livekit/psrpc"
lksdk "github.com/livekit/server-sdk-go/v2"
"github.com/livekit/sipgo/sip"

"github.com/livekit/sip/pkg/config"
"github.com/livekit/sip/pkg/media"
Expand Down Expand Up @@ -906,16 +906,15 @@ func (s *Server) newInbound(id LocalTag, contact URI, invite *sip.Request, invit
cancelled: make(chan struct{}),
referDone: make(chan error), // Do not buffer the channel to avoid reading a result for an old request
}
c.from, _ = invite.From()
c.from = invite.From()
if c.from != nil {
c.tag, _ = getTagFrom(c.from.Params)
}
c.to, _ = invite.To()
h, _ := invite.CSeq()
if h != nil {
c.to = invite.To()
if h := invite.CSeq(); h != nil {
c.nextRequestCSeq = h.SeqNo + 1
}
if callID, _ := invite.CallID(); callID != nil {
if callID := invite.CallID(); callID != nil {
c.callID = callID.Value()
}
return c
Expand Down Expand Up @@ -1090,7 +1089,7 @@ func (c *sipInbound) setDestFromVia(r *sip.Response) {
//
// Thus, instead of relying on LB, we will contact the source IP directly (should be the first Via).
// BYE will also copy the same destination address from our response to INVITE.
if h, ok := c.invite.Via(); ok && h.Host != "" {
if h := c.invite.Via(); h != nil && h.Host != "" {
port := 5060
if h.Port != 0 {
port = h.Port
Expand Down Expand Up @@ -1135,18 +1134,18 @@ func (c *sipInbound) AcceptBye(req *sip.Request, tx sip.ServerTransaction) {
}

func (c *sipInbound) swapSrcDst(req *sip.Request) {
if contact, ok := c.invite.Contact(); ok {
req.Recipient = &contact.Address
if contact := c.invite.Contact(); contact != nil {
req.Recipient = contact.Address
} else {
req.Recipient = &c.from.Address
req.Recipient = c.from.Address
}
req.SetSource(c.inviteOk.Source())
req.SetDestination(c.inviteOk.Destination())
req.RemoveHeader("From")
req.AppendHeader((*sip.FromHeader)(c.to))
req.RemoveHeader("To")
req.AppendHeader((*sip.ToHeader)(c.from))
if route, ok := req.RecordRoute(); ok {
if route := req.RecordRoute(); route != nil {
req.RemoveHeader("Record-Route")
req.AppendHeader(&sip.RouteHeader{Address: route.Address})
}
Expand Down Expand Up @@ -1209,7 +1208,7 @@ func (c *sipInbound) newReferReq(transferTo string) (*sip.Request, error) {
return nil, psrpc.NewErrorf(psrpc.FailedPrecondition, "can't transfer non established call") // call wasn't established
}

from, _ := c.invite.From()
from := c.invite.From()
if from == nil {
return nil, psrpc.NewErrorf(psrpc.InvalidArgument, "no From URI in invite")
}
Expand All @@ -1219,7 +1218,7 @@ func (c *sipInbound) newReferReq(transferTo string) (*sip.Request, error) {
c.setCSeq(req)
c.swapSrcDst(req)

cseq, _ := req.CSeq()
cseq := req.CSeq()
if cseq == nil {
return nil, psrpc.NewErrorf(psrpc.Internal, "missing CSeq header in REFER request")
}
Expand Down
29 changes: 14 additions & 15 deletions pkg/sip/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"sync"
"time"

"github.com/emiago/sipgo/sip"
"github.com/frostbyte73/core"
"github.com/icholy/digest"
"github.com/pkg/errors"
Expand All @@ -34,6 +33,7 @@ import (
"github.com/livekit/protocol/tracer"
"github.com/livekit/psrpc"
lksdk "github.com/livekit/server-sdk-go/v2"
"github.com/livekit/sipgo/sip"

"github.com/livekit/sip/pkg/config"
"github.com/livekit/sip/pkg/media"
Expand Down Expand Up @@ -653,8 +653,8 @@ authLoop:
if err != nil {
return nil, err
}
toHeader, ok := resp.To()
if !ok {
toHeader := resp.To()
if toHeader == nil {
return nil, errors.New("no 'To' header on Response")
}

Expand All @@ -672,31 +672,30 @@ authLoop:
}

c.invite, c.inviteOk = req, resp
var ok bool
toHeader, ok = resp.To()
if !ok {
toHeader = resp.To()
if toHeader == nil {
return nil, errors.New("no To header in INVITE response")
}
var ok bool
c.tag, ok = getTagFrom(toHeader.Params)
if !ok {
return nil, errors.New("no tag in To header in INVITE response")
}
if callID, _ := c.invite.CallID(); callID != nil {
if callID := c.invite.CallID(); callID != nil {
c.callID = callID.Value()
}
h, _ := c.invite.CSeq()
if h != nil {
if h := c.invite.CSeq(); h != nil {
c.nextRequestCSeq = h.SeqNo + 1
}

if cont, ok := resp.Contact(); ok {
req.Recipient = &cont.Address
if cont := resp.Contact(); cont != nil {
req.Recipient = cont.Address
if req.Recipient.Port == 0 {
req.Recipient.Port = 5060
}
}

if recordRouteHeader, ok := resp.RecordRoute(); ok {
if recordRouteHeader := resp.RecordRoute(); recordRouteHeader != nil {
req.AppendHeader(&sip.RouteHeader{Address: recordRouteHeader.Address})
}

Expand All @@ -714,9 +713,9 @@ func (c *sipOutbound) AckInviteOK(ctx context.Context) error {
func (c *sipOutbound) attemptInvite(ctx context.Context, prev *sip.Request, dest string, to *sip.ToHeader, offer []byte, authHeaderName, authHeader string, headers Headers, setState func(code sip.StatusCode)) (*sip.Request, *sip.Response, error) {
ctx, span := tracer.Start(ctx, "sipOutbound.attemptInvite")
defer span.End()
req := sip.NewRequest(sip.INVITE, &to.Address)
req := sip.NewRequest(sip.INVITE, to.Address)
if prev != nil {
if cid, _ := prev.CallID(); cid != nil {
if cid := prev.CallID(); cid != nil {
req.RemoveHeader("Call-ID")
req.AppendHeader(cid)
}
Expand Down Expand Up @@ -807,7 +806,7 @@ func (c *sipOutbound) transferCall(ctx context.Context, transferTo string) error

req := NewReferRequest(c.invite, c.inviteOk, c.contact, transferTo)
c.setCSeq(req)
cseq, _ := req.CSeq()
cseq := req.CSeq()

if cseq == nil {
c.mu.Unlock()
Expand Down
21 changes: 11 additions & 10 deletions pkg/sip/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ import (
"strings"
"time"

"github.com/emiago/sipgo/sip"
"github.com/livekit/psrpc"
"github.com/pkg/errors"

"github.com/livekit/psrpc"
"github.com/livekit/sipgo/sip"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same cosmetics remark as above. (I know there is already an import wrongly placed here 😊 )


"github.com/livekit/sip/pkg/config"
)

Expand Down Expand Up @@ -66,12 +67,12 @@ type Signaling interface {
}

func transportFromReq(req *sip.Request) Transport {
if to, _ := req.To(); to != nil {
if to := req.To(); to != nil {
if tr, _ := to.Params.Get("transport"); tr != "" {
return Transport(strings.ToLower(tr))
}
}
if via, _ := req.Via(); via != nil {
if via := req.Via(); via != nil {
return Transport(strings.ToLower(via.Transport))
}
return ""
Expand Down Expand Up @@ -116,7 +117,7 @@ func NewReferRequest(inviteRequest *sip.Request, inviteResponse *sip.Response, c
sip.CopyHeaders("Via", inviteRequest, req)
// if inviteResponse.IsSuccess() {
// update branch, 2xx ACK is separate Tx
viaHop, _ := req.Via()
viaHop := req.Via()
viaHop.Params.Add("branch", sip.GenerateBranch())
// }

Expand All @@ -138,25 +139,25 @@ func NewReferRequest(inviteRequest *sip.Request, inviteResponse *sip.Response, c
maxForwardsHeader := sip.MaxForwardsHeader(70)
req.AppendHeader(&maxForwardsHeader)

if h, _ := inviteRequest.From(); h != nil {
if h := inviteRequest.From(); h != nil {
sip.CopyHeaders("From", inviteRequest, req)
}

if h, _ := inviteResponse.To(); h != nil {
if h := inviteResponse.To(); h != nil {
sip.CopyHeaders("To", inviteResponse, req)
}

if h, _ := inviteRequest.CallID(); h != nil {
if h := inviteRequest.CallID(); h != nil {
sip.CopyHeaders("Call-ID", inviteRequest, req)
}

if h, _ := inviteRequest.CSeq(); h != nil {
if h := inviteRequest.CSeq(); h != nil {
sip.CopyHeaders("CSeq", inviteRequest, req)
}

req.AppendHeader(contactHeader)

cseq, _ := req.CSeq()
cseq := req.CSeq()
cseq.SeqNo = cseq.SeqNo + 1
cseq.MethodName = sip.REFER

Expand Down
Loading
Loading