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)
            };
            _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)
            };
            _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)
            };

            _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, _userStorage, _servers);
            _profile    = new Profile()
            {
                ProfileType = ProfileType.Fastest,
                Protocol    = Protocol.Auto
            };
        }
示例#2
0
        private IEnumerable <Server> GetSortedCandidateServers(Profile profile)
        {
            ServerCandidates       candidates       = _profileConnector.ServerCandidates(profile);
            IReadOnlyList <Server> candidateServers = _profileConnector.Servers(candidates);

            return(_profileConnector.SortServers(candidateServers, profile.ProfileType));
        }
示例#3
0
        private async Task ConnectToSimilarServerAsync(bool isToTryLastServer, Protocol protocol)
        {
            ServerCandidates serverCandidates = _similarServerCandidatesGenerator
                                                .Generate(isToTryLastServer, _targetServer, _targetProfile);

            await ConnectToPreSortedCandidatesAsync(serverCandidates, protocol);
        }
示例#4
0
        public async Task Connect(ServerCandidates candidates, Profile profile)
        {
            var servers = Servers(candidates);

            var sortedServers = Sorted(servers, profile.ProfileType);

            await Connect(sortedServers, VpnProtocol(profile.Protocol));
        }
示例#5
0
        private IReadOnlyList <Server> Servers(ServerCandidates candidates)
        {
            var servers = candidates.Items
                          .OnlineServers()
                          .UpToTierServers(_userStorage.User().MaxTier)
                          .ToList();

            return(servers);
        }
示例#6
0
        private async Task ConnectAsync(Profile profile, ServerCandidates candidates, Protocol?protocol = null, int?maxServers = null)
        {
            if (profile.IsPredefined || profile.IsTemporary)
            {
                profile.Protocol = _appSettings.GetProtocol();
            }

            LastProfile          = profile;
            LastServerCandidates = candidates;
            await _profileConnector.Connect(candidates, profile, protocol, maxServers);
        }
示例#7
0
        private async Task ConnectAsync(Profile profile, ServerCandidates candidates)
        {
            if (profile.IsPredefined || profile.IsTemporary)
            {
                profile.Protocol = ToProtocol(_appSettings.OvpnProtocol);
            }

            _lastProfile          = profile;
            _lastServerCandidates = candidates;
            await _profileConnector.Connect(candidates, profile);
        }
示例#8
0
        public bool CanConnect(ServerCandidates candidates, Profile profile)
        {
            IReadOnlyList <Server> servers = Servers(candidates);

            if (servers.Any())
            {
                SwitchSecureCoreMode(servers.First().IsSecureCore());
                return(true);
            }

            return(false);
        }
示例#9
0
        private async Task ConnectToPreSortedCandidatesAsync(ServerCandidates serverCandidates, VpnProtocol vpnProtocol)
        {
            string firstServerMessage = string.Empty;

            if (serverCandidates.Items.Any())
            {
                Server firstServer = serverCandidates.Items.First();
                firstServerMessage = $" First server is {firstServer.Name} ({firstServer.ExitIp}).";
            }
            _logger.Info($"Reconnecting to {serverCandidates.Items.Count} servers.{firstServerMessage}");
            await _vpnConnector.ConnectToPreSortedCandidatesAsync(serverCandidates, vpnProtocol);
        }
示例#10
0
 public VpnManager(
     ILogger logger,
     ProfileConnector profileConnector,
     IVpnServiceManager vpnServiceManager,
     IAppSettings appSettings)
 {
     _logger               = logger;
     _profileConnector     = profileConnector;
     _appSettings          = appSettings;
     _vpnServiceManager    = vpnServiceManager;
     _lastServerCandidates = _profileConnector.ServerCandidates(null);
 }
示例#11
0
        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);
        }
示例#12
0
        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);
        }
