mirror of
https://github.com/SagerNet/sing-box.git
synced 2025-06-13 21:54:13 +08:00
Add dialer options for remote ruleset
This commit is contained in:
parent
75f526cb29
commit
34f6e10fd4
@ -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
|
||||
|
||||
|
@ -113,6 +113,7 @@ icon: material/alert-decagram
|
||||
详情参阅 [拨号字段](/configuration/shared/dial/#domain_resolver)。
|
||||
|
||||
可以被 `outbound.domain_resolver` 覆盖。
|
||||
可以被 `ruleset.domain_resolver` 覆盖。
|
||||
|
||||
#### network_strategy
|
||||
|
||||
|
@ -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.
|
@ -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/)。
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
||||
detour := s.options.RemoteOptions.Detour
|
||||
if detour == "" && s.options.RemoteOptions.DownloadDetour != "" {
|
||||
detour = s.options.RemoteOptions.DownloadDetour
|
||||
s.options.RemoteOptions.DialerOptions.Detour = detour
|
||||
}
|
||||
dialer = outbound
|
||||
} else {
|
||||
dialer = s.outbound.Default()
|
||||
|
||||
outboundDialer, err := dialer.NewWithOptions(dialer.Options{
|
||||
Context: ctx,
|
||||
Options: s.options.RemoteOptions.DialerOptions,
|
||||
RemoteIsDomain: true,
|
||||
ResolverOnDetour: detour != "",
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.dialer = dialer
|
||||
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{
|
||||
|
Loading…
x
Reference in New Issue
Block a user