Exemple #1
0
        public void Cleanup()
        {
            OpenVPNClient client = null;

            lock (m_clientSync)
            {
                if (m_client == null)
                {
                    throw new Exception("client not initialized");
                }

                client   = m_client;
                m_client = null;
            }

            try
            {
                if (!client.Stop())
                {
                    throw new Exception("client stop failed");
                }
            }
            finally
            {
                ClearContexts();
            }
        }
Exemple #2
0
        private void DoRun()
        {
            OpenVPNClient client = null;

            lock (clientSync)
            {
                if (openVPNClient == null)
                {
                    string errMsg = "OpenVPNTunnel::DoRun(): OpenVPN client is not initialized";

                    EddieLogger.Error(errMsg);

                    throw new Exception(errMsg);
                }

                client = openVPNClient;

                // Do NOT call m_client.Start under m_clientSync'lock
            }

            // Dispatcher must be instantiated before starting to allow handling stop requests from outside while the client isn't started yet

            // RunDispatcher();

            NativeMethods.EddieLibraryResult result = client.Start();

            if (result.code != NativeMethods.ResultCode.SUCCESS)
            {
                string errMsg = string.Format("OpenVPNTunnel::DoRun(): Failed to start OpenVPN client. {0}", result.description);

                EddieLogger.Error(errMsg);

                throw new Exception(errMsg);
            }
        }
Exemple #3
0
        public void Init()
        {
            lock (m_clientSync)
            {
                if (m_client != null)
                {
                    throw new Exception("client already initialized");
                }

                m_client = OpenVPNClient.Create(ref m_clientInterface);
                if (m_client == null)
                {
                    throw new Exception("client creation failed");
                }
            }
        }
Exemple #4
0
        public void Cleanup()
        {
            OpenVPNClient client = null;

            lock (clientSync)
            {
                if (openVPNClient == null)
                {
                    string errMsg = "OpenVPNTunnel::Cleanup(): OpenVPN client is not initialized";

                    EddieLogger.Error(errMsg);

                    throw new Exception(errMsg);
                }

                client = openVPNClient;

                openVPNClient = null;
            }

            try
            {
                NativeMethods.EddieLibraryResult result = client.Stop();

                if (result.code != NativeMethods.ResultCode.SUCCESS)
                {
                    string errMsg = string.Format("OpenVPNTunnel::Cleanup(): Failed to stop OpenVPN client. {0}", result.description);

                    EddieLogger.Error(errMsg);

                    throw new Exception(errMsg);
                }
            }
            finally
            {
                ClearContexts();
            }
        }
Exemple #5
0
        private void DoRun()
        {
            OpenVPNClient client = null;

            lock (m_clientSync)
            {
                if (m_client == null)
                {
                    throw new Exception("client not initialized");
                }

                client = m_client;

                // Do NOT call m_client.Start under m_clientSync'lock
            }

            // Dispatcher must be instantiated before starting to allow handling stop requests from outside while the client isn't started yet
            RunDispatcher();

            if (!client.Start())
            {
                throw new Exception("client start failed");
            }
        }