use ip address instead of domain address in Connector.Connect
This commit is contained in:
parent
b16f878c39
commit
c91e424cbe
2
chain.go
2
chain.go
@ -143,7 +143,7 @@ func (c *Chain) dialWithOptions(addr string, options *ChainOptions) (net.Conn, e
|
|||||||
return nil, err
|
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 {
|
if err != nil {
|
||||||
conn.Close()
|
conn.Close()
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -202,15 +202,15 @@ func QUICConfigHandshakeOption(config *QUICConfig) HandshakeOption {
|
|||||||
|
|
||||||
// ConnectOptions describes the options for Connector.Connect.
|
// ConnectOptions describes the options for Connector.Connect.
|
||||||
type ConnectOptions struct {
|
type ConnectOptions struct {
|
||||||
IPAddr string
|
Addr string
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConnectOption allows a common way to set ConnectOptions.
|
// ConnectOption allows a common way to set ConnectOptions.
|
||||||
type ConnectOption func(opts *ConnectOptions)
|
type ConnectOption func(opts *ConnectOptions)
|
||||||
|
|
||||||
// IPAddrConnectOption specifies the corresponding IP:PORT of the connected target address.
|
// AddrConnectOption specifies the corresponding address of the target.
|
||||||
func IPAddrConnectOption(ipAddr string) ConnectOption {
|
func AddrConnectOption(addr string) ConnectOption {
|
||||||
return func(opts *ConnectOptions) {
|
return func(opts *ConnectOptions) {
|
||||||
opts.IPAddr = ipAddr
|
opts.Addr = addr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
8
http2.go
8
http2.go
@ -29,11 +29,6 @@ func HTTP2Connector(user *url.Userinfo) Connector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *http2Connector) Connect(conn net.Conn, addr string, options ...ConnectOption) (net.Conn, error) {
|
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)
|
cc, ok := conn.(*http2ClientConn)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("wrong connection type")
|
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{}),
|
closed: make(chan struct{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
if cOpts.IPAddr != "" {
|
|
||||||
addr = cOpts.IPAddr
|
|
||||||
}
|
|
||||||
hc.remoteAddr, _ = net.ResolveTCPAddr("tcp", addr)
|
hc.remoteAddr, _ = net.ResolveTCPAddr("tcp", addr)
|
||||||
hc.localAddr, _ = net.ResolveTCPAddr("tcp", cc.addr)
|
hc.localAddr, _ = net.ResolveTCPAddr("tcp", cc.addr)
|
||||||
|
|
||||||
|
8
socks.go
8
socks.go
@ -262,14 +262,6 @@ func SOCKS4Connector() Connector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *socks4Connector) Connect(conn net.Conn, addr string, options ...ConnectOption) (net.Conn, error) {
|
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)
|
taddr, err := net.ResolveTCPAddr("tcp4", addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
Reference in New Issue
Block a user