Skip to content

Commit

Permalink
Change Reconfig Behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
trudyhood committed May 18, 2022
1 parent d619377 commit 4f76935
Show file tree
Hide file tree
Showing 25 changed files with 518 additions and 4,078 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Upcoming

### Developer
* Update: Move VpnHood.Client.WebUI to a standalone repo

# v2.4.299
### Client
* Fix: Windows: Installation Package
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified VpnHood.Client.App.Android/Assets/SPA.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion VpnHood.Client.App.Android/Resources/Resource.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

508 changes: 0 additions & 508 deletions VpnHood.Client.App.Win.Setup/VpnHood.Client.App.Win.Setup.back (1).aip

This file was deleted.

508 changes: 0 additions & 508 deletions VpnHood.Client.App.Win.Setup/VpnHood.Client.App.Win.Setup.back (2).aip

This file was deleted.

505 changes: 0 additions & 505 deletions VpnHood.Client.App.Win.Setup/VpnHood.Client.App.Win.Setup.back (3).aip

This file was deleted.

513 changes: 0 additions & 513 deletions VpnHood.Client.App.Win.Setup/VpnHood.Client.App.Win.Setup.back (4).aip

This file was deleted.

516 changes: 0 additions & 516 deletions VpnHood.Client.App.Win.Setup/VpnHood.Client.App.Win.Setup.back (5).aip

This file was deleted.

517 changes: 0 additions & 517 deletions VpnHood.Client.App.Win.Setup/VpnHood.Client.App.Win.Setup.back (6).aip

This file was deleted.

508 changes: 0 additions & 508 deletions VpnHood.Client.App.Win.Setup/VpnHood.Client.App.Win.Setup.back.aip

This file was deleted.

Binary file modified VpnHood.Client.App.Win/Resources/SPA.zip
Binary file not shown.
897 changes: 448 additions & 449 deletions VpnHood.Client.App/VpnHoodApp.cs

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 24 additions & 25 deletions VpnHood.Client/ClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,33 @@
using VpnHood.Common.Net;
using VpnHood.Tunneling.Factory;

namespace VpnHood.Client
namespace VpnHood.Client;

public class ClientOptions
{
public class ClientOptions
{
/// <summary>
/// a never used IPv4 that must be outside the local network
/// </summary>
public IPAddress TcpProxyLoopbackAddressIpV4 { get; set; } = IPAddress.Parse("11.0.0.0");
/// <summary>
/// a never used IPv6 ip that must be outside the machine
/// </summary>
public IPAddress TcpProxyLoopbackAddressIpV6 { get; set; } = IPAddress.Parse("2000::");
/// <summary>
/// a never used IPv4 that must be outside the local network
/// </summary>
public IPAddress TcpProxyLoopbackAddressIpV4 { get; set; } = IPAddress.Parse("11.0.0.0");
/// <summary>
/// a never used IPv6 ip that must be outside the machine
/// </summary>
public IPAddress TcpProxyLoopbackAddressIpV6 { get; set; } = IPAddress.Parse("2000::");

public IPAddress[] DnsServers { get; set; } = { IPAddress.Parse("8.8.8.8"), IPAddress.Parse("8.8.4.4"),
IPAddress.Parse("2001:4860:4860::8888"), IPAddress.Parse("2001:4860:4860::8844") };
public bool AutoDisposePacketCapture { get; set; } = true;
public TimeSpan Timeout { get; set; } = TimeSpan.FromSeconds(60);
public Version Version { get; set; } = typeof(ClientOptions).Assembly.GetName().Version;
public bool UseUdpChannel { get; set; } = false;
public bool ExcludeLocalNetwork { get; set; } = true;
public IpRange[]? IncludeIpRanges { get; set; }
public IpRange[]? PacketCaptureIncludeIpRanges { get; set; }
public SocketFactory SocketFactory { get; set; } = new();
public int MaxDatagramChannelCount { get; set; } = 4;
public string UserAgent { get; set; } = Environment.OSVersion.ToString();
public IPAddress[] DnsServers { get; set; } = { IPAddress.Parse("8.8.8.8"), IPAddress.Parse("8.8.4.4"),
IPAddress.Parse("2001:4860:4860::8888"), IPAddress.Parse("2001:4860:4860::8844") };
public bool AutoDisposePacketCapture { get; set; } = true;
public TimeSpan Timeout { get; set; } = TimeSpan.FromSeconds(60);
public Version Version { get; set; } = typeof(ClientOptions).Assembly.GetName().Version;
public bool UseUdpChannel { get; set; } = false;
public bool ExcludeLocalNetwork { get; set; } = true;
public IpRange[]? IncludeIpRanges { get; set; }
public IpRange[]? PacketCaptureIncludeIpRanges { get; set; }
public SocketFactory SocketFactory { get; set; } = new();
public int MaxDatagramChannelCount { get; set; } = 4;
public string UserAgent { get; set; } = Environment.OSVersion.ToString();

#if DEBUG
public int ProtocolVersion { get; set; }
public int ProtocolVersion { get; set; }
#endif
}
}
2 changes: 1 addition & 1 deletion VpnHood.Server.Access/AccessServers/FileAccessServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public FileAccessServer(string storagePath, FileAccessServerOptions options)
public Task<ServerCommand> Server_UpdateStatus(ServerStatus serverStatus)
{
ServerStatus = serverStatus;
return Task.FromResult(new ServerCommand());
return Task.FromResult(new ServerCommand(ServerConfig.ConfigCode));
}

