Ejemplo n.º 1
0
 internal void error()
 {
     m_state = OVPNState.ERROR;
     disconnectLogic();
     m_state = OVPNState.STOPPED;
     changeState(OVPNState.ERROR);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Connect the management logic to OpenVPN
        /// </summary>
        protected bool connectLogic()
        {
            m_ovpnMLogic.reset();
            for (int i = 0; i < 8; ++i)
            {
                try
                {
                    System.Threading.Thread.Sleep(500); // TODO: 500
                    m_ovpnMLogic.connect();

                    return(true);
                }
                catch (System.Net.Sockets.SocketException ex)
                {
                    m_logs.logDebugLine(1, "Could not establish connection " +
                                        "to management interface:" + ex.Message);
                    if (i != 5)
                    {
                        m_logs.logDebugLine(1, "Trying again in a second");
                        System.Threading.Thread.Sleep(500);
                    }
                }
            }
            m_logs.logDebugLine(1, "Could not establish connection, abording");
            m_state = OVPNState.RUNNING;
            disconnect();

            while (m_state != OVPNState.STOPPED)
            {
                Thread.Sleep(200);
            }

            changeState(OVPNState.ERROR);
            return(false);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// change the state of the class
        /// </summary>
        /// <param name="newstate">new state</param>
        internal void changeState(OVPNState newstate)
        {
            if (m_state != newstate)
            {
                m_state = newstate;

                if (stateChanged != null && !noevents)
                {
                    stateChanged(this, new EventArgs());
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Checks wheather the requested state can be reached. If not, the methods throws an error.
        /// </summary>
        /// <param name="newState"></param>
        protected void checkState(OVPNState newState)
        {
            switch (newState)
            {
            case OVPNState.INITIALIZING:
                if (m_state != OVPNState.STOPPED &&
                    m_state != OVPNState.ERROR)
                {
                    throw new InvalidOperationException("Already connected");
                }

                break;

            case OVPNState.STOPPING:
                if (m_state == OVPNState.INITIALIZING)
                {
                    throw new InvalidOperationException("Can't disconnect and connect at the same time");
                }
                break;
            }
        }
Ejemplo n.º 5
0
 internal void error()
 {
     m_state = OVPNState.ERROR;
     disconnectLogic();
     m_state = OVPNState.STOPPED;
     changeState(OVPNState.ERROR);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// change the state of the class
 /// </summary>
 /// <param name="newstate">new state</param>
 internal void changeState(OVPNState newstate)
 {
     if (m_state != newstate)
     {
         m_state = newstate;
     
         if(stateChanged != null && !noevents)
             stateChanged(this, new EventArgs());
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Connect the management logic to OpenVPN
        /// </summary>
        protected bool connectLogic()
        {
            m_ovpnMLogic.reset();
            for(int i = 0; i < 8; ++i) {
                try
                {
                    System.Threading.Thread.Sleep(500); // TODO: 500
                    m_ovpnMLogic.connect();
                    
                    return true;
                }
                catch (System.Net.Sockets.SocketException ex)
                {
                    m_logs.logDebugLine(1, "Could not establish connection " +
                        "to management interface:" + ex.Message);
                    if (i != 5)
                    {
                        m_logs.logDebugLine(1, "Trying again in a second");
                        System.Threading.Thread.Sleep(500);
                    }
                }
            }
            m_logs.logDebugLine(1, "Could not establish connection, abording");
            m_state = OVPNState.RUNNING;
            disconnect();

            while (m_state != OVPNState.STOPPED)
                Thread.Sleep(200);

            changeState(OVPNState.ERROR);
            return false;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Checks wheather the requested state can be reached. If not, the methods throws an error.
        /// </summary>
        /// <param name="newState"></param>
        protected void checkState(OVPNState newState)
        {
            switch (newState)
            {
                case OVPNState.INITIALIZING:
                    if (m_state != OVPNState.STOPPED &&
                        m_state != OVPNState.ERROR)
                        throw new InvalidOperationException("Already connected");

                    break;
                case OVPNState.STOPPING:
                    if (m_state == OVPNState.INITIALIZING)
                        throw new InvalidOperationException("Can't disconnect and connect at the same time");
                    break;
            }
        }