forked from mirror/serenity
Fix geo rules
This commit is contained in:
parent
97bb8fbf09
commit
ba6391b4ab
@ -1,11 +1,9 @@
|
|||||||
package option
|
package option
|
||||||
|
|
||||||
import (
|
import (
|
||||||
M "github.com/sagernet/serenity/common/metadata"
|
|
||||||
"github.com/sagernet/serenity/common/semver"
|
"github.com/sagernet/serenity/common/semver"
|
||||||
"github.com/sagernet/sing-box/option"
|
"github.com/sagernet/sing-box/option"
|
||||||
"github.com/sagernet/sing-dns"
|
"github.com/sagernet/sing-dns"
|
||||||
"github.com/sagernet/sing/common"
|
|
||||||
"github.com/sagernet/sing/common/json/badjson"
|
"github.com/sagernet/sing/common/json/badjson"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -69,20 +67,6 @@ func (t Template) DisableIPv6() bool {
|
|||||||
return t.DomainStrategy == option.DomainStrategy(dns.DomainStrategyUseIPv4)
|
return t.DomainStrategy == option.DomainStrategy(dns.DomainStrategyUseIPv4)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t Template) ChinaGeositeList(metadata M.Metadata) []string {
|
|
||||||
chinaCodes := []string{"cn", "category-companies@cn"}
|
|
||||||
if metadata.Platform.IsApple() {
|
|
||||||
chinaCodes = append(chinaCodes, "apple-update")
|
|
||||||
}
|
|
||||||
return chinaCodes
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t Template) ChinaGeositeRuleSetList(metadata M.Metadata) []string {
|
|
||||||
return common.Map(t.ChinaGeositeList(metadata), func(it string) string {
|
|
||||||
return "geosite-" + it
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
type ExtraGroup struct {
|
type ExtraGroup struct {
|
||||||
Tag string `json:"tag,omitempty"`
|
Tag string `json:"tag,omitempty"`
|
||||||
Type string `json:"type,omitempty"`
|
Type string `json:"type,omitempty"`
|
||||||
|
@ -128,7 +128,7 @@ func (t *Template) renderDNS(metadata M.Metadata, options *option.Options) error
|
|||||||
{
|
{
|
||||||
Type: C.RuleTypeDefault,
|
Type: C.RuleTypeDefault,
|
||||||
DefaultOptions: option.DefaultDNSRule{
|
DefaultOptions: option.DefaultDNSRule{
|
||||||
Geosite: t.ChinaGeositeList(metadata),
|
Geosite: []string{"cn"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -151,8 +151,7 @@ func (t *Template) renderDNS(metadata M.Metadata, options *option.Options) error
|
|||||||
{
|
{
|
||||||
Type: C.RuleTypeDefault,
|
Type: C.RuleTypeDefault,
|
||||||
DefaultOptions: option.DefaultDNSRule{
|
DefaultOptions: option.DefaultDNSRule{
|
||||||
RuleSet: t.ChinaGeositeRuleSetList(metadata),
|
RuleSet: []string{"geosite-cn"},
|
||||||
DomainSuffix: []string{"download.jetbrains.com"},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -84,26 +84,6 @@ func (t *Template) renderGeoResources(metadata M.Metadata, options *option.Optio
|
|||||||
DownloadDetour: downloadDetour,
|
DownloadDetour: downloadDetour,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
Type: C.RuleSetTypeRemote,
|
|
||||||
Tag: "geosite-category-companies@cn",
|
|
||||||
Format: C.RuleSetFormatBinary,
|
|
||||||
RemoteOptions: option.RemoteRuleSet{
|
|
||||||
URL: downloadURL + "SagerNet/sing-geosite" + branchSplit + "rule-set/geosite-category-companies@cn.srs",
|
|
||||||
DownloadDetour: downloadDetour,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
if metadata.Platform.IsApple() {
|
|
||||||
options.Route.RuleSet = append(options.Route.RuleSet, option.RuleSet{
|
|
||||||
Type: C.RuleSetTypeRemote,
|
|
||||||
Tag: "geosite-apple-update",
|
|
||||||
Format: C.RuleSetFormatBinary,
|
|
||||||
RemoteOptions: option.RemoteRuleSet{
|
|
||||||
URL: downloadURL + "SagerNet/sing-geosite" + branchSplit + "rule-set/geosite-apple-update.srs",
|
|
||||||
DownloadDetour: downloadDetour,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -136,7 +136,7 @@ func (t *Template) renderRoute(metadata M.Metadata, options *option.Options) err
|
|||||||
Type: C.RuleTypeDefault,
|
Type: C.RuleTypeDefault,
|
||||||
DefaultOptions: option.DefaultRule{
|
DefaultOptions: option.DefaultRule{
|
||||||
GeoIP: []string{"cn"},
|
GeoIP: []string{"cn"},
|
||||||
Geosite: t.ChinaGeositeList(metadata),
|
Geosite: []string{"cn"},
|
||||||
Domain: []string{"download.jetbrains.com"},
|
Domain: []string{"download.jetbrains.com"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -160,8 +160,7 @@ func (t *Template) renderRoute(metadata M.Metadata, options *option.Options) err
|
|||||||
{
|
{
|
||||||
Type: C.RuleTypeDefault,
|
Type: C.RuleTypeDefault,
|
||||||
DefaultOptions: option.DefaultRule{
|
DefaultOptions: option.DefaultRule{
|
||||||
RuleSet: append([]string{"geoip-cn"}, t.ChinaGeositeRuleSetList(metadata)...),
|
RuleSet: []string{"geoip-cn", "geosite-cn"},
|
||||||
Domain: []string{"download.jetbrains.com"},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user