Skip to content

Commit

Permalink
Merge branch 'release/1.20.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
mindaugasveblauskas committed May 11, 2021
2 parents fb40c4c + 5171e81 commit 5fc8111
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 86 deletions.
6 changes: 3 additions & 3 deletions Setup/ProtonVPN.aip
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
<ROW Property="Manufacturer" Value="Proton Technologies AG"/>
<ROW Property="MsiLogging" MultiBuildValue="DefaultBuild:vp"/>
<ROW Property="PENDING_REBOOT" Value="0"/>
<ROW Property="ProductCode" Value="1031:{F9E5055B-A5F1-4E15-821C-EE35DD62A676} 1033:{F9E5055B-A5F1-4E15-821C-EE35DD62A676} 1036:{F9E5055B-A5F1-4E15-821C-EE35DD62A676} 1040:{F9E5055B-A5F1-4E15-821C-EE35DD62A676} 1043:{F9E5055B-A5F1-4E15-821C-EE35DD62A676} 1045:{F9E5055B-A5F1-4E15-821C-EE35DD62A676} 1046:{F9E5055B-A5F1-4E15-821C-EE35DD62A676} 1049:{F9E5055B-A5F1-4E15-821C-EE35DD62A676} 1065:{F9E5055B-A5F1-4E15-821C-EE35DD62A676} 2070:{F9E5055B-A5F1-4E15-821C-EE35DD62A676} 3082:{F9E5055B-A5F1-4E15-821C-EE35DD62A676} " Type="16"/>
<ROW Property="ProductCode" Value="1031:{31E6E510-4199-4F1A-94EB-C4A242DCFFFA} 1033:{31E6E510-4199-4F1A-94EB-C4A242DCFFFA} 1036:{31E6E510-4199-4F1A-94EB-C4A242DCFFFA} 1040:{31E6E510-4199-4F1A-94EB-C4A242DCFFFA} 1043:{31E6E510-4199-4F1A-94EB-C4A242DCFFFA} 1045:{31E6E510-4199-4F1A-94EB-C4A242DCFFFA} 1046:{31E6E510-4199-4F1A-94EB-C4A242DCFFFA} 1049:{31E6E510-4199-4F1A-94EB-C4A242DCFFFA} 1065:{31E6E510-4199-4F1A-94EB-C4A242DCFFFA} 2070:{31E6E510-4199-4F1A-94EB-C4A242DCFFFA} 3082:{31E6E510-4199-4F1A-94EB-C4A242DCFFFA} " Type="16"/>
<ROW Property="ProductLanguage" Value="1033"/>
<ROW Property="ProductName" Value="ProtonVPN"/>
<ROW Property="ProductVersion" Value="1.20.3" Type="32"/>
<ROW Property="ProductVersion" Value="1.20.4" Type="32"/>
<ROW Property="REBOOT" MultiBuildValue="DefaultBuild:ReallySuppress"/>
<ROW Property="SecureCustomProperties" Value="OLDPRODUCTS;AI_NEWERPRODUCTFOUND;AI_SETUPEXEPATH;SETUPEXEDIR"/>
<ROW Property="SelectedLanguage" Value="This will be set by custom action"/>
Expand Down Expand Up @@ -74,7 +74,7 @@
</COMPONENT>
<COMPONENT cid="caphyon.advinst.msicomp.MsiCompsComponent">
<ROW Component="A7C0318B44EF690B391D753065B05" ComponentId="{8DFC0212-F989-444F-81FB-9D221A745FE8}" Directory_="APPDIR" Attributes="0" Options="2"/>
<ROW Component="AI_CustomARPName" ComponentId="{F9B406DA-18A1-412C-889B-24995C55CDD6}" Directory_="APPDIR" Attributes="4" KeyPath="DisplayName" Options="1"/>
<ROW Component="AI_CustomARPName" ComponentId="{A3A945A6-2C69-4094-B833-738010BA0264}" Directory_="APPDIR" Attributes="4" KeyPath="DisplayName" Options="1"/>
<ROW Component="AI_ExePath" ComponentId="{47427A21-60A2-43B4-A150-6CBA74CF4A07}" Directory_="APPDIR" Attributes="4" KeyPath="AI_ExePath"/>
<ROW Component="APPDIR" ComponentId="{75DDD993-CDFE-4D39-8C1A-07484ADD1A4E}" Directory_="APPDIR" Attributes="0"/>
<ROW Component="ARSoft.Tools.Net.dll" ComponentId="{05CE9A73-14A8-494D-B2D3-8438A2A16DDB}" Directory_="APPDIR" Attributes="0" KeyPath="ARSoft.Tools.Net.dll"/>
Expand Down
4 changes: 2 additions & 2 deletions src/GlobalAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

