Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/xray
diff options
context:
space:
mode:
authorsurbiks <43953720+surbiks@users.noreply.github.com>2026-02-09 23:43:17 +0300
committerGitHub <noreply@github.com>2026-02-09 23:43:17 +0300
commit4779939424eb047d30161631fd89a9876104084c (patch)
tree89e2682aa528281879b3afb535f2b34124a17335 /xray
parent4a455aa5322e0803005da2d5d65b85a19dfc42e5 (diff)
Add url speed test for outbound (#3767)
* add outbound testing functionality with configurable test URL * use no kernel tun for conflict errors
Diffstat (limited to 'xray')
-rw-r--r--xray/process.go38
1 files changed, 34 insertions, 4 deletions
diff --git a/xray/process.go b/xray/process.go
index f45d6cc9..009ec7a5 100644
--- a/xray/process.go
+++ b/xray/process.go
@@ -110,6 +110,15 @@ func NewProcess(xrayConfig *Config) *Process {
return p
}
+// NewTestProcess creates a new Xray process that uses a specific config file path.
+// Used for test runs (e.g. outbound test) so the main config.json is not overwritten.
+// The config file at configPath is removed when the process is stopped.
+func NewTestProcess(xrayConfig *Config, configPath string) *Process {
+ p := &Process{newTestProcess(xrayConfig, configPath)}
+ runtime.SetFinalizer(p, stopProcess)
+ return p
+}
+
type process struct {
cmd *exec.Cmd
@@ -118,10 +127,11 @@ type process struct {
onlineClients []string
- config *Config
- logWriter *LogWriter
- exitErr error
- startTime time.Time
+ config *Config
+ configPath string // if set, use this path instead of GetConfigPath() and remove on Stop
+ logWriter *LogWriter
+ exitErr error
+ startTime time.Time
}
// newProcess creates a new internal process struct for Xray.
@@ -134,6 +144,13 @@ func newProcess(config *Config) *process {
}
}
+// newTestProcess creates a process that writes and runs with a specific config path.
+func newTestProcess(config *Config, configPath string) *process {
+ p := newProcess(config)
+ p.configPath = configPath
+ return p
+}
+
// IsRunning returns true if the Xray process is currently running.
func (p *process) IsRunning() bool {
if p.cmd == nil || p.cmd.Process == nil {
@@ -238,6 +255,9 @@ func (p *process) Start() (err error) {
}
configPath := GetConfigPath()
+ if p.configPath != "" {
+ configPath = p.configPath
+ }
err = os.WriteFile(configPath, data, fs.ModePerm)
if err != nil {
return common.NewErrorf("Failed to write configuration file: %v", err)
@@ -278,6 +298,16 @@ func (p *process) Stop() error {
return errors.New("xray is not running")
}
+ // Remove temporary config file used for test runs so main config is never touched
+ if p.configPath != "" {
+ if p.configPath != GetConfigPath() {
+ // Check if file exists before removing
+ if _, err := os.Stat(p.configPath); err == nil {
+ _ = os.Remove(p.configPath)
+ }
+ }
+ }
+
if runtime.GOOS == "windows" {
return p.cmd.Process.Kill()
} else {