mirror of
https://github.com/Stone-Red-Code/HyperbolicDownloader.git
synced 2026-09-04 00:56:09 +02:00
Update naming and add auto retry if hash is wrong
This commit is contained in:
@@ -9,12 +9,12 @@ public class ClientCommands
|
||||
{
|
||||
if (ApiManager.PublicIpAddress is not null)
|
||||
{
|
||||
ApiManager.SendMessageNewLine($"The public IP address is: {ApiManager.PublicIpAddress}", NotificationMessageType.Info);
|
||||
ApiManager.SendMessageNewLine($"The public port is: {ApiConfiguration.PublicPort}", NotificationMessageType.Info);
|
||||
ApiManager.SendMessageNewLine(string.Empty, NotificationMessageType.Info);
|
||||
ApiManager.SendNotificationMessageNewLine($"The public IP address is: {ApiManager.PublicIpAddress}", NotificationMessageType.Info);
|
||||
ApiManager.SendNotificationMessageNewLine($"The public port is: {ApiConfiguration.PublicPort}", NotificationMessageType.Info);
|
||||
ApiManager.SendNotificationMessageNewLine(string.Empty, NotificationMessageType.Info);
|
||||
}
|
||||
|
||||
ApiManager.SendMessageNewLine($"The private IP address is: {NetworkUtilities.GetIP4Adress()}", NotificationMessageType.Info);
|
||||
ApiManager.SendMessageNewLine($"The private port is: {ApiConfiguration.PrivatePort}", NotificationMessageType.Info);
|
||||
ApiManager.SendNotificationMessageNewLine($"The private IP address is: {NetworkUtilities.GetIP4Adress()}", NotificationMessageType.Info);
|
||||
ApiManager.SendNotificationMessageNewLine($"The private port is: {ApiConfiguration.PrivatePort}", NotificationMessageType.Info);
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ public class DownloadCommands
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(path))
|
||||
{
|
||||
ApiManager.SendMessageNewLine("Path is empty!", NotificationMessageType.Error);
|
||||
ApiManager.SendNotificationMessageNewLine("Path is empty!", NotificationMessageType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public class DownloadCommands
|
||||
|
||||
if (!File.Exists(fullPath))
|
||||
{
|
||||
ApiManager.SendMessageNewLine("Invalid file path!", NotificationMessageType.Error);
|
||||
ApiManager.SendNotificationMessageNewLine("Invalid file path!", NotificationMessageType.Error);
|
||||
}
|
||||
|
||||
string json = File.ReadAllText(fullPath);
|
||||
@@ -43,7 +43,7 @@ public class DownloadCommands
|
||||
PublicHyperFileInfo? publicHyperFileInfo = JsonSerializer.Deserialize<PublicHyperFileInfo>(json);
|
||||
if (publicHyperFileInfo == null)
|
||||
{
|
||||
ApiManager.SendMessageNewLine("Parsing file failed!", NotificationMessageType.Error);
|
||||
ApiManager.SendNotificationMessageNewLine("Parsing file failed!", NotificationMessageType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public class DownloadCommands
|
||||
{
|
||||
if (string.IsNullOrEmpty(hash))
|
||||
{
|
||||
ApiManager.SendMessageNewLine("No hash value specified!", NotificationMessageType.Error);
|
||||
ApiManager.SendNotificationMessageNewLine("No hash value specified!", NotificationMessageType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public class DownloadCommands
|
||||
continue;
|
||||
}
|
||||
|
||||
ApiManager.SendMessage($"{host.IPAddress}:{host.Port} > ???", NotificationMessageType.Warning);
|
||||
ApiManager.SendNotificationMessage($"{host.IPAddress}:{host.Port} > ???", NotificationMessageType.Warning);
|
||||
|
||||
Console.CursorLeft = 0;
|
||||
|
||||
@@ -82,7 +82,7 @@ public class DownloadCommands
|
||||
if (!sendTask.IsCompletedSuccessfully)
|
||||
{
|
||||
Console.CursorLeft = 0;
|
||||
ApiManager.SendMessageNewLine($"{host.IPAddress}:{host.Port} > Inactive", NotificationMessageType.Error);
|
||||
ApiManager.SendNotificationMessageNewLine($"{host.IPAddress}:{host.Port} > Inactive", NotificationMessageType.Error);
|
||||
|
||||
hostsManager.Remove(host);
|
||||
continue;
|
||||
@@ -90,14 +90,14 @@ public class DownloadCommands
|
||||
else if (!sendTask.Result)
|
||||
{
|
||||
host.LastActive = DateTime.Now;
|
||||
ApiManager.SendMessageNewLine($"{host.IPAddress}:{host.Port} > Does not have the requested file", NotificationMessageType.Error);
|
||||
ApiManager.SendNotificationMessageNewLine($"{host.IPAddress}:{host.Port} > Does not have the requested file", NotificationMessageType.Error);
|
||||
continue;
|
||||
}
|
||||
|
||||
host.LastActive = DateTime.Now;
|
||||
|
||||
ApiManager.SendMessageNewLine($"{host.IPAddress}:{host.Port} > Has the requested file", NotificationMessageType.Success);
|
||||
ApiManager.SendMessageNewLine("Requesting file...");
|
||||
ApiManager.SendNotificationMessageNewLine($"{host.IPAddress}:{host.Port} > Has the requested file", NotificationMessageType.Success);
|
||||
ApiManager.SendNotificationMessageNewLine("Requesting file...");
|
||||
|
||||
using TcpClient tcpClient = new TcpClient();
|
||||
tcpClient.Connect(ipAddress!, host.Port);
|
||||
@@ -118,8 +118,8 @@ public class DownloadCommands
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
ApiManager.SendMessageNewLine(string.Empty);
|
||||
ApiManager.SendMessageNewLine("Lost connection to other host!", NotificationMessageType.Error);
|
||||
ApiManager.SendNotificationMessageNewLine(string.Empty);
|
||||
ApiManager.SendNotificationMessageNewLine("Lost connection to other host!", NotificationMessageType.Error);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ public class DownloadCommands
|
||||
|
||||
if (parts.Length != 2) //If received data does not contain 2 parts -> error
|
||||
{
|
||||
ApiManager.SendMessageNewLine(dataReceived, NotificationMessageType.Error);
|
||||
ApiManager.SendNotificationMessageNewLine(dataReceived, NotificationMessageType.Error);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ public class DownloadCommands
|
||||
|
||||
if (!validFileSize || fileSize <= 0)
|
||||
{
|
||||
ApiManager.SendMessageNewLine("Invalid file size!", NotificationMessageType.Error);
|
||||
ApiManager.SendNotificationMessageNewLine("Invalid file size!", NotificationMessageType.Error);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -145,8 +145,8 @@ public class DownloadCommands
|
||||
string directoryPath = Path.Combine(ApiConfiguration.BasePath, "Downloads");
|
||||
string filePath = Path.Combine(directoryPath, fileName);
|
||||
|
||||
ApiManager.SendMessageNewLine($"File name: {fileName}");
|
||||
ApiManager.SendMessageNewLine($"Starting download...");
|
||||
ApiManager.SendNotificationMessageNewLine($"File name: {fileName}");
|
||||
ApiManager.SendNotificationMessageNewLine($"Starting download...");
|
||||
|
||||
int totalBytesRead = 0;
|
||||
|
||||
@@ -172,8 +172,8 @@ public class DownloadCommands
|
||||
catch (IOException ex)
|
||||
{
|
||||
Debug.WriteLine(ex);
|
||||
ApiManager.SendMessageNewLine(string.Empty);
|
||||
ApiManager.SendMessageNewLine("Lost connection to other host!", NotificationMessageType.Error);
|
||||
ApiManager.SendNotificationMessageNewLine(string.Empty);
|
||||
ApiManager.SendNotificationMessageNewLine("Lost connection to other host!", NotificationMessageType.Error);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -201,7 +201,7 @@ public class DownloadCommands
|
||||
stopWatch.Restart();
|
||||
}
|
||||
|
||||
ApiManager.SendMessage($"\rDownloading: {Math.Clamp(Math.Ceiling(100d / fileSize * totalBytesRead), 0, 100)}% {totalBytesRead / 1000}/{fileSize / 1000}KB [{unitsPerSecond}{unit}/s] ");
|
||||
ApiManager.SendNotificationMessage($"\rDownloading: {Math.Clamp(Math.Ceiling(100d / fileSize * totalBytesRead), 0, 100)}% {totalBytesRead / 1000}/{fileSize / 1000}KB [{unitsPerSecond}{unit}/s] ");
|
||||
}
|
||||
|
||||
fileStream.Close();
|
||||
@@ -211,25 +211,26 @@ public class DownloadCommands
|
||||
continue;
|
||||
}
|
||||
|
||||
ApiManager.SendMessageNewLine(string.Empty);
|
||||
ApiManager.SendNotificationMessageNewLine(string.Empty);
|
||||
|
||||
ApiManager.SendMessageNewLine("Validating file...");
|
||||
ApiManager.SendNotificationMessageNewLine("Validating file...");
|
||||
if (FileValidator.ValidateHash(filePath, hash))
|
||||
{
|
||||
_ = filesManager.TryAdd(filePath, out _, out _);
|
||||
}
|
||||
else
|
||||
{
|
||||
ApiManager.SendMessageNewLine("Warning: File hash does not match! File might me corrupted or manipulated!", NotificationMessageType.Warning);
|
||||
ApiManager.SendNotificationMessageNewLine("Warning: File hash does not match! File might me corrupted or manipulated! Trying next host...", NotificationMessageType.Warning);
|
||||
continue;
|
||||
}
|
||||
|
||||
ApiManager.SendMessageNewLine($"File saved at: {Path.GetFullPath(filePath)}");
|
||||
ApiManager.SendMessageNewLine("Done", NotificationMessageType.Success);
|
||||
ApiManager.SendNotificationMessageNewLine($"File saved at: {Path.GetFullPath(filePath)}");
|
||||
ApiManager.SendNotificationMessageNewLine("Done", NotificationMessageType.Success);
|
||||
stopWatch.Stop();
|
||||
hostsManager.SaveHosts();
|
||||
return;
|
||||
}
|
||||
ApiManager.SendMessageNewLine("None of the available hosts have the requested file!", NotificationMessageType.Error);
|
||||
ApiManager.SendNotificationMessageNewLine("None of the available hosts have the requested file!", NotificationMessageType.Error);
|
||||
hostsManager.SaveHosts();
|
||||
}
|
||||
}
|
||||
@@ -23,12 +23,12 @@ public class FileCommands
|
||||
{
|
||||
if (filesManager.TryAdd(path, out PrivateHyperFileInfo? fileInfo, out string? message))
|
||||
{
|
||||
ApiManager.SendMessageNewLine($"Added file: {fileInfo!.FilePath}", NotificationMessageType.Success);
|
||||
ApiManager.SendMessageNewLine($"Hash: {fileInfo.Hash}");
|
||||
ApiManager.SendNotificationMessageNewLine($"Added file: {fileInfo!.FilePath}", NotificationMessageType.Success);
|
||||
ApiManager.SendNotificationMessageNewLine($"Hash: {fileInfo.Hash}");
|
||||
}
|
||||
else
|
||||
{
|
||||
ApiManager.SendMessageNewLine(message!, NotificationMessageType.Error);
|
||||
ApiManager.SendNotificationMessageNewLine(message!, NotificationMessageType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,11 +38,11 @@ public class FileCommands
|
||||
|
||||
if (filesManager.TryRemove(hash))
|
||||
{
|
||||
ApiManager.SendMessageNewLine($"Successfully removed file!", NotificationMessageType.Success);
|
||||
ApiManager.SendNotificationMessageNewLine($"Successfully removed file!", NotificationMessageType.Success);
|
||||
}
|
||||
else
|
||||
{
|
||||
ApiManager.SendMessageNewLine("The file is not being tracked!", NotificationMessageType.Error);
|
||||
ApiManager.SendNotificationMessageNewLine("The file is not being tracked!", NotificationMessageType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,16 +53,16 @@ public class FileCommands
|
||||
|
||||
if (fileInfos.Count == 0)
|
||||
{
|
||||
ApiManager.SendMessageNewLine("No tracked files!", NotificationMessageType.Warning);
|
||||
ApiManager.SendNotificationMessageNewLine("No tracked files!", NotificationMessageType.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (PrivateHyperFileInfo fileInfo in fileInfos)
|
||||
{
|
||||
index++;
|
||||
ApiManager.SendMessageNewLine($"{index}) {fileInfo.FilePath}");
|
||||
ApiManager.SendMessageNewLine($"Hash: {fileInfo.Hash}");
|
||||
ApiManager.SendMessageNewLine(string.Empty);
|
||||
ApiManager.SendNotificationMessageNewLine($"{index}) {fileInfo.FilePath}");
|
||||
ApiManager.SendNotificationMessageNewLine($"Hash: {fileInfo.Hash}");
|
||||
ApiManager.SendNotificationMessageNewLine(string.Empty);
|
||||
}
|
||||
Console.CursorTop--;
|
||||
}
|
||||
@@ -79,7 +79,7 @@ public class FileCommands
|
||||
|
||||
if (!filesManager.TryGet(hash, out PrivateHyperFileInfo? localHyperFileInfo))
|
||||
{
|
||||
ApiManager.SendMessageNewLine("The file is not being tracked!", NotificationMessageType.Error);
|
||||
ApiManager.SendNotificationMessageNewLine("The file is not being tracked!", NotificationMessageType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ public class FileCommands
|
||||
NetworkSocket? localHost = ApiManager.GetLocalSocket();
|
||||
if (localHost is null)
|
||||
{
|
||||
ApiManager.SendMessageNewLine("Network error!", NotificationMessageType.Error);
|
||||
ApiManager.SendNotificationMessageNewLine("Network error!", NotificationMessageType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -102,8 +102,8 @@ public class FileCommands
|
||||
|
||||
File.WriteAllText(filePath, json);
|
||||
|
||||
ApiManager.SendMessageNewLine("Done", NotificationMessageType.Success);
|
||||
ApiManager.SendMessageNewLine($"File saved at: {Path.GetFullPath(filePath)}");
|
||||
ApiManager.SendNotificationMessageNewLine("Done", NotificationMessageType.Success);
|
||||
ApiManager.SendNotificationMessageNewLine($"File saved at: {Path.GetFullPath(filePath)}");
|
||||
}
|
||||
|
||||
public void GenerateFileFull(string hash)
|
||||
@@ -118,7 +118,7 @@ public class FileCommands
|
||||
|
||||
if (!filesManager.TryGet(hash, out PrivateHyperFileInfo? localHyperFileInfo))
|
||||
{
|
||||
ApiManager.SendMessageNewLine("The file is not being tracked!", NotificationMessageType.Error);
|
||||
ApiManager.SendNotificationMessageNewLine("The file is not being tracked!", NotificationMessageType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ public class FileCommands
|
||||
NetworkSocket? localHost = ApiManager.GetLocalSocket();
|
||||
if (localHost is null)
|
||||
{
|
||||
ApiManager.SendMessageNewLine("Network error!", NotificationMessageType.Error);
|
||||
ApiManager.SendNotificationMessageNewLine("Network error!", NotificationMessageType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ public class FileCommands
|
||||
continue;
|
||||
}
|
||||
|
||||
ApiManager.SendMessage($"{host.IPAddress}:{host.Port} > ???", NotificationMessageType.Warning);
|
||||
ApiManager.SendNotificationMessage($"{host.IPAddress}:{host.Port} > ???", NotificationMessageType.Warning);
|
||||
|
||||
Console.CursorLeft = 0;
|
||||
|
||||
@@ -155,7 +155,7 @@ public class FileCommands
|
||||
if (!sendTask.IsCompletedSuccessfully)
|
||||
{
|
||||
Console.CursorLeft = 0;
|
||||
ApiManager.SendMessageNewLine($"{host.IPAddress}:{host.Port} > Inactive", NotificationMessageType.Error);
|
||||
ApiManager.SendNotificationMessageNewLine($"{host.IPAddress}:{host.Port} > Inactive", NotificationMessageType.Error);
|
||||
|
||||
hostsManager.Remove(host);
|
||||
continue;
|
||||
@@ -163,13 +163,13 @@ public class FileCommands
|
||||
else if (!sendTask.Result)
|
||||
{
|
||||
host.LastActive = DateTime.Now;
|
||||
ApiManager.SendMessageNewLine($"{host.IPAddress}:{host.Port} > Does not have the requested file", NotificationMessageType.Error);
|
||||
ApiManager.SendNotificationMessageNewLine($"{host.IPAddress}:{host.Port} > Does not have the requested file", NotificationMessageType.Error);
|
||||
continue;
|
||||
}
|
||||
|
||||
host.LastActive = DateTime.Now;
|
||||
|
||||
ApiManager.SendMessageNewLine($"{host.IPAddress}:{host.Port} > Has the requested file", NotificationMessageType.Success);
|
||||
ApiManager.SendNotificationMessageNewLine($"{host.IPAddress}:{host.Port} > Has the requested file", NotificationMessageType.Success);
|
||||
publicHyperFileInfo.Hosts.Add(host);
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ public class FileCommands
|
||||
|
||||
File.WriteAllText(filePath, json);
|
||||
|
||||
ApiManager.SendMessageNewLine("Done", NotificationMessageType.Success);
|
||||
ApiManager.SendMessageNewLine($"File saved at: {Path.GetFullPath(filePath)}");
|
||||
ApiManager.SendNotificationMessageNewLine("Done", NotificationMessageType.Success);
|
||||
ApiManager.SendNotificationMessageNewLine($"File saved at: {Path.GetFullPath(filePath)}");
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ public class HostCommands
|
||||
|
||||
public void Discover(string _)
|
||||
{
|
||||
ApiManager.SendMessageNewLine("Running local discovery routine...", NotificationMessageType.Info);
|
||||
ApiManager.SendNotificationMessageNewLine("Running local discovery routine...", NotificationMessageType.Info);
|
||||
BroadcastClient.Send(ApiConfiguration.BroadcastPort, ApiConfiguration.PrivatePort.ToString());
|
||||
Thread.Sleep(3000);
|
||||
}
|
||||
@@ -28,13 +28,13 @@ public class HostCommands
|
||||
int activeHostsCount = hostsManager.CheckHostsActivity();
|
||||
if (activeHostsCount == 0)
|
||||
{
|
||||
ApiManager.SendMessageNewLine("No active hosts found!", NotificationMessageType.Error);
|
||||
ApiManager.SendMessageNewLine("Use 'add host xxx.xxx.xxx.xxx:yyyy' to add a new host.", NotificationMessageType.Error);
|
||||
ApiManager.SendNotificationMessageNewLine("No active hosts found!", NotificationMessageType.Error);
|
||||
ApiManager.SendNotificationMessageNewLine("Use 'add host xxx.xxx.xxx.xxx:yyyy' to add a new host.", NotificationMessageType.Error);
|
||||
}
|
||||
|
||||
ApiManager.SendMessageNewLine(string.Empty, NotificationMessageType.Info);
|
||||
ApiManager.SendMessageNewLine($"{hostsManager.Count} known host(s).", NotificationMessageType.Info);
|
||||
ApiManager.SendMessageNewLine($"{activeHostsCount} active host(s).", NotificationMessageType.Info);
|
||||
ApiManager.SendNotificationMessageNewLine(string.Empty, NotificationMessageType.Info);
|
||||
ApiManager.SendNotificationMessageNewLine($"{hostsManager.Count} known host(s).", NotificationMessageType.Info);
|
||||
ApiManager.SendNotificationMessageNewLine($"{activeHostsCount} active host(s).", NotificationMessageType.Info);
|
||||
}
|
||||
|
||||
public void ListHosts(string _)
|
||||
@@ -44,16 +44,16 @@ public class HostCommands
|
||||
|
||||
if (hosts.Count == 0)
|
||||
{
|
||||
ApiManager.SendMessageNewLine("No known hosts", NotificationMessageType.Warning);
|
||||
ApiManager.SendNotificationMessageNewLine("No known hosts", NotificationMessageType.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (NetworkSocket host in hosts)
|
||||
{
|
||||
index++;
|
||||
ApiManager.SendMessageNewLine($"{index}) {host.IPAddress}:{host.Port}", NotificationMessageType.Info);
|
||||
ApiManager.SendMessageNewLine($"Last active: {host.LastActive}", NotificationMessageType.Info);
|
||||
ApiManager.SendMessageNewLine(string.Empty, NotificationMessageType.Info);
|
||||
ApiManager.SendNotificationMessageNewLine($"{index}) {host.IPAddress}:{host.Port}", NotificationMessageType.Info);
|
||||
ApiManager.SendNotificationMessageNewLine($"Last active: {host.LastActive}", NotificationMessageType.Info);
|
||||
ApiManager.SendNotificationMessageNewLine(string.Empty, NotificationMessageType.Info);
|
||||
}
|
||||
Console.CursorTop--;
|
||||
}
|
||||
@@ -64,7 +64,7 @@ public class HostCommands
|
||||
|
||||
if (parts.Length != 2)
|
||||
{
|
||||
ApiManager.SendMessageNewLine("Invalid format! Use this format: (xxx.xxx.xxx.xxx:yyyy)", NotificationMessageType.Error);
|
||||
ApiManager.SendNotificationMessageNewLine("Invalid format! Use this format: (xxx.xxx.xxx.xxx:yyyy)", NotificationMessageType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -74,13 +74,13 @@ public class HostCommands
|
||||
_ = int.TryParse(portInput, out int port);
|
||||
if (port < 1000 || port >= 6000)
|
||||
{
|
||||
ApiManager.SendMessageNewLine("Invalid port number!", NotificationMessageType.Error);
|
||||
ApiManager.SendNotificationMessageNewLine("Invalid port number!", NotificationMessageType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!IPAddress.TryParse(ipAddressInput, out IPAddress? ipAddress))
|
||||
{
|
||||
ApiManager.SendMessageNewLine("Invalid IP address!", NotificationMessageType.Error);
|
||||
ApiManager.SendNotificationMessageNewLine("Invalid IP address!", NotificationMessageType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -88,12 +88,12 @@ public class HostCommands
|
||||
|
||||
if (!hostsManager.Contains(hostToRemove))
|
||||
{
|
||||
ApiManager.SendMessageNewLine("Host not in list", NotificationMessageType.Error);
|
||||
ApiManager.SendNotificationMessageNewLine("Host not in list", NotificationMessageType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
hostsManager.Remove(new NetworkSocket(ipAddress.ToString(), port, DateTime.MinValue), true);
|
||||
ApiManager.SendMessageNewLine($"Successfully Removed host!", NotificationMessageType.Success);
|
||||
ApiManager.SendNotificationMessageNewLine($"Successfully Removed host!", NotificationMessageType.Success);
|
||||
}
|
||||
|
||||
public void AddHost(string args)
|
||||
@@ -102,7 +102,7 @@ public class HostCommands
|
||||
|
||||
if (parts.Length != 2)
|
||||
{
|
||||
ApiManager.SendMessageNewLine("Invalid format! Use this format: (xxx.xxx.xxx.xxx:yyyy)", NotificationMessageType.Error);
|
||||
ApiManager.SendNotificationMessageNewLine("Invalid format! Use this format: (xxx.xxx.xxx.xxx:yyyy)", NotificationMessageType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ public class HostCommands
|
||||
|
||||
if (port < 1000 || port >= 6000)
|
||||
{
|
||||
ApiManager.SendMessageNewLine("Invalid port number!", NotificationMessageType.Error);
|
||||
ApiManager.SendNotificationMessageNewLine("Invalid port number!", NotificationMessageType.Error);
|
||||
return;
|
||||
}
|
||||
else if (!IPAddress.TryParse(ipAddressInput, out ipAddress))
|
||||
@@ -131,33 +131,33 @@ public class HostCommands
|
||||
|
||||
if (ipAddress is null)
|
||||
{
|
||||
ApiManager.SendMessageNewLine("Invalid IP address!", NotificationMessageType.Error);
|
||||
ApiManager.SendNotificationMessageNewLine("Invalid IP address!", NotificationMessageType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
ApiManager.SendMessageNewLine("Waiting for response...", NotificationMessageType.Info);
|
||||
ApiManager.SendNotificationMessageNewLine("Waiting for response...", NotificationMessageType.Info);
|
||||
NetworkSocket? localSocket = ApiManager.GetLocalSocket() ?? new NetworkSocket("0.0.0.0", 0, DateTime.MinValue);
|
||||
List<NetworkSocket>? recivedHosts = NetworkClient.Send<List<NetworkSocket>>(ipAddress, port, "GetHostsList", localSocket);
|
||||
|
||||
if (recivedHosts is not null)
|
||||
{
|
||||
ApiManager.SendMessageNewLine($"Success! Added {recivedHosts.Count} new host(s).", NotificationMessageType.Success);
|
||||
ApiManager.SendNotificationMessageNewLine($"Success! Added {recivedHosts.Count} new host(s).", NotificationMessageType.Success);
|
||||
hostsManager.AddRange(recivedHosts);
|
||||
}
|
||||
else
|
||||
{
|
||||
ApiManager.SendMessageNewLine($"Invalid response!", NotificationMessageType.Error);
|
||||
ApiManager.SendNotificationMessageNewLine($"Invalid response!", NotificationMessageType.Error);
|
||||
}
|
||||
}
|
||||
catch (SocketException ex)
|
||||
{
|
||||
ApiManager.SendMessageNewLine($"Invalid host! Error message: {ex.Message}", NotificationMessageType.Error);
|
||||
ApiManager.SendNotificationMessageNewLine($"Invalid host! Error message: {ex.Message}", NotificationMessageType.Error);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
ApiManager.SendMessageNewLine($"Invalid host! Error message: {ex.Message}", NotificationMessageType.Error);
|
||||
ApiManager.SendNotificationMessageNewLine($"Invalid host! Error message: {ex.Message}", NotificationMessageType.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -62,30 +62,30 @@ public class ApiManager
|
||||
device = await discoverer.DiscoverDeviceAsync();
|
||||
|
||||
IPAddress? ip = await device.GetExternalIPAsync();
|
||||
SendMessageNewLine($"The public IP address is: {ip} ", NotificationMessageType.Success);
|
||||
SendNotificationMessageNewLine($"The public IP address is: {ip} ", NotificationMessageType.Success);
|
||||
|
||||
portMapping = new Mapping(Protocol.Tcp, ApiConfiguration.PrivatePort, ApiConfiguration.PublicPort, "HyperbolicDowloader");
|
||||
|
||||
await device.CreatePortMapAsync(portMapping);
|
||||
|
||||
SendMessageNewLine($"The public port is: {ApiConfiguration.PublicPort}", NotificationMessageType.Success);
|
||||
SendNotificationMessageNewLine($"The public port is: {ApiConfiguration.PublicPort}", NotificationMessageType.Success);
|
||||
return true;
|
||||
}
|
||||
catch (NatDeviceNotFoundException)
|
||||
{
|
||||
SendMessageNewLine($"Could not find a UPnP or NAT-PMP device!", NotificationMessageType.Error);
|
||||
SendNotificationMessageNewLine($"Could not find a UPnP or NAT-PMP device!", NotificationMessageType.Error);
|
||||
return false;
|
||||
}
|
||||
catch (MappingException ex)
|
||||
{
|
||||
SendMessageNewLine($"An error occurred while mapping the private port ({ApiConfiguration.PrivatePort}) to the public port ({ApiConfiguration.PublicPort})! Error message: {ex.Message}", NotificationMessageType.Error);
|
||||
SendNotificationMessageNewLine($"An error occurred while mapping the private port ({ApiConfiguration.PrivatePort}) to the public port ({ApiConfiguration.PublicPort})! Error message: {ex.Message}", NotificationMessageType.Error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void ClosePorts()
|
||||
{
|
||||
SendMessageNewLine("Closing ports...", NotificationMessageType.Info);
|
||||
SendNotificationMessageNewLine("Closing ports...", NotificationMessageType.Info);
|
||||
if (device is not null)
|
||||
{
|
||||
try
|
||||
@@ -101,11 +101,11 @@ public class ApiManager
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SendMessageNewLine(ex.ToString(), NotificationMessageType.Error);
|
||||
SendNotificationMessageNewLine(ex.ToString(), NotificationMessageType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
SendMessageNewLine("Ports closed!", NotificationMessageType.Warning);
|
||||
SendNotificationMessageNewLine("Ports closed!", NotificationMessageType.Warning);
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ public class ApiManager
|
||||
}
|
||||
catch (SocketException ex)
|
||||
{
|
||||
SendMessageNewLine($"An error occurred while starting the TCP listener! Error message: {ex.Message}", NotificationMessageType.Error); // net stop hens && net start hns
|
||||
SendNotificationMessageNewLine($"An error occurred while starting the TCP listener! Error message: {ex.Message}", NotificationMessageType.Error); // net stop hens && net start hns
|
||||
Console.ReadKey();
|
||||
}
|
||||
}
|
||||
@@ -165,7 +165,7 @@ public class ApiManager
|
||||
|
||||
private void DiscoverAnswer(object? sender, MessageRecivedEventArgs<List<NetworkSocket>> recivedEventArgs)
|
||||
{
|
||||
SendMessageNewLine($"Received answer from {recivedEventArgs.IpAddress}. Returned {recivedEventArgs.Data.Count} host(s).", NotificationMessageType.Info);
|
||||
SendNotificationMessageNewLine($"Received answer from {recivedEventArgs.IpAddress}. Returned {recivedEventArgs.Data.Count} host(s).", NotificationMessageType.Info);
|
||||
HostsManager.AddRange(recivedEventArgs.Data);
|
||||
}
|
||||
|
||||
@@ -198,15 +198,15 @@ public class ApiManager
|
||||
|
||||
private void ReciveMessage(object? sender, MessageRecivedEventArgs<string> recivedEventArgs)
|
||||
{
|
||||
SendMessageNewLine($"Received \"{recivedEventArgs.Data}\" from {recivedEventArgs.IpAddress}.", NotificationMessageType.Info);
|
||||
SendNotificationMessageNewLine($"Received \"{recivedEventArgs.Data}\" from {recivedEventArgs.IpAddress}.", NotificationMessageType.Info);
|
||||
}
|
||||
|
||||
internal static void SendMessage(string message, NotificationMessageType messageType = NotificationMessageType.Info)
|
||||
internal static void SendNotificationMessage(string message, NotificationMessageType messageType = NotificationMessageType.Info)
|
||||
{
|
||||
OnNotificationMessageRecived?.Invoke(null, new NotificationMessageEventArgs(messageType, message));
|
||||
}
|
||||
|
||||
internal static void SendMessageNewLine(string message, NotificationMessageType messageType = NotificationMessageType.Info)
|
||||
internal static void SendNotificationMessageNewLine(string message, NotificationMessageType messageType = NotificationMessageType.Info)
|
||||
{
|
||||
OnNotificationMessageRecived?.Invoke(null, new NotificationMessageEventArgs(messageType, message + Environment.NewLine));
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ internal class BroadcastClient
|
||||
|
||||
if (ip4Address is null)
|
||||
{
|
||||
ApiManager.SendMessageNewLine("Could not find suitable network adapter!", NotificationMessageType.Error);
|
||||
ApiManager.SendNotificationMessageNewLine("Could not find suitable network adapter!", NotificationMessageType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ internal class BroadcastClient
|
||||
|
||||
if (addressInformation is null)
|
||||
{
|
||||
ApiManager.SendMessageNewLine("Could not find suitable network adapter!", NotificationMessageType.Error);
|
||||
ApiManager.SendNotificationMessageNewLine("Could not find suitable network adapter!", NotificationMessageType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ public class HostsManager
|
||||
int activeHostsCount = 0;
|
||||
foreach (NetworkSocket host in hosts)
|
||||
{
|
||||
ApiManager.SendMessage($"{host.IPAddress}:{host.Port} > ???", NotificationMessageType.Warning);
|
||||
ApiManager.SendNotificationMessage($"{host.IPAddress}:{host.Port} > ???", NotificationMessageType.Warning);
|
||||
using TcpClient tcpClient = new TcpClient();
|
||||
|
||||
try
|
||||
@@ -62,7 +62,7 @@ public class HostsManager
|
||||
Console.CursorLeft = 0;
|
||||
if (tcpClient.Connected)
|
||||
{
|
||||
ApiManager.SendMessageNewLine($"{host.IPAddress}:{host.Port} > Active", NotificationMessageType.Success);
|
||||
ApiManager.SendNotificationMessageNewLine($"{host.IPAddress}:{host.Port} > Active", NotificationMessageType.Success);
|
||||
host.LastActive = DateTime.Now;
|
||||
activeHostsCount++;
|
||||
}
|
||||
@@ -72,7 +72,7 @@ public class HostsManager
|
||||
{
|
||||
hostsToRemove.Add(host);
|
||||
}
|
||||
ApiManager.SendMessageNewLine($"{host.IPAddress}:{host.Port} > Inactive", NotificationMessageType.Error);
|
||||
ApiManager.SendNotificationMessageNewLine($"{host.IPAddress}:{host.Port} > Inactive", NotificationMessageType.Error);
|
||||
}
|
||||
}
|
||||
catch
|
||||
@@ -82,7 +82,7 @@ public class HostsManager
|
||||
hostsToRemove.Add(host);
|
||||
}
|
||||
Console.CursorLeft = 0;
|
||||
ApiManager.SendMessageNewLine($"{host.IPAddress}:{host.Port} > Inactive", NotificationMessageType.Error);
|
||||
ApiManager.SendNotificationMessageNewLine($"{host.IPAddress}:{host.Port} > Inactive", NotificationMessageType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user