Skip to content

Commit

Permalink
merge Config; fix TCP buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
trudyhood committed Feb 16, 2023
1 parent 461c5fb commit 31f7fef
Show file tree
Hide file tree
Showing 21 changed files with 115 additions and 43 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Upcoming
### Server
* Farture: Merge Server Configuration
* Fix: Setting TCP kernel buffer

# v2.7.350
### Client
* Feature: Follow server-supported networks by IP range
Expand Down
6 changes: 3 additions & 3 deletions Pub/Version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Version": "2.7.350",
"BumpTime": "2023-02-13T21:10:19.5187587Z",
"Prerelease": false,
"Version": "2.7.351",
"BumpTime": "2023-02-16T10:04:31.2844324Z",
"Prerelease": true,
"DeprecatedVersion": "2.0.0"
}
4 changes: 2 additions & 2 deletions VpnHood.Client.App.UI/VpnHood.Client.App.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<PackageIcon>VpnHood.png</PackageIcon>
<Description>Tiny internal webserver to server your single-page application (SPA). You need this only if you want to create a UI for your VpnHood client by single-page application (SPA).</Description>
<PackageId>VpnHood.Client.App.UI</PackageId>
<Version>2.7.350</Version>
<AssemblyVersion>2.7.350</AssemblyVersion>
<Version>2.7.351</Version>
<AssemblyVersion>2.7.351</AssemblyVersion>
<FileVersion>$([System.DateTime]::Now.ToString("yyyy.M.d.HHmm"))</FileVersion>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
Expand Down
4 changes: 2 additions & 2 deletions VpnHood.Client.App.Win/VpnHood.Client.App.Win.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
<PackageIcon>VpnHood.png</PackageIcon>
<PackageId>VpnHood.Client.App.Win</PackageId>
<StartupObject></StartupObject>
<Version>2.7.350</Version>
<AssemblyVersion>2.7.350</AssemblyVersion>
<Version>2.7.351</Version>
<AssemblyVersion>2.7.351</AssemblyVersion>
<FileVersion>$([System.DateTime]::Now.ToString("yyyy.M.d.HHmm"))</FileVersion>
<Nullable>enable</Nullable>
<LangVersion>11</LangVersion>
Expand Down
4 changes: 2 additions & 2 deletions VpnHood.Client.App/VpnHood.Client.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<RepositoryUrl>https://github.com/vpnhood/vpnhood</RepositoryUrl>
<Description>Readymade Vpn App skeleton for VpnHood clients. You just need to create a UI on it.</Description>
<PackageId>VpnHood.Client.App</PackageId>
<Version>2.7.350</Version>
<AssemblyVersion>2.7.350</AssemblyVersion>
<Version>2.7.351</Version>
<AssemblyVersion>2.7.351</AssemblyVersion>
<FileVersion>$([System.DateTime]::Now.ToString("yyyy.M.d.HHmm"))</FileVersion>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
<RepositoryUrl>https://github.com/vpnhood/vpnhood</RepositoryUrl>
<PackageIcon>VpnHood.png</PackageIcon>
<Description>VpnHood client device provider for Windows using WinDivert.</Description>
<Version>2.7.350</Version>
<Version>2.7.351</Version>
<PackageId>VpnHood.Client.Device.WinDivert</PackageId>
<Version>1.1.226</Version>
<AssemblyVersion>2.7.350</AssemblyVersion>
<AssemblyVersion>2.7.351</AssemblyVersion>
<FileVersion>$([System.DateTime]::Now.ToString("yyyy.M.d.HHmm"))</FileVersion>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
Expand Down
4 changes: 2 additions & 2 deletions VpnHood.Client.Device/VpnHood.Client.Device.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<RepositoryType></RepositoryType>
<PackageId>VpnHood.Client.Device</PackageId>
<RootNamespace>VpnHood.Client.Device</RootNamespace>
<Version>2.7.350</Version>
<AssemblyVersion>2.7.350</AssemblyVersion>
<Version>2.7.351</Version>
<AssemblyVersion>2.7.351</AssemblyVersion>
<FileVersion>$([System.DateTime]::Now.ToString("yyyy.M.d.HHmm"))</FileVersion>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
Expand Down
4 changes: 2 additions & 2 deletions VpnHood.Client/VpnHood.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<Copyright>2022 VpnHood</Copyright>
<PackageId>VpnHood.Client</PackageId>
<PackageTags>VPN VpnClient Proxy</PackageTags>
<Version>2.7.350</Version>
<AssemblyVersion>2.7.350</AssemblyVersion>
<Version>2.7.351</Version>
<AssemblyVersion>2.7.351</AssemblyVersion>
<FileVersion>$([System.DateTime]::Now.ToString("yyyy.M.d.HHmm"))</FileVersion>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
Expand Down
4 changes: 2 additions & 2 deletions VpnHood.Common/VpnHood.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<PackageId>VpnHood.Common</PackageId>
<PackageIcon>VpnHood.png</PackageIcon>
<Description>VpnHood Common Library is shared among all other VpnHood modules.</Description>
<Version>2.7.350</Version>
<AssemblyVersion>2.7.350</AssemblyVersion>
<Version>2.7.351</Version>
<AssemblyVersion>2.7.351</AssemblyVersion>
<FileVersion>$([System.DateTime]::Now.ToString("yyyy.M.d.HHmm"))</FileVersion>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
Expand Down
4 changes: 4 additions & 0 deletions VpnHood.Server.Access/Configurations/NetFilterOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,9 @@ public void Merge(NetFilterOptions obj)
if (obj.IncludeIpRanges != null) IncludeIpRanges = obj.IncludeIpRanges;
if (obj.ExcludeIpRanges != null) ExcludeIpRanges = obj.ExcludeIpRanges;
}
public void ApplyDefaults()
{
ExcludeLocalNetwork = ExcludeLocalNetworkValue;
}

}
19 changes: 15 additions & 4 deletions VpnHood.Server.Access/Configurations/ServerConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public class ServerConfig

