Browse Source

feat: support multi proxy core

v1.x.x
dnomd343 2 years ago
parent
commit
89392f22fc
  1. 7
      cmd/config/decode.go
  2. 10
      cmd/controller.go
  3. 4
      cmd/proxy/main.go

7
cmd/config/decode.go

@ -88,7 +88,14 @@ func decodeIPv6(rawConfig *yamlConfig, config *Config) {
func decodeProxy(rawConfig *yamlConfig, config *Config) { func decodeProxy(rawConfig *yamlConfig, config *Config) {
config.Proxy = rawConfig.Proxy config.Proxy = rawConfig.Proxy
if config.Proxy.Core == "" {
config.Proxy.Core = "xray" // use xray in default
}
if config.Proxy.Core != "xray" && config.Proxy.Core != "v2ray" && config.Proxy.Core != "sagray" {
log.Warningf("Unknown core type -> %s", config.Proxy.Core)
}
log.Debugf("Proxy log level -> %s", config.Proxy.Log) log.Debugf("Proxy log level -> %s", config.Proxy.Log)
log.Debugf("Core type -> %s", config.Proxy.Core)
log.Debugf("Http inbounds -> %v", config.Proxy.Http) log.Debugf("Http inbounds -> %v", config.Proxy.Http)
log.Debugf("Socks5 inbounds -> %v", config.Proxy.Socks) log.Debugf("Socks5 inbounds -> %v", config.Proxy.Socks)
log.Debugf("Add-on inbounds -> %v", config.Proxy.AddOn) log.Debugf("Add-on inbounds -> %v", config.Proxy.AddOn)

10
cmd/controller.go

@ -58,7 +58,15 @@ func runScript(settings *config.Config) {
} }
func runProxy(settings *config.Config) { func runProxy(settings *config.Config) {
runProcess("xray", "-confdir", configDir) if settings.Proxy.Core == "xray" { // xray-core
runProcess("xray", "-confdir", configDir)
} else if settings.Proxy.Core == "v2ray" { // v2fly-core
runProcess("v2ray", "-confdir", configDir)
} else if settings.Proxy.Core == "sagray" { // sager-core
runProcess("sagray", "run", "-confdir", configDir)
} else {
log.Panicf("Unknown core type -> %s", settings.Proxy.Core)
}
} }
func runRadvd(settings *config.Config) { func runRadvd(settings *config.Config) {

4
cmd/proxy/main.go

@ -6,6 +6,7 @@ import (
type Config struct { type Config struct {
Log string `yaml:"log" json:"json"` Log string `yaml:"log" json:"json"`
Core string `yaml:"core" json:"core"`
Http map[string]int `yaml:"http" json:"http"` Http map[string]int `yaml:"http" json:"http"`
Socks map[string]int `yaml:"socks" json:"socks"` Socks map[string]int `yaml:"socks" json:"socks"`
AddOn []interface{} `yaml:"addon" json:"addon"` AddOn []interface{} `yaml:"addon" json:"addon"`
@ -30,6 +31,9 @@ func loadInbounds(config *Config) string {
DestOverride: []string{"http", "tls", "quic"}, DestOverride: []string{"http", "tls", "quic"},
DomainsExcluded: config.Sniff.Exclude, DomainsExcluded: config.Sniff.Exclude,
} }
if config.Core == "v2ray" { // PATCH: v2fly-core v4 not support quic sniff
sniff.DestOverride = sniff.DestOverride[:len(sniff.DestOverride)-1]
}
var inbounds []interface{} var inbounds []interface{}
inbounds = append(inbounds, loadTProxyConfig("tproxy", config.V4TProxyPort, sniff)) inbounds = append(inbounds, loadTProxyConfig("tproxy", config.V4TProxyPort, sniff))
inbounds = append(inbounds, loadTProxyConfig("tproxy6", config.V6TProxyPort, sniff)) inbounds = append(inbounds, loadTProxyConfig("tproxy6", config.V6TProxyPort, sniff))

Loading…
Cancel
Save