Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
trudyhood committed Dec 21, 2022
2 parents a2f558f + 16cc08f commit a6a3c50
Show file tree
Hide file tree
Showing 20 changed files with 93 additions and 2,466 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# v2.6.329
### Server
* Fix: Report CPU Usage on Linux
* Fix: Windows Server Auto Update
* Fix: Windows Auto Install
* Fix: Stop accepting connection on specific errors
* Update: Report more config on start up

# v2.6.327
### Server
* Fix: Error on centos
Expand Down
4 changes: 2 additions & 2 deletions Pub/Version.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Major": 2,
"Minor": 6,
"Build": 328,
"BumpTime": "2022-12-19T10:20:18.3580504Z",
"Build": 329,
"BumpTime": "2022-12-21T20:27:01.6131547Z",
"Prerelease": false
}
6 changes: 3 additions & 3 deletions VpnHood.Client.App.UI/VpnHood.Client.App.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
<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.6.328</Version>
<AssemblyVersion>2.6.328</AssemblyVersion>
<FileVersion>2.6.328</FileVersion>
<Version>2.6.329</Version>
<AssemblyVersion>2.6.329</AssemblyVersion>
<FileVersion>2.6.329</FileVersion>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
</PropertyGroup>
Expand Down
1,860 changes: 0 additions & 1,860 deletions VpnHood.Client.App.Win.Setup/VpnHood.Client.App.Win.Setup.back (1).aip

This file was deleted.

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

This file was deleted.

6 changes: 3 additions & 3 deletions VpnHood.Client.App/VpnHood.Client.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
<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.6.328</Version>
<AssemblyVersion>2.6.328</AssemblyVersion>
<FileVersion>2.6.328</FileVersion>
<Version>2.6.329</Version>
<AssemblyVersion>2.6.329</AssemblyVersion>
<FileVersion>2.6.329</FileVersion>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
<RepositoryUrl>https://github.com/vpnhood/vpnhood</RepositoryUrl>
<PackageIcon>VpnHood.png</PackageIcon>
<Description>VpnHood client device provider for Windows using WinDivert.</Description>
<Version>2.6.328</Version>
<Version>2.6.329</Version>
<PackageId>VpnHood.Client.Device.WinDivert</PackageId>
<Version>1.1.226</Version>
<AssemblyVersion>2.6.328</AssemblyVersion>
<FileVersion>2.6.328</FileVersion>
<AssemblyVersion>2.6.329</AssemblyVersion>
<FileVersion>2.6.329</FileVersion>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
</PropertyGroup>
Expand Down
6 changes: 3 additions & 3 deletions VpnHood.Client.Device/VpnHood.Client.Device.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
<RepositoryType></RepositoryType>
<PackageId>VpnHood.Client.Device</PackageId>
<RootNamespace>VpnHood.Client.Device</RootNamespace>
<Version>2.6.328</Version>
<AssemblyVersion>2.6.328</AssemblyVersion>
<FileVersion>2.6.328</FileVersion>
<Version>2.6.329</Version>
<AssemblyVersion>2.6.329</AssemblyVersion>
<FileVersion>2.6.329</FileVersion>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
</PropertyGroup>
Expand Down
6 changes: 3 additions & 3 deletions VpnHood.Client/VpnHood.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
<Copyright>2022 VpnHood</Copyright>
<PackageId>VpnHood.Client</PackageId>
<PackageTags>VPN VpnClient Proxy</PackageTags>
<Version>2.6.328</Version>
<AssemblyVersion>2.6.328</AssemblyVersion>
<FileVersion>2.6.328</FileVersion>
<Version>2.6.329</Version>
<AssemblyVersion>2.6.329</AssemblyVersion>
<FileVersion>2.6.329</FileVersion>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
</PropertyGroup>
Expand Down
6 changes: 3 additions & 3 deletions VpnHood.Common/VpnHood.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
<PackageId>VpnHood.Common</PackageId>
<PackageIcon>VpnHood.png</PackageIcon>
<Description>VpnHood Common Library is shared among all other VpnHood modules.</Description>
<Version>2.6.328</Version>
<AssemblyVersion>2.6.328</AssemblyVersion>
<FileVersion>2.6.328</FileVersion>
<Version>2.6.329</Version>
<AssemblyVersion>2.6.329</AssemblyVersion>
<FileVersion>2.6.329</FileVersion>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
</PropertyGroup>
Expand Down
6 changes: 3 additions & 3 deletions VpnHood.Server.Access/VpnHood.Server.Access.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
<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.6.328</Version>
<AssemblyVersion>2.6.328</AssemblyVersion>
<FileVersion>2.6.328</FileVersion>
<Version>2.6.329</Version>
<AssemblyVersion>2.6.329</AssemblyVersion>
<FileVersion>2.6.329</FileVersion>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
</PropertyGroup>
Expand Down
1 change: 1 addition & 0 deletions VpnHood.Server.App.Net/Pub/Win/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ if ("$restBaseUrl" -ne "") {
};