public Task<ServerConfig> Server_Configure(ServerInfo serverInfo)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using System.Net;
using System;
using System.Net;

namespace VpnHood.Server.AccessServers
{
public class FileAccessServerOptions : ServerConfig
{
public FileAccessServerOptions()
: base(new IPEndPoint[] { new(IPAddress.Any, 443), new(IPAddress.IPv6Any, 443) } )
: base(new IPEndPoint[] { new(IPAddress.Any, 443), new(IPAddress.IPv6Any, 443) }, Guid.Empty.ToString())
{
}

public string? SslCertificatesPassword { get; set; }
}
}
7 changes: 6 additions & 1 deletion VpnHood.Server.Access/ServerCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ namespace VpnHood.Server
{
public class ServerCommand
{
public Guid? ConfigCode { get; set; }
public string ConfigCode { get; set; }

public ServerCommand(string configCode)
{
ConfigCode = configCode;
}
}
}
4 changes: 3 additions & 1 deletion VpnHood.Server.Access/ServerConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ public class ServerConfig
public TrackingOptions TrackingOptions { get; set; } = new();
public SessionOptions SessionOptions { get; set; } = new();
public int UdpPort { get; set; }
public string ConfigCode { get; set; }

[JsonConverter(typeof(ArrayConverter<IPEndPoint, IPEndPointConverter>))]
public IPEndPoint[] TcpEndPoints { get; set; }

[JsonConverter(typeof(TimeSpanConverter))]
public TimeSpan UpdateStatusInterval { get; set; } = TimeSpan.FromSeconds(120);

public ServerConfig(IPEndPoint[] tcpEndPoints)
public ServerConfig(IPEndPoint[] tcpEndPoints, string configCode)
{
TcpEndPoints = tcpEndPoints;
ConfigCode = configCode;
}
}
}
2 changes: 0 additions & 2 deletions VpnHood.Server.Access/ServerInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

namespace VpnHood.Server
{

public class ServerInfo
{
[JsonConstructor]
Expand Down Expand Up @@ -38,7 +37,6 @@ public ServerInfo(Version version,
public string? OsVersion { get; set; }
public long TotalMemory { get; set; }
public string? MachineName { get; set; }
public Guid? ConfigCode { get; set; }
public string? LastError { get; set; }
}
}
1 change: 1 addition & 0 deletions VpnHood.Server.Access/ServerStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public class ServerStatus
public int ThreadCount { get; set; }
public long TunnelSendSpeed { get; set; }
public long TunnelReceiveSpeed { get; set; }
public string ConfigCode { get; set; } = default!;
}
}
24 changes: 12 additions & 12 deletions VpnHood.Server/VpnHoodServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class VpnHoodServer : IDisposable
private Timer? _updateStatusTimer;
private bool _disposed;
private string? _lastConfigError;
private string _lastConfigCode = "";

public VpnHoodServer(IAccessServer accessServer, ServerOptions options)
{
Expand Down Expand Up @@ -113,7 +114,7 @@ public async Task Start()
await Configure();
}

private async Task Configure(Guid? configurationCode = null)
private async Task Configure()
{
if (_tcpHost.IsDisposed)
throw new ObjectDisposedException($"Could not configure after disposing {nameof(TcpHost)}!");
Expand All @@ -139,7 +140,6 @@ private async Task Configure(Guid? configurationCode = null)
OsInfo = SystemInfoProvider.GetOperatingSystemInfo(),
OsVersion = Environment.OSVersion.ToString(),
TotalMemory = SystemInfoProvider.GetSystemInfo().TotalMemory,
ConfigCode = configurationCode,
LastError = _lastConfigError
};

Expand All @@ -152,6 +152,7 @@ private async Task Configure(Guid? configurationCode = null)
_tcpHost.OrgStreamReadBufferSize = serverConfig.SessionOptions.TcpBufferSize;
_tcpHost.TunnelStreamReadBufferSize = serverConfig.SessionOptions.TcpBufferSize;
_tcpHost.TcpTimeout = serverConfig.SessionOptions.TcpTimeout;
_lastConfigCode = serverConfig.ConfigCode;

