diff --git a/server.go b/server.go index 48dacda..9dd9c7f 100644 --- a/server.go +++ b/server.go @@ -47,7 +47,6 @@ type Server interface { type TransportLayerFactory func( ip net.IP, - proxy string, dnsResolver *net.Resolver, msgMapper sip.MessageMapper, logger log.Logger, @@ -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, diff --git a/sip/message.go b/sip/message.go index 5a005f3..b82d050 100644 --- a/sip/message.go +++ b/sip/message.go @@ -111,6 +111,8 @@ type Message interface { SetSource(src string) Destination() string SetDestination(dest string) + Proxy() string + SetProxy(proxy string) IsCancel() bool IsAck() bool @@ -415,6 +417,7 @@ type message struct { startLine func() string tp string src string + proxy string dest string fields log.Fields } @@ -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) { diff --git a/sip/request.go b/sip/request.go index 2d7cc95..01abdff 100644 --- a/sip/request.go +++ b/sip/request.go @@ -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 diff --git a/transport/layer.go b/transport/layer.go index ceb4947..b5cff19 100644 --- a/transport/layer.go +++ b/transport/layer.go @@ -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 @@ -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, @@ -105,7 +103,6 @@ func NewLayer( ip: ip, dnsResolver: dnsResolver, msgMapper: msgMapper, - proxy: proxy, msgs: make(chan sip.Message), errs: make(chan error), @@ -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() } @@ -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() }