[assembly: AssemblyVersion("1.20.3.0")]
[assembly: AssemblyFileVersion("1.20.3.0")]
[assembly: AssemblyVersion("1.20.4.0")]
[assembly: AssemblyFileVersion("1.20.4.0")]
[assembly: ComVisible(false)]
[assembly: AssemblyInformationalVersion("$AssemblyVersion")]
2 changes: 1 addition & 1 deletion src/ProtonVPN.App/Core/Service/Vpn/VpnManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void OnVpnStateChanged(VpnStateChangedEventArgs e)

if (!string.IsNullOrEmpty(state.EntryIp))
{
_lastServer = _lastServerCandidates.ServerByEntryIp(state.EntryIp);
_lastServer = _lastServerCandidates.ServerByEntryIpAndLabel(state.EntryIp, e.State.Label);
}

_state = new VpnState(state.Status, _lastServer);
Expand Down
2 changes: 1 addition & 1 deletion src/ProtonVPN.App/Core/Service/Vpn/VpnServiceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private static VpnStateChangedEventArgs Map(VpnStateContract contract)
VpnError error = Map(contract.Error);
VpnProtocol protocol = Map(contract.Protocol);

return new VpnStateChangedEventArgs(status, error, contract.EndpointIp, contract.NetworkBlocked, protocol);
return new VpnStateChangedEventArgs(status, error, contract.EndpointIp, contract.NetworkBlocked, protocol, contract.Label);
}

private static InOutBytes Map(InOutBytesContract bytes)
Expand Down
55 changes: 21 additions & 34 deletions src/ProtonVPN.Core/Servers/ServerCandidates.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020 Proton Technologies AG
* Copyright (c) 2021 Proton Technologies AG
*
* This file is part of ProtonVPN.
*
Expand All @@ -18,61 +18,48 @@
*/

using System.Collections.Generic;
using System.Linq;
using ProtonVPN.Core.Servers.Models;
using ProtonVPN.Core.Servers.Specs;
using ProtonVPN.Core.Settings;

namespace ProtonVPN.Core.Servers
{
public class ServerCandidates
{
private readonly ServerManager _serverManager;
private readonly IUserStorage _userStorage;

public ServerCandidates(ServerManager serverManager, IUserStorage userStorage, IReadOnlyCollection<Server> items)
public ServerCandidates(ServerManager serverManager, IReadOnlyCollection<Server> items)
{
_serverManager = serverManager;
_userStorage = userStorage;
Items = items;
}

public IReadOnlyCollection<Server> Items { get; }

public Server ServerByEntryIp(string ip)
public Server ServerByEntryIpAndLabel(string entryIp, string label)
{
if (string.IsNullOrEmpty(ip))
if (string.IsNullOrEmpty(entryIp))
{
return Server.Empty();
}

var maxTier = _userStorage.User().MaxTier;
var servers = Items.Where(l => l.Servers.Any(p => p.EntryIp == ip));
var server = FirstByUserTier(servers, maxTier);
if (server != null)
return WithExitIp(server, ip);

servers = _serverManager.GetServers(new ServerByEntryIp(ip));
server = FirstByUserTier(servers, maxTier);
return WithExitIp(server ?? Server.Empty(), ip);
}

private Server FirstByUserTier(IEnumerable<Server> servers, sbyte maxTier)
{
return servers
.OrderByDescending(s => s.Tier <= maxTier ? s.Tier : -1)
.FirstOrDefault();
}

private Server WithExitIp(Server server, string entryIp)
{
var result = server.Clone();
IReadOnlyCollection<Server> servers = Items == null || Items.Count == 0
? _serverManager.GetServers(new ServerByEntryIp(entryIp))
: Items;

var physical = server.Servers.FirstOrDefault(p => p.EntryIp == entryIp);
if (physical != null)
foreach (Server server in servers)
{
result.ExitIp = physical.ExitIp;
foreach (PhysicalServer physicalServer in server.Servers)
{
if (entryIp == physicalServer.EntryIp && (string.IsNullOrEmpty(label) || label == physicalServer.Label))
{
Server clone = server.Clone();
clone.ExitIp = physicalServer.ExitIp;
return clone;
}
}
}

return result;
return Server.Empty();
}
}
}
}
11 changes: 4 additions & 7 deletions src/ProtonVPN.Core/Servers/ServerCandidatesFactory.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020 Proton Technologies AG
* Copyright (c) 2021 Proton Technologies AG
*
* This file is part of ProtonVPN.
*
Expand All @@ -19,24 +19,21 @@