// starting the listeners
var verb = _tcpHost.IsStarted ? "Restarting" : "Starting";
Expand Down Expand Up @@ -228,32 +229,31 @@ public ServerStatus Status
FreeMemory = systemInfo.FreeMemory,
UsedMemory = Process.GetCurrentProcess().WorkingSet64,
TunnelSendSpeed = SessionManager.Sessions.Sum(x => x.Value.Tunnel.SendSpeed),
TunnelReceiveSpeed = SessionManager.Sessions.Sum(x => x.Value.Tunnel.ReceiveSpeed)
TunnelReceiveSpeed = SessionManager.Sessions.Sum(x => x.Value.Tunnel.ReceiveSpeed),
ConfigCode = _lastConfigCode
};
return serverStatus;
}
}

private async Task SendStatusToAccessServer()
{
Guid? configurationCode = null;
try
{
VhLogger.Instance.LogTrace("Sending status to AccessServer...");
var res = await AccessServer.Server_UpdateStatus(Status);
configurationCode = res.ConfigCode;

// reconfigure
if (res.ConfigCode != _lastConfigCode)
{
VhLogger.Instance.LogInformation("Reconfiguration was requested.");
_ = Configure();
}
}
catch (Exception ex)
{
VhLogger.Instance.LogError(ex, "Could not send server status.");
}

// reconfigure
if (configurationCode != null)
{
VhLogger.Instance.LogInformation("Reconfiguration was requested.");
_ = Configure(configurationCode);
}
}
}
}
8 changes: 5 additions & 3 deletions VpnHood.ZTest/TestAccessServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public TestAccessServer(IAccessServer baseAccessServer)
}

public DateTime? LastConfigureTime { get; private set; }
public ServerInfo? LastServerInfo { get; private set; }
public ServerStatus? LastServerStatus { get; private set; }

public TestEmbedIoAccessServer EmbedIoAccessServer { get; }
public IAccessServer BaseAccessServer { get; }
Expand All @@ -32,15 +34,15 @@ public TestAccessServer(IAccessServer baseAccessServer)
public async Task<ServerCommand> Server_UpdateStatus(ServerStatus serverStatus)
{
var ret = await _restAccessServer.Server_UpdateStatus(serverStatus);
ret.ConfigCode = ConfigCode;
LastServerStatus = serverStatus;
return ret;
}

public Task<ServerConfig> Server_Configure(ServerInfo serverInfo)
{
LastConfigureTime = DateTime.Now;
if (ConfigCode == serverInfo.ConfigCode)
ConfigCode = null;
LastServerInfo = serverInfo;
LastServerStatus = serverInfo.Status;
return _restAccessServer.Server_Configure(serverInfo);
}

Expand Down
9 changes: 5 additions & 4 deletions VpnHood.ZTest/Tests/ServerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public async Task Reconfigure()
var fileAccessServerOptions = new FileAccessServerOptions { TcpEndPoints = new[] { serverEndPoint } };
using var fileAccessServer = TestHelper.CreateFileAccessServer(fileAccessServerOptions);
var serverConfig = fileAccessServer.ServerConfig;
serverConfig.UpdateStatusInterval = TimeSpan.FromSeconds(1);
serverConfig.UpdateStatusInterval = TimeSpan.FromMilliseconds(500);
serverConfig.TrackingOptions.LogClientIp = true;
serverConfig.TrackingOptions.LogLocalPort = true;
serverConfig.SessionOptions.TcpTimeout = TimeSpan.FromSeconds(2070);
Expand All @@ -81,9 +81,10 @@ public async Task Reconfigure()
Assert.IsTrue(testAccessServer.LastConfigureTime > dateTime);

dateTime = DateTime.Now;
testAccessServer.ConfigCode = Guid.NewGuid();
await Task.Delay(2500);
Assert.IsNull(testAccessServer.ConfigCode);
fileAccessServer.ServerConfig.ConfigCode = Guid.NewGuid().ToString();
await Task.Delay(TimeSpan.FromSeconds(2));

Assert.AreEqual(fileAccessServer.ServerConfig.ConfigCode, testAccessServer.LastServerStatus!.ConfigCode);
Assert.IsTrue(testAccessServer.LastConfigureTime > dateTime);
Assert.IsTrue(server.SessionManager.TrackingOptions.LogClientIp);
Assert.IsTrue(server.SessionManager.TrackingOptions.LogLocalPort);
Expand Down
1 change: 1 addition & 0 deletions VpnHood.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Digi/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=dow_0022_002C_0020St/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Encipherment/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ffff/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Icmp/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ipgroups/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=lastcheck/@EntryIndexedValue">True</s:Boolean>
Expand Down

0 comments on commit 4f76935

Please sign in to comment.