Fix legacy rule-set download_detour blocked by empty direct check
This commit is contained in:
+12
-12
@@ -17,20 +17,20 @@ type DirectDialer interface {
|
||||
}
|
||||
|
||||
type DetourDialer struct {
|
||||
outboundManager adapter.OutboundManager
|
||||
detour string
|
||||
defaultOutbound bool
|
||||
legacyDNSDialer bool
|
||||
dialer N.Dialer
|
||||
initOnce sync.Once
|
||||
initErr error
|
||||
outboundManager adapter.OutboundManager
|
||||
detour string
|
||||
defaultOutbound bool
|
||||
disableEmptyDirectCheck bool
|
||||
dialer N.Dialer
|
||||
initOnce sync.Once
|
||||
initErr error
|
||||
}
|
||||
|
||||
func NewDetour(outboundManager adapter.OutboundManager, detour string, legacyDNSDialer bool) N.Dialer {
|
||||
func NewDetour(outboundManager adapter.OutboundManager, detour string, disableEmptyDirectCheck bool) N.Dialer {
|
||||
return &DetourDialer{
|
||||
outboundManager: outboundManager,
|
||||
detour: detour,
|
||||
legacyDNSDialer: legacyDNSDialer,
|
||||
outboundManager: outboundManager,
|
||||
detour: detour,
|
||||
disableEmptyDirectCheck: disableEmptyDirectCheck,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ func (d *DetourDialer) init() {
|
||||
} else {
|
||||
dialer = d.outboundManager.Default()
|
||||
}
|
||||
if !d.defaultOutbound && !d.legacyDNSDialer {
|
||||
if !d.defaultOutbound && !d.disableEmptyDirectCheck {
|
||||
if directDialer, isDirect := dialer.(DirectDialer); isDirect {
|
||||
if directDialer.IsEmpty() {
|
||||
d.initErr = E.New("detour to an empty direct outbound makes no sense")
|
||||
|
||||
+10
-10
@@ -17,15 +17,15 @@ import (
|
||||
)
|
||||
|
||||
type Options struct {
|
||||
Context context.Context
|
||||
Options option.DialerOptions
|
||||
RemoteIsDomain bool
|
||||
DirectResolver bool
|
||||
ResolverOnDetour bool
|
||||
NewDialer bool
|
||||
LegacyDNSDialer bool
|
||||
DirectOutbound bool
|
||||
DefaultOutbound bool
|
||||
Context context.Context
|
||||
Options option.DialerOptions
|
||||
RemoteIsDomain bool
|
||||
DirectResolver bool
|
||||
ResolverOnDetour bool
|
||||
NewDialer bool
|
||||
DisableEmptyDirectCheck bool
|
||||
DirectOutbound bool
|
||||
DefaultOutbound bool
|
||||
}
|
||||
|
||||
// TODO: merge with NewWithOptions
|
||||
@@ -49,7 +49,7 @@ func NewWithOptions(options Options) (N.Dialer, error) {
|
||||
if outboundManager == nil {
|
||||
return nil, E.New("missing outbound manager")
|
||||
}
|
||||
dialer = NewDetour(outboundManager, dialOptions.Detour, options.LegacyDNSDialer)
|
||||
dialer = NewDetour(outboundManager, dialOptions.Detour, options.DisableEmptyDirectCheck)
|
||||
} else if options.DefaultOutbound {
|
||||
outboundManager := service.FromContext[adapter.OutboundManager](options.Context)
|
||||
if outboundManager == nil {
|
||||
|
||||
@@ -16,13 +16,14 @@ import (
|
||||
|
||||
func NewTransport(ctx context.Context, logger logger.ContextLogger, tag string, options option.HTTPClientOptions) (*ManagedTransport, error) {
|
||||
rawDialer, err := dialer.NewWithOptions(dialer.Options{
|
||||
Context: ctx,
|
||||
Options: options.DialerOptions,
|
||||
RemoteIsDomain: true,
|
||||
DirectResolver: options.DirectResolver,
|
||||
ResolverOnDetour: options.ResolveOnDetour,
|
||||
NewDialer: options.ResolveOnDetour,
|
||||
DefaultOutbound: options.DefaultOutbound,
|
||||
Context: ctx,
|
||||
Options: options.DialerOptions,
|
||||
RemoteIsDomain: true,
|
||||
DirectResolver: options.DirectResolver,
|
||||
ResolverOnDetour: options.ResolveOnDetour,
|
||||
NewDialer: options.ResolveOnDetour,
|
||||
DisableEmptyDirectCheck: options.DisableEmptyDirectCheck,
|
||||
DefaultOutbound: options.DefaultOutbound,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
+11
-10
@@ -25,16 +25,17 @@ type QUICOptions struct {
|
||||
}
|
||||
|
||||
type _HTTPClientOptions struct {
|
||||
Tag string `json:"tag,omitempty"`
|
||||
Engine string `json:"engine,omitempty"`
|
||||
Version int `json:"version,omitempty"`
|
||||
DisableVersionFallback bool `json:"disable_version_fallback,omitempty"`
|
||||
Headers badoption.HTTPHeader `json:"headers,omitempty"`
|
||||
HTTP2Options HTTP2Options `json:"-"`
|
||||
HTTP3Options QUICOptions `json:"-"`
|
||||
DefaultOutbound bool `json:"-"`
|
||||
ResolveOnDetour bool `json:"-"`
|
||||
DirectResolver bool `json:"-"`
|
||||
Tag string `json:"tag,omitempty"`
|
||||
Engine string `json:"engine,omitempty"`
|
||||
Version int `json:"version,omitempty"`
|
||||
DisableVersionFallback bool `json:"disable_version_fallback,omitempty"`
|
||||
Headers badoption.HTTPHeader `json:"headers,omitempty"`
|
||||
HTTP2Options HTTP2Options `json:"-"`
|
||||
HTTP3Options QUICOptions `json:"-"`
|
||||
DefaultOutbound bool `json:"-"`
|
||||
DisableEmptyDirectCheck bool `json:"-"`
|
||||
ResolveOnDetour bool `json:"-"`
|
||||
DirectResolver bool `json:"-"`
|
||||
OutboundTLSOptionsContainer
|
||||
DialerOptions
|
||||
}
|
||||
|
||||
@@ -294,11 +294,12 @@ func (s *RemoteRuleSet) resolveTransport() (adapter.HTTPTransport, error) {
|
||||
}
|
||||
if s.options.RemoteOptions.DownloadDetour != "" { //nolint:staticcheck
|
||||
deprecated.Report(s.ctx, deprecated.OptionLegacyRuleSetDownloadDetour)
|
||||
var httpClientOptions option.HTTPClientOptions
|
||||
httpClientOptions.DialerOptions = option.DialerOptions{
|
||||
Detour: s.options.RemoteOptions.DownloadDetour, //nolint:staticcheck
|
||||
}
|
||||
return httpClientManager.ResolveTransport(s.ctx, s.logger, httpClientOptions)
|
||||
return httpClientManager.ResolveTransport(s.ctx, s.logger, option.HTTPClientOptions{
|
||||
DialerOptions: option.DialerOptions{
|
||||
Detour: s.options.RemoteOptions.DownloadDetour, //nolint:staticcheck
|
||||
},
|
||||
DisableEmptyDirectCheck: true,
|
||||
})
|
||||
}
|
||||
defaultTransport := httpClientManager.DefaultTransport()
|
||||
if defaultTransport == nil {
|
||||
|
||||
Reference in New Issue
Block a user