Skip to content

Commit

Permalink
Switch to slog for structured logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennwc committed Oct 19, 2024
1 parent 7bd3a58 commit 4b4f54e
Show file tree
Hide file tree
Showing 32 changed files with 341 additions and 406 deletions.
12 changes: 6 additions & 6 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package sipgo
import (
"context"
"fmt"
"log/slog"
"net"

"github.com/emiago/sipgo/sip"
"github.com/google/uuid"
"github.com/icholy/digest"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"

"github.com/emiago/sipgo/sip"
)

func Init() {
Expand All @@ -25,7 +25,7 @@ type Client struct {
host string
port int
rport bool
log zerolog.Logger
log *slog.Logger

// TxRequester allows you to use your transaction requester instead default from transaction layer
// Useful only for testing
Expand All @@ -37,7 +37,7 @@ type Client struct {
type ClientOption func(c *Client) error

// WithClientLogger allows customizing client logger
func WithClientLogger(logger zerolog.Logger) ClientOption {
func WithClientLogger(logger *slog.Logger) ClientOption {
return func(s *Client) error {
s.log = logger
return nil
Expand Down Expand Up @@ -94,7 +94,7 @@ func WithClientAddr(addr string) ClientOption {
func NewClient(ua *UserAgent, options ...ClientOption) (*Client, error) {
c := &Client{
UserAgent: ua,
log: log.Logger.With().Str("caller", "Client").Logger(),
log: slog.With("caller", "Client"),
}

for _, o := range options {
Expand Down
7 changes: 4 additions & 3 deletions dialog_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package sipgo

import (
"context"
"log/slog"
"testing"

"github.com/emiago/sipgo/sip"
"github.com/rs/zerolog/log"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/emiago/sipgo/sip"
)

func TestDialogServerByeRequest(t *testing.T) {
Expand All @@ -26,7 +27,7 @@ func TestDialogServerByeRequest(t *testing.T) {
invite.AppendHeader(&sip.RecordRouteHeader{Address: sip.Uri{Host: "P2", Port: 5060}})
invite.AppendHeader(&sip.RecordRouteHeader{Address: sip.Uri{Host: "P3", Port: 5060}})

dialog, err := dialogSrv.ReadInvite(invite, sip.NewServerTx("test", invite, nil, log.Logger))
dialog, err := dialogSrv.ReadInvite(invite, sip.NewServerTx("test", invite, nil, slog.Default()))
require.NoError(t, err)

res := sip.NewResponseFromRequest(invite, sip.StatusOK, "OK", nil)
Expand Down
6 changes: 1 addition & 5 deletions example/proxysip/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ require (
github.com/arl/statsviz v0.6.0
github.com/emiago/sipgo v0.23.1-0.20240913054121-597f4c4406dd
github.com/prometheus/client_golang v1.17.0
github.com/rs/zerolog v1.32.0
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.9.0
)

Expand All @@ -25,15 +23,13 @@ require (
github.com/gorilla/websocket v1.5.0 // indirect
github.com/icholy/digest v0.1.22 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.11.1 // indirect
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/sys v0.24.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
29 changes: 4 additions & 25 deletions example/proxysip/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gobwas/httphead v0.1.0 h1:exrUm0f4YX0L7EBwZHuCF4GDp8aJfVeBrlLQrs6NqWU=
Expand All @@ -15,7 +13,6 @@ 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.3.2 h1:zlnbNHxumkRvfPWgfXu8RBwyNR1x8wh9cf5PTOCqs9Q=
github.com/gobwas/ws v1.3.2/go.mod h1:hRKAFb8wOxFROYNsT1bqfWnhX+b5MFeJM9r2ZSwg/KY=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
Expand All @@ -34,16 +31,9 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
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/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v1.17.0 h1:rl2sfwZMtSthVU752MqfjQozy7blglC+1SOtjMAMh+Q=
Expand All @@ -54,31 +44,21 @@ github.com/prometheus/common v0.44.0 h1:+5BrQJwiBB9xsMygAB3TNvpQKOwlkc25LbISbrdO
github.com/prometheus/common v0.44.0/go.mod h1:ofAIvZbQ1e/nugmZGz4/qCb9Ap1VoSTIO7x0VV9VvuY=
github.com/prometheus/procfs v0.11.1 h1:xRC8Iq1yyca5ypa9n1EZnWZkt7dwcoRPQwX/5gwaUuI=
github.com/prometheus/procfs v0.11.1/go.mod h1:eesXgaPo1q7lBpVMoMy0ZOFTth9hBn4W/y0/p/ScXhY=
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.32.0 h1:keLypqrlIjaFsbmJOBdB/qvyF8KEtCWHwobLp5l/mQ0=
github.com/rs/zerolog v1.32.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b h1:gQZ0qzfKHQIybLANtM3mBXNUtOfsCFXeTsnBqCsx1KM=
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190624222133-a101b041ded4/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU=
Expand All @@ -91,7 +71,6 @@ google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
Expand Down
63 changes: 30 additions & 33 deletions example/proxysip/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,22 @@ import (
"encoding/json"
"errors"
"flag"
"log/slog"
"net/http"
_ "net/http/pprof"
"os"
"os/signal"
"runtime"
"runtime/pprof"
"strconv"
"time"

"github.com/arl/statsviz"
"github.com/emiago/sipgo/sip"

_ "net/http/pprof"
"github.com/emiago/sipgo/sip"

"github.com/emiago/sipgo"

"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
// _ "go.uber.org/automaxprocs"
)

Expand All @@ -45,21 +43,17 @@ func main() {
runtime.MemProfileRate = 64
}

lev := zerolog.InfoLevel
lev := slog.LevelInfo
debuglev := os.Getenv("LOGDEBUG")
if *debflag || debuglev != "" {
lev = zerolog.DebugLevel
lev = slog.LevelDebug
sip.SIPDebug = true
}

zerolog.TimeFieldFormat = zerolog.TimeFormatUnixMicro
log.Logger = zerolog.New(zerolog.ConsoleWriter{
Out: os.Stdout,
TimeFormat: time.StampMicro,
}).With().Timestamp().Logger().Level(lev)
slog.SetDefault(slog.New(slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{Level: lev})))

log.Info().Int("cpus", runtime.NumCPU()).Msg("Runtime")
log.Info().Msg("Server routes setuped")
slog.Info("Runtime", "cpus", runtime.NumCPU())
slog.Info("Server routes setuped")
go httpServer(":8080")

srv := setupSipProxy(*dst, *extIP)
Expand All @@ -68,7 +62,7 @@ func main() {
defer stop()

if err := srv.ListenAndServe(ctx, *transportType, *extIP); err != nil {
log.Error().Err(err).Msg("Fail to start sip server")
slog.Error("Fail to start sip server", "error", err)
return
}
}
Expand All @@ -90,7 +84,7 @@ func httpServer(address string) {
})
statsviz.Register(http.DefaultServeMux)

log.Info().Msgf("Http server started address=%s", address)
slog.Info("Http server started address=%s", address)
http.ListenAndServe(address, nil)
}

Expand All @@ -99,19 +93,22 @@ func setupSipProxy(proxydst string, ip string) *sipgo.Server {
host, port, _ := sip.ParseAddr(ip)
ua, err := sipgo.NewUA()
if err != nil {
log.Fatal().Err(err).Msg("Fail to setup user agent")
slog.Error("Fail to setup user agent", "error", err)
os.Exit(1)
}

srv, err := sipgo.NewServer(ua)
if err != nil {
log.Fatal().Err(err).Msg("Fail to setup server handle")
slog.Error("Fail to setup server handle", "error", err)
os.Exit(1)
}

client, err := sipgo.NewClient(ua, sipgo.WithClientAddr(
ip,
))
if err != nil {
log.Fatal().Err(err).Msg("Fail to setup client handle")
slog.Error("Fail to setup client handle", "error", err)
os.Exit(1)
}

registry := NewRegistry()
Expand All @@ -130,7 +127,7 @@ func setupSipProxy(proxydst string, ip string) *sipgo.Server {
resp := sip.NewResponseFromRequest(req, code, reason, nil)
resp.SetDestination(req.Source()) //This is optional, but can make sure not wrong via is read
if err := tx.Respond(resp); err != nil {
log.Error().Err(err).Msg("Fail to respond on transaction")
slog.Error("Fail to respond on transaction", "error", err)
}
}

Expand All @@ -150,14 +147,14 @@ func setupSipProxy(proxydst string, ip string) *sipgo.Server {
// Start client transaction and relay our request
clTx, err := client.TransactionRequest(ctx, req, sipgo.ClientRequestAddVia, sipgo.ClientRequestAddRecordRoute)
if err != nil {
log.Error().Err(err).Msg("RequestWithContext failed")
slog.Error("RequestWithContext failed", "error", err)
reply(tx, req, 500, "")
return
}
defer clTx.Terminate()

// Keep monitoring transactions, and proxy client responses to server transaction
log.Debug().Str("req", req.Method.String()).Msg("Starting transaction")
slog.Debug("Starting transaction", "req", req.Method.String())
for {
select {

Expand All @@ -174,7 +171,7 @@ func setupSipProxy(proxydst string, ip string) *sipgo.Server {
// Removes top most header
res.RemoveHeader("Via")
if err := tx.Respond(res); err != nil {
log.Error().Err(err).Msg("ResponseHandler transaction respond failed")
slog.Error("ResponseHandler transaction respond failed", "error", err)
}

// Early terminate
Expand All @@ -184,13 +181,13 @@ func setupSipProxy(proxydst string, ip string) *sipgo.Server {
// }
case <-clTx.Done():
if err := tx.Err(); err != nil {
log.Error().Err(err).Str("req", req.Method.String()).Msg("Client Transaction done with error")
slog.Error("Client Transaction done with error", "error", err, "req", req.Method.String())
}
return

case m := <-tx.Acks():
// Acks can not be send directly trough destination
log.Info().Str("m", m.StartLine()).Str("dst", dst).Msg("Proxing ACK")
slog.Info("Proxing ACK", "m", m.StartLine(), "dst", dst)
m.SetDestination(dst)
client.WriteRequest(m)

Expand All @@ -203,21 +200,21 @@ func setupSipProxy(proxydst string, ip string) *sipgo.Server {
r := newCancelRequest(req)
res, err := client.Do(ctx, r)
if err != nil {
log.Error().Err(err).Str("req", req.Method.String()).Msg("Canceling transaction failed")
slog.Error("Canceling transaction failed", "err", err, "req", req.Method.String())
return
}
if res.StatusCode != 200 {
log.Error().Err(err).Str("req", req.Method.String()).Msg("Canceling transaction failed with non 200 code")
slog.Error("Canceling transaction failed with non 200 code", "err", err, "req", req.Method.String())
return
}
return
}
}

log.Error().Err(err).Str("req", req.Method.String()).Msg("Transaction done with error")
slog.Error("Transaction done with error", "err", err, "req", req.Method.String())
return
}
log.Debug().Str("req", req.Method.String()).Msg("Transaction done")
slog.Debug("Transaction done", "req", req.Method.String())
return
}
}
Expand All @@ -241,17 +238,17 @@ func setupSipProxy(proxydst string, ip string) *sipgo.Server {
addr := uri.Host + ":" + strconv.Itoa(uri.Port)

registry.Add(uri.User, addr)
log.Debug().Msgf("Contact added %s -> %s", uri.User, addr)
slog.Debug("Contact added %s -> %s", "src", uri.User, "dst", addr)

res := sip.NewResponseFromRequest(req, 200, "OK", nil)
// log.Debug().Msgf("Sending response: \n%s", res.String())
// slog.Debug().Msgf("Sending response: \n%s", res.String())

// URI params must be reset or this should be regenetad
cont.Address.UriParams = sip.NewParams()
cont.Address.UriParams.Add("transport", req.Transport())

if err := tx.Respond(res); err != nil {
log.Error().Err(err).Msg("Sending REGISTER OK failed")
slog.Error("Sending REGISTER OK failed", "error", err)
return
}
}
Expand All @@ -267,7 +264,7 @@ func setupSipProxy(proxydst string, ip string) *sipgo.Server {
}
req.SetDestination(dst)
if err := client.WriteRequest(req, sipgo.ClientRequestAddVia); err != nil {
log.Error().Err(err).Msg("Send failed")
slog.Error("Send failed", "error", err)
reply(tx, req, 500, "")
}
}
Expand Down
Loading

0 comments on commit 4b4f54e

Please sign in to comment.