using System.Collections.Generic;
using ProtonVPN.Core.Servers.Models;
using ProtonVPN.Core.Settings;

namespace ProtonVPN.Core.Servers
{
public class ServerCandidatesFactory
{
private readonly ServerManager _serverManager;
private readonly IUserStorage _userStorage;

public ServerCandidatesFactory(ServerManager serverManager, IUserStorage userStorage)
public ServerCandidatesFactory(ServerManager serverManager)
{
_serverManager = serverManager;
_userStorage = userStorage;
}

public ServerCandidates ServerCandidates(IReadOnlyCollection<Server> servers)
{
return new ServerCandidates(_serverManager, _userStorage, servers);
return new(_serverManager, servers);
}
}
}
}
4 changes: 3 additions & 1 deletion src/ProtonVPN.Core/Vpn/VpnState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ public class VpnState
public string EntryIp { get; }
public Server Server { get; }
public VpnProtocol Protocol { get; }
public string Label { get; }

public VpnState(VpnStatus status, string entryIp, VpnProtocol protocol)
public VpnState(VpnStatus status, string entryIp, VpnProtocol protocol, string label = "")
{
Status = status;
EntryIp = entryIp;
Protocol = protocol;
Label = label;
}

public VpnState(VpnStatus status, Server server = null)
Expand Down
4 changes: 2 additions & 2 deletions src/ProtonVPN.Core/Vpn/VpnStateChangedEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public class VpnStateChangedEventArgs
public bool NetworkBlocked { get; }
public VpnProtocol Protocol { get; }

public VpnStateChangedEventArgs(VpnStatus status, VpnError error, string endpointIp, bool networkBlocked, VpnProtocol protocol)
: this(new VpnState(status, endpointIp, protocol), error, networkBlocked, protocol)
public VpnStateChangedEventArgs(VpnStatus status, VpnError error, string endpointIp, bool networkBlocked, VpnProtocol protocol, string label = "")
: this(new VpnState(status, endpointIp, protocol, label), error, networkBlocked, protocol)
{
}

Expand Down
23 changes: 11 additions & 12 deletions src/ProtonVPN.Service.Contract/Vpn/VpnStateContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,27 @@ public VpnStateContract(
VpnErrorTypeContract error,
string endpointIp,
bool networkBlocked,
VpnProtocolContract protocol)
VpnProtocolContract protocol,
string label)
{
Status = status;
Error = error;
EndpointIp = endpointIp;
NetworkBlocked = networkBlocked;
Protocol = protocol;
Label = label;
}

[DataMember]
public VpnStatusContract Status { get; private set; }
[DataMember] public VpnStatusContract Status { get; private set; }

[DataMember]
public VpnErrorTypeContract Error { get; private set; }
[DataMember] public VpnErrorTypeContract Error { get; private set; }

[DataMember]
public bool NetworkBlocked { get; private set; }
[DataMember] public bool NetworkBlocked { get; private set; }

[DataMember]
public string EndpointIp { get; private set; }
[DataMember] public string EndpointIp { get; private set; }

[DataMember]
public VpnProtocolContract Protocol { get; private set; }
[DataMember] public VpnProtocolContract Protocol { get; private set; }

