Skip to content

Commit

Permalink
update: use proxy address from sip message
Browse files Browse the repository at this point in the history
  • Loading branch information
sreeram-narayanan committed Dec 13, 2022
1 parent c453e89 commit 138f3a8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
3 changes: 1 addition & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ type Server interface {

type TransportLayerFactory func(
ip net.IP,
proxy string,
dnsResolver *net.Resolver,
msgMapper sip.MessageMapper,
logger log.Logger,
Expand Down Expand Up @@ -151,7 +150,7 @@ func NewServer(
srv.log = logger.WithFields(log.Fields{
"sip_server_ptr": fmt.Sprintf("%p", srv),
})
srv.tp = tpFactory(ip, "", dnsResolver, config.MsgMapper, srv.Log())
srv.tp = tpFactory(ip, dnsResolver, config.MsgMapper, srv.Log())
sipTp := &sipTransport{
tpl: srv.tp,
srv: srv,
Expand Down
15 changes: 15 additions & 0 deletions sip/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ type Message interface {
SetSource(src string)
Destination() string
SetDestination(dest string)
Proxy() string
SetProxy(proxy string)

IsCancel() bool
IsAck() bool
Expand Down Expand Up @@ -415,6 +417,7 @@ type message struct {
startLine func() string
tp string
src string
proxy string
dest string
fields log.Fields
}
Expand Down Expand Up @@ -523,6 +526,18 @@ func (msg *message) SetDestination(dest string) {
msg.mu.Unlock()
}

func (msg *message) Proxy() string {
msg.mu.RLock()
defer msg.mu.RUnlock()
return msg.proxy
}

func (msg *message) SetProxy(proxy string) {
msg.mu.Lock()
msg.proxy = proxy
msg.mu.Unlock()
}

// Copy all headers of one type from one message to another.
// Appending to any headers that were already there.
func CopyHeaders(name string, from, to Message) {
Expand Down
4 changes: 4 additions & 0 deletions sip/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ func (req *request) Source() string {
return fmt.Sprintf("%v:%v", host, port)
}

func (req *request) Proxy() string {
return req.message.Proxy()
}

func (req *request) Destination() string {
if dest := req.message.Destination(); dest != "" {
return dest
Expand Down
11 changes: 4 additions & 7 deletions transport/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ type layer struct {
protocols *protocolStore
listenPorts map[string][]sip.Port
ip net.IP
proxy string
dnsResolver *net.Resolver
msgMapper sip.MessageMapper

Expand All @@ -94,7 +93,6 @@ type layer struct {
// - dnsAddr - DNS server address, default is 127.0.0.1:53
func NewLayer(
ip net.IP,
proxy string,
dnsResolver *net.Resolver,
msgMapper sip.MessageMapper,
logger log.Logger,
Expand All @@ -105,7 +103,6 @@ func NewLayer(
ip: ip,
dnsResolver: dnsResolver,
msgMapper: msgMapper,
proxy: proxy,

msgs: make(chan sip.Message),
errs: make(chan error),
Expand Down Expand Up @@ -261,8 +258,8 @@ func (tpl *layer) Send(msg sip.Message) error {

var dest string

if tpl.proxy != "" {
dest = tpl.proxy
if msg.Proxy() != "" {
dest = msg.Proxy()
} else {
dest = msg.Destination()
}
Expand Down Expand Up @@ -328,8 +325,8 @@ func (tpl *layer) Send(msg sip.Message) error {

var dest string

if tpl.proxy != "" {
dest = tpl.proxy
if msg.Proxy() != "" {
dest = msg.Proxy()
} else {
dest = msg.Destination()
}
Expand Down

0 comments on commit 138f3a8

Please sign in to comment.