Beispiel #1
0
        /// <summary>
        ///		启动
        /// </summary>
        /// <param name="server">服务器</param>
        /// <param name="mode">模式</param>
        /// <returns>是否启动成功</returns>
        public bool Start(Models.Server server, Models.Mode mode)
        {
            FlushDNSResolverCache();

            var result = false;

            switch (server.Type)
            {
            case "Socks5":
                if (mode.Type == 4)
                {
                    result = false;
                }
                else
                {
                    result = true;
                }
                break;

            case "SS":
                KillProcess("Shadowsocks");
                if (pSSController == null)
                {
                    pSSController = new SSController();
                }
                result = pSSController.Start(server, mode);
                break;

            case "SSR":
                KillProcess("ShadowsocksR");
                if (pSSRController == null)
                {
                    pSSRController = new SSRController();
                }
                result = pSSRController.Start(server, mode);
                break;

            case "VMess":
                KillProcess("v2ray");
                if (pVMessController == null)
                {
                    pVMessController = new VMessController();
                }
                result = pVMessController.Start(server, mode);
                break;
            }

            if (result)
            {
                if (mode.Type == 0)
                {
                    if (pNFController == null)
                    {
                        pNFController = new NFController();
                    }
                    if (pNTTController == null)
                    {
                        pNTTController = new NTTController();
                    }
                    // 进程代理模式,启动 NF 控制器
                    result = pNFController.Start(server, mode);
                    if (result)
                    {
                        Task.Run(() =>
                        {
                            pNTTController.Start();
                        });
                    }
                }
                else if (mode.Type == 1)
                {
                    if (pTUNTAPController == null)
                    {
                        pTUNTAPController = new TUNTAPController();
                    }
                    if (pNTTController == null)
                    {
                        pNTTController = new NTTController();
                    }
                    // TUN/TAP 黑名单代理模式,启动 TUN/TAP 控制器
                    result = pTUNTAPController.Start(server, mode);
                    if (result)
                    {
                        Task.Run(() =>
                        {
                            pNTTController.Start();
                        });
                    }
                }
                else if (mode.Type == 2)
                {
                    if (pTUNTAPController == null)
                    {
                        pTUNTAPController = new TUNTAPController();
                    }
                    if (pNTTController == null)
                    {
                        pNTTController = new NTTController();
                    }
                    // TUN/TAP 白名单代理模式,启动 TUN/TAP 控制器
                    result = pTUNTAPController.Start(server, mode);
                    if (result)
                    {
                        Task.Run(() =>
                        {
                            pNTTController.Start();
                        });
                    }
                }
                else if (mode.Type == 3 || mode.Type == 5)
                {
                    if (pHTTPController == null)
                    {
                        pHTTPController = new HTTPController();
                    }
                    // HTTP 系统代理和 Socks5 和 HTTP 代理模式,启动 HTTP 控制器
                    result = pHTTPController.Start(server, mode);
                }
                else if (mode.Type == 4)
                {
                    // Socks5 代理模式,不需要启动额外的控制器
                }
                else
                {
                    result = false;
                }
            }

            if (!result)
            {
                Stop();
            }

            return(result);
        }
Beispiel #2
0
        /// <summary>
        ///		启动
        /// </summary>
        /// <param name="server">服务器</param>
        /// <param name="mode">模式</param>
        /// <returns>是否启动成功</returns>
        public bool Start(Server server, Mode mode)
        {
            FlushDNSResolverCache();

            var result = false;

            switch (server.Type)
            {
            case "Socks5":
                if (mode.Type == 4)
                {
                    result = false;
                }
                else
                {
                    result = true;
                }
                break;

            case "SS":
                KillProcess("Shadowsocks");
                if (pSSController == null)
                {
                    pSSController = new SSController();
                }
                result = pSSController.Start(server, mode);
                break;

            case "SSR":
                KillProcess("ShadowsocksR");
                if (pSSRController == null)
                {
                    pSSRController = new SSRController();
                }
                result = pSSRController.Start(server, mode);
                break;

            case "VMess":
                KillProcess("v2ray");
                if (pVMessController == null)
                {
                    pVMessController = new VMessController();
                }
                result = pVMessController.Start(server, mode);
                break;

            case "Trojan":
                KillProcess("Trojan");
                if (pTrojanController == null)
                {
                    pTrojanController = new TrojanController();
                }
                result = pTrojanController.Start(server, mode);
                break;
            }

            if (result)
            {
                if (mode.Type == 0)
                {
                    if (pNFController == null)
                    {
                        pNFController = new NFController();
                    }
                    if (pNTTController == null)
                    {
                        pNTTController = new NTTController();
                    }
                    // 进程代理模式,启动 NF 控制器
                    result = pNFController.Start(server, mode, false);
                    if (!result)
                    {
                        MainForm.Instance.StatusText($"{i18N.Translate("Status")}{i18N.Translate(": ")}{i18N.Translate("Restarting Redirector")}");
                        Logging.Info("正常启动失败后尝试停止驱动服务再重新启动");
                        //正常启动失败后尝试停止驱动服务再重新启动
                        result = pNFController.Start(server, mode, true);
                    }
                    else
                    {
                        Task.Run(() => pNTTController.Start());
                    }
                }
                else if (mode.Type == 1)
                {
                    if (pTUNTAPController == null)
                    {
                        pTUNTAPController = new TUNTAPController();
                    }
                    if (pNTTController == null)
                    {
                        pNTTController = new NTTController();
                    }
                    // TUN/TAP 黑名单代理模式,启动 TUN/TAP 控制器
                    result = pTUNTAPController.Start(server, mode);
                    if (result)
                    {
                        Task.Run(() => pNTTController.Start());
                    }
                }
                else if (mode.Type == 2)
                {
                    if (pTUNTAPController == null)
                    {
                        pTUNTAPController = new TUNTAPController();
                    }
                    if (pNTTController == null)
                    {
                        pNTTController = new NTTController();
                    }
                    // TUN/TAP 白名单代理模式,启动 TUN/TAP 控制器
                    result = pTUNTAPController.Start(server, mode);
                    if (result)
                    {
                        Task.Run(() => pNTTController.Start());
                    }
                }
                else if (mode.Type == 3 || mode.Type == 5)
                {
                    if (pHTTPController == null)
                    {
                        pHTTPController = new HTTPController();
                    }
                    // HTTP 系统代理和 Socks5 和 HTTP 代理模式,启动 HTTP 控制器
                    result = pHTTPController.Start(server, mode);
                }
                else if (mode.Type == 4)
                {
                    // Socks5 代理模式,不需要启动额外的控制器
                }
                else
                {
                    result = false;
                }
            }

            if (!result)
            {
                Stop();
            }

            return(result);
        }
Beispiel #3
0
        /// <summary>
        ///		启动
        /// </summary>
        /// <param name="server">服务器</param>
        /// <param name="mode">模式</param>
        /// <returns>是否启动成功</returns>
        public (bool, string) Start(Models.Server server, Models.Mode mode)
        {
            var result = (false, "");

            switch (server.Type)
            {
            case "Socks5":
                if (mode.Type == 4)
                {
                    result = (false, null);
                }
                else
                {
                    result = (true, null);
                }
                break;

            case "SS":
                KillProcess("Shadowsocks");
                if (pSSController == null)
                {
                    pSSController = new SSController();
                }
                result = (pSSController.Start(server, mode), null);
                break;

            case "SSR":
                KillProcess("ShadowsocksR");
                if (pSSRController == null)
                {
                    pSSRController = new SSRController();
                }
                result = (pSSRController.Start(server, mode), null);
                break;

            case "VMess":
                KillProcess("v2ray");
                if (pVMessController == null)
                {
                    pVMessController = new VMessController();
                }
                result = (pVMessController.Start(server, mode), null);
                break;
            }

            if (result.Item1)
            {
                if (mode.Type == 0)
                {
                    if (pNFController == null)
                    {
                        pNFController = new NFController();
                    }
                    if (pNTTController == null)
                    {
                        pNTTController = new NTTController();
                    }
                    // 进程代理模式,启动 NF 控制器
                    result = (pNFController.Start(server, mode), pNTTController.Start().Item2);
                }
                else if (mode.Type == 1)
                {
                    if (pTUNTAPController == null)
                    {
                        pTUNTAPController = new TUNTAPController();
                    }
                    if (pNTTController == null)
                    {
                        pNTTController = new NTTController();
                    }
                    // TUN/TAP 黑名单代理模式,启动 TUN/TAP 控制器
                    result = (pTUNTAPController.Start(server, mode), pNTTController.Start().Item2);
                }
                else if (mode.Type == 2)
                {
                    if (pTUNTAPController == null)
                    {
                        pTUNTAPController = new TUNTAPController();
                    }
                    if (pNTTController == null)
                    {
                        pNTTController = new NTTController();
                    }
                    // TUN/TAP 白名单代理模式,启动 TUN/TAP 控制器
                    result = (pTUNTAPController.Start(server, mode), pNTTController.Start().Item2);
                }
                else if (mode.Type == 3 || mode.Type == 5)
                {
                    if (pHTTPController == null)
                    {
                        pHTTPController = new HTTPController();
                    }
                    // HTTP 系统代理和 Socks5 和 HTTP 代理模式,启动 HTTP 控制器
                    result = (pHTTPController.Start(server, mode), null);
                }
                else if (mode.Type == 4)
                {
                    // Socks5 代理模式,不需要启动额外的控制器
                }
                else
                {
                    result = (false, null);
                }
            }

            if (!result.Item1)
            {
                Stop();
            }

            return(result);
        }