[DataMember] public string Label { get; private set; }
}
}
}
3 changes: 2 additions & 1 deletion src/ProtonVPN.Service/VpnConnectionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ private VpnStateContract Map(VpnState state)
Map(state.Error),
state.RemoteIp,
killSwitchEnabled,
Map(state.Protocol));
Map(state.Protocol),
state.Label);
}

private static VpnStatusContract Map(VpnStatus vpnStatus)
Expand Down
14 changes: 10 additions & 4 deletions src/ProtonVPN.Vpn/Common/VpnState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,22 @@ namespace ProtonVPN.Vpn.Common
public class VpnState
{
public VpnState(VpnStatus status) : this(status, VpnError.None, string.Empty, string.Empty)
{ }
{
}

public VpnState(VpnStatus status, VpnError error) : this(status, error, string.Empty, string.Empty)
{ }
{
}

public VpnState(VpnStatus status, VpnError error, string localIp, string remoteIp, VpnProtocol protocol = VpnProtocol.Auto)
public VpnState(VpnStatus status, VpnError error, string localIp, string remoteIp,
VpnProtocol protocol = VpnProtocol.Auto, string label = "")
{
Status = status;
Error = error;
LocalIp = localIp;
RemoteIp = remoteIp;
Protocol = protocol;
Label = label;
}

public VpnStatus Status { get; }
Expand All @@ -47,5 +51,7 @@ public VpnState(VpnStatus status, VpnError error, string localIp, string remoteI
public string RemoteIp { get; }

public VpnProtocol Protocol { get; }

public string Label { get; }
}
}
}
21 changes: 15 additions & 6 deletions src/ProtonVPN.Vpn/Connection/ReconnectingWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ private void Origin_StateChanged(object sender, EventArgs<VpnState> e)
_state = e.Data;

if (_reconnecting && !Reconnecting(_state))
{
_reconnecting = false;
}

if (ReconnectRequired(_state))
{
Expand Down Expand Up @@ -182,14 +184,21 @@ private VpnState Filtered(VpnState state)

if (ShouldBeReconnecting(state))
{
return new VpnState(
VpnStatus.Reconnecting,
state.Error,
state.LocalIp,
state.RemoteIp);
return CreateVpnState(state, VpnStatus.Reconnecting, VpnProtocol.Auto);
}

return state;
return CreateVpnState(state);
}

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 bool ShouldSuppress(VpnState state)
Expand Down
10 changes: 0 additions & 10 deletions src/ProtonVPN.Vpn/OpenVpn/Arguments/BaseRouteArgument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,6 @@ public IEnumerator<string> GetEnumerator()
yield return "--pull-filter ignore \"redirect-gateway\"";
yield return "--route 0.0.0.0 0.0.0.0 vpn_gateway 32000";
break;
case SplitTunnelMode.Block:
yield return "--pull-filter ignore \"redirect-gateway\"";
yield return "--route 0.0.0.0 0.0.0.0 net_gateway 32000";
yield return "--route 0.0.0.0 0.0.0.0 vpn_gateway";
break;
default:
yield return "--pull-filter ignore \"redirect-gateway def1\"";
yield return "--redirect-gateway";
yield return "--route 0.0.0.0 0.0.0.0 net_gateway";
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void Initialize()
private void InitializeDependencies()
{
_serverManager = Substitute.For<ServerManager>(_userStorage);
_serverCandidatesFactory = Substitute.For<ServerCandidatesFactory>(_serverManager, _userStorage);
_serverCandidatesFactory = Substitute.For<ServerCandidatesFactory>(_serverManager);
_vpnCredentialProvider = Substitute.For<VpnCredentialProvider>(_config, _appSettings, _userStorage);

_profileConnector = new ProfileConnector(_logger, _userStorage, _appSettings,
Expand Down Expand Up @@ -111,7 +111,7 @@ private void InitializeArrangeVariables()
_p2pServer,
_torServer
};
_candidates = new ServerCandidates(_serverManager, _userStorage, _servers);
_candidates = new ServerCandidates(_serverManager, _servers);
_profile = new Profile()
{
ProfileType = ProfileType.Fastest,
Expand Down

0 comments on commit 5fc8111

Please sign in to comment.