private bool?UpdatedLeakProtectionStatus(VpnState state) { switch (state.Status) { case VpnStatus.Connecting: case VpnStatus.Reconnecting: { return(_serviceSettings.SplitTunnelSettings.Mode == SplitTunnelMode.Disabled || _serviceSettings.SplitTunnelSettings.Mode == SplitTunnelMode.Block); } case VpnStatus.Disconnecting: case VpnStatus.Disconnected: { if (state.Error == VpnError.None || !_serviceSettings.KillSwitchSettings.Enabled) { return(false); } break; } } return(null); }
private void ManagementClient_StateChanged(object sender, EventArgs <VpnState> e) { _logger.Info($"ManagementClient: State changed to {e.Data.Status}"); VpnState state = new( e.Data.Status, e.Data.Error, e.Data.LocalIp, e.Data.RemoteIp, _endpoint.VpnProtocol, _config.OpenVpnAdapter, e.Data.Label); if ((state.Status == VpnStatus.Pinging || state.Status == VpnStatus.Connecting || state.Status == VpnStatus.Reconnecting) && string.IsNullOrEmpty(state.RemoteIp)) { state = new VpnState( state.Status, VpnError.None, string.Empty, _endpoint.Server.Ip, _endpoint.VpnProtocol, state.OpenVpnAdapter, _endpoint.Server.Label); } if (state.Status == VpnStatus.Disconnecting && !_disconnectAction.IsRunning) { _disconnectError = state.Error; } OnStateChanged(state); }
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 OnStateChanged(VpnRuntimeState runtimeState) { VpnState state = VpnState.Connected; if (!runtimeState.Connected) { if (runtimeState.ErrorMessage == null) { state = VpnState.Idle; } else { state = VpnState.Reconnecting; } } if (_coreData.ThisDevice.VpnState != state) { Log.Information($"Vpn state changing to {state} ({runtimeState.ErrorMessage})"); } _coreData.ThisDevice.VpnServerIpAddress = runtimeState.ServerIpAddress; _coreData.ThisDevice.VpnState = state; _coreData.ThisDevice.KPIs.Vpn.State = state switch { VpnState.Connecting => IndicatorState.Warning, VpnState.Reconnecting => IndicatorState.Error, VpnState.Connected => IndicatorState.Ok, _ => IndicatorState.Disabled, }; _coreData.ThisDevice.KPIs.Vpn.Sent = runtimeState.SentKbs; _coreData.ThisDevice.KPIs.Vpn.Received = runtimeState.ReceivedKbs; }
private void OnServerConnectionStatusChanged(object sender, ConnectionChangedEventArgs <GeographicalServer> e) { if (e.State == null) { this.SetDisconnected(); } else if (e.State == 1) { if (this._previousState == 3) { this.SetDisconnected(); } else if (this._previousState == 2) { this.SetConnecting(); } else { this.SetDisconnected(); } } else if (e.State == 2) { this.SetConnecting(); } else if (e.State == 3) { this.SetConnected(); } this._previousState = e.State; }
public Task OnVpnStateChanged(VpnStateChangedEventArgs e) { if (!_config.MaintenanceTrackerEnabled) { return(Task.CompletedTask); } _state = e.State; if (e.State.Status == VpnStatus.Connected) { if (!_timer.IsEnabled) { _timer.Interval = _config.MaintenanceCheckInterval; _timer.Start(); } } else { if (_timer.IsEnabled) { _timer.Stop(); } } return(Task.CompletedTask); }
private void OnGeoServerConnectionStatusChanged(object sender, ConnectionChangedEventArgs <GeographicalServer> e) { switch (e.State) { case 0: this.ShowDisconnected(); break; case 1: this.ShowDisconnecting(); break; case 2: this.ShowConnecting(e.Server); break; case 3: this.ShowConnected(e.Server); break; default: throw new NotSupportedException(); } this._currentServer = e.Server; this._currentState = e.State; }
public void OnVpnDisconnected(VpnState state) { if (state.VpnProtocol != VpnProtocol.WireGuard) { RestoreNetworkSettings(state.VpnProtocol, state.OpenVpnAdapter); } }
private void OnStateChanged(VpnState state) { _disconnected = state.Status == VpnStatus.Disconnected; if (_connectRequested) { InvokeConnecting(); if (_disconnected) { _logger.Info("HandlingRequestsWrapper: Already disconnected, queuing Connect"); Queued(Connect); } return; } if (_disconnectRequested || _disconnecting) { if (state.Status == VpnStatus.Disconnecting || state.Status == VpnStatus.Disconnected) { InvokeStateChanged(state.WithError(_disconnectError)); return; } InvokeDisconnecting(); return; } if (_connecting && state.Status == VpnStatus.Disconnecting) { // Force disconnect if disconnected while connecting _disconnectRequested = true; _disconnectError = state.Error == VpnError.None ? VpnError.Unknown : state.Error; _logger.Info("HandlingRequestsWrapper: Disconnecting unexpectedly, queuing Disconnect"); Queued(Disconnect); } if (state.Status == VpnStatus.Disconnecting || state.Status == VpnStatus.Disconnected) { var error = state.Error == VpnError.None ? VpnError.Unknown : state.Error; if (_connecting) { // Force disconnect if disconnected while connecting _disconnectRequested = true; _disconnectError = error; _logger.Info("HandlingRequestsWrapper: Disconnecting unexpectedly, queuing Disconnect"); Queued(Disconnect); return; } InvokeStateChanged(state.WithError(error)); return; } InvokeStateChanged(WithFallbackRemoteIp(state, _endpoint.Server.Ip)); }
public void OnVpnConnecting(VpnState state) { if (state.VpnProtocol == VpnProtocol.OpenVpnTcp || state.VpnProtocol == VpnProtocol.OpenVpnUdp) { ApplyNetworkSettings(state.VpnProtocol, state.OpenVpnAdapter); _wintunRegistryFixer.EnsureTunAdapterRegistryIsCorrect(); } }
public void OnVpnDisconnected(VpnState state) { if (state.Error == VpnError.None) { DisableSplitTunnel(); _appFilter.RemoveAll(); } }
private void EnableReversed(VpnState state) { _splitTunnelClient.EnableIncludeMode( _reverseSplitTunnelApps.Value(), _serviceSettings.SplitTunnelSettings.Ips, state.LocalIp); _reverseEnabled = true; }
private void Origin_StateChanged(object sender, EventArgs <VpnState> e) { VpnState state = e.Data; _logger.Info($"VPN state changed: {state.Status}, Error: {state.Error}, LocalIP: {state.LocalIp}, " + $"RemoteIP: {state.RemoteIp}, Label: {state.Label}"); OnStateChanged(state); }
private VpnStateContract Map(VpnState state) { return(new VpnStateContract( Map(state.Status), Map(state.Error), state.RemoteIp, _killSwitch.ExpectedLeakProtectionStatus(state), Map(state.Protocol))); }
private void OnStateChanged(VpnState state) { if (state == null) { return; } StateChanged?.Invoke(this, new EventArgs <VpnState>(state)); }
private bool ReconnectRequired(VpnState state) { return(!_reconnectPending && !_disconnecting && (state.Status == VpnStatus.Disconnecting || state.Status == VpnStatus.Disconnected) && (state.Error == VpnError.NetshError || state.Error == VpnError.TimeoutError || state.Error == VpnError.Unknown)); }
private VpnState CreateVpnState(VpnState state, VpnStatus?status = null, VpnProtocol?protocol = null) { return(new( status ?? state.Status, state.Error, state.LocalIp, state.RemoteIp, protocol ?? state.Protocol, _endpoint?.Server.Label ?? string.Empty)); }
private void OnStateChanged(VpnState state) { if (state.Status != _prevState.Status || state.Error != _prevState.Error || !string.Equals(state.RemoteIp, _prevState.RemoteIp)) { StateChanged?.Invoke(this, new EventArgs <VpnState>(state)); } _prevState = state; }
private void Origin_StateChanged(object sender, EventArgs <VpnState> e) { var state = new VpnState( e.Data.Status, e.Data.Error, e.Data.LocalIp, e.Data.RemoteIp, _vpnEndpoint.Protocol); StateChanged?.Invoke(this, new EventArgs <VpnState>(state)); }
private VpnState WithFallbackRemoteIp(VpnState state, string remoteIp) { if (state.Status == VpnStatus.Disconnecting || state.Status == VpnStatus.Disconnected || !string.IsNullOrEmpty(state.RemoteIp)) { return(state); } return(state.WithRemoteIp(remoteIp)); }
private VpnState WithFallbackRemoteServer(VpnState state, VpnHost remoteServer) { if (state.Status == VpnStatus.Disconnecting || state.Status == VpnStatus.Disconnected || !string.IsNullOrEmpty(state.RemoteIp)) { return(state); } return(state.WithRemoteIp(remoteServer.Ip, remoteServer.Label)); }
public override void OnVpnStateChanged(VpnState state) { Connected = state.Status.Equals(VpnStatus.Connected) && state.Server is Server server && server.IsSecureCore() && server.ExitCountry.Equals(CountryCode); foreach (var s in Servers) { s.OnVpnStateChanged(state); } }
private void SetPropertiesOnVpnStateChanged(VpnStateChangedEventArgs e) { if (!string.IsNullOrEmpty(e.State.EntryIp)) { LastServer = LastServerCandidates.ServerByEntryIpAndLabel(e.State.EntryIp, e.State.Label); } State = new VpnState(e.State.Status, LastServer); NetworkBlocked = e.NetworkBlocked; RaiseVpnStateChanged(new VpnStateChangedEventArgs(State, e.Error, e.NetworkBlocked, e.Protocol)); }
public void OnVpnConnecting(VpnState state) { DisableReversed(); Disable(); _appFilter.RemoveAll(); _permittedRemoteAddress.RemoveAll(); if (_serviceSettings.SplitTunnelSettings.Mode == SplitTunnelMode.Permit) { _appFilter.Add(_serviceSettings.SplitTunnelSettings.AppPaths, Action.SoftBlock); } }
private void UpdateLeakProtectionStatus(VpnState state) { switch (UpdatedLeakProtectionStatus(state)) { case true: _firewall.EnableLeakProtection(state.RemoteIp); break; case false: _firewall.DisableLeakProtection(); break; } }
public void OnVpnStateChanged(VpnStateChangedEventArgs e) { var state = e.State; if (!string.IsNullOrEmpty(state.EntryIp)) { _lastServer = _lastServerCandidates.ServerByEntryIp(state.EntryIp); } State = new VpnState(state.Status, _lastServer); _networkBlocked = e.NetworkBlocked; RaiseVpnStateChanged(new VpnStateChangedEventArgs(State, e.Error, e.NetworkBlocked, e.Protocol)); }
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 VpnState Filtered(VpnState state) { if (ShouldSuppress(state)) { return(null); } if (ShouldBeReconnecting(state)) { return(CreateVpnState(state, VpnStatus.Reconnecting, VpnProtocol.Auto)); } return(CreateVpnState(state)); }
public Task OnVpnStateChanged(VpnStateChangedEventArgs e) { _vpnState = e.State; if (e.State.Status.Equals(VpnStatus.Connected)) { StartTimer(); } else { StopTimer(); } return(Task.CompletedTask); }
public async Task GetState() { var state = await _vpnServiceManager.ConnectionState(); var protocol = VpnProtocol.Auto; if (state != null) { _lastServer = _lastServerCandidates.ServerByEntryIp(state.EntryIp); State = new VpnState(state.Status, _lastServer); protocol = state.Protocol; } RaiseVpnStateChanged(new VpnStateChangedEventArgs(State, VpnError.None, false, protocol)); }