diff --git a/client/client.go b/client/client.go index d74331afb..7b1a1f3ca 100644 --- a/client/client.go +++ b/client/client.go @@ -147,6 +147,7 @@ type Client struct { socksWg sync.WaitGroup DNSResolutionMapForDirectDialsEventual eventual.Value + useProxyless func() bool } // NewClient creates a new client that does things like starts the HTTP and @@ -168,6 +169,7 @@ func NewClient( eventWithLabel func(category, action, label string), onDialError func(error, bool), onSucceedingProxy func(), + useProxyless func() bool, ) (*Client, error) { // A small LRU to detect redirect loop rewriteLRU, err := lru.New(100) @@ -204,6 +206,7 @@ func NewClient( httpListener: eventual.NewValue(), socksListener: eventual.NewValue(), DNSResolutionMapForDirectDialsEventual: eventual.NewValue(), + useProxyless: useProxyless, } keepAliveIdleTimeout := chained.IdleTimeout - 5*time.Second @@ -754,7 +757,7 @@ func (client *Client) initDialers(proxies map[string]*commonconfig.ProxyConfig) OnNewDialer: func(dialer dialer.Dialer) { client.dialer.set(dialer) }, - ProxyAll: client.proxyAll, + UseProxyless: client.useProxyless, }, ) client.dialer.set(newDialer) diff --git a/dialer/dialer.go b/dialer/dialer.go index a77dd2517..37c5aba5e 100644 --- a/dialer/dialer.go +++ b/dialer/dialer.go @@ -48,9 +48,9 @@ type Options struct { OnNewDialer func(Dialer) - // Specifies whether or not to proxy all traffic. In this case, that means bypasses the proxyless - // dialer and uses the proxy dialers to connect to the destination site. - ProxyAll func() bool + // Specifies whether or not to enable proxyless dialing for all traffic. Proxyless is + // off when proxy all is on. + UseProxyless func() bool } // Clone creates a deep copy of the Options object @@ -65,7 +65,7 @@ func (o *Options) Clone() *Options { BanditDir: o.BanditDir, proxylessDialer: o.proxylessDialer, OnNewDialer: o.OnNewDialer, - ProxyAll: o.ProxyAll, + UseProxyless: o.UseProxyless, } } diff --git a/dialer/parallel_dialer.go b/dialer/parallel_dialer.go index d5e538cb5..b1c0d48aa 100644 --- a/dialer/parallel_dialer.go +++ b/dialer/parallel_dialer.go @@ -23,8 +23,7 @@ func newParallelPreferProxyless(proxyless proxyless, d Dialer, opts *Options) Di } func (d *parallelDialer) DialContext(ctx context.Context, network, addr string) (net.Conn, error) { - if !common.SupportsProxyless() { - log.Debugf("Proxyless transport not supported, falling back to default dialer for %s", addr) + if !common.SupportsProxyless() || !d.opts.UseProxyless() { // If the proxyless transport is not supported, we fall back to the default dialer. return d.dialer.DialContext(ctx, network, addr) } diff --git a/flashlight.go b/flashlight.go index e631d9835..44782bf41 100644 --- a/flashlight.go +++ b/flashlight.go @@ -84,6 +84,7 @@ type Flashlight struct { errorHandler func(HandledErrorType, error) mxProxyListeners sync.RWMutex proxyListeners []func(map[string]*commonconfig.ProxyConfig, config.Source) + useProxyless func() bool } // clientCallbacks are callbacks the client is configured with @@ -215,7 +216,6 @@ func New( useDetour := func() bool { return !_proxyAll() && f.featureEnabled(config.FeatureDetour) && !f.featureEnabled(config.FeatureProxyWhitelistedOnly) } - proxyAll := func() bool { useShortcutOrDetour := useShortcut() || useDetour() return !useShortcutOrDetour && !f.featureEnabled(config.FeatureProxyWhitelistedOnly) @@ -243,6 +243,7 @@ func New( eventWithLabel, f.callbacks.onDialError, f.callbacks.onSucceedingProxy, + f.useProxyless, ) if err != nil { diff --git a/option.go b/option.go index 1eadb005a..ab79ae65a 100644 --- a/option.go +++ b/option.go @@ -42,3 +42,10 @@ func WithOnProxies(onProxiesUpdate func([]dialer.ProxyDialer, config.Source)) Op client.callbacks.onProxiesUpdate = onProxiesUpdate } } + +// WithUseProxyless sets the function to determine if proxyless dialing should be used. +func WithUseProxyless(useProxyless func() bool) Option { + return func(client *Flashlight) { + client.useProxyless = useProxyless + } +}