diff --git a/docs/configuration/route/index.md b/docs/configuration/route/index.md index 1fc9bfd2..09de9f42 100644 --- a/docs/configuration/route/index.md +++ b/docs/configuration/route/index.md @@ -114,6 +114,7 @@ Takes no effect if `outbound.routing_mark` is set. See [Dial Fields](/configuration/shared/dial/#domain_resolver) for details. Can be overrides by `outbound.domain_resolver`. +Can be overrides by `ruleset.domain_resolver`. #### default_network_strategy diff --git a/docs/configuration/route/index.zh.md b/docs/configuration/route/index.zh.md index 3748a522..110823a0 100644 --- a/docs/configuration/route/index.zh.md +++ b/docs/configuration/route/index.zh.md @@ -113,6 +113,7 @@ icon: material/alert-decagram 详情参阅 [拨号字段](/configuration/shared/dial/#domain_resolver)。 可以被 `outbound.domain_resolver` 覆盖。 +可以被 `ruleset.domain_resolver` 覆盖。 #### network_strategy diff --git a/docs/configuration/rule-set/index.md b/docs/configuration/rule-set/index.md index 944ea838..ac83f7e6 100644 --- a/docs/configuration/rule-set/index.md +++ b/docs/configuration/rule-set/index.md @@ -43,8 +43,12 @@ "tag": "", "format": "source", // or binary "url": "", + "update_interval": "", // optional "download_detour": "", // optional - "update_interval": "" // optional + "detour": "", // optional + "domain_resolver": "" // optional + + ... // Dial Fields } ``` @@ -100,14 +104,28 @@ File path of rule-set. Download URL of rule-set. -#### download_detour - -Tag of the outbound to download rule-set. - -Default outbound will be used if empty. - #### update_interval Update interval of rule-set. `1d` will be used if empty. + +### download_detour +This field is retained for compatibility only, please use the detour field. +When both this field and the detour field have valid content, the content of the detour field takes precedence. + +#### detour + +Tag of the outbound to download rule-set. + +Default outbound will be used if empty. + +#### domain_resolver + +Set domain resolver to use for resolving domain names. + +If this option and router.default_domain_resolver are set at the same time, router.default_domain_resolver will be overwritten + +### Dial Fields + +See [Dial Fields](/configuration/shared/dial/) for details. \ No newline at end of file diff --git a/docs/configuration/rule-set/index.zh.md b/docs/configuration/rule-set/index.zh.md index c38a57b5..9a3bdd5e 100644 --- a/docs/configuration/rule-set/index.zh.md +++ b/docs/configuration/rule-set/index.zh.md @@ -43,8 +43,12 @@ "tag": "", "format": "source", // or binary "url": "", + "update_interval": "", // 可选 "download_detour": "", // 可选 - "update_interval": "" // 可选 + "detour": "", // 可选 + "domain_resolver": "" // 可选 + + ... // 拨号字段 } ``` @@ -100,14 +104,28 @@ 规则集的下载 URL。 -#### download_detour - -用于下载规则集的出站的标签。 - -如果为空,将使用默认出站。 - #### update_interval 规则集的更新间隔。 默认使用 `1d`。 + +### download_detour +保留此字段只是为了保证兼容性,请使用detour字段 +在此字段和detour字段的内容都有效时,优先使用detour字段的内容 + +#### detour + +用于下载规则集的出站的标签。 + +如果为空,将使用默认出站。 + +#### domain_resolver + +用于设置解析域名的域名解析器。 + +如果此选项和router.default_domain_resolver同时设置,router.default_domain_resolver会被覆盖 + +### 拨号字段 + +参阅 [拨号字段](/zh/configuration/shared/dial/)。 diff --git a/option/rule_set.go b/option/rule_set.go index bf644764..70bcc066 100644 --- a/option/rule_set.go +++ b/option/rule_set.go @@ -85,9 +85,11 @@ type LocalRuleSet struct { } type RemoteRuleSet struct { + DialerOptions URL string `json:"url"` - DownloadDetour string `json:"download_detour,omitempty"` UpdateInterval badoption.Duration `json:"update_interval,omitempty"` + // keep this filed for compatibility, use Detour field please + DownloadDetour string `json:"download_detour,omitempty"` } type _HeadlessRule struct { diff --git a/route/rule/rule_set_remote.go b/route/rule/rule_set_remote.go index 8e89285b..10aea083 100644 --- a/route/rule/rule_set_remote.go +++ b/route/rule/rule_set_remote.go @@ -13,6 +13,7 @@ import ( "time" "github.com/sagernet/sing-box/adapter" + "github.com/sagernet/sing-box/common/dialer" "github.com/sagernet/sing-box/common/srs" C "github.com/sagernet/sing-box/constant" "github.com/sagernet/sing-box/option" @@ -83,17 +84,23 @@ func (s *RemoteRuleSet) String() string { func (s *RemoteRuleSet) StartContext(ctx context.Context, startContext *adapter.HTTPStartContext) error { s.cacheFile = service.FromContext[adapter.CacheFile](s.ctx) - var dialer N.Dialer - if s.options.RemoteOptions.DownloadDetour != "" { - outbound, loaded := s.outbound.Outbound(s.options.RemoteOptions.DownloadDetour) - if !loaded { - return E.New("download detour not found: ", s.options.RemoteOptions.DownloadDetour) - } - dialer = outbound - } else { - dialer = s.outbound.Default() + + detour := s.options.RemoteOptions.Detour + if detour == "" && s.options.RemoteOptions.DownloadDetour != "" { + detour = s.options.RemoteOptions.DownloadDetour + s.options.RemoteOptions.DialerOptions.Detour = detour } - s.dialer = dialer + + outboundDialer, err := dialer.NewWithOptions(dialer.Options{ + Context: ctx, + Options: s.options.RemoteOptions.DialerOptions, + RemoteIsDomain: true, + ResolverOnDetour: detour != "", + }) + if err != nil { + return err + } + s.dialer = outboundDialer if s.cacheFile != nil { if savedSet := s.cacheFile.LoadRuleSet(s.options.Tag); savedSet != nil { err := s.loadBytes(savedSet.Content) @@ -228,7 +235,7 @@ func (s *RemoteRuleSet) fetchOnce(ctx context.Context, startContext *adapter.HTT s.logger.Debug("updating rule-set ", s.options.Tag, " from URL: ", s.options.RemoteOptions.URL) var httpClient *http.Client if startContext != nil { - httpClient = startContext.HTTPClient(s.options.RemoteOptions.DownloadDetour, s.dialer) + httpClient = startContext.HTTPClient(s.options.RemoteOptions.Detour, s.dialer) } else { httpClient = &http.Client{ Transport: &http.Transport{