public PassThroughProxy(int listenPort, Configuration configuration)
        {
            Action <TcpClient, CancellationToken> handleClient =
                async(client, token) => await new Session().Run(client, configuration);

            _proxyListener = new ProxyListener(listenPort, handleClient);
        }
示例#2
0
        private ProxyListener GetListener(ProxyConfig config, bool allowBypass = true)
        {
            lock (locker)
            {
                SocksWebProxy.allowBypass = allowBypass;
                if (listeners == null)
                {
                    listeners = new List <ProxyListener>();
                }

                var listener = listeners.Where(x => x.Port == config.HttpPort).FirstOrDefault();

                if (listener == null)
                {
                    listener = new ProxyListener(config);
                    listener.Start();
                    listeners.Add(listener);
                }

                if (listener.Version != config.Version)
                {
                    throw new Exception("Socks Version Mismatch for Port " + config.HttpPort);
                }

                return(listener);
            }
        }
示例#3
0
 public override void Stop()
 {
     proxyListener.Stop();
     httpListener.Stop();
     proxyListener = null;
     httpListener  = null;
 }
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (_proxyListener != null)
         {
             _proxyListener.Dispose();
             _proxyListener = null;
         }
     }
 }
示例#5
0
        public override async Task Start(TestContext ctx, CancellationToken cancellationToken)
        {
            var listener = new ProxyListener(ctx, this);

            if (Interlocked.CompareExchange(ref currentListener, listener, null) != null)
            {
                throw new InternalErrorException();
            }
            await Target.Start(ctx, cancellationToken).ConfigureAwait(false);

            await listener.Start();
        }
示例#6
0
        private ProxyListener GetListener(ProxyConfig config, bool allowBypass = true)
        {
            this.allowBypass = allowBypass;

            if (listener == null)
            {
                listener = new ProxyListener(config);
                listener.Start();
            }

            if (listener.Version != config.Version)
            {
                throw new Exception("Socks Version Mismatch for Port " + config.HttpPort);
            }

            return(listener);
        }
