Commit c91e424c authored by ginuerzh's avatar ginuerzh

use ip address instead of domain address in Connector.Connect

parent b16f878c
......@@ -143,7 +143,7 @@ func (c *Chain) dialWithOptions(addr string, options *ChainOptions) (net.Conn, e
return nil, err
}
cc, err := route.LastNode().Client.Connect(conn, addr, IPAddrConnectOption(ipAddr))
cc, err := route.LastNode().Client.Connect(conn, ipAddr, AddrConnectOption(addr))
if err != nil {
conn.Close()
return nil, err
......
......@@ -202,15 +202,15 @@ func QUICConfigHandshakeOption(config *QUICConfig) HandshakeOption {
// ConnectOptions describes the options for Connector.Connect.
type ConnectOptions struct {
IPAddr string
Addr string
}
// ConnectOption allows a common way to set ConnectOptions.
type ConnectOption func(opts *ConnectOptions)
// IPAddrConnectOption specifies the corresponding IP:PORT of the connected target address.
func IPAddrConnectOption(ipAddr string) ConnectOption {
// AddrConnectOption specifies the corresponding address of the target.
func AddrConnectOption(addr string) ConnectOption {
return func(opts *ConnectOptions) {
opts.IPAddr = ipAddr
opts.Addr = addr
}
}
......@@ -29,11 +29,6 @@ func HTTP2Connector(user *url.Userinfo) Connector {
}
func (c *http2Connector) Connect(conn net.Conn, addr string, options ...ConnectOption) (net.Conn, error) {
var cOpts ConnectOptions
for _, opt := range options {
opt(&cOpts)
}
cc, ok := conn.(*http2ClientConn)
if !ok {
return nil, errors.New("wrong connection type")
......@@ -81,9 +76,6 @@ func (c *http2Connector) Connect(conn net.Conn, addr string, options ...ConnectO
closed: make(chan struct{}),
}
if cOpts.IPAddr != "" {
addr = cOpts.IPAddr
}
hc.remoteAddr, _ = net.ResolveTCPAddr("tcp", addr)
hc.localAddr, _ = net.ResolveTCPAddr("tcp", cc.addr)
......
......@@ -262,14 +262,6 @@ func SOCKS4Connector() Connector {
}
func (c *socks4Connector) Connect(conn net.Conn, addr string, options ...ConnectOption) (net.Conn, error) {
var cOpts ConnectOptions
for _, opt := range options {
opt(&cOpts)
}
if cOpts.IPAddr != "" {
addr = cOpts.IPAddr
}
taddr, err := net.ResolveTCPAddr("tcp4", addr)
if err != nil {
return nil, err
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment