From b758fa3dd5f91518c3ac4475e4ba6940102a76d4 Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Thu, 27 Jan 2022 23:46:59 +0100 Subject: [PATCH] - Add host expiration check to the `HostManager.Remove` method --- HyperbolicDownloader/Networking/HostsManager.cs | 7 +++++-- HyperbolicDownloader/UserInterface/InputHandler.cs | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/HyperbolicDownloader/Networking/HostsManager.cs b/HyperbolicDownloader/Networking/HostsManager.cs index 8f39129..b485bc8 100644 --- a/HyperbolicDownloader/Networking/HostsManager.cs +++ b/HyperbolicDownloader/Networking/HostsManager.cs @@ -34,9 +34,12 @@ internal class HostsManager SaveHosts(); } - public void Remove(NetworkSocket host) + public void Remove(NetworkSocket host, bool forceRemove = false) { - hosts.RemoveAll(x => x.IPAddress == host.IPAddress && x.Port == host.Port); + if (DateTime.Now - host.LastActive >= new TimeSpan(24, 0, 0) || forceRemove) + { + hosts.RemoveAll(x => x.IPAddress == host.IPAddress && x.Port == host.Port); + } SaveHosts(); } diff --git a/HyperbolicDownloader/UserInterface/InputHandler.cs b/HyperbolicDownloader/UserInterface/InputHandler.cs index 6715f5a..f2d50ce 100644 --- a/HyperbolicDownloader/UserInterface/InputHandler.cs +++ b/HyperbolicDownloader/UserInterface/InputHandler.cs @@ -194,7 +194,7 @@ internal class InputHandler if (!validIpAdress) { - hostsManager.Remove(host); + hostsManager.Remove(host, true); continue; } @@ -210,6 +210,7 @@ internal class InputHandler { Console.CursorLeft = 0; ConsoleExt.WriteLine($"{host.IPAddress}:{host.Port} > Inactive", ConsoleColor.Red); + hostsManager.Remove(host); continue; }