Ejemplo n.º 1
0
        /// <summary>
        /// Saves a config file to the users' AppData folder and sends a connect command to the Broker.
        /// </summary>
        /// <returns>True if successfully sent connection command.</returns>
        public bool Connect()
        {
            uptimeStart = DateTime.MinValue;
            SetConnecting();
            Manager.Broker.ReportHeartbeat();

            ErrorHandling.DebugLogger.LogDebugMsg("Starting broker");
            if (!InitiateBroker())
            {
                IsConnecting    = false;
                IsDisconnecting = false;
                return(false);
            }

            var configFilePath = ProductConstants.FirefoxPrivateNetworkConfFile;
            var connectMessage = new IPCMessage(IPCCommand.IpcConnect);

            connectMessage.AddAttribute("config", configFilePath);
            brokerIPC.WriteToPipe(connectMessage);

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Thread for waiting on the broker to send a PID and then checking whether the the broker is still active.
        /// </summary>
        public void BrokerStatusCheckThread()
        {
            int strikes           = 0;
            var pidRequestMessage = new IPCMessage(IPCCommand.IpcRequestPid);

            isPipeActive    = true;
            remoteBrokerPid = 0;

            while (true)
            {
                Thread.Sleep(1000);

                // Do we have a broker process ID? If so, break and wait
                if (remoteBrokerPid > 0)
                {
                    isPipeActive = true;
                    break;
                }

                // Did we even attempt to initialize the broker?
                if (brokerIPC == null)
                {
                    isPipeActive = false;
                    continue;
                }

                // Try to send a PID request message
                if (!brokerIPC.WriteToPipe(pidRequestMessage))
                {
                    isPipeActive = false;
                    continue;
                }

                // Check for any previously received PIDs
                if ((DateTime.Now - lastReceivedHeartBeat).TotalSeconds > ProductConstants.BrokerToubleGracePeriod)
                {
                    // No heartbeat received for at least ProductConstants.BrokerToubleGracePeriod seconds, try to recover
                    if (++strikes >= 3)
                    {
                        ErrorHandling.ErrorHandler.Handle(new ErrorHandling.UserFacingMessage("toast-vpn-start-error"), ErrorHandling.UserFacingErrorType.Toast, ErrorHandling.LogLevel.Error);
                        ErrorHandling.ErrorHandler.Handle(string.Format("Broker timed out, no heartbeat received for {0} seconds.", ProductConstants.BrokerToubleGracePeriod), ErrorHandling.LogLevel.Error);
                        break;
                    }

                    continue;
                }
            }

            // If the broker is running, wait on exit
            if (remoteBrokerPid > 0)
            {
                ErrorHandling.ErrorHandler.WriteToLog("Broker is running. Waiting on exit.", ErrorHandling.LogLevel.Info);

                var remoteBrokerProcess = Process.GetProcessById(remoteBrokerPid);
                remoteBrokerProcess.WaitForExit();
                remoteBrokerPid = 0;

                ErrorHandling.ErrorHandler.WriteToLog("Broker has exited.", ErrorHandling.LogLevel.Info);
            }

            // Nothing seems to be running, destroy pipes and move on
            DestroyPipes();
            brokerIPC = null;
        }