Esempio n. 1
0
        public void Initialize(int port, UInt64 secret, Requests.RawCredentials creds)
        {
            __IsExiting = false;
            if (__Thread != null)
            {
                throw new InvalidOperationException("client is already running");
            }

            ServicePort = port;
            Secret      = secret;

            __Thread = new Thread(() => ClientThread(creds))
            {
                Name = "IVPN Client Proxy", IsBackground = true
            };
            __Thread.Start();
        }
Esempio n. 2
0
        private void ClientThread(Requests.RawCredentials registerCreds)
        {
            try
            {
                __CancellationToken = new CancellationTokenSource();
                ConnectToService();

                // send hello
                SendRequest(new Requests.Hello
                {
                    Version           = Platform.Version,
                    Secret            = Secret,
                    GetServersList    = true,
                    GetStatus         = true,
                    GetConfigParams   = true,
                    SetRawCredentials = registerCreds
                });

                while (HandleResponse())
                {
                }

                Logging.Info("Handle request loop finished");
            }
            catch (Exception ex)
            {
                Logging.Info($"ERROR: {ex} Stack:" + ex.StackTrace);
                ClientException(ex);
            }
            finally
            {
                Logging.Info("closing socket");

                __Client?.Close();

                ServiceConnected = false;

                __CancellationToken.Cancel();
                __Thread = null;

                ClientProxyDisconnected(this, new EventArgs());
            }
        }