diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bf37f3b1..9b5242a0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Pub/Version.json b/Pub/Version.json index e22be8035..bf4e85026 100644 --- a/Pub/Version.json +++ b/Pub/Version.json @@ -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 } diff --git a/VpnHood.Client.App.UI/VpnHood.Client.App.UI.csproj b/VpnHood.Client.App.UI/VpnHood.Client.App.UI.csproj index f5de5eed2..50d35d975 100644 --- a/VpnHood.Client.App.UI/VpnHood.Client.App.UI.csproj +++ b/VpnHood.Client.App.UI/VpnHood.Client.App.UI.csproj @@ -12,9 +12,9 @@ VpnHood.png 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). VpnHood.Client.App.UI - 2.6.328 - 2.6.328 - 2.6.328 + 2.6.329 + 2.6.329 + 2.6.329 enable latest diff --git a/VpnHood.Client.App.Win.Setup/VpnHood.Client.App.Win.Setup.back (1).aip b/VpnHood.Client.App.Win.Setup/VpnHood.Client.App.Win.Setup.back (1).aip deleted file mode 100644 index 8f8b54d72..000000000 --- a/VpnHood.Client.App.Win.Setup/VpnHood.Client.App.Win.Setup.back (1).aip +++ /dev/null @@ -1,1860 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/VpnHood.Client.App.Win.Setup/VpnHood.Client.App.Win.Setup.back.aip b/VpnHood.Client.App.Win.Setup/VpnHood.Client.App.Win.Setup.back.aip deleted file mode 100644 index 463a7e2e2..000000000 --- a/VpnHood.Client.App.Win.Setup/VpnHood.Client.App.Win.Setup.back.aip +++ /dev/null @@ -1,545 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/VpnHood.Client.App/VpnHood.Client.App.csproj b/VpnHood.Client.App/VpnHood.Client.App.csproj index a9bce033e..d30ac4cbc 100644 --- a/VpnHood.Client.App/VpnHood.Client.App.csproj +++ b/VpnHood.Client.App/VpnHood.Client.App.csproj @@ -11,9 +11,9 @@ https://github.com/vpnhood/vpnhood Readymade Vpn App skeleton for VpnHood clients. You just need to create a UI on it. VpnHood.Client.App - 2.6.328 - 2.6.328 - 2.6.328 + 2.6.329 + 2.6.329 + 2.6.329 enable latest diff --git a/VpnHood.Client.Device.WinDivert/VpnHood.Client.Device.WinDivert.csproj b/VpnHood.Client.Device.WinDivert/VpnHood.Client.Device.WinDivert.csproj index 20345c29e..335a8f593 100644 --- a/VpnHood.Client.Device.WinDivert/VpnHood.Client.Device.WinDivert.csproj +++ b/VpnHood.Client.Device.WinDivert/VpnHood.Client.Device.WinDivert.csproj @@ -9,11 +9,11 @@ https://github.com/vpnhood/vpnhood VpnHood.png VpnHood client device provider for Windows using WinDivert. - 2.6.328 + 2.6.329 VpnHood.Client.Device.WinDivert 1.1.226 - 2.6.328 - 2.6.328 + 2.6.329 + 2.6.329 enable latest diff --git a/VpnHood.Client.Device/VpnHood.Client.Device.csproj b/VpnHood.Client.Device/VpnHood.Client.Device.csproj index db7117ac9..44295288a 100644 --- a/VpnHood.Client.Device/VpnHood.Client.Device.csproj +++ b/VpnHood.Client.Device/VpnHood.Client.Device.csproj @@ -14,9 +14,9 @@ VpnHood.Client.Device VpnHood.Client.Device - 2.6.328 - 2.6.328 - 2.6.328 + 2.6.329 + 2.6.329 + 2.6.329 enable latest diff --git a/VpnHood.Client/VpnHood.Client.csproj b/VpnHood.Client/VpnHood.Client.csproj index c3c58d379..b9539df7b 100644 --- a/VpnHood.Client/VpnHood.Client.csproj +++ b/VpnHood.Client/VpnHood.Client.csproj @@ -13,9 +13,9 @@ 2022 VpnHood VpnHood.Client VPN VpnClient Proxy - 2.6.328 - 2.6.328 - 2.6.328 + 2.6.329 + 2.6.329 + 2.6.329 enable latest diff --git a/VpnHood.Common/VpnHood.Common.csproj b/VpnHood.Common/VpnHood.Common.csproj index ff1ce36c5..95111cf40 100644 --- a/VpnHood.Common/VpnHood.Common.csproj +++ b/VpnHood.Common/VpnHood.Common.csproj @@ -12,9 +12,9 @@ VpnHood.Common VpnHood.png VpnHood Common Library is shared among all other VpnHood modules. - 2.6.328 - 2.6.328 - 2.6.328 + 2.6.329 + 2.6.329 + 2.6.329 enable latest diff --git a/VpnHood.Server.Access/VpnHood.Server.Access.csproj b/VpnHood.Server.Access/VpnHood.Server.Access.csproj index 3919b9dd9..951424eca 100644 --- a/VpnHood.Server.Access/VpnHood.Server.Access.csproj +++ b/VpnHood.Server.Access/VpnHood.Server.Access.csproj @@ -12,9 +12,9 @@ VpnHood.Server.Access VpnHood.png Stores, and retrieves end users' access and usage. Provides required interfaces and classes to use or create an access server and accounting. - 2.6.328 - 2.6.328 - 2.6.328 + 2.6.329 + 2.6.329 + 2.6.329 enable latest diff --git a/VpnHood.Server.App.Net/Pub/Win/install.ps1 b/VpnHood.Server.App.Net/Pub/Win/install.ps1 index 1bc6145a5..e93c0639f 100644 --- a/VpnHood.Server.App.Net/Pub/Win/install.ps1 +++ b/VpnHood.Server.App.Net/Pub/Win/install.ps1 @@ -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"; } diff --git a/VpnHood.Server.App.Net/Pub/Win/updater.ps1 b/VpnHood.Server.App.Net/Pub/Win/updater.ps1 index 1c45d0979..5a40f28d9 100644 --- a/VpnHood.Server.App.Net/Pub/Win/updater.ps1 +++ b/VpnHood.Server.App.Net/Pub/Win/updater.ps1 @@ -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; diff --git a/VpnHood.Server.App.Net/SystemInformation/LinuxSystemInfoProvider.cs b/VpnHood.Server.App.Net/SystemInformation/LinuxSystemInfoProvider.cs index 1f563c066..a71f5d0ac 100644 --- a/VpnHood.Server.App.Net/SystemInformation/LinuxSystemInfoProvider.cs +++ b/VpnHood.Server.App.Net/SystemInformation/LinuxSystemInfoProvider.cs @@ -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; @@ -33,6 +33,8 @@ public class LinuxSystemInfoProvider : ISystemInfoProvider } } + private long _lastCpuTotalTime; + private long _lastCpuIdleTime; private int? GetCpuUsage() { try @@ -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) { diff --git a/VpnHood.Server.App.Net/VpnHood.Server.App.Net.csproj b/VpnHood.Server.App.Net/VpnHood.Server.App.Net.csproj index 12e19bbe6..170092cf0 100644 --- a/VpnHood.Server.App.Net/VpnHood.Server.App.Net.csproj +++ b/VpnHood.Server.App.Net/VpnHood.Server.App.Net.csproj @@ -12,9 +12,9 @@ https://github.com/vpnhood/vpnhood LGPL-2.1-only VpnHood.png - 2.6.328 - 2.6.328 - 2.6.328 + 2.6.329 + 2.6.329 + 2.6.329 enable latest Linux diff --git a/VpnHood.Server/SessionManager.cs b/VpnHood.Server/SessionManager.cs index c1566db29..4f76f3cd8 100644 --- a/VpnHood.Server/SessionManager.cs +++ b/VpnHood.Server/SessionManager.cs @@ -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(); diff --git a/VpnHood.Server/TcpHost.cs b/VpnHood.Server/TcpHost.cs index 32f395a39..f2cddf39e 100644 --- a/VpnHood.Server/TcpHost.cs +++ b/VpnHood.Server/TcpHost.cs @@ -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 AuthenticateAsServerAsync(TcpClient tcpClient, X509Certificate certificate, @@ -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 @@ -489,7 +500,7 @@ await Util.RunTask( tcpClient2?.Dispose(); tcpClientStream2?.Dispose(); tcpProxyChannel?.Dispose(); - + if (isRequestedEpException) throw new SessionException(SessionErrorCode.GeneralError, ex.Message); diff --git a/VpnHood.Server/VpnHood.Server.csproj b/VpnHood.Server/VpnHood.Server.csproj index 498f39526..33b3dccb6 100644 --- a/VpnHood.Server/VpnHood.Server.csproj +++ b/VpnHood.Server/VpnHood.Server.csproj @@ -13,9 +13,9 @@ VpnHood.png The core of VpnHood server. It can listen and accept connections from VpnHood clients. VpnHood.Server - 2.6.328 - 2.6.328 - 2.6.328 + 2.6.329 + 2.6.329 + 2.6.329 enable latest diff --git a/VpnHood.Server/VpnHoodServer.cs b/VpnHood.Server/VpnHoodServer.cs index 7bd5dc124..b74e3fa8d 100644 --- a/VpnHood.Server/VpnHoodServer.cs +++ b/VpnHood.Server/VpnHoodServer.cs @@ -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); @@ -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( @@ -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; @@ -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(); diff --git a/VpnHood.Tunneling/VpnHood.Tunneling.csproj b/VpnHood.Tunneling/VpnHood.Tunneling.csproj index 2598b8598..e53796eaa 100644 --- a/VpnHood.Tunneling/VpnHood.Tunneling.csproj +++ b/VpnHood.Tunneling/VpnHood.Tunneling.csproj @@ -15,9 +15,9 @@ VpnHood.png VpnHood.Tunneling Provides tunnelling classes and protocols shared between VpnHood.Client and VpnHood.Server. - 2.6.328 - 2.6.328 - 2.6.328 + 2.6.329 + 2.6.329 + 2.6.329 enable latest