示例#13
0
 public VpnManager(
     ILogger logger,
     ProfileConnector profileConnector,
     IVpnServiceManager vpnServiceManager,
     IAppSettings appSettings,
     GuestHoleState guestHoleState,
     IUserStorage userStorage)
 {
     _logger               = logger;
     _profileConnector     = profileConnector;
     _appSettings          = appSettings;
     _vpnServiceManager    = vpnServiceManager;
     _guestHoleState       = guestHoleState;
     _userStorage          = userStorage;
     _lastServerCandidates = _profileConnector.ServerCandidates(null);
 }
示例#14
0
        private async Task UpdateServersOrDisconnect(VpnError disconnectReason)
        {
            if (_state.Status == VpnStatus.Disconnecting ||
                _state.Status == VpnStatus.Disconnected ||
                _lastProfile == null)
            {
                return;
            }

            _lastServerCandidates = _profileConnector.ServerCandidates(_lastProfile);

            if (!await _profileConnector.UpdateServers(_lastServerCandidates, _lastProfile))
            {
                await _vpnServiceManager.Disconnect(disconnectReason);
            }
        }
示例#15
0
        private async Task ConnectInternal(Profile profile)
        {
            var candidates = _profileConnector.ServerCandidates(profile);
            var canConnect = _profileConnector.CanConnect(candidates, profile);

            if (canConnect)
            {
                if (profile.IsPredefined || profile.IsTemporary)
                {
                    profile.Protocol = ToProtocol(_appSettings.OvpnProtocol);
                }
                _lastProfile          = profile;
                _lastServerCandidates = candidates;
                await _profileConnector.Connect(candidates, profile);
            }
        }
示例#16
0
        private async Task ConnectToSimilarServerOrQuickConnectAsync(bool isToTryLastServer, VpnProtocol vpnProtocol)
        {
            IList <Server> serverCandidates = _similarServerCandidatesGenerator
                                              .GenerateList(isToTryLastServer, _targetServer, _targetProfile);
            IEnumerable <Server> quickConnectServers = (await _vpnConnector.GetSortedAndValidQuickConnectServersAsync(
                                                            _config.MaxQuickConnectServersOnReconnection)).Except(serverCandidates);

            serverCandidates.AddRange(quickConnectServers);
            if (_config.MaxQuickConnectServersOnReconnection.HasValue)
            {
                serverCandidates = serverCandidates.Take(_config.MaxQuickConnectServersOnReconnection.Value).ToList();
            }
            ServerCandidates sortedCandidates =
                _serverCandidatesFactory.ServerCandidates((IReadOnlyCollection <Server>)serverCandidates);

            await ConnectToPreSortedCandidatesAsync(sortedCandidates, vpnProtocol);
        }
示例#17
0
 public VpnManager(
     ProfileConnector profileConnector,
     ProfileManager profileManager,
     IVpnServiceManager vpnServiceManager,
     IAppSettings appSettings,
     GuestHoleState guestHoleState,
     IUserStorage userStorage,
     INetworkInterfaceLoader networkInterfaceLoader,
     IPopupWindows popupWindows)
 {
     _profileConnector       = profileConnector;
     _profileManager         = profileManager;
     _vpnServiceManager      = vpnServiceManager;
     _appSettings            = appSettings;
     _guestHoleState         = guestHoleState;
     _userStorage            = userStorage;
     _networkInterfaceLoader = networkInterfaceLoader;
     _popupWindows           = popupWindows;
     _lastServerCandidates   = _profileConnector.ServerCandidates(null);
 }
示例#18
0
 private async Task ExecuteConnectToPreSortedCandidatesAsync(ServerCandidates sortedCandidates, Protocol protocol)
 {
     LastServerCandidates = sortedCandidates;
     await _profileConnector.ConnectWithPreSortedCandidates(sortedCandidates, protocol);
 }
示例#19
0
 public async Task ConnectToPreSortedCandidatesAsync(ServerCandidates sortedCandidates, Protocol protocol)
 {
     await ValidateConnectionAsync(() => ExecuteConnectToPreSortedCandidatesAsync(sortedCandidates, protocol));
 }