示例#7
0
        static void Main()
        {
            Config = JsonConvert.DeserializeObject <Config>(File.ReadAllText("Config.json"));

            if (CfxRuntime.PlatformArch == CfxPlatformArch.x64)
            {
                CfxRuntime.LibCefDirPath = Path.GetFullPath(@"..\..\..\libcef\x64");
            }
            else
            {
                CfxRuntime.LibCefDirPath = System.IO.Path.GetFullPath(@"..\..\..\libcef\x86");
            }

            CfxRuntime.LibCfxDirPath = CfxRuntime.LibCefDirPath;

            string assemblyDir = System.IO.Path.GetDirectoryName(
                new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath
                );

            //CfxRuntime.EnableHighDpiSupport();

            int exitCode = CfxRuntime.ExecuteProcess(null);

            if (exitCode >= 0)
            {
                Environment.Exit(exitCode);
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var settings = new CfxSettings();

            settings.WindowlessRenderingEnabled = true;
            settings.NoSandbox = true;

            //settings.SingleProcess = true;
            settings.BrowserSubprocessPath = Path.Combine(assemblyDir, "xRemote");

            //settings.LogSeverity = CfxLogSeverity.Disable;

            settings.ResourcesDirPath = Path.GetFullPath(@"..\..\..\libcef\Resources");
            settings.LocalesDirPath   = Path.GetFullPath(@"..\..\..\libcef\Resources\locales");

            var app = new CfxApp();

            app.OnBeforeCommandLineProcessing += (s, e) =>
            {
                e.CommandLine.AppendSwitch("disable-web-security");
                e.CommandLine.AppendSwitch("enable-system-flash");

                // optimizations following recommendations from issue #84
                //e.CommandLine.AppendSwitch("disable-gpu");
                //e.CommandLine.AppendSwitch("disable-gpu-compositing");
                //e.CommandLine.AppendSwitch("disable-gpu-vsync");
            };

            if (!CfxRuntime.Initialize(settings, app))
            {
                Environment.Exit(-1);
            }

            Common.GlobalObjectPool.InitializePool();

            // 监听连接请求
            ProxyListener.Initialize();

            var f = new MainForm();

            f.Show();
            Application.Idle += (s, e) => CfxRuntime.DoMessageLoopWork();
            Application.Run(f);

            Common.GlobalObjectPool.DestroyPool();

            CfxRuntime.Shutdown();
        }
示例#8
0
        private static void RunApplication(object data)
        {
            try
            {
                bool   verboseOff  = (bool)((object[])data)[0];
                string oprFilename = (string)((object[])data)[1];

                // check whether opr file exists
                if (oprFilename == null)
                {
                    Console.WriteLine("Error: -r switch was not specified.");
                    _exitCode = 3;
                    return;
                }

                FileInfo fileInfo = new FileInfo(oprFilename);
                if (!fileInfo.Exists)
                {
                    Console.WriteLine("Error: cannot find input file " + oprFilename);
                    _exitCode = 4;
                    return;
                }


                // open OPR
                CompositionManager composition = new CompositionManager();

                if (!verboseOff)
                {
                    Console.WriteLine("Loading project file " + fileInfo.FullName + "...");
                }
                composition.LoadFromFile(fileInfo.FullName);


                // prepare listeners
                if (!verboseOff)
                {
                    Console.WriteLine("Preparing listener(s)...");
                }
                ArrayList listOfListeners = new ArrayList();

                // logfile listener
                if (composition.LogToFile != null && composition.LogToFile != "")
                {
                    // get composition file's directory to logfile is saved in same directory
                    string          logFileName     = Utils.GetFileInfo(fileInfo.DirectoryName, composition.LogToFile).FullName;
                    LogFileListener logFileListener = new LogFileListener(composition.ListenedEventTypes, logFileName);
                    listOfListeners.Add(logFileListener);
                }

                // console listener
                if (!verboseOff)
                {
                    ConsoleListener consoleListener = new ConsoleListener(composition.ListenedEventTypes);
                    listOfListeners.Add(consoleListener);
                }

                // create proxy listener
                ProxyListener proxyListener = new ProxyListener();
                proxyListener.Initialize(listOfListeners);

                // run simulation
                if (!verboseOff)
                {
                    Console.WriteLine("Starting composition run...");
                }
                composition.Run(proxyListener, true);

                if (!verboseOff)
                {
                    Console.WriteLine("Closing composition...");
                }
                composition.Release();

                _exitCode = 0;
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception occured: " + e.ToString());
                _exitCode = -2;
                return;
            }
        }
示例#9
0
        /// <summary>
        /// Runs simulation.
        /// </summary>
        /// <param name="runListener">Simulation listener.</param>
        /// <param name="runInSameThread">If <c>true</c>, simulation is run in same thread like caller,
        /// ie. method blocks until simulation don't finish. If <c>false</c>, simulation is
        /// run in separate thread and method returns immediately.</param>
        /// <remarks>
        /// Simulation is run the way that trigger invokes <see cref="ILinkableComponent.GetValues">ILinkableComponent.GetValues</see>
        /// method of the model it's connected to
        /// at the time specified by <see cref="TriggerInvokeTime">TriggerInvokeTime</see> property.
        /// If you need to use more than one listener you can use <see cref="ProxyListener">ProxyListener</see>
        /// class or <see cref="ProxyMultiThreadListener">ProxyMultiThreadListener</see> if <c>runInSameThread</c> is <c>false</c>.
        /// </remarks>
        public void Run(Logger logger, bool runInSameThread)
        {
            LoggerListener loggerListener = new LoggerListener(logger);
            ProgressListener progressListener = new ProgressListener();
            progressListener.ModelProgressChangedHandler += new ModelProgressChangedDelegate(delegate(ILinkableComponent linkableComponent, ITimeStamp simTime)
            {
                string guid = cmGuidMapping[linkableComponent];
                string progress = CalendarConverter.ModifiedJulian2Gregorian(simTime.ModifiedJulianDay).ToString();
                CompositionModelProgressChangedHandler(this, guid, progress);
            });

            ArrayList listeners = new ArrayList();
            listeners.Add(loggerListener);
            listeners.Add(progressListener);
            ProxyListener proxyListener = new ProxyListener();
            proxyListener.Initialize(listeners);

            startTime = DateTime.Now;

            if (_running)
                throw (new Exception("Simulation is already running."));

            _running = true;
            _runListener = proxyListener;

            try
            {
                TimeStamp runToTime = new TimeStamp(CalendarConverter.Gregorian2ModifiedJulian(_triggerInvokeTime));

                // Create informative message
                if (_runListener != null)
                {
                    StringBuilder description = new StringBuilder();
                    description.Append("Starting simulation at ");
                    description.Append(DateTime.Now.ToString());
                    description.Append(",");

                    description.Append(" composition consists from following models:\n");
                    foreach (Model model in _models)
                    {
                        description.Append(model.ModelID);
                        description.Append(", ");
                    }

                    // todo: add more info?

                    Event theEvent = new Event(EventType.Informative);
                    theEvent.Description = description.ToString();
                    _runListener.OnEvent(theEvent);
                }

                _runPrepareForComputationStarted = true;

                // prepare for computation
                if (_runListener != null)
                {
                    Event theEvent = new Event(EventType.Informative);
                    theEvent.Description = "Preparing for computation....";
                    _runListener.OnEvent(theEvent);
                }

                // subscribing event listener to all models
                if (_runListener != null)
                {
                    Event theEvent = new Event(EventType.Informative);
                    theEvent.Description = "Subscribing proxy event listener....";
                    _runListener.OnEvent(theEvent);

                    for (int i = 0; i < _runListener.GetAcceptedEventTypeCount(); i++)
                        foreach (Model uimodel in _models)
                        {
                            theEvent = new Event(EventType.Informative);
                            theEvent.Description = "Calling Subscribe() method with EventType." + ((EventType)i).ToString() + " of model " + uimodel.ModelID;
                            _runListener.OnEvent(theEvent);

                            for (int j = 0; j < uimodel.LinkableComponent.GetPublishedEventTypeCount(); j++)
                                if (uimodel.LinkableComponent.GetPublishedEventType(j) == _runListener.GetAcceptedEventType(i))
                                {
                                    uimodel.LinkableComponent.Subscribe(_runListener, _runListener.GetAcceptedEventType(i));
                                    break;
                                }
                        }
                }

                if (!runInSameThread)
                {
                    // creating run thread
                    if (_runListener != null)
                    {
                        Event theEvent = new Event(EventType.Informative);
                        theEvent.Description = "Creating run thread....";
                        _runListener.OnEvent(theEvent);
                    }

                    _runThread = new Thread(RunThreadFunction) { Priority = ThreadPriority.Normal };

                    // starting thread...
                    if (_runListener != null)
                    {
                        Event theEvent = new Event(EventType.GlobalProgress);
                        theEvent.Description = "Starting run thread....";
                        _runListener.OnEvent(theEvent);
                    }

                    _runThread.Start();
                }
                else
                {
                    // run simulation in same thread (for example when running from console)
                    if (_runListener != null)
                    {
                        Event theEvent = new Event(EventType.Informative);
                        theEvent.Description = "Running simulation in same thread....";
                        _runListener.OnEvent(theEvent);
                    }
                    RunThreadFunction();
                }
            }
            catch (System.Exception e)
            {
                if (_runListener != null)
                {
                    Event theEvent = new Event(EventType.Informative);
                    theEvent.Description = "Exception occured while initiating simulation run: " + e.ToString();
                    _runListener.OnEvent(theEvent);
                    _runListener.OnEvent(SimulationFailedEvent); // todo: add info about time to this event

                    endTime = DateTime.Now;
                    var ev = new Event
                    {
                        Description = "Elapsed time: " + (endTime - startTime),
                        Type = EventType.GlobalProgress
                    };

                    _runListener.OnEvent(ev);
                }
            }
            finally
            {
            }
        }
示例#10
0
 public override void Start()
 {
     httpListener  = new HttpListener(endpoint.Address, endpoint.Port, UseSSL);
     proxyListener = new ProxyListener(httpListener, proxyEndpoint.Address, proxyEndpoint.Port, authType);
 }