Feature: resolve ip with a proxy adapter

This commit is contained in:
yaling888
2022-02-23 02:38:50 +08:00
parent b192238699
commit d876d6e74c
14 changed files with 357 additions and 101 deletions

View File

@ -15,10 +15,11 @@ import (
type client struct {
*D.Client
r *Resolver
port string
host string
iface string
r *Resolver
port string
host string
iface string
proxyAdapter string
}
func (c *client) Exchange(m *D.Msg) (*D.Msg, error) {
@ -50,7 +51,14 @@ func (c *client) ExchangeContext(ctx context.Context, m *D.Msg) (*D.Msg, error)
if c.iface != "" {
options = append(options, dialer.WithInterface(c.iface))
}
conn, err := dialer.DialContext(ctx, network, net.JoinHostPort(ip.String(), c.port), options...)
var conn net.Conn
if c.proxyAdapter == "" {
conn, err = dialer.DialContext(ctx, network, net.JoinHostPort(ip.String(), c.port), options...)
} else {
conn, err = dialContextWithProxyAdapter(ctx, c.proxyAdapter, network, ip, c.port, options...)
}
if err != nil {
return nil, err
}