Пример #1
0
 public NFController()
 {
     Name     = "Redirector";
     MainFile = "Redirector.exe";
     StartedKeywords.Add("Started");
     StoppedKeywords.AddRange(new[] { "Failed", "Unable" });
 }
Пример #2
0
 public SSRController()
 {
     Name     = "ShadowsocksR";
     MainFile = "ShadowsocksR.exe";
     StartedKeywords.Add("listening at");
     StoppedKeywords.AddRange(new[] { "Invalid config path", "usage" });
 }
Пример #3
0
 public TUNTAPController()
 {
     Name     = "tun2socks";
     MainFile = "tun2socks.exe";
     StartedKeywords.Add("Running");
     StoppedKeywords.AddRange(new[] { "failed", "invalid vconfig file" });
 }
Пример #4
0
 public SSController()
 {
     Name     = "Shadowsocks";
     MainFile = "Shadowsocks.exe";
     StartedKeywords.Add("listening at");
     StoppedKeywords.AddRange(new[] { "Invalid config path", "usage", "plugin service exit unexpectedly" });
 }
Пример #5
0
 public VMessController()
 {
     Name = "V2Ray";
     MainFile = "v2ray.exe";
     StartedKeywords.Add("started");
     StoppedKeywords.AddRange(new[] {"config file not readable", "failed to"});
 }
Пример #6
0
        private void ReadOutput(TextReader reader)
        {
            string?line;

            while ((line = reader.ReadLine()) != null)
            {
                _logStreamWriter !.WriteLine(line);
                OnReadNewLine(line);

                if (State == State.Starting)
                {
                    if (StartedKeywords.Any(s => line.Contains(s)))
                    {
                        State = State.Started;
                    }
                    else if (FailedKeywords.Any(s => line.Contains(s)))
                    {
                        OnStartFailed();
                        State = State.Stopped;
                    }
                }
            }

            State = State.Stopped;
        }
Пример #7
0
 public TrojanController()
 {
     Name     = "Trojan";
     MainFile = "Trojan.exe";
     StartedKeywords.Add("started");
     StoppedKeywords.Add("exiting");
 }
Пример #8
0
    protected async Task StartGuardAsync(string argument, ProcessPriorityClass priority = ProcessPriorityClass.Normal)
    {
        State = State.Starting;

        _logFileStream   = new FileStream(LogPath, FileMode.Create, FileAccess.Write, FileShare.Read, 4096, true);
        _logStreamWriter = new StreamWriter(_logFileStream)
        {
            AutoFlush = true
        };

        Instance.StartInfo.Arguments = argument;
        Instance.Start();
        Global.Job.AddProcess(Instance);

        if (priority != ProcessPriorityClass.Normal)
        {
            Instance.PriorityClass = priority;
        }

        if (RedirectOutput)
        {
            ReadOutputAsync(Instance.StandardOutput).Forget();
            ReadOutputAsync(Instance.StandardError).Forget();

            if (!StartedKeywords.Any())
            {
                // Skip, No started keyword
                State = State.Started;
                return;
            }

            // wait ReadOutput change State
            for (var i = 0; i < 1000; i++)
            {
                await Task.Delay(50);

                switch (State)
                {
                case State.Started:
                    OnStarted();
                    return;

                case State.Stopped:
                    await StopGuardAsync();

                    OnStartFailed();
                    throw new MessageException($"{Name} 控制器启动失败");
                }
            }

            await StopGuardAsync();

            throw new MessageException($"{Name} 控制器启动超时");
        }
    }
Пример #9
0
 public TrojanController()
 {
     StartedKeywords.Add("started");
     StoppedKeywords.Add("exiting");
 }
Пример #10
0
 public VMessController()
 {
     StartedKeywords.Add("started");
     StoppedKeywords.AddRange(new[] { "config file not readable", "failed to" });
 }
Пример #11
0
 public TUNTAPController()
 {
     StartedKeywords.Add("Running");
     StoppedKeywords.AddRange(new[] { "failed", "invalid vconfig file" });
 }