mirror of
https://github.com/SagerNet/sing-box.git
synced 2025-06-13 21:54:13 +08:00
Merge 10d1733ceb58b201e792ba405f0e67ded4b4ea3f into c5e620ed7b1975766e36284f904ab966b15face0
This commit is contained in:
commit
8e9433ec0d
@ -83,7 +83,7 @@ type LocalRuleSet struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type RemoteRuleSet struct {
|
type RemoteRuleSet struct {
|
||||||
URL string `json:"url"`
|
URL Listable[string] `json:"url"`
|
||||||
DownloadDetour string `json:"download_detour,omitempty"`
|
DownloadDetour string `json:"download_detour,omitempty"`
|
||||||
UpdateInterval Duration `json:"update_interval,omitempty"`
|
UpdateInterval Duration `json:"update_interval,omitempty"`
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,9 @@ func NewRuleSet(ctx context.Context, router adapter.Router, logger logger.Contex
|
|||||||
case C.RuleSetTypeInline, C.RuleSetTypeLocal, "":
|
case C.RuleSetTypeInline, C.RuleSetTypeLocal, "":
|
||||||
return NewLocalRuleSet(router, logger, options)
|
return NewLocalRuleSet(router, logger, options)
|
||||||
case C.RuleSetTypeRemote:
|
case C.RuleSetTypeRemote:
|
||||||
|
if len(options.RemoteOptions.URL) == 0 {
|
||||||
|
return nil, E.New("missing urls")
|
||||||
|
}
|
||||||
return NewRemoteRuleSet(ctx, router, logger, options), nil
|
return NewRemoteRuleSet(ctx, router, logger, options), nil
|
||||||
default:
|
default:
|
||||||
return nil, E.New("unknown rule-set type: ", options.Type)
|
return nil, E.New("unknown rule-set type: ", options.Type)
|
||||||
|
@ -227,7 +227,18 @@ func (s *RemoteRuleSet) loopUpdate() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *RemoteRuleSet) fetchOnce(ctx context.Context, startContext adapter.RuleSetStartContext) error {
|
func (s *RemoteRuleSet) fetchOnce(ctx context.Context, startContext adapter.RuleSetStartContext) error {
|
||||||
s.logger.Debug("updating rule-set ", s.options.Tag, " from URL: ", s.options.RemoteOptions.URL)
|
var err error
|
||||||
|
for _, url := range s.options.RemoteOptions.URL {
|
||||||
|
err = s.fetchURL(ctx, url, startContext)
|
||||||
|
if err == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *RemoteRuleSet) fetchURL(ctx context.Context, url string, startContext adapter.RuleSetStartContext) error {
|
||||||
|
s.logger.Debug("updating rule-set ", s.options.Tag, " from URL: ", url)
|
||||||
var httpClient *http.Client
|
var httpClient *http.Client
|
||||||
if startContext != nil {
|
if startContext != nil {
|
||||||
httpClient = startContext.HTTPClient(s.options.RemoteOptions.DownloadDetour, s.dialer)
|
httpClient = startContext.HTTPClient(s.options.RemoteOptions.DownloadDetour, s.dialer)
|
||||||
@ -242,7 +253,7 @@ func (s *RemoteRuleSet) fetchOnce(ctx context.Context, startContext adapter.Rule
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
request, err := http.NewRequest("GET", s.options.RemoteOptions.URL, nil)
|
request, err := http.NewRequest("GET", url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user