Fix legacy rule-set download_detour blocked by empty direct check
This commit is contained in:
parent
44ee81ccb4
commit
2581c6c99c
5 changed files with 47 additions and 44 deletions
|
|
@ -20,17 +20,17 @@ type DetourDialer struct {
|
|||
outboundManager adapter.OutboundManager
|
||||
detour string
|
||||
defaultOutbound bool
|
||||
legacyDNSDialer 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,
|
||||
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")
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ type Options struct {
|
|||
DirectResolver bool
|
||||
ResolverOnDetour bool
|
||||
NewDialer bool
|
||||
LegacyDNSDialer bool
|
||||
DisableEmptyDirectCheck bool
|
||||
DirectOutbound bool
|
||||
DefaultOutbound bool
|
||||
}
|
||||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ func NewTransport(ctx context.Context, logger logger.ContextLogger, tag string,
|
|||
DirectResolver: options.DirectResolver,
|
||||
ResolverOnDetour: options.ResolveOnDetour,
|
||||
NewDialer: options.ResolveOnDetour,
|
||||
DisableEmptyDirectCheck: options.DisableEmptyDirectCheck,
|
||||
DefaultOutbound: options.DefaultOutbound,
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ type _HTTPClientOptions struct {
|
|||
HTTP2Options HTTP2Options `json:"-"`
|
||||
HTTP3Options QUICOptions `json:"-"`
|
||||
DefaultOutbound bool `json:"-"`
|
||||
DisableEmptyDirectCheck bool `json:"-"`
|
||||
ResolveOnDetour bool `json:"-"`
|
||||
DirectResolver bool `json:"-"`
|
||||
OutboundTLSOptionsContainer
|
||||
|
|
|
|||
|
|
@ -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{
|
||||
return httpClientManager.ResolveTransport(s.ctx, s.logger, option.HTTPClientOptions{
|
||||
DialerOptions: option.DialerOptions{
|
||||
Detour: s.options.RemoteOptions.DownloadDetour, //nolint:staticcheck
|
||||
}
|
||||
return httpClientManager.ResolveTransport(s.ctx, s.logger, httpClientOptions)
|
||||
},
|
||||
DisableEmptyDirectCheck: true,
|
||||
})
|
||||
}
|
||||
defaultTransport := httpClientManager.DefaultTransport()
|
||||
if defaultTransport == nil {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue