mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-07-03 02:08:45 +00:00
MPH domian matcher: Support building & using cache directly (instead of building from geosite.dat when Xray starts) (#5505)
Like https://github.com/XTLS/Xray-core/pull/5488#issuecomment-3710995080
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package all
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/xtls/xray-core/common/platform"
|
||||
"github.com/xtls/xray-core/infra/conf/serial"
|
||||
"github.com/xtls/xray-core/main/commands/base"
|
||||
)
|
||||
|
||||
var cmdBuildMphCache = &base.Command{
|
||||
UsageLine: `{{.Exec}} buildMphCache [-c config.json] [-o domain.cache]`,
|
||||
Short: `Build domain matcher cache`,
|
||||
Long: `
|
||||
Build domain matcher cache from a configuration file.
|
||||
|
||||
Example: {{.Exec}} buildMphCache -c config.json -o domain.cache
|
||||
`,
|
||||
}
|
||||
|
||||
func init() {
|
||||
cmdBuildMphCache.Run = executeBuildMphCache
|
||||
}
|
||||
|
||||
var (
|
||||
configPath = cmdBuildMphCache.Flag.String("c", "config.json", "Config file path")
|
||||
outputPath = cmdBuildMphCache.Flag.String("o", "domain.cache", "Output cache file path")
|
||||
)
|
||||
|
||||
func executeBuildMphCache(cmd *base.Command, args []string) {
|
||||
cf, err := os.Open(*configPath)
|
||||
if err != nil {
|
||||
base.Fatalf("failed to open config file: %v", err)
|
||||
}
|
||||
defer cf.Close()
|
||||
|
||||
// prevent using existing cache
|
||||
domainMatcherPath := platform.NewEnvFlag(platform.MphCachePath).GetValue(func() string { return "" })
|
||||
if domainMatcherPath != "" {
|
||||
os.Setenv("XRAY_MPH_CACHE", "")
|
||||
defer os.Setenv("XRAY_MPH_CACHE", domainMatcherPath)
|
||||
}
|
||||
|
||||
config, err := serial.DecodeJSONConfig(cf)
|
||||
if err != nil {
|
||||
base.Fatalf("failed to decode config file: %v", err)
|
||||
}
|
||||
|
||||
if err := config.BuildMPHCache(outputPath); err != nil {
|
||||
base.Fatalf("failed to build MPH cache: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -19,5 +19,6 @@ func init() {
|
||||
cmdMLDSA65,
|
||||
cmdMLKEM768,
|
||||
cmdVLESSEnc,
|
||||
cmdBuildMphCache,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user