diff --git a/cmd/run.go b/cmd/run.go index f7dde16e6..e2603804d 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -330,8 +330,7 @@ func newControlPlane(log *logrus.Logger, bpf interface{}, dnsCache map[string]*c client := http.Client{ Transport: &http.Transport{ DialContext: func(ctx context.Context, network, addr string) (c net.Conn, err error) { - cd := netproxy.ContextDialerConverter{Dialer: direct.SymmetricDirect} - conn, err := cd.DialContext(ctx, common.MagicNetwork("tcp", conf.Global.SoMarkFromDae, conf.Global.Mptcp), addr) + conn, err := direct.SymmetricDirect.DialContext(ctx, common.MagicNetwork("tcp", conf.Global.SoMarkFromDae, conf.Global.Mptcp), addr) if err != nil { return nil, err } @@ -372,8 +371,7 @@ func newControlPlane(log *logrus.Logger, bpf interface{}, dnsCache map[string]*c client := http.Client{ Transport: &http.Transport{ DialContext: func(ctx context.Context, network, addr string) (c net.Conn, err error) { - cd := netproxy.ContextDialerConverter{Dialer: direct.SymmetricDirect} - conn, err := cd.DialContext(ctx, common.MagicNetwork("tcp", conf.Global.SoMarkFromDae, conf.Global.Mptcp), addr) + conn, err := direct.SymmetricDirect.DialContext(ctx, common.MagicNetwork("tcp", conf.Global.SoMarkFromDae, conf.Global.Mptcp), addr) if err != nil { return nil, err } diff --git a/common/netutils/dns.go b/common/netutils/dns.go index 7c374471e..fdb3eb6df 100644 --- a/common/netutils/dns.go +++ b/common/netutils/dns.go @@ -207,8 +207,7 @@ func resolve(ctx context.Context, d netproxy.Dialer, dns netip.AddrPort, host st } // Dial and write. - cd := &netproxy.ContextDialerConverter{Dialer: d} - c, err := cd.DialContext(ctx, network, dns.String()) + c, err := d.DialContext(ctx, network, dns.String()) if err != nil { return nil, err } diff --git a/component/outbound/dialer/connectivity_check.go b/component/outbound/dialer/connectivity_check.go index 4d330e38b..a725a9627 100644 --- a/component/outbound/dialer/connectivity_check.go +++ b/component/outbound/dialer/connectivity_check.go @@ -600,12 +600,11 @@ func (d *Dialer) HttpCheck(ctx context.Context, u *netutils.URL, ip netip.Addr, if method == "" { method = http.MethodGet } - cd := &netproxy.ContextDialerConverter{Dialer: d.Dialer} cli := http.Client{ Transport: &http.Transport{ DialContext: func(ctx context.Context, network, addr string) (c net.Conn, err error) { // Force to dial "ip". - conn, err := cd.DialContext(ctx, common.MagicNetwork("tcp", soMark, mptcp), net.JoinHostPort(ip.String(), u.Port())) + conn, err := d.Dialer.DialContext(ctx, common.MagicNetwork("tcp", soMark, mptcp), net.JoinHostPort(ip.String(), u.Port())) if err != nil { return nil, err } diff --git a/control/dns_control.go b/control/dns_control.go index 8b41c309d..14f4f618e 100644 --- a/control/dns_control.go +++ b/control/dns_control.go @@ -560,16 +560,13 @@ func (c *DnsController) dialSend(invokingDepth int, req *udpRequest, data []byte ctxDial, cancel := context.WithTimeout(context.TODO(), consts.DefaultDialTimeout) defer cancel() - bestContextDialer := netproxy.ContextDialerConverter{ - Dialer: dialArgument.bestDialer, - } switch dialArgument.l4proto { case consts.L4ProtoStr_UDP: // Get udp endpoint. // TODO: connection pool. - conn, err = bestContextDialer.DialContext( + conn, err = dialArgument.bestDialer.DialContext( ctxDial, common.MagicNetwork("udp", dialArgument.mark, dialArgument.mptcp), dialArgument.bestTarget.String(), @@ -634,7 +631,7 @@ func (c *DnsController) dialSend(invokingDepth int, req *udpRequest, data []byte case consts.L4ProtoStr_TCP: // We can block here because we are in a coroutine. - conn, err = bestContextDialer.DialContext(ctxDial, common.MagicNetwork("tcp", dialArgument.mark, dialArgument.mptcp), dialArgument.bestTarget.String()) + conn, err = dialArgument.bestDialer.DialContext(ctxDial, common.MagicNetwork("tcp", dialArgument.mark, dialArgument.mptcp), dialArgument.bestTarget.String()) if err != nil { return fmt.Errorf("failed to dial proxy to tcp: %w", err) } diff --git a/control/tcp.go b/control/tcp.go index acdb14bfc..67a05442e 100644 --- a/control/tcp.go +++ b/control/tcp.go @@ -164,10 +164,7 @@ func (c *ControlPlane) RouteDialTcp(p *RouteDialParam) (conn netproxy.Conn, err } ctx, cancel := context.WithTimeout(context.TODO(), consts.DefaultDialTimeout) defer cancel() - cd := netproxy.ContextDialerConverter{ - Dialer: d, - } - return cd.DialContext(ctx, common.MagicNetwork("tcp", routingResult.Mark, c.mptcp), dialTarget) + return d.DialContext(ctx, common.MagicNetwork("tcp", routingResult.Mark, c.mptcp), dialTarget) } type WriteCloser interface { diff --git a/control/udp_endpoint_pool.go b/control/udp_endpoint_pool.go index 1bb29e004..da7ef00f3 100644 --- a/control/udp_endpoint_pool.go +++ b/control/udp_endpoint_pool.go @@ -134,12 +134,9 @@ begin: if err != nil { return nil, false, err } - cd := netproxy.ContextDialerConverter{ - Dialer: dialOption.Dialer, - } ctx, cancel := context.WithTimeout(context.TODO(), consts.DefaultDialTimeout) defer cancel() - udpConn, err := cd.DialContext(ctx, dialOption.Network, dialOption.Target) + udpConn, err := dialOption.Dialer.DialContext(ctx, dialOption.Network, dialOption.Target) if err != nil { return nil, true, err }