Exemple #1
0
        void DoProxyChange()
        {
            logger.Debug($"Changing IP, Proxy ID: {ID}");

            proxyListener.IsPaused = true;

            proxyListener.CloseAllSockets();
            //proxyListener.CloseClients();
            interfaceConnected = false;

            try
            {
                ExecuteAction(ActionType.Disconnect);
            }
            catch (Exception ex)
            {
                //Console.WriteLine("Error Disconnecting: {0}", ex.ToString());
                logger.Debug($"Error Disconnecting, Proxy ID: {ID}");
            }

            Thread.Sleep(10000);

            try
            {
                ExecuteAction(ActionType.Connect);
            }
            catch (Exception ex)
            {
                logger.Debug($"Error Connecting: {ex}");
            }

            Thread.Sleep(5000);

            IPAddress ip    = null;
            int       tries = 0;

            while (ip == null && tries < 10)
            {
                Thread.Sleep(500);

                ++tries;
                ip = GetIP();
            }

            interfaceConnected = true;

            if (ip == null)
            {
                logger.Debug($"Couldnt get interface IP! Proxy ID: {ID}, Time: '{(int) deltaTime.TotalSeconds}'");
                ChangeIP(true);
            }
            else
            {
                //proxyListener.ChangeLocalEndPoint(new IPEndPoint(ip, 0));
                proxyListener.CloseAllSockets();

                proxyListener.IsPaused = false;
                //proxyListener.ReconnectAllSockets(ip);

                logger.Debug($"IP Changed! Proxy ID: {ID}, Time: '{(int) deltaTime.TotalSeconds}', Bind: '{ip}'");

                //new Thread(() =>
                //{
                //    DoIPCheck();
                //}).Start();

                makeIPCheck = true;
            }
        }