Ejemplo n.º 1
0
        private async Task ConnectAction(CancellationToken cancellationToken)
        {
            _logger.Info("OpenVpnConnection: Connect action started");

            OnStateChanged(VpnStatus.Connecting);

            var port          = _managementPorts.Port();
            var password      = ManagementPassword();
            var processParams = new OpenVpnProcessParams(_endpoint, port, password, _config.CustomDns, _config.SplitTunnelMode, _config.SplitTunnelIPs);

            cancellationToken.ThrowIfCancellationRequested();

            if (!await _process.Start(processParams))
            {
                _disconnectError = VpnError.Unknown;
            }
            else
            {
                await _managementClient.Connect(port, password);

                if (cancellationToken.IsCancellationRequested)
                {
                    await _managementClient.CloseVpnConnection();

                    cancellationToken.ThrowIfCancellationRequested();
                }

                await _managementClient.StartVpnConnection(_credentials, cancellationToken);
            }

            cancellationToken.ThrowIfCancellationRequested();
        }