diff --git a/go.mod b/go.mod index 5292bd0..1f3bdd6 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 @@ -56,6 +56,7 @@ 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 @@ -63,7 +64,7 @@ require ( 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 @@ -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 @@ -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 @@ -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 diff --git a/go.sum b/go.sum index 5fcf89c..b2ca36a 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= @@ -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= @@ -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= @@ -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= @@ -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= diff --git a/pkg/sip/client.go b/pkg/sip/client.go index 9588845..0b05324 100644 --- a/pkg/sip/client.go +++ b/pkg/sip/client.go @@ -24,8 +24,6 @@ import ( "sync" "time" - "github.com/emiago/sipgo" - "github.com/emiago/sipgo/sip" "github.com/frostbyte73/core" "golang.org/x/exp/maps" @@ -33,6 +31,8 @@ import ( "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" diff --git a/pkg/sip/inbound.go b/pkg/sip/inbound.go index 0132f12..d4783b5 100644 --- a/pkg/sip/inbound.go +++ b/pkg/sip/inbound.go @@ -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" @@ -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" @@ -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 @@ -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 @@ -1135,10 +1134,10 @@ 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()) @@ -1146,7 +1145,7 @@ func (c *sipInbound) swapSrcDst(req *sip.Request) { 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}) } @@ -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") } @@ -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") } diff --git a/pkg/sip/outbound.go b/pkg/sip/outbound.go index abcdce1..8c873e5 100644 --- a/pkg/sip/outbound.go +++ b/pkg/sip/outbound.go @@ -22,7 +22,6 @@ import ( "sync" "time" - "github.com/emiago/sipgo/sip" "github.com/frostbyte73/core" "github.com/icholy/digest" "github.com/pkg/errors" @@ -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" @@ -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") } @@ -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}) } @@ -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) } @@ -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() diff --git a/pkg/sip/protocol.go b/pkg/sip/protocol.go index 68e12ad..66b0a5f 100644 --- a/pkg/sip/protocol.go +++ b/pkg/sip/protocol.go @@ -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" + "github.com/livekit/sip/pkg/config" ) @@ -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 "" @@ -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()) // } @@ -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 diff --git a/pkg/sip/protocol_test.go b/pkg/sip/protocol_test.go index 421c93d..736ecb6 100644 --- a/pkg/sip/protocol_test.go +++ b/pkg/sip/protocol_test.go @@ -3,12 +3,13 @@ package sip import ( "testing" - "github.com/emiago/sipgo/sip" "github.com/stretchr/testify/require" + + "github.com/livekit/sipgo/sip" ) func TestHandleNotify(t *testing.T) { - req := sip.NewRequest(sip.NOTIFY, &sip.Uri{ + req := sip.NewRequest(sip.NOTIFY, sip.Uri{ Host: "foo.bar", }) @@ -21,7 +22,7 @@ func TestHandleNotify(t *testing.T) { require.Equal(t, uint32(0), c) require.Equal(t, 200, s) - req = sip.NewRequest(sip.NOTIFY, &sip.Uri{ + req = sip.NewRequest(sip.NOTIFY, sip.Uri{ Host: "foo.bar", }) @@ -34,7 +35,7 @@ func TestHandleNotify(t *testing.T) { require.Equal(t, uint32(1234), c) require.Equal(t, 200, s) - req = sip.NewRequest(sip.NOTIFY, &sip.Uri{ + req = sip.NewRequest(sip.NOTIFY, sip.Uri{ Host: "foo.bar", }) @@ -47,7 +48,7 @@ func TestHandleNotify(t *testing.T) { require.Equal(t, uint32(1234), c) require.Equal(t, 404, s) - req = sip.NewRequest(sip.NOTIFY, &sip.Uri{ + req = sip.NewRequest(sip.NOTIFY, sip.Uri{ Host: "foo.bar", }) @@ -57,7 +58,7 @@ func TestHandleNotify(t *testing.T) { m, c, s, err = handleNotify(req) require.Error(t, err) - req = sip.NewRequest(sip.NOTIFY, &sip.Uri{ + req = sip.NewRequest(sip.NOTIFY, sip.Uri{ Host: "foo.bar", }) diff --git a/pkg/sip/room.go b/pkg/sip/room.go index eafcd52..ca697e9 100644 --- a/pkg/sip/room.go +++ b/pkg/sip/room.go @@ -24,9 +24,8 @@ import ( "github.com/pion/webrtc/v3" "github.com/livekit/protocol/livekit" - "github.com/livekit/protocol/sip" - "github.com/livekit/protocol/logger" + "github.com/livekit/protocol/sip" lksdk "github.com/livekit/server-sdk-go/v2" "github.com/livekit/sip/pkg/config" diff --git a/pkg/sip/server.go b/pkg/sip/server.go index cbb83a9..1096fa9 100644 --- a/pkg/sip/server.go +++ b/pkg/sip/server.go @@ -26,18 +26,17 @@ import ( "sync" "time" - "github.com/emiago/sipgo" - "github.com/emiago/sipgo/sip" "github.com/frostbyte73/core" "github.com/icholy/digest" "golang.org/x/exp/maps" "github.com/livekit/protocol/logger" "github.com/livekit/protocol/rpc" - - "github.com/livekit/sip/pkg/media" + "github.com/livekit/sipgo" + "github.com/livekit/sipgo/sip" "github.com/livekit/sip/pkg/config" + "github.com/livekit/sip/pkg/media" "github.com/livekit/sip/pkg/stats" ) diff --git a/pkg/sip/service.go b/pkg/sip/service.go index 8d2ee77..d1b8b40 100644 --- a/pkg/sip/service.go +++ b/pkg/sip/service.go @@ -23,12 +23,12 @@ import ( "sync/atomic" "time" - "github.com/emiago/sipgo" "google.golang.org/protobuf/types/known/emptypb" "github.com/livekit/protocol/logger" "github.com/livekit/protocol/rpc" "github.com/livekit/psrpc" + "github.com/livekit/sipgo" "github.com/livekit/sip/pkg/config" "github.com/livekit/sip/pkg/media" diff --git a/pkg/sip/service_test.go b/pkg/sip/service_test.go index abfe25b..4b5b558 100644 --- a/pkg/sip/service_test.go +++ b/pkg/sip/service_test.go @@ -8,20 +8,17 @@ import ( "testing" "time" - "github.com/emiago/sipgo" - "github.com/emiago/sipgo/sip" + "github.com/stretchr/testify/require" "github.com/livekit/mediatransportutil/pkg/rtcconfig" "github.com/livekit/protocol/logger" "github.com/livekit/protocol/rpc" + "github.com/livekit/sipgo" + "github.com/livekit/sipgo/sip" + "github.com/livekit/sip/pkg/config" "github.com/livekit/sip/pkg/media" - "github.com/livekit/sip/pkg/stats" - - "github.com/stretchr/testify/require" - - "github.com/livekit/sip/pkg/config" ) const ( @@ -113,7 +110,7 @@ func testInvite(t *testing.T, h Handler, hidden bool, from, to string, test func offer, err := sdpGenerateOffer(localIP, 0xB0B) require.NoError(t, err) - inviteRecipent := &sip.Uri{User: to, Host: sipServerAddress} + inviteRecipent := sip.Uri{User: to, Host: sipServerAddress} inviteRequest := sip.NewRequest(sip.INVITE, inviteRecipent) inviteRequest.SetDestination(sipServerAddress) inviteRequest.SetBody(offer) diff --git a/pkg/sip/types.go b/pkg/sip/types.go index 83a84fa..84f6834 100644 --- a/pkg/sip/types.go +++ b/pkg/sip/types.go @@ -20,9 +20,9 @@ import ( "net/netip" "strconv" - "github.com/emiago/sipgo/sip" "github.com/livekit/protocol/livekit" "github.com/livekit/protocol/logger" + "github.com/livekit/sipgo/sip" ) type Headers []sip.Header @@ -183,8 +183,8 @@ type LocalTag string type RemoteTag string func getFromTag(r *sip.Request) (RemoteTag, error) { - from, ok := r.From() - if !ok { + from := r.From() + if from == nil { return "", errors.New("no From on Request") } tag, ok := getTagFrom(from.Params) @@ -195,8 +195,8 @@ func getFromTag(r *sip.Request) (RemoteTag, error) { } func getToTag(r *sip.Response) (RemoteTag, error) { - to, ok := r.To() - if !ok { + to := r.To() + if to == nil { return "", errors.New("no To on Response") } tag, ok := getTagFrom(to.Params) diff --git a/pkg/siptest/client.go b/pkg/siptest/client.go index f14eb92..4eacdec 100644 --- a/pkg/siptest/client.go +++ b/pkg/siptest/client.go @@ -33,12 +33,13 @@ import ( "github.com/at-wat/ebml-go" "github.com/at-wat/ebml-go/webm" - "github.com/emiago/sipgo" - "github.com/emiago/sipgo/sip" "github.com/frostbyte73/core" "github.com/icholy/digest" "github.com/pion/sdp/v3" + "github.com/livekit/sipgo" + "github.com/livekit/sipgo/sip" + "github.com/livekit/sip/pkg/audiotest" "github.com/livekit/sip/pkg/config" "github.com/livekit/sip/pkg/media" @@ -286,8 +287,8 @@ func (c *Client) Dial(ip string, uri string, number string, headers map[string]s return err } - toHeader, ok := resp.To() - if !ok { + toHeader := resp.To() + if toHeader == nil { return errors.New("no To header on Request") } @@ -308,14 +309,14 @@ func (c *Client) Dial(ip string, uri string, number string, headers map[string]s break } - if contactHeader, ok := resp.Contact(); ok { - req.Recipient = &contactHeader.Address + if contactHeader := resp.Contact(); contactHeader != nil { + req.Recipient = contactHeader.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}) } @@ -334,7 +335,7 @@ func (c *Client) Dial(ip string, uri string, number string, headers map[string]s c.inviteReq = req c.inviteResp = resp - if h, ok := req.CSeq(); ok { + if h := req.CSeq(); h != nil { c.lastCSeq.Store(h.SeqNo) } @@ -344,7 +345,7 @@ func (c *Client) Dial(ip string, uri string, number string, headers map[string]s } func (c *Client) attemptInvite(ip, uri, number string, offer []byte, authHeader string, headers map[string]string) (*sip.Request, *sip.Response, error) { - req := sip.NewRequest(sip.INVITE, &sip.Uri{User: number, Host: uri}) + req := sip.NewRequest(sip.INVITE, sip.Uri{User: number, Host: uri}) req.SetDestination(ip) req.SetBody(offer) req.AppendHeader(sip.NewHeader("Content-Type", "application/sdp")) @@ -378,7 +379,7 @@ func (c *Client) sendBye() { req.AppendHeader(sip.NewHeader("User-Agent", "LiveKit")) cseq := c.lastCSeq.Add(1) - cseqH, _ := req.CSeq() + cseqH := req.CSeq() cseqH.SeqNo = cseq tx, err := c.sipClient.TransactionRequest(req) @@ -402,12 +403,12 @@ func (c *Client) SendDTMF(digits string) error { } func (c *Client) SendNotify(eventReq *sip.Request, notifyStatus string) error { - var recipient *sip.Uri + var recipient sip.Uri - if contact, ok := eventReq.Contact(); ok { - recipient = &contact.Address - } else if from, ok := eventReq.From(); ok { - recipient = &from.Address + if contact := eventReq.Contact(); contact != nil { + recipient = contact.Address + } else if from := eventReq.From(); from != nil { + recipient = from.Address } else { return errors.New("missing destination address") } @@ -435,19 +436,19 @@ func (c *Client) SendNotify(eventReq *sip.Request, notifyStatus string) error { maxForwardsHeader := sip.MaxForwardsHeader(70) req.AppendHeader(&maxForwardsHeader) - if to, ok := eventReq.To(); ok { + if to := eventReq.To(); to != nil { req.AppendHeader((*sip.FromHeader)(to)) } else { return errors.New("missing To header in REFER request") } - if from, ok := eventReq.From(); ok { + if from := eventReq.From(); from != nil { req.AppendHeader((*sip.ToHeader)(from)) } else { return errors.New("missing From header in REFER request") } - if callId, ok := eventReq.CallID(); ok { + if callId := eventReq.CallID(); callId != nil { req.AppendHeader(callId) } @@ -465,7 +466,7 @@ func (c *Client) SendNotify(eventReq *sip.Request, notifyStatus string) error { req.SetSource(eventReq.Destination()) req.SetDestination(eventReq.Source()) - if eventCSeq, ok := eventReq.CSeq(); ok { + if eventCSeq := eventReq.CSeq(); eventCSeq != nil { req.AppendHeader(sip.NewHeader("Event", fmt.Sprintf("refer;id=%d", eventCSeq.SeqNo))) } else { return errors.New("missing CSeq header in REFER request") diff --git a/test/integration/livekit_test.go b/test/integration/livekit_test.go index 43b022e..c02d05f 100644 --- a/test/integration/livekit_test.go +++ b/test/integration/livekit_test.go @@ -8,11 +8,12 @@ import ( "sync/atomic" "testing" + "github.com/ory/dockertest/v3" + "github.com/ory/dockertest/v3/docker" + "github.com/livekit/protocol/livekit" "github.com/livekit/protocol/redis" lksdk "github.com/livekit/server-sdk-go/v2" - "github.com/ory/dockertest/v3" - "github.com/ory/dockertest/v3/docker" "github.com/livekit/sip/test/lktest" ) diff --git a/test/integration/sip_test.go b/test/integration/sip_test.go index 5a0b3c0..e81411e 100644 --- a/test/integration/sip_test.go +++ b/test/integration/sip_test.go @@ -11,7 +11,6 @@ import ( "testing" "time" - sipgo "github.com/emiago/sipgo/sip" "github.com/stretchr/testify/require" "github.com/livekit/mediatransportutil/pkg/rtcconfig" @@ -22,6 +21,7 @@ import ( "github.com/livekit/protocol/utils" "github.com/livekit/psrpc" lksdk "github.com/livekit/server-sdk-go/v2" + sipgo "github.com/livekit/sipgo/sip" "github.com/livekit/sip/pkg/config" "github.com/livekit/sip/pkg/media/dtmf" diff --git a/test/lktest/dtmf.go b/test/lktest/dtmf.go index 9c1af1d..3e70892 100644 --- a/test/lktest/dtmf.go +++ b/test/lktest/dtmf.go @@ -19,9 +19,10 @@ import ( "errors" "time" + "github.com/stretchr/testify/require" + "github.com/livekit/protocol/livekit" lksdk "github.com/livekit/server-sdk-go/v2" - "github.com/stretchr/testify/require" ) type DTMFParticipant interface { diff --git a/test/lktest/sip.go b/test/lktest/sip.go index 8c5ccce..38770cd 100644 --- a/test/lktest/sip.go +++ b/test/lktest/sip.go @@ -20,10 +20,11 @@ import ( "slices" "strings" + "github.com/stretchr/testify/require" + "github.com/livekit/protocol/livekit" "github.com/livekit/protocol/utils/guid" lksdk "github.com/livekit/server-sdk-go/v2" - "github.com/stretchr/testify/require" ) func checkSIPAttrs(t TB, exp, got map[string]string) (_, _ map[string]string) {