[JsonConverter(typeof(TimeSpanConverter))]
public TimeSpan? UpdateStatusInterval { get; set; }
public int? MinCompletionPortThreads { get; set; }
public int? MaxCompletionPortThreads { get; set; }
public bool? LogAnonymizer { get; set; }
public bool? AllowIpV6 { get; set; }
public string ConfigCode { get; set; } = string.Empty;
public int? MinCompletionPortThreads { get; set; }
public int? MaxCompletionPortThreads { get; set; }

// Inherit
[JsonIgnore] public IPEndPoint[] TcpEndPointsValue => TcpEndPoints ?? new IPEndPoint[] { new(IPAddress.Any, 443), new(IPAddress.IPv6Any, 443) };
Expand All @@ -40,9 +40,20 @@ public void Merge(ServerConfig obj)
NetFilterOptions.Merge(obj.NetFilterOptions);
if (obj.TcpEndPoints != null) TcpEndPoints = obj.TcpEndPoints;
if (obj.UpdateStatusInterval != null) UpdateStatusInterval = obj.UpdateStatusInterval;
if (obj.MinCompletionPortThreads != null) MinCompletionPortThreads = obj.MinCompletionPortThreads;
if (obj.MaxCompletionPortThreads != null) MaxCompletionPortThreads = obj.MaxCompletionPortThreads;
if (obj.LogAnonymizer != null) LogAnonymizer = obj.LogAnonymizer;
if (obj.AllowIpV6 != null) AllowIpV6 = obj.AllowIpV6;
if (obj.MinCompletionPortThreads != null) MinCompletionPortThreads = obj.MinCompletionPortThreads;
if (obj.MaxCompletionPortThreads != null) MaxCompletionPortThreads = obj.MaxCompletionPortThreads;
}

public void ApplyDefaults()
{
TrackingOptions.ApplyDefaults();
SessionOptions.ApplyDefaults();
NetFilterOptions.ApplyDefaults();
TcpEndPoints = TcpEndPointsValue;
UpdateStatusInterval = UpdateStatusIntervalValue;
LogAnonymizer = LogAnonymizerValue;
AllowIpV6 = AllowIpV6Value;
}
}
19 changes: 19 additions & 0 deletions VpnHood.Server.Access/Configurations/SessionOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,23 @@ public void Merge(SessionOptions obj)
if (obj.NetScanTimeout != null) NetScanTimeout = obj.NetScanTimeout;
if (obj.UseUdpProxy2 != null) UseUdpProxy2 = obj.UseUdpProxy2;
}

public void ApplyDefaults()
{
Timeout = TimeoutValue;
UdpTimeout = UdpTimeoutValue;
TcpTimeout = TcpTimeoutValue;
IcmpTimeout = IcmpTimeoutValue;
SyncInterval = SyncIntervalValue;
SyncCacheSize = SyncCacheSizeValue;
MaxDatagramChannelCount = MaxDatagramChannelCountValue;
MaxUdpPortCount = MaxUdpPortCountValue;
TcpBufferSize = TcpBufferSize;
TcpConnectTimeout = TcpConnectTimeoutValue;
MaxTcpConnectWaitCount = MaxTcpConnectWaitCountValue;
MaxTcpChannelCount = MaxTcpChannelCountValue;
NetScanLimit = NetScanLimit;
NetScanTimeout = NetScanTimeout;
UseUdpProxy2 = UseUdpProxy2Value;
}
}
12 changes: 12 additions & 0 deletions VpnHood.Server.Access/Configurations/TrackingOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,16 @@ public void Merge(TrackingOptions obj)
if (obj.TrackTcp != null) TrackTcp = obj.TrackTcp;
if (obj.TrackIcmp != null) TrackIcmp = obj.TrackIcmp;
}

public void ApplyDefaults()
{
TrackClientIp = TrackClientIpValue;
TrackLocalPort = TrackLocalPortValue;
TrackDestinationIp = TrackDestinationIpValue;
TrackDestinationPort = TrackDestinationPortValue;
TrackUdp = TrackUdpValue;
TrackTcp = TrackTcpValue;
TrackIcmp = TrackIcmpValue;
}

}
4 changes: 2 additions & 2 deletions VpnHood.Server.Access/VpnHood.Server.Access.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<PackageId>VpnHood.Server.Access</PackageId>
<PackageIcon>VpnHood.png</PackageIcon>
<Description>Stores, and retrieves end users' access and usage. Provides required interfaces and classes to use or create an access server and accounting.</Description>
<Version>2.7.350</Version>
<AssemblyVersion>2.7.350</AssemblyVersion>
<Version>2.7.351</Version>
<AssemblyVersion>2.7.351</AssemblyVersion>
<FileVersion>$([System.DateTime]::Now.ToString("yyyy.M.d.HHmm"))</FileVersion>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
Expand Down
1 change: 0 additions & 1 deletion VpnHood.Server.App.Net/ServerApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using VpnHood.Common.Trackers;
using VpnHood.Common.Utils;
using VpnHood.Server.App.SystemInformation;
using VpnHood.Server.Configurations;
using VpnHood.Server.Providers.FileAccessServerProvider;
using VpnHood.Server.Providers.HttpAccessServerProvider;
using VpnHood.Server.SystemInformation;
Expand Down
4 changes: 2 additions & 2 deletions VpnHood.Server.App.Net/VpnHood.Server.App.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<RepositoryUrl>https://github.com/vpnhood/vpnhood</RepositoryUrl>
<PackageLicenseExpression>LGPL-2.1-only</PackageLicenseExpression>
<PackageIcon>VpnHood.png</PackageIcon>
<Version>2.7.350</Version>
<AssemblyVersion>2.7.350</AssemblyVersion>
<Version>2.7.351</Version>
<AssemblyVersion>2.7.351</AssemblyVersion>
<FileVersion>$([System.DateTime]::Now.ToString("yyyy.M.d.HHmm"))</FileVersion>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
Expand Down
4 changes: 2 additions & 2 deletions VpnHood.Server/VpnHood.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<PackageIcon>VpnHood.png</PackageIcon>
<Description>The core of VpnHood server. It can listen and accept connections from VpnHood clients.</Description>
<PackageId>VpnHood.Server</PackageId>
<Version>2.7.350</Version>
<AssemblyVersion>2.7.350</AssemblyVersion>
<Version>2.7.351</Version>
<AssemblyVersion>2.7.351</AssemblyVersion>
<FileVersion>$([System.DateTime]::Now.ToString("yyyy.M.d.HHmm"))</FileVersion>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
Expand Down
33 changes: 21 additions & 12 deletions VpnHood.Server/VpnHoodServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,6 @@ private async Task Configure()
// get configuration from access server
VhLogger.Instance.LogTrace("Sending config request to the Access Server...");
var serverConfig = await ReadConfig(serverInfo);
VhLogger.Instance.LogInformation($"ServerConfig: {JsonSerializer.Serialize(serverConfig, new JsonSerializerOptions { WriteIndented = true })}");
serverConfig.SessionOptions.TcpBufferSize = GetBestTcpBufferSize(serverInfo.TotalMemory, serverConfig.SessionOptions.TcpBufferSize);
SessionManager.TrackingOptions = serverConfig.TrackingOptions;
SessionManager.SessionOptions = serverConfig.SessionOptions;
JobSection.Interval = serverConfig.UpdateStatusIntervalValue;
Expand All @@ -169,7 +167,7 @@ private async Task Configure()
var verb = _tcpHost.IsStarted ? "Restarting" : "Starting";
VhLogger.Instance.LogInformation($"{verb} {VhLogger.FormatType(_tcpHost)}...");
if (_tcpHost.IsStarted) await _tcpHost.Stop();
_tcpHost.Start(serverConfig.TcpEndPointsValue, isIpV6Supported && serverConfig.AllowIpV6Value);
_tcpHost.Start(serverConfig.TcpEndPointsValue, isIpV6Supported && serverConfig.AllowIpV6Value);

// set config status
State = ServerState.Ready;
Expand Down Expand Up @@ -232,21 +230,32 @@ private static int GetBestTcpBufferSize(long? totalMemory, int? configValue)
}

private async Task<ServerConfig> ReadConfig(ServerInfo serverInfo)
{
var serverConfig = await ReadConfigImpl(serverInfo);
serverConfig.SessionOptions.TcpBufferSize = GetBestTcpBufferSize(serverInfo.TotalMemory, serverConfig.SessionOptions.TcpBufferSize);
serverConfig.ApplyDefaults();
VhLogger.Instance.LogInformation($"RemoteConfig: {JsonSerializer.Serialize(serverConfig, new JsonSerializerOptions { WriteIndented = true })}");

if (_config != null)
{
_config.ConfigCode = serverConfig.ConfigCode;
serverConfig.Merge(_config);
VhLogger.Instance.LogWarning("Remote configuration has been overwritten by the local settings.");
VhLogger.Instance.LogInformation($"RemoteConfig: {JsonSerializer.Serialize(serverConfig, new JsonSerializerOptions { WriteIndented = true })}");
}

// override defaults

return serverConfig;
}

private async Task<ServerConfig> ReadConfigImpl(ServerInfo serverInfo)
{
try
{
var serverConfig = await AccessServer.Server_Configure(serverInfo);
try { await File.WriteAllTextAsync(_lastConfigFilePath, JsonSerializer.Serialize(serverConfig)); }
catch { /* Ignore */ }

if (_config != null)
{
VhLogger.Instance.LogInformation($"RemoteConfig: {JsonSerializer.Serialize(serverConfig, new JsonSerializerOptions { WriteIndented = true })}");
VhLogger.Instance.LogWarning("Remote configuration has been overwritten by the local settings.");
_config.ConfigCode = serverConfig.ConfigCode;
return _config;
}

return serverConfig;
}
catch (MaintenanceException)
Expand Down
2 changes: 2 additions & 0 deletions VpnHood.Tunneling/TcpProxyChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public TcpProxyChannel(TcpClientStream orgTcpClientStream, TcpClientStream tunne
$"Value must be greater or equal than {BufferSizeMin} and less than {BufferSizeMax}");

// We don't know about client or server delay, so lets pessimistic
orgTcpClientStream.TcpClient.ReceiveBufferSize = _orgStreamReadBufferSize;
orgTcpClientStream.TcpClient.NoDelay = true;
tunnelTcpClientStream.TcpClient.ReceiveBufferSize = _tunnelStreamReadBufferSize;
tunnelTcpClientStream.TcpClient.NoDelay = true;

JobSection = new JobSection(tcpTimeout);
Expand Down
4 changes: 2 additions & 2 deletions VpnHood.Tunneling/VpnHood.Tunneling.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<PackageIcon>VpnHood.png</PackageIcon>
<Product>VpnHood.Tunneling</Product>
<Description>Provides tunnelling classes and protocols shared between VpnHood.Client and VpnHood.Server.</Description>
<Version>2.7.350</Version>
<AssemblyVersion>2.7.350</AssemblyVersion>
<Version>2.7.351</Version>
<AssemblyVersion>2.7.351</AssemblyVersion>
<FileVersion>$([System.DateTime]::Now.ToString("yyyy.M.d.HHmm"))</FileVersion>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
Expand Down
13 changes: 12 additions & 1 deletion VpnHood.ZTest/Tests/AccessTest.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using VpnHood.Client;
using VpnHood.Common.Logging;
using VpnHood.Common.Messaging;
using VpnHood.Common.Net;
using VpnHood.Server.Configurations;

namespace VpnHood.Test.Tests;
Expand All @@ -18,6 +18,17 @@ public class AccessTest
public async Task Foo()
{
await Task.Delay(100);

var serverConfig = new ServerConfig();
serverConfig.ApplyDefaults();
var s = JsonSerializer.Serialize(serverConfig, new JsonSerializerOptions
{
IgnoreReadOnlyProperties= false,
WriteIndented= true,
});

Console.WriteLine(s);

}

[TestInitialize]
Expand Down

0 comments on commit 31f7fef

Please sign in to comment.