Browse Source

use ip address instead of domain address in Connector.Connect

pull/350/head
ginuerzh 8 years ago
parent
commit
c91e424cbe
  1. 2
      chain.go
  2. 8
      client.go
  3. 8
      http2.go
  4. 8
      socks.go

2
chain.go

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

8
client.go

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

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

8
socks.go

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

Loading…
Cancel
Save