public override void OnVpnStateChanged(VpnStateChangedEventArgs e) { _vpnStatus = e.State.Status; Connected = e.State.Status == VpnStatus.Connected && e.State.Server.EntryCountry.EqualsIgnoringCase(CountryCode); }
public VpnState(VpnStatus status, string entryIp, VpnProtocol protocol, string label = "") { Status = status; EntryIp = entryIp; Protocol = protocol; Label = label; }
public Task OnVpnStateChanged(VpnStateChangedEventArgs e) { if (_appSettings.UseTunAdapter && e.Error == VpnError.TapAdapterInUseError) { _modals.Show <TunInUseModalViewModel>(); return(Task.CompletedTask); } VpnStatus status = e.State.Status; if (ModalShouldBeShown(e)) { Post(() => ShowModal(e)); } else { if (status == VpnStatus.Connecting || status == VpnStatus.Connected || (status == VpnStatus.Disconnecting || status == VpnStatus.Disconnected) && e.Error == VpnError.None) { Post(CloseModal); _modalShowed = false; } } return(Task.CompletedTask); }
private void OnStateChanged(VpnStatus status) { VpnState state; switch (status) { case VpnStatus.Pinging: case VpnStatus.Connecting: state = new VpnState(status, VpnError.None, string.Empty, _endpoint.Server.Ip, _endpoint.VpnProtocol, _config.OpenVpnAdapter, _endpoint.Server.Label); break; case VpnStatus.Disconnecting: case VpnStatus.Disconnected: state = new VpnState(status, _disconnectError, _config?.VpnProtocol ?? VpnProtocol.Smart); break; default: state = new VpnState(status, VpnError.None, _config?.VpnProtocol ?? VpnProtocol.Smart); break; } _logger.Info($"OpenVpnConnection: State changed to {state.Status}, Error: {state.Error}"); OnStateChanged(state); }
private void InvokeStateChange(VpnStatus status, VpnError error = VpnError.None) { StateChanged?.Invoke(this, new EventArgs <VpnState>( new VpnState(status, error, _config.WireGuard.DefaultClientAddress, _endpoint?.Server.Ip ?? string.Empty, VpnProtocol.WireGuard, null, _endpoint?.Server.Label ?? string.Empty))); }
public VpnState(VpnStatus status, string entryIp, VpnProtocol vpnProtocol, OpenVpnAdapter?networkAdapterType = null, string label = "") { Status = status; EntryIp = entryIp; NetworkAdapterType = networkAdapterType; VpnProtocol = vpnProtocol; Label = label; }
public VpnState(VpnStatus status, VpnError error, string localIp, string remoteIp, VpnProtocol protocol = VpnProtocol.Auto) { Status = status; Error = error; LocalIp = localIp; RemoteIp = remoteIp; Protocol = protocol; }
private static VpnStateChangedEventArgs Map(VpnStateContract contract) { VpnStatus status = Map(contract.Status); VpnError error = Map(contract.Error); VpnProtocol protocol = Map(contract.Protocol); return(new VpnStateChangedEventArgs(status, error, contract.EndpointIp, contract.NetworkBlocked, protocol)); }
private static VpnStateChangedEventArgs Map(VpnStateContract contract) { VpnStatus status = Map(contract.Status); VpnError error = Map(contract.Error); VpnProtocol protocol = Map(contract.VpnProtocol); return(new(status, error, contract.EndpointIp, contract.NetworkBlocked, protocol, contract.OpenVpnAdapterType, contract.Label)); }
public async Task OnVpnStateChanged(VpnStateChangedEventArgs e) { if (_vpnStatus == e.State.Status) { return; } _vpnStatus = e.State.Status; HandleNotification(); }
public VpnState(VpnStatus status, VpnError error, string localIp, string remoteIp, VpnProtocol vpnProtocol, OpenVpnAdapter?openVpnAdapter = null, string label = "") { Status = status; Error = error; LocalIp = localIp; RemoteIp = remoteIp; OpenVpnAdapter = openVpnAdapter; VpnProtocol = vpnProtocol; Label = label; }
public async Task OnVpnStateChanged(VpnStateChangedEventArgs e) { if (_appSettings.NetworkAdapterType == OpenVpnAdapter.Tun && e.Error == VpnError.TapAdapterInUseError) { _modals.Show <TunInUseModalViewModel>(); return; } VpnStatus status = e.State.Status; switch (e.Error) { case VpnError.CertRevokedOrExpired: await _authCertificateManager.ForceRequestNewKeyPairAndCertificateAsync(); await _vpnManager.ReconnectAsync(new VpnReconnectionSettings { IsToReconnectIfDisconnected = true }); return; case VpnError.CertificateExpired when e.State.Status == VpnStatus.ActionRequired: _lastAuthCertificate = _appSettings.AuthenticationCertificatePem; await _authCertificateManager.ForceRequestNewCertificateAsync(); if (FailedToUpdateAuthCert()) { await _vpnManager.ReconnectAsync(new VpnReconnectionSettings { IsToReconnectIfDisconnected = true }); } else { await _vpnServiceManager.UpdateAuthCertificate(_appSettings.AuthenticationCertificatePem); } return; } if (ModalShouldBeShown(e)) { Post(() => ShowModalAsync(e)); } else { if (status == VpnStatus.Pinging || status == VpnStatus.Connecting || status == VpnStatus.Connected || (status == VpnStatus.Disconnecting || status == VpnStatus.Disconnected) && e.Error == VpnError.None) { Post(CloseModalAsync); } } }
public Task OnVpnStateChanged(VpnStateChangedEventArgs e) { _vpnStatus = e.State.Status; if (_vpnStatus == VpnStatus.Connected) { _reconnectRequiredSettings = _settingsBuilder.Build(); } return(Task.CompletedTask); }
public Task OnVpnStateChanged(VpnStateChangedEventArgs e) { _vpnStatus = e.State.Status; if (_vpnStatus == VpnStatus.Disconnected && !string.IsNullOrEmpty(_name)) { ShowNotification(); } return(Task.CompletedTask); }
public Task OnVpnStateChanged(VpnStateChangedEventArgs e) { _vpnStatus = e.State.Status; _server = e.State.Server; if (_vpnStatus == VpnStatus.Connected || _vpnStatus == VpnStatus.Disconnected) { _pendingReconnect = false; } return(Task.CompletedTask); }
public void ExpectedLeakProtectionStatus_ShouldBe_Firewall_LeakProtectionEnabled_WhenOtherStatus( VpnStatus status, bool leakProtectionEnabled) { // Arrange var state = new VpnState(status, default); _firewall.LeakProtectionEnabled.Returns(leakProtectionEnabled); Service.KillSwitch.KillSwitch killSwitch = new Service.KillSwitch.KillSwitch(_firewall, _serviceSettings, _networkInterfaceLoader); // Act bool result = killSwitch.ExpectedLeakProtectionStatus(state); //Assert result.Should().Be(leakProtectionEnabled); }
public void ExpectedLeakProtectionStatus_ShouldBe_Expected_WhenDisconnecting(VpnStatus status, VpnError error, KillSwitchMode killSwitchMode, bool leakProtectionEnabled, bool expected) { // Arrange var state = new VpnState(status, error, default); _serviceSettings.KillSwitchMode.Returns(killSwitchMode); _firewall.LeakProtectionEnabled.Returns(leakProtectionEnabled); Service.KillSwitch.KillSwitch killSwitch = new Service.KillSwitch.KillSwitch(_firewall, _serviceSettings, _networkInterfaceLoader); // Act bool result = killSwitch.ExpectedLeakProtectionStatus(state); //Assert result.Should().Be(expected); }
public void ExpectedLeakProtectionStatus_ShouldBe_Expected_WhenConnecting(VpnStatus status, SplitTunnelMode splitTunnelMode, bool expected) { // Arrange var state = new VpnState(status); _serviceSettings.SplitTunnelSettings.Returns(new SplitTunnelSettingsContract { Mode = splitTunnelMode }); var killSwitch = new Service.KillSwitch.KillSwitch(_firewall, _serviceSettings); // Act var result = killSwitch.ExpectedLeakProtectionStatus(state); //Assert result.Should().Be(expected); }
public void ExpectedLeakProtectionStatus_ShouldBe_Enabled_WhenConnecting(VpnStatus status) { // Arrange var state = new VpnState(status, default); _serviceSettings.SplitTunnelSettings.Returns(new SplitTunnelSettingsContract { Mode = SplitTunnelMode.Block }); Service.KillSwitch.KillSwitch killSwitch = new Service.KillSwitch.KillSwitch(_firewall, _serviceSettings, _networkInterfaceLoader); // Act bool result = killSwitch.ExpectedLeakProtectionStatus(state); //Assert result.Should().Be(true); }
public void ExpectedLeakProtectionStatus_ShouldBe_Expected_WhenDisconnecting(VpnStatus status, VpnError error, bool killSwitchEnabled, bool leakProtectionEnabled, bool expected) { // Arrange var state = new VpnState(status, error); _serviceSettings.KillSwitchSettings.Returns(new KillSwitchSettingsContract { Enabled = killSwitchEnabled }); _firewall.LeakProtectionEnabled.Returns(leakProtectionEnabled); var killSwitch = new Service.KillSwitch.KillSwitch(_firewall, _serviceSettings); // Act var result = killSwitch.ExpectedLeakProtectionStatus(state); //Assert result.Should().Be(expected); }
public Task OnVpnStateChanged(VpnStateChangedEventArgs e) { VpnStatus status = e.State.Status; _disconnected = status == VpnStatus.Disconnected; _connected = status == VpnStatus.Connected; if ((status == VpnStatus.Pinging || status == VpnStatus.Connecting || status == VpnStatus.Reconnecting || status == VpnStatus.Disconnected) && _networkAddressChanged) { _updateAction.Run(); } return(Task.CompletedTask); }
public Task OnVpnStateChanged(VpnStateChangedEventArgs e) { var server = e.State.Server; switch (e.State.Status) { case VpnStatus.Connected: _systemNotification.Show(Translation.Format("Notifications_VpnState_msg_Connected", server?.Name, Environment.NewLine, server?.ExitIp)); break; case VpnStatus.Disconnecting when _lastVpnStatus == VpnStatus.Connected: case VpnStatus.Disconnected when _lastVpnStatus == VpnStatus.Connected: _systemNotification.Show(Translation.Get("Notifications_VpnState_msg_Disconnected")); break; } _lastVpnStatus = e.State.Status; return(Task.CompletedTask); }
private void Origin_StateChanged(object sender, EventArgs <VpnState> e) { VpnState state = e.Data; _vpnStatus = e.Data.Status; if (_connectRequested) { InvokeConnecting(); return; } InvokeStateChanged(state); _disconnectedReceived = state.Status == VpnStatus.Disconnected; if (_disconnectedReceived) { Disconnected(); } }
private void OnStateChanged(VpnStatus status) { VpnState state; switch (status) { case VpnStatus.Connecting: state = new VpnState(status, VpnError.None, string.Empty, _endpoint.Server.Ip, _endpoint.Protocol); break; case VpnStatus.Disconnecting: case VpnStatus.Disconnected: state = new VpnState(status, _disconnectError); break; default: state = new VpnState(status); break; } _logger.Info($"OpenVpnConnection: State changed to {state.Status}, Error: {state.Error}"); OnStateChanged(state); }
public Task OnVpnStateChanged(VpnStateChangedEventArgs e) { _vpnStatus = e.State.Status; return(Task.CompletedTask); }
public Task OnVpnStateChanged(VpnStateChangedEventArgs e) { _lastVpnStatus = e.State.Status; _isNetworkBlocked = e.NetworkBlocked; return(Task.CompletedTask); }
public VpnState(VpnStatus status, VpnError error, VpnProtocol vpnProtocol) : this(status, error, string.Empty, string.Empty, vpnProtocol) { }
public async Task OnVpnStateChanged_ShouldStopTimer_WhenVpnStatus_IsNotConnected(VpnStatus status) { // Arrange P2PDetector detector = new P2PDetector(_logger, _appConfig, _blockedTraffic, _forwardedTraffic, _scheduler, _modals, _dialogs); await detector.OnVpnStateChanged(new VpnStateChangedEventArgs(VpnStatus.Connected, VpnError.None, "", false, VpnProtocol.Smart)); // Act await detector.OnVpnStateChanged(new VpnStateChangedEventArgs(status, VpnError.None, "", false, VpnProtocol.Smart)); // Assert _timer.IsEnabled.Should().BeFalse(); }
public void ExpectedLeakProtectionStatus_ShouldBe_Firewall_LeakProtectionEnabled_WhenOtherStatus(VpnStatus status, bool leakProtectionEnabled) { // Arrange var state = new VpnState(status); _firewall.LeakProtectionEnabled.Returns(leakProtectionEnabled); var killSwitch = new Service.KillSwitch.KillSwitch(_firewall, _serviceSettings); // Act var result = killSwitch.ExpectedLeakProtectionStatus(state); //Assert result.Should().Be(leakProtectionEnabled); }
private void InvokeStateChange(VpnStatus status, VpnError error = VpnError.None) { StateChanged?.Invoke(this, new EventArgs <VpnState>(new VpnState(status, error, VpnProtocol.WireGuard))); }