use ip address instead of domain address in Connector.Connect

This commit is contained in:
ginuerzh 2018-11-12 10:40:42 +08:00
parent b16f878c39
commit c91e424cbe
4 changed files with 5 additions and 21 deletions

View File

@ -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

View File

@ -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
}
}

View File

@ -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)

View File

@ -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