public bool CanConnect(ServerCandidates candidates, Profile profile) { var servers = Servers(candidates); if (servers.Any()) { return(SwitchSecureCoreMode(servers.First().IsSecureCore())); } HandleNoServersAvailable(candidates.Items, profile); return(false); }
public async Task <bool> UpdateServers(ServerCandidates candidates, Profile profile) { var servers = Servers(candidates); if (!servers.Any()) { return(false); } var sortedServers = Sorted(servers, profile.ProfileType); await UpdateServers(sortedServers); return(true); }
private Specification <LogicalServerContract> ProfileServerSpec(Profile profile) { if (profile.ProfileType == ProfileType.Custom) { return(new ServerById(profile.ServerId)); } Specification <LogicalServerContract> spec = new ServerByFeatures(ServerFeatures(profile)); if (!string.IsNullOrEmpty(profile.CountryCode)) { spec &= new ExitCountryServer(profile.CountryCode); } return(spec); }
private Features ServerFeatures(Profile profile) { if (profile.IsPredefined) { if (_appSettings.SecureCore) { return(Features.SecureCore); } if (_appSettings.IsPortForwardingEnabled()) { return(profile.Features); } return(Features.None); } return(profile.Features); }
private void InitializeArrangeVariables() { _standardPhysicalServers = new List <PhysicalServer> { new PhysicalServer(id: "Standard-PS", entryIp: "192.168.0.1", exitIp: "192.168.1.1", domain: "standard.protonvpn.ps", status: 1, label: string.Empty, x25519PublicKey: string.Empty) }; _p2pPhysicalServers = new List <PhysicalServer> { new PhysicalServer(id: "P2P-PS", entryIp: "192.168.0.2", exitIp: "192.168.1.2", domain: "p2p.protonvpn.ps", status: 1, label: string.Empty, x25519PublicKey: string.Empty) }; _torPhysicalServers = new List <PhysicalServer> { new PhysicalServer(id: "Tor-PS", entryIp: "192.168.0.3", exitIp: "192.168.1.3", domain: "tor.protonvpn.ps", status: 1, label: string.Empty, x25519PublicKey: string.Empty) }; _standardServer = new Server(id: "Standard-S", name: "Standard", city: "City", entryCountry: "CH", exitCountry: "CH", domain: "standard.protonvpn.s", status: 1, tier: ServerTiers.Basic, features: (sbyte)Features.None, load: 0, score: 1, location: Substitute.For <Location>(), physicalServers: _standardPhysicalServers, exitIp: "192.168.2.1"); _p2pServer = new Server(id: "P2P-S", name: "P2P", city: "City", entryCountry: "CH", exitCountry: "CH", domain: "p2p.protonvpn.s", status: 1, tier: ServerTiers.Plus, features: (sbyte)Features.P2P, load: 100, score: 999, location: Substitute.For <Location>(), physicalServers: _p2pPhysicalServers, exitIp: "192.168.2.2"); _torServer = new Server(id: "Tor-S", name: "Tor", city: "City", entryCountry: "CH", exitCountry: "CH", domain: "tor.protonvpn.s", status: 1, tier: ServerTiers.Plus, features: (sbyte)Features.Tor, load: 0, score: 0, location: Substitute.For <Location>(), physicalServers: _torPhysicalServers, exitIp: "192.168.2.3"); _servers = new List <Server> { _standardServer, _p2pServer, _torServer }; _candidates = new ServerCandidates(_serverManager, _servers); _profile = new Profile() { ProfileType = ProfileType.Fastest, VpnProtocol = VpnProtocol.Smart }; }
private Server GetBestServerForNoFeaturesAndDifferentCountry(Server originalServer, IList <Server> excludedServers, Profile baseProfile) { Profile profile = new() { ProfileType = ProfileType.Fastest, Features = Features.None }; return(GetBestServer(originalServer, excludedServers, profile, s => s.ExitCountry != baseProfile.CountryCode)); }
private Server GetBestServerForSameCityAndNoFeatures(Server originalServer, IList <Server> excludedServers, Profile baseProfile) { Profile profile = new() { ProfileType = ProfileType.Fastest, Features = Features.None, CountryCode = baseProfile.CountryCode, City = baseProfile.City }; return(GetBestServer(originalServer, excludedServers, profile)); }
private Server GetBestServerForSameCountryFeaturesAndDifferentCity(Server originalServer, IList <Server> excludedServers, Profile baseProfile) { Profile profile = new() { ProfileType = ProfileType.Fastest, Features = baseProfile.Features, CountryCode = baseProfile.CountryCode }; return(GetBestServer(originalServer, excludedServers, profile, s => s.City != baseProfile.City)); }
private Server GetBestServerForSameCountryTierFeatures(Server originalServer, IList <Server> excludedServers, Profile baseProfile) { Profile profile = new() { ProfileType = ProfileType.Fastest, Features = baseProfile.Features, CountryCode = baseProfile.CountryCode, ExactTier = baseProfile.ExactTier }; return(GetBestServer(originalServer, excludedServers, profile)); }
private Server GetBestServerForDifferentEntryAndExitCountries(Server originalServer, IList <Server> excludedServers, Profile baseProfile) { Profile profile = new() { ProfileType = ProfileType.Fastest, Features = baseProfile.Features }; return(GetBestServer(originalServer, excludedServers, profile, s => s.EntryCountry != baseProfile.EntryCountryCode && s.ExitCountry != baseProfile.CountryCode)); }
private Server GetBestServer(Server originalServer, IList <Server> excludedServers, Profile profile, Func <Server, bool> filter = null) { IEnumerable <Server> sortedCandidateServers = GetSortedCandidateServers(profile); Server server = filter == null ? sortedCandidateServers.FirstOrDefault(s => !s.Equals(originalServer) && !excludedServers.Contains(s)) : sortedCandidateServers.FirstOrDefault(s => !s.Equals(originalServer) && !excludedServers.Contains(s) && filter(s)); return(server); }
private IList <Server> GetSimilarServers(bool isToIncludeOriginalServer, Server originalServer, Profile baseProfile) { IList <Server> servers = new List <Server>(); servers.AddIfNotNull(GetOriginalServerIfRequired(isToIncludeOriginalServer, originalServer)); if ((baseProfile.Features & Features.SecureCore) > 0) { servers.AddIfNotNull(GetBestServerForSameExitCountryAndDifferentEntryCountry(originalServer, servers, baseProfile)); servers.AddIfNotNull(GetBestServerForSameEntryCountryAndDifferentExitCountry(originalServer, servers, baseProfile)); servers.AddIfNotNull(GetBestServerForDifferentEntryAndExitCountries(originalServer, servers, baseProfile)); } else { servers.AddIfNotNull(GetBestServerForSameCityTierFeatures(originalServer, servers, baseProfile)); servers.AddIfNotNull(GetBestServerForSameCountryTierFeatures(originalServer, servers, baseProfile)); servers.AddIfNotNull(GetBestServerForSameCountryFeaturesAndDifferentCity(originalServer, servers, baseProfile)); if (baseProfile.Features > 0) { servers.AddIfNotNull(GetBestServerForSameFeaturesAndDifferentCountry(originalServer, servers, baseProfile)); } servers.AddIfNotNull(GetBestServerForSameCityAndNoFeatures(originalServer, servers, baseProfile)); servers.AddIfNotNull(GetBestServerForSameCountryAndNoFeaturesAndDifferentCity(originalServer, servers, baseProfile)); servers.AddIfNotNull(GetBestServerForNoFeaturesAndDifferentCountry(originalServer, servers, baseProfile)); } return(servers); }
private void HandleNoServersAvailable(IReadOnlyCollection <Server> candidates, Profile profile) { if (profile.ProfileType == ProfileType.Custom) { HandleNoCustomServerAvailable(candidates.FirstOrDefault()); return; } if ((profile.Features.IsSecureCore() || profile.IsPredefined && _appSettings.SecureCore) && _userStorage.User().MaxTier < ServerTiers.Plus) { _modals.Show <ScUpsellModalViewModel>(); return; } if (!string.IsNullOrEmpty(profile.CountryCode)) { HandleNoCountryServersAvailable(candidates); return; } if (!candidates.Any()) { _dialogs.ShowWarning(StringResources.Get("Profiles_msg_NoServersAvailable")); return; } var userTierServers = candidates.UpToTierServers(_userStorage.User().MaxTier); if (!userTierServers.Any()) { if (candidates.BasicServers().Any()) { _modals.Show <UpsellModalViewModel>(); return; } if (candidates.PlusServers().Any()) { _modals.Show <PlusUpsellModalViewModel>(); return; } } if (!candidates.OnlineServers().Any()) { _dialogs.ShowWarning(StringResources.Get("Profiles_msg_AllServersOffline")); return; } _modals.Show <NoServerDueTierUpsellModalViewModel>(); }
private Features ServerFeatures(Profile profile) { return(profile.IsPredefined ? _appSettings.SecureCore ? Features.SecureCore : Features.None : profile.Features); }
public async Task Delete(Profile profile) { await _profiles.Delete(profile); Sync(); }
public async Task Update(Profile profile) { await _profiles.Update(profile); Sync(); }