mirror of
https://github.com/v2rayA/v2rayA.git
synced 2026-11-20 23:02:25 +03:00
feat: try to re-support xray
This commit is contained in:
1 parent
37845ad79e
commit
de9b9cd255
5 files changed
+61
-33
No files matched your search
@@ -2,6 +2,7 @@ package service
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/v2rayA/v2rayA/common"
|
||||
"github.com/v2rayA/v2rayA/core/v2ray/asset"
|
||||
@@ -10,6 +11,8 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
var LowVersionError = fmt.Errorf("core version too low")
|
||||
|
||||
func IsV2rayServiceValid() bool {
|
||||
if !asset.DoesV2rayAssetExist("geoip.dat") || !asset.DoesV2rayAssetExist("geosite.dat") {
|
||||
return false
|
||||
@@ -38,25 +41,24 @@ func CheckAndProbeTProxy() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func isVersionSatisfied(version string, mustV2rayCore bool) error {
|
||||
func isVersionSatisfied(version string) (where.Variant, error) {
|
||||
variant, ver, err := where.GetV2rayServiceVersion()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get the version of v2ray-core")
|
||||
}
|
||||
if variant != where.V2ray {
|
||||
if mustV2rayCore {
|
||||
return fmt.Errorf("v2fly/v2ray-core only feature")
|
||||
} else {
|
||||
// do not check the version for non-v2ray core
|
||||
return nil
|
||||
}
|
||||
return where.Unknown, fmt.Errorf("failed to get the version of v2ray-core: %v", err)
|
||||
}
|
||||
if greaterEqual, err := common.VersionGreaterEqual(ver, version); err != nil || !greaterEqual {
|
||||
return fmt.Errorf("the version of v2ray-core is lower than %v", version)
|
||||
return variant, fmt.Errorf("%w: the version %v is lower than %v", LowVersionError, ver, version)
|
||||
}
|
||||
return nil
|
||||
return variant, nil
|
||||
}
|
||||
|
||||
func CheckV5() (err error) {
|
||||
return isVersionSatisfied("5.0.0", true)
|
||||
func CheckV5() (variant where.Variant, err error) {
|
||||
variant, err = isVersionSatisfied("5.0.0")
|
||||
if err != nil {
|
||||
if errors.Is(err, LowVersionError) && variant != where.V2ray {
|
||||
return variant, nil
|
||||
}
|
||||
return variant, err
|
||||
}
|
||||
return variant, nil
|
||||
}
|
||||
@@ -23,7 +23,7 @@ const (
|
||||
)
|
||||
|
||||
var NotFoundErr = fmt.Errorf("not found")
|
||||
var ServiceNameList = []string{"v2ray"}
|
||||
var ServiceNameList = []string{"xray", "v2ray"}
|
||||
var v2rayVersion struct {
|
||||
variant Variant
|
||||
version string
|
||||
@@ -43,23 +43,20 @@ func GetV2rayServiceVersion() (variant Variant, ver string, err error) {
|
||||
if err != nil || len(v2rayPath) <= 0 {
|
||||
return Unknown, "", fmt.Errorf("cannot find v2ray executable binary")
|
||||
}
|
||||
var done = make(chan struct{}, 2)
|
||||
cmd := exec.Command(v2rayPath, "version")
|
||||
output := bytes.NewBuffer(nil)
|
||||
cmd.Stdout = output
|
||||
cmd.Stderr = cmd.Stdout
|
||||
cmd.Stderr = output
|
||||
go func() {
|
||||
time.Sleep(5 * time.Second)
|
||||
_ = cmd.Process.Kill()
|
||||
}()
|
||||
if err := cmd.Start(); err != nil {
|
||||
return Unknown, "", err
|
||||
}
|
||||
go func() {
|
||||
time.Sleep(3 * time.Second)
|
||||
_ = cmd.Process.Kill()
|
||||
_, _ = cmd.Process.Wait()
|
||||
done <- struct{}{}
|
||||
}()
|
||||
<-done
|
||||
cmd.Wait()
|
||||
var fields []string
|
||||
if fields = strings.Fields(output.String()); len(fields) < 2 {
|
||||
if fields = strings.Fields(strings.TrimSpace(output.String())); len(fields) < 2 {
|
||||
return Unknown, "", fmt.Errorf("cannot parse version of v2ray")
|
||||
}
|
||||
ver = fields[1]
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
jsonIteratorExtra "github.com/json-iterator/go/extra"
|
||||
"github.com/v2rayA/v2rayA/common/netTools/ports"
|
||||
"github.com/v2rayA/v2rayA/conf"
|
||||
"github.com/v2rayA/v2rayA/core/ipforward"
|
||||
"github.com/v2rayA/v2rayA/core/v2ray"
|
||||
"github.com/v2rayA/v2rayA/core/v2ray/asset"
|
||||
"github.com/v2rayA/v2rayA/core/v2ray/asset/dat"
|
||||
@@ -315,6 +316,15 @@ func checkUpdate() {
|
||||
func run() (err error) {
|
||||
//判别需要启动v2ray吗
|
||||
if configure.GetRunning() {
|
||||
//configure the ip forward
|
||||
setting := service.GetSetting()
|
||||
if setting.IpForward != ipforward.IsIpForwardOn() {
|
||||
e := ipforward.WriteIpForward(setting.IpForward)
|
||||
if e != nil {
|
||||
log.Warn("Connect: %v", e)
|
||||
}
|
||||
}
|
||||
// Start.
|
||||
err := v2ray.UpdateV2RayConfig()
|
||||
if err != nil {
|
||||
log.Error("failed to start v2ray-core: %v", err)
|
||||
|
||||
@@ -14,13 +14,13 @@ func GetVersion(ctx *gin.Context) {
|
||||
if conf.GetEnvironmentConfig().Lite {
|
||||
lite = 1
|
||||
}
|
||||
v5 := service.CheckV5() == nil
|
||||
_, versionErr := service.CheckV5()
|
||||
common.ResponseSuccess(ctx, gin.H{
|
||||
"version": conf.Version,
|
||||
"foundNew": conf.FoundNew,
|
||||
"remoteVersion": conf.RemoteVersion,
|
||||
"serviceValid": service.IsV2rayServiceValid(),
|
||||
"v5": v5,
|
||||
"v5": versionErr == nil, // FIXME: Compomise on compatibility.
|
||||
"lite": lite,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/v2rayA/v2rayA/core/v2ray"
|
||||
"github.com/v2rayA/v2rayA/core/v2ray/asset"
|
||||
"github.com/v2rayA/v2rayA/core/v2ray/service"
|
||||
"github.com/v2rayA/v2rayA/core/v2ray/where"
|
||||
"github.com/v2rayA/v2rayA/db/configure"
|
||||
"github.com/v2rayA/v2rayA/pkg/util/log"
|
||||
)
|
||||
@@ -15,9 +16,17 @@ func StopV2ray() (err error) {
|
||||
return nil
|
||||
}
|
||||
func StartV2ray() (err error) {
|
||||
if err = checkSupport(); err != nil {
|
||||
if err = checkSupport(nil); err != nil {
|
||||
return err
|
||||
}
|
||||
//configure the ip forward
|
||||
setting := GetSetting()
|
||||
if setting.IpForward != ipforward.IsIpForwardOn() {
|
||||
e := ipforward.WriteIpForward(setting.IpForward)
|
||||
if e != nil {
|
||||
log.Warn("Connect: %v", e)
|
||||
}
|
||||
}
|
||||
if css := configure.GetConnectedServers(); css.Len() == 0 {
|
||||
return fmt.Errorf("failed: no server is selected. please select at least one server")
|
||||
}
|
||||
@@ -56,7 +65,7 @@ func Disconnect(which configure.Which, clearOutbound bool) (err error) {
|
||||
|
||||
func checkAssetsExist(setting *configure.Setting) error {
|
||||
if !asset.DoesV2rayAssetExist("geoip.dat") || !asset.DoesV2rayAssetExist("geosite.dat") {
|
||||
return fmt.Errorf("geoip.dat or geosite.dat file does not exists. Try updating GFWList please")
|
||||
return fmt.Errorf("geoip.dat or geosite.dat file does not exists")
|
||||
}
|
||||
if setting.RulePortMode == configure.GfwlistMode || setting.Transparent == configure.TransparentGfwlist {
|
||||
if !asset.DoesV2rayAssetExist("LoyalsoldierSite.dat") {
|
||||
@@ -66,13 +75,23 @@ func checkAssetsExist(setting *configure.Setting) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkSupport() (err error) {
|
||||
func checkSupport(toAppend []*configure.Which) (err error) {
|
||||
setting := GetSetting()
|
||||
if err = checkAssetsExist(setting); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = service.CheckV5(); err != nil {
|
||||
return fmt.Errorf("current version of v2rayA only support v2ray-core v5: %v", err)
|
||||
variant, err := service.CheckV5()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if variant != where.V2ray {
|
||||
outbound2cnt := map[string]int{}
|
||||
for _, wt := range append(toAppend, configure.GetConnectedServers().Get()...) {
|
||||
outbound2cnt[wt.Outbound]++
|
||||
if outbound2cnt[wt.Outbound] > 1 {
|
||||
return fmt.Errorf("cannot connect to multiple servers: v2fly/v2ray-core only feature")
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -86,7 +105,7 @@ func Connect(which *configure.Which) (err error) {
|
||||
}
|
||||
}()
|
||||
setting := GetSetting()
|
||||
if err = checkSupport(); err != nil {
|
||||
if err = checkSupport([]*configure.Which{which}); err != nil {
|
||||
return err
|
||||
}
|
||||
if which == nil {
|
||||
|
||||
Reference in new issue
Block a user