# publish info
New-Item -ItemType Directory -Force -Path "$destinationPath/storage";
$appSettings | ConvertTo-Json | Out-File "$destinationPath/storage/appsettings.json";
}

Expand Down
2 changes: 1 addition & 1 deletion VpnHood.Server.App.Net/Pub/Win/updater.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ if ([Version]$localVersion -ge [Version]"$onlineVersion") {

# Install the new version
Write-Output "Installing the latest version...";
& ([scriptblock]::Create((Invoke-WebRequest($onlineInstallScriptUrl)))) -q -autostart;
& ([scriptblock]::Create((Invoke-RestMethod -Uri $onlineInstallScriptUrl))) -q -autostart;
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class LinuxSystemInfoProvider : ISystemInfoProvider
if (memTotalLine == null)
return null;

var tokenize = memTotalLine.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
var tokenize = memTotalLine.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
if (tokenize.Length < 1)
return null;

Expand All @@ -33,6 +33,8 @@ public class LinuxSystemInfoProvider : ISystemInfoProvider
}
}

private long _lastCpuTotalTime;
private long _lastCpuIdleTime;
private int? GetCpuUsage()
{
try
Expand All @@ -58,9 +60,13 @@ public class LinuxSystemInfoProvider : ISystemInfoProvider
var totalTime = userTime + niceTime + systemTime + idleTime + ioWaitTime + irqTime + softIrqTime;

// Calculate the CPU usage
var usage = 100.0 * (totalTime - idleTime) / totalTime;
return (int)usage;
var lapIdleTime = idleTime - _lastCpuIdleTime;
var lapTotalTime = totalTime - _lastCpuTotalTime;
var usage = 100.0 * (lapTotalTime - lapIdleTime) / lapTotalTime;

_lastCpuIdleTime = idleTime;
_lastCpuTotalTime = totalTime;
return (int)usage;
}
catch (Exception ex)
{
Expand Down
6 changes: 3 additions & 3 deletions VpnHood.Server.App.Net/VpnHood.Server.App.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
<RepositoryUrl>https://github.com/vpnhood/vpnhood</RepositoryUrl>
<PackageLicenseExpression>LGPL-2.1-only</PackageLicenseExpression>
<PackageIcon>VpnHood.png</PackageIcon>
<Version>2.6.328</Version>
<AssemblyVersion>2.6.328</AssemblyVersion>
<FileVersion>2.6.328</FileVersion>
<Version>2.6.329</Version>
<AssemblyVersion>2.6.329</AssemblyVersion>
<FileVersion>2.6.329</FileVersion>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
Expand Down
5 changes: 4 additions & 1 deletion VpnHood.Server/SessionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ private void Cleanup()
{
// update all sessions status
var minSessionActivityTime = DateTime.Now - SessionOptions.Timeout;
var timeoutSessions = Sessions.Where(x => x.Value.IsDisposed || x.Value.LastActivityTime < minSessionActivityTime).ToArray();
var timeoutSessions = Sessions
.Where(x => x.Value.IsDisposed || x.Value.LastActivityTime < minSessionActivityTime)
.ToArray();

foreach (var session in timeoutSessions)
{
session.Value.Dispose();
Expand Down
47 changes: 29 additions & 18 deletions VpnHood.Server/TcpHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,32 +131,43 @@ private void EnableKeepAlive(Socket client)
private async Task ListenTask(TcpListener tcpListener, CancellationToken cancellationToken)
{
var localEp = (IPEndPoint)tcpListener.LocalEndpoint;
var errorCounter = 0;
const int maxErrorCount = 200;

try
// Listening for new connection
while (!cancellationToken.IsCancellationRequested)
{
// Listening for new connection
while (!cancellationToken.IsCancellationRequested)
try
{
var tcpClient = await tcpListener.AcceptTcpClientAsync();
EnableKeepAlive(tcpClient.Client);

// create cancellation token
_ = ProcessClient(tcpClient, cancellationToken);
errorCounter = 0;
}
catch (SocketException ex) when (ex.SocketErrorCode == SocketError.OperationAborted)
{
errorCounter++;
}
catch (ObjectDisposedException)
{
errorCounter++;
}
catch (Exception ex)
{
errorCounter++;
VhLogger.Instance.LogError(GeneralEventId.Tcp, ex, "TcpHost could not AcceptTcpClient. ErrorCounter: {ErrorCounter}", errorCounter);
if (errorCounter > maxErrorCount)
{
VhLogger.Instance.LogError("Too many unexpected errors in AcceptTcpClient. Stopping the TcpHost...");
_ = Stop();
}
}
}
catch (SocketException ex) when (ex.SocketErrorCode == SocketError.OperationAborted)
{
}
catch (Exception ex)
{
if (ex is not ObjectDisposedException)
VhLogger.Instance.LogError(ex, $"{nameof(TcpHost)} Could not AcceptTcpClient.");
}
finally
{
tcpListener.Stop();
VhLogger.Instance.LogInformation($"Stop listening on {VhLogger.Format(localEp)}");
}

tcpListener.Stop();
VhLogger.Instance.LogInformation($"Listening on {VhLogger.Format(localEp)} has been stopped.");
}

private static async Task<SslStream> AuthenticateAsServerAsync(TcpClient tcpClient, X509Certificate certificate,
Expand Down Expand Up @@ -452,7 +463,7 @@ private async Task ProcessTcpProxyChannel(TcpClientStream tcpClientStream, Cance
EnableKeepAlive(tcpClient2.Client);

//tracking
session.LogTrack(ProtocolType.Tcp.ToString(),
session.LogTrack(ProtocolType.Tcp.ToString(),
((IPEndPoint)tcpClient2.Client.LocalEndPoint).Port, request.DestinationEndPoint);

// connect to requested destination
Expand Down Expand Up @@ -489,7 +500,7 @@ await Util.RunTask(
tcpClient2?.Dispose();
tcpClientStream2?.Dispose();
tcpProxyChannel?.Dispose();

if (isRequestedEpException)
throw new SessionException(SessionErrorCode.GeneralError, ex.Message);

Expand Down
6 changes: 3 additions & 3 deletions VpnHood.Server/VpnHood.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
<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.6.328</Version>
<AssemblyVersion>2.6.328</AssemblyVersion>
<FileVersion>2.6.328</FileVersion>
<Version>2.6.329</Version>
<AssemblyVersion>2.6.329</AssemblyVersion>
<FileVersion>2.6.329</FileVersion>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
</PropertyGroup>
Expand Down
15 changes: 9 additions & 6 deletions VpnHood.Server/VpnHoodServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public VpnHoodServer(IAccessServer accessServer, ServerOptions options)
MaxTcpConnectWaitCount = options.MaxTcpConnectWaitCount,
MaxTcpChannelCount = options.MaxTcpChannelCount
};

// Configure thread pool size
ThreadPool.GetMinThreads(out var workerThreads, out var completionPortThreads);
ThreadPool.SetMinThreads(workerThreads, completionPortThreads * 30);
Expand Down Expand Up @@ -120,6 +120,10 @@ public async Task Start()
VhLogger.Instance.LogInformation($"OS: {SystemInfoProvider.GetSystemInfo()}");

// report config
VhLogger.Instance.LogInformation(
"TcpConnectTimeout: {TcpConnectTimeout}, MaxTcpConnectWaitCount: {MaxTcpConnectWaitCount}, MaxTcpChannelCount: {MaxTcpChannelCount}",
_tcpHost.TcpConnectTimeout, _tcpHost.MaxTcpConnectWaitCount, _tcpHost.MaxTcpChannelCount);

ThreadPool.GetMinThreads(out var minWorkerThreads, out var minCompletionPortThreads);
ThreadPool.GetMaxThreads(out var maxWorkerThreads, out var maxCompletionPortThreads);
VhLogger.Instance.LogInformation(
Expand Down Expand Up @@ -167,12 +171,11 @@ private async Task Configure()
VhLogger.Instance.LogTrace("Sending config request to the Access Server...");
var serverConfig = await ReadConfig(serverInfo);
VhLogger.Instance.LogInformation($"ServerConfig: {JsonSerializer.Serialize(serverConfig)}");
var tcpBufferSize = serverConfig.SessionOptions.TcpBufferSize == 0 ? GetBestTcpBufferSize(serverInfo.TotalMemory) : serverConfig.SessionOptions.TcpBufferSize;
SessionManager.TrackingOptions = serverConfig.TrackingOptions;
SessionManager.SessionOptions = serverConfig.SessionOptions;
_tcpHost.OrgStreamReadBufferSize = serverConfig.SessionOptions.TcpBufferSize == 0
? GetBestTcpBufferSize(serverInfo.TotalMemory) : serverConfig.SessionOptions.TcpBufferSize;
_tcpHost.TunnelStreamReadBufferSize = serverConfig.SessionOptions.TcpBufferSize == 0
? GetBestTcpBufferSize(serverInfo.TotalMemory) : serverConfig.SessionOptions.TcpBufferSize;
_tcpHost.OrgStreamReadBufferSize = tcpBufferSize;
_tcpHost.TunnelStreamReadBufferSize = tcpBufferSize;
_tcpHost.TcpTimeout = serverConfig.SessionOptions.TcpTimeout;
_lastConfigCode = serverConfig.ConfigCode;

Expand Down Expand Up @@ -279,7 +282,7 @@ private async Task SendStatusToAccessServer()
var res = await AccessServer.Server_UpdateStatus(Status);

// reconfigure
if (res.ConfigCode != _lastConfigCode)
if (res.ConfigCode != _lastConfigCode || !_tcpHost.IsStarted)
{
VhLogger.Instance.LogInformation("Reconfiguration was requested.");
_ = Configure();
Expand Down
6 changes: 3 additions & 3 deletions VpnHood.Tunneling/VpnHood.Tunneling.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
<PackageIcon>VpnHood.png</PackageIcon>
<Product>VpnHood.Tunneling</Product>
<Description>Provides tunnelling classes and protocols shared between VpnHood.Client and VpnHood.Server.</Description>
<Version>2.6.328</Version>
<AssemblyVersion>2.6.328</AssemblyVersion>
<FileVersion>2.6.328</FileVersion>
<Version>2.6.329</Version>
<AssemblyVersion>2.6.329</AssemblyVersion>
<FileVersion>2.6.329</FileVersion>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
</PropertyGroup>
Expand Down

0 comments on commit a6a3c50

Please sign in to comment.