예제 #1
0
        public void WaitingForUserInput()
        {
            PrintVersion();
            _ = Task.Run(() =>
            {
                while (true)
                {
                    var key = Console.Read();

                    if (key == 'h')
                    {
                        PrintHelp();
                    }
                    else if (key == '1')
                    {
                        _proxySetting.SetPacProxy(Helper.GetPacAddress(_options.PacServerPort));

                        Console.WriteLine("Pac Proxy set  success");
                    }
                    else if (key == '2')
                    {
                        _proxySetting.SetGlobalProxy("127.0.0.1:" + _options.HttpProxyPort);

                        Console.WriteLine("Global Proxy set  success");
                    }
                }
            }
                         );
        }
예제 #2
0
        public Task StartAsync(CancellationToken cancellationToken)
        {
            GeneratePacFile(_setting.HttpProxyPort.ToString());
            _ = Task.Run(async() =>
            {
                var pacAddress = Helper.GetPacAddress(_setting.PacServerPort);
                _proxySetting.SetPacProxy(pacAddress);
                string[] prefixes = new string[] { pacAddress };
                await new PacServer().SimpleListenerExampleAsync(prefixes);
            }, cancellationToken);

            _ = Task.Factory.StartNew(async() =>
            {
                _httpProxy = new HttpProxy(_setting.HttpProxyPort);
                while (true)
                {
                    var client = await _httpProxy.BeginListenAsync();

                    Channel channel = new Channel(client,
                                                  new TrojanClientOutProxy(_trojanContext.GetUseTrojan().Pass, _trojanContext.GetUseTrojan().Host, _trojanContext.GetUseTrojan().Port, _trojanContext.GetUseTrojan().ValidServerCert));
                    channel.StartChannel();
                }
            }, cancellationToken);
            while (true)
            {
                _action.Invoke();
            }
        }