From fb649510033e912b2431c83321a5d37e9fdb8487 Mon Sep 17 00:00:00 2001 From: ChsBuffer <33744752+chsbuffer@users.noreply.github.com> Date: Fri, 30 Apr 2021 15:24:37 +0800 Subject: [PATCH] Refactor: name, namespace --- Netch/Controllers/DNSController.cs | 3 ++- Netch/Controllers/MainController.cs | 7 ++--- Netch/Controllers/NFController.cs | 15 ++++++----- Netch/Controllers/NTTController.cs | 5 ++-- Netch/Controllers/PcapController.cs | 10 ++++--- Netch/Controllers/TUNController.cs | 20 +++++++------- Netch/{Models => Interfaces}/IAdapter.cs | 2 +- .../IController.cs | 2 +- .../IModeController.cs | 2 +- .../IServerController.cs | 2 +- Netch/{Models => Interfaces}/IServerUtil.cs | 6 ++--- .../Interops/{AioDNSInterops.cs => AioDNS.cs} | 2 +- .../{RedirectorInterop.cs => Redirector.cs} | 2 +- Netch/Interops/RouteHelper.cs | 26 +++++++++++++++++++ .../Interops/{TUNInterop.cs => tun2socks.cs} | 2 +- Netch/Models/{ => Adapter}/OutboundAdapter.cs | 3 ++- Netch/Models/{ => Adapter}/TunAdapter.cs | 9 ++++--- Netch/Models/{Range.cs => NumberRange.cs} | 4 +-- Netch/NativeMethods.cs | 21 +-------------- Netch/Servers/Shadowsocks/SSController.cs | 5 ++-- Netch/Servers/Shadowsocks/SSUtil.cs | 12 ++++----- Netch/Servers/ShadowsocksR/SSRController.cs | 5 ++-- Netch/Servers/ShadowsocksR/SSRUtil.cs | 8 +++--- Netch/Servers/Socks5/S5Util.cs | 8 +++--- Netch/Servers/Trojan/TrojanController.cs | 9 ++++--- Netch/Servers/Trojan/TrojanUtil.cs | 6 ++--- Netch/Servers/V2ray/V2rayController.cs | 7 ++--- Netch/Servers/VLESS/VLESSUtil.cs | 6 ++--- Netch/Servers/VMess/VMessUtil.cs | 12 ++++----- Netch/Utils/ModeHelper.cs | 9 ++++--- Netch/Utils/PortHelper.cs | 10 +++---- Netch/Utils/ServerHelper.cs | 6 ++--- Netch/Utils/Utils.cs | 6 ++--- 33 files changed, 137 insertions(+), 115 deletions(-) rename Netch/{Models => Interfaces}/IAdapter.cs (89%) rename Netch/{Controllers => Interfaces}/IController.cs (89%) rename Netch/{Controllers => Interfaces}/IModeController.cs (91%) rename Netch/{Controllers => Interfaces}/IServerController.cs (96%) rename Netch/{Models => Interfaces}/IServerUtil.cs (93%) rename Netch/Interops/{AioDNSInterops.cs => AioDNS.cs} (95%) rename Netch/Interops/{RedirectorInterop.cs => Redirector.cs} (98%) create mode 100644 Netch/Interops/RouteHelper.cs rename Netch/Interops/{TUNInterop.cs => tun2socks.cs} (98%) rename Netch/Models/{ => Adapter}/OutboundAdapter.cs (96%) rename Netch/Models/{ => Adapter}/TunAdapter.cs (79%) rename Netch/Models/{Range.cs => NumberRange.cs} (76%) diff --git a/Netch/Controllers/DNSController.cs b/Netch/Controllers/DNSController.cs index c704cdbb..810aec1c 100644 --- a/Netch/Controllers/DNSController.cs +++ b/Netch/Controllers/DNSController.cs @@ -1,6 +1,7 @@ using System; using System.IO; -using static Netch.Interops.AioDNSInterops; +using Netch.Interfaces; +using static Netch.Interops.AioDNS; namespace Netch.Controllers { diff --git a/Netch/Controllers/MainController.cs b/Netch/Controllers/MainController.cs index f9c977b4..220e92a4 100644 --- a/Netch/Controllers/MainController.cs +++ b/Netch/Controllers/MainController.cs @@ -1,9 +1,10 @@ -using Netch.Models; -using Netch.Servers.Socks5; -using Netch.Utils; using System; using System.IO; using System.Threading.Tasks; +using Netch.Interfaces; +using Netch.Models; +using Netch.Servers.Socks5; +using Netch.Utils; namespace Netch.Controllers { diff --git a/Netch/Controllers/NFController.cs b/Netch/Controllers/NFController.cs index ee25ca06..6d3572b8 100644 --- a/Netch/Controllers/NFController.cs +++ b/Netch/Controllers/NFController.cs @@ -1,14 +1,15 @@ -using Netch.Interops; -using Netch.Models; -using Netch.Servers.Shadowsocks; -using Netch.Servers.Socks5; -using Netch.Utils; -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.ServiceProcess; -using static Netch.Interops.RedirectorInterop; +using Netch.Interfaces; +using Netch.Interops; +using Netch.Models; +using Netch.Servers.Shadowsocks; +using Netch.Servers.Socks5; +using Netch.Utils; +using static Netch.Interops.Redirector; namespace Netch.Controllers { diff --git a/Netch/Controllers/NTTController.cs b/Netch/Controllers/NTTController.cs index c556f098..9f9139d2 100644 --- a/Netch/Controllers/NTTController.cs +++ b/Netch/Controllers/NTTController.cs @@ -1,8 +1,9 @@ -using Netch.Utils; -using System; +using System; using System.IO; using System.Linq; using System.Threading.Tasks; +using Netch.Interfaces; +using Netch.Utils; namespace Netch.Controllers { diff --git a/Netch/Controllers/PcapController.cs b/Netch/Controllers/PcapController.cs index 687d689d..ef6f280b 100644 --- a/Netch/Controllers/PcapController.cs +++ b/Netch/Controllers/PcapController.cs @@ -1,13 +1,15 @@ -using Netch.Forms; -using Netch.Models; -using Netch.Servers.Socks5; -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; +using Netch.Forms; +using Netch.Interfaces; +using Netch.Models; +using Netch.Models.Adapter; +using Netch.Servers.Socks5; namespace Netch.Controllers { diff --git a/Netch/Controllers/TUNController.cs b/Netch/Controllers/TUNController.cs index 5ae3a559..6c4d8f58 100644 --- a/Netch/Controllers/TUNController.cs +++ b/Netch/Controllers/TUNController.cs @@ -1,14 +1,16 @@ -using Netch.Models; -using Netch.Servers.Socks5; -using Netch.Utils; -using System; +using System; using System.Collections.Generic; using System.IO; -using System.Linq; using System.Net; using System.Net.Sockets; using System.Threading.Tasks; -using static Netch.Interops.TUNInterop; +using Netch.Interfaces; +using Netch.Interops; +using Netch.Models; +using Netch.Models.Adapter; +using Netch.Servers.Socks5; +using Netch.Utils; +using static Netch.Interops.tun2socks; namespace Netch.Controllers { @@ -98,7 +100,7 @@ namespace Netch.Controllers break; } - NativeMethods.CreateUnicastIP(AddressFamily.InterNetwork, + RouteHelper.CreateUnicastIP(AddressFamily.InterNetwork, Global.Settings.TUNTAP.Address, (byte) Utils.Utils.SubnetToCidr(Global.Settings.TUNTAP.Netmask), _tunAdapter.InterfaceIndex); @@ -268,13 +270,13 @@ namespace Netch.Controllers switch (action) { case Action.Create: - result = NativeMethods.CreateRoute(AddressFamily.InterNetwork, ip, (byte) cidr, gateway, index, metric); + result = RouteHelper.CreateRoute(AddressFamily.InterNetwork, ip, (byte) cidr, gateway, index, metric); if (record) ipList.Add(ipNetwork); break; case Action.Delete: - result = NativeMethods.DeleteRoute(AddressFamily.InterNetwork, ip, (byte) cidr, gateway, index, metric); + result = RouteHelper.DeleteRoute(AddressFamily.InterNetwork, ip, (byte) cidr, gateway, index, metric); break; default: throw new ArgumentOutOfRangeException(nameof(action), action, null); diff --git a/Netch/Models/IAdapter.cs b/Netch/Interfaces/IAdapter.cs similarity index 89% rename from Netch/Models/IAdapter.cs rename to Netch/Interfaces/IAdapter.cs index 147c4e99..819dc023 100644 --- a/Netch/Models/IAdapter.cs +++ b/Netch/Interfaces/IAdapter.cs @@ -1,7 +1,7 @@ using System.Net; using System.Net.NetworkInformation; -namespace Netch.Models +namespace Netch.Interfaces { public interface IAdapter { diff --git a/Netch/Controllers/IController.cs b/Netch/Interfaces/IController.cs similarity index 89% rename from Netch/Controllers/IController.cs rename to Netch/Interfaces/IController.cs index 2eb3b29b..9d914b02 100644 --- a/Netch/Controllers/IController.cs +++ b/Netch/Interfaces/IController.cs @@ -1,4 +1,4 @@ -namespace Netch.Controllers +namespace Netch.Interfaces { public interface IController { diff --git a/Netch/Controllers/IModeController.cs b/Netch/Interfaces/IModeController.cs similarity index 91% rename from Netch/Controllers/IModeController.cs rename to Netch/Interfaces/IModeController.cs index 3760597b..76d78b42 100644 --- a/Netch/Controllers/IModeController.cs +++ b/Netch/Interfaces/IModeController.cs @@ -1,6 +1,6 @@ using Netch.Models; -namespace Netch.Controllers +namespace Netch.Interfaces { public interface IModeController : IController { diff --git a/Netch/Controllers/IServerController.cs b/Netch/Interfaces/IServerController.cs similarity index 96% rename from Netch/Controllers/IServerController.cs rename to Netch/Interfaces/IServerController.cs index 93c9b34f..93d13203 100644 --- a/Netch/Controllers/IServerController.cs +++ b/Netch/Interfaces/IServerController.cs @@ -1,6 +1,6 @@ using Netch.Models; -namespace Netch.Controllers +namespace Netch.Interfaces { public interface IServerController : IController { diff --git a/Netch/Models/IServerUtil.cs b/Netch/Interfaces/IServerUtil.cs similarity index 93% rename from Netch/Models/IServerUtil.cs rename to Netch/Interfaces/IServerUtil.cs index 35610d13..2242c087 100644 --- a/Netch/Models/IServerUtil.cs +++ b/Netch/Interfaces/IServerUtil.cs @@ -1,8 +1,8 @@ -using Netch.Controllers; -using System; +using System; using System.Collections.Generic; +using Netch.Models; -namespace Netch.Models +namespace Netch.Interfaces { public interface IServerUtil { diff --git a/Netch/Interops/AioDNSInterops.cs b/Netch/Interops/AioDNS.cs similarity index 95% rename from Netch/Interops/AioDNSInterops.cs rename to Netch/Interops/AioDNS.cs index f2a8cc5e..271f12a4 100644 --- a/Netch/Interops/AioDNSInterops.cs +++ b/Netch/Interops/AioDNS.cs @@ -3,7 +3,7 @@ using System.Text; namespace Netch.Interops { - public static class AioDNSInterops + public static class AioDNS { private const string aiodns_bin = "aiodns.bin"; diff --git a/Netch/Interops/RedirectorInterop.cs b/Netch/Interops/Redirector.cs similarity index 98% rename from Netch/Interops/RedirectorInterop.cs rename to Netch/Interops/Redirector.cs index 65338dee..a317f2ef 100644 --- a/Netch/Interops/RedirectorInterop.cs +++ b/Netch/Interops/Redirector.cs @@ -2,7 +2,7 @@ using System.Runtime.InteropServices; namespace Netch.Interops { - public static class RedirectorInterop + public static class Redirector { public enum NameList { diff --git a/Netch/Interops/RouteHelper.cs b/Netch/Interops/RouteHelper.cs new file mode 100644 index 00000000..3c3c6f6c --- /dev/null +++ b/Netch/Interops/RouteHelper.cs @@ -0,0 +1,26 @@ +using System.Net.Sockets; +using System.Runtime.InteropServices; + +namespace Netch.Interops +{ + public static class RouteHelper + { + [DllImport("RouteHelper.bin", CallingConvention = CallingConvention.Cdecl)] + public static extern ulong ConvertLuidToIndex(ulong id); + + [DllImport("RouteHelper.bin", CallingConvention = CallingConvention.Cdecl)] + public static extern bool CreateIPv4(string address, string netmask, ulong index); + + [DllImport("RouteHelper.bin", CallingConvention = CallingConvention.Cdecl)] + public static extern bool CreateUnicastIP(AddressFamily inet, string address, byte cidr, ulong index); + + [DllImport("RouteHelper.bin", CallingConvention = CallingConvention.Cdecl)] + public static extern bool RefreshIPTable(AddressFamily inet, ulong index); + + [DllImport("RouteHelper.bin", CallingConvention = CallingConvention.Cdecl)] + public static extern bool CreateRoute(AddressFamily inet, string address, byte cidr, string gateway, ulong index, int metric); + + [DllImport("RouteHelper.bin", CallingConvention = CallingConvention.Cdecl)] + public static extern bool DeleteRoute(AddressFamily inet, string address, byte cidr, string gateway, ulong index, int metric); + } +} \ No newline at end of file diff --git a/Netch/Interops/TUNInterop.cs b/Netch/Interops/tun2socks.cs similarity index 98% rename from Netch/Interops/TUNInterop.cs rename to Netch/Interops/tun2socks.cs index 90d91b7e..fec80bae 100644 --- a/Netch/Interops/TUNInterop.cs +++ b/Netch/Interops/tun2socks.cs @@ -3,7 +3,7 @@ using System.Text; namespace Netch.Interops { - public static class TUNInterop + public static class tun2socks { public enum NameList { diff --git a/Netch/Models/OutboundAdapter.cs b/Netch/Models/Adapter/OutboundAdapter.cs similarity index 96% rename from Netch/Models/OutboundAdapter.cs rename to Netch/Models/Adapter/OutboundAdapter.cs index b83dd404..30e1cf04 100644 --- a/Netch/Models/OutboundAdapter.cs +++ b/Netch/Models/Adapter/OutboundAdapter.cs @@ -2,9 +2,10 @@ using System.Linq; using System.Net; using System.Net.NetworkInformation; +using Netch.Interfaces; using Vanara.PInvoke; -namespace Netch.Models +namespace Netch.Models.Adapter { public class OutboundAdapter : IAdapter { diff --git a/Netch/Models/TunAdapter.cs b/Netch/Models/Adapter/TunAdapter.cs similarity index 79% rename from Netch/Models/TunAdapter.cs rename to Netch/Models/Adapter/TunAdapter.cs index 547f979e..480b181b 100644 --- a/Netch/Models/TunAdapter.cs +++ b/Netch/Models/Adapter/TunAdapter.cs @@ -1,15 +1,16 @@ -using Netch.Interops; -using System.Linq; +using System.Linq; using System.Net; using System.Net.NetworkInformation; +using Netch.Interfaces; +using Netch.Interops; -namespace Netch.Models +namespace Netch.Models.Adapter { public class TunAdapter : IAdapter { public TunAdapter() { - InterfaceIndex = NativeMethods.ConvertLuidToIndex(TUNInterop.tun_luid()); + InterfaceIndex = RouteHelper.ConvertLuidToIndex(tun2socks.tun_luid()); NetworkInterface = NetworkInterface.GetAllNetworkInterfaces().First(i => i.GetIPProperties().GetIPv4Properties().Index == (int)InterfaceIndex); Gateway = IPAddress.Parse(Global.Settings.TUNTAP.Gateway); diff --git a/Netch/Models/Range.cs b/Netch/Models/NumberRange.cs similarity index 76% rename from Netch/Models/Range.cs rename to Netch/Models/NumberRange.cs index 1fdaa3b3..148f91fc 100644 --- a/Netch/Models/Range.cs +++ b/Netch/Models/NumberRange.cs @@ -1,12 +1,12 @@ namespace Netch.Models { - public readonly struct Range + public readonly struct NumberRange { public int Start { get; } public int End { get; } - public Range(int start, int end) + public NumberRange(int start, int end) { Start = start; End = end; diff --git a/Netch/NativeMethods.cs b/Netch/NativeMethods.cs index 94133e17..194ba651 100644 --- a/Netch/NativeMethods.cs +++ b/Netch/NativeMethods.cs @@ -1,5 +1,4 @@ -using System.Net.Sockets; -using System.Runtime.InteropServices; +using System.Runtime.InteropServices; namespace Netch { @@ -7,23 +6,5 @@ namespace Netch { [DllImport("dnsapi", EntryPoint = "DnsFlushResolverCache")] public static extern uint RefreshDNSCache(); - - [DllImport("RouteHelper.bin", CallingConvention = CallingConvention.Cdecl)] - public static extern ulong ConvertLuidToIndex(ulong id); - - [DllImport("RouteHelper.bin", CallingConvention = CallingConvention.Cdecl)] - public static extern bool CreateIPv4(string address, string netmask, ulong index); - - [DllImport("RouteHelper.bin", CallingConvention = CallingConvention.Cdecl)] - public static extern bool CreateUnicastIP(AddressFamily inet, string address, byte cidr, ulong index); - - [DllImport("RouteHelper.bin", CallingConvention = CallingConvention.Cdecl)] - public static extern bool RefreshIPTable(AddressFamily inet, ulong index); - - [DllImport("RouteHelper.bin", CallingConvention = CallingConvention.Cdecl)] - public static extern bool CreateRoute(AddressFamily inet, string address, byte cidr, string gateway, ulong index, int metric); - - [DllImport("RouteHelper.bin", CallingConvention = CallingConvention.Cdecl)] - public static extern bool DeleteRoute(AddressFamily inet, string address, byte cidr, string gateway, ulong index, int metric); } } diff --git a/Netch/Servers/Shadowsocks/SSController.cs b/Netch/Servers/Shadowsocks/SSController.cs index 0ec55f31..6490bdd4 100644 --- a/Netch/Servers/Shadowsocks/SSController.cs +++ b/Netch/Servers/Shadowsocks/SSController.cs @@ -1,6 +1,7 @@ -using Netch.Controllers; -using Netch.Models; using System.Collections.Generic; +using Netch.Controllers; +using Netch.Interfaces; +using Netch.Models; namespace Netch.Servers.Shadowsocks { diff --git a/Netch/Servers/Shadowsocks/SSUtil.cs b/Netch/Servers/Shadowsocks/SSUtil.cs index 78ac24bf..3e401428 100644 --- a/Netch/Servers/Shadowsocks/SSUtil.cs +++ b/Netch/Servers/Shadowsocks/SSUtil.cs @@ -1,14 +1,14 @@ -using Netch.Controllers; -using Netch.Models; -using Netch.Servers.Shadowsocks.Form; -using Netch.Servers.Shadowsocks.Models.SSD; -using Netch.Utils; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text.Json; using System.Text.RegularExpressions; using System.Web; +using Netch.Interfaces; +using Netch.Models; +using Netch.Servers.Shadowsocks.Form; +using Netch.Servers.Shadowsocks.Models.SSD; +using Netch.Utils; namespace Netch.Servers.Shadowsocks { diff --git a/Netch/Servers/ShadowsocksR/SSRController.cs b/Netch/Servers/ShadowsocksR/SSRController.cs index 3c73fb85..80d9843c 100644 --- a/Netch/Servers/ShadowsocksR/SSRController.cs +++ b/Netch/Servers/ShadowsocksR/SSRController.cs @@ -1,6 +1,7 @@ -using Netch.Controllers; -using Netch.Models; using System.Collections.Generic; +using Netch.Controllers; +using Netch.Interfaces; +using Netch.Models; namespace Netch.Servers.ShadowsocksR { diff --git a/Netch/Servers/ShadowsocksR/SSRUtil.cs b/Netch/Servers/ShadowsocksR/SSRUtil.cs index 52e946bf..24ed3d64 100644 --- a/Netch/Servers/ShadowsocksR/SSRUtil.cs +++ b/Netch/Servers/ShadowsocksR/SSRUtil.cs @@ -1,11 +1,11 @@ -using Netch.Controllers; +using System; +using System.Collections.Generic; +using System.Text.RegularExpressions; +using Netch.Interfaces; using Netch.Models; using Netch.Servers.Shadowsocks; using Netch.Servers.ShadowsocksR.Form; using Netch.Utils; -using System; -using System.Collections.Generic; -using System.Text.RegularExpressions; namespace Netch.Servers.ShadowsocksR { diff --git a/Netch/Servers/Socks5/S5Util.cs b/Netch/Servers/Socks5/S5Util.cs index a51b8717..a518f8f5 100644 --- a/Netch/Servers/Socks5/S5Util.cs +++ b/Netch/Servers/Socks5/S5Util.cs @@ -1,9 +1,9 @@ -using Netch.Controllers; -using Netch.Models; -using Netch.Servers.Socks5.Form; -using System; +using System; using System.Collections.Generic; using System.Linq; +using Netch.Interfaces; +using Netch.Models; +using Netch.Servers.Socks5.Form; namespace Netch.Servers.Socks5 { diff --git a/Netch/Servers/Trojan/TrojanController.cs b/Netch/Servers/Trojan/TrojanController.cs index f8bf1e66..dcf254c5 100644 --- a/Netch/Servers/Trojan/TrojanController.cs +++ b/Netch/Servers/Trojan/TrojanController.cs @@ -1,9 +1,10 @@ -using Netch.Controllers; -using Netch.Models; -using Netch.Servers.Trojan.Models; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using System.Text.Json; +using Netch.Controllers; +using Netch.Interfaces; +using Netch.Models; +using Netch.Servers.Trojan.Models; namespace Netch.Servers.Trojan { diff --git a/Netch/Servers/Trojan/TrojanUtil.cs b/Netch/Servers/Trojan/TrojanUtil.cs index 788889be..5fcf5227 100644 --- a/Netch/Servers/Trojan/TrojanUtil.cs +++ b/Netch/Servers/Trojan/TrojanUtil.cs @@ -1,10 +1,10 @@ -using Netch.Controllers; -using Netch.Models; -using Netch.Servers.Trojan.Form; using System; using System.Collections.Generic; using System.Text.RegularExpressions; using System.Web; +using Netch.Interfaces; +using Netch.Models; +using Netch.Servers.Trojan.Form; namespace Netch.Servers.Trojan { diff --git a/Netch/Servers/V2ray/V2rayController.cs b/Netch/Servers/V2ray/V2rayController.cs index b2372245..4ccc4797 100644 --- a/Netch/Servers/V2ray/V2rayController.cs +++ b/Netch/Servers/V2ray/V2rayController.cs @@ -1,8 +1,9 @@ -using Netch.Controllers; -using Netch.Models; -using Netch.Servers.V2ray.Utils; using System.Collections.Generic; using System.IO; +using Netch.Controllers; +using Netch.Interfaces; +using Netch.Models; +using Netch.Servers.V2ray.Utils; namespace Netch.Servers.V2ray { diff --git a/Netch/Servers/VLESS/VLESSUtil.cs b/Netch/Servers/VLESS/VLESSUtil.cs index 606be73b..a24ddc3a 100644 --- a/Netch/Servers/VLESS/VLESSUtil.cs +++ b/Netch/Servers/VLESS/VLESSUtil.cs @@ -1,8 +1,8 @@ -using Netch.Controllers; -using Netch.Models; -using Netch.Servers.V2ray; using System; using System.Collections.Generic; +using Netch.Interfaces; +using Netch.Models; +using Netch.Servers.V2ray; namespace Netch.Servers.VLESS { diff --git a/Netch/Servers/VMess/VMessUtil.cs b/Netch/Servers/VMess/VMessUtil.cs index 5ea788ef..cb4559b0 100644 --- a/Netch/Servers/VMess/VMessUtil.cs +++ b/Netch/Servers/VMess/VMessUtil.cs @@ -1,14 +1,14 @@ -using Netch.Controllers; -using Netch.Models; -using Netch.Servers.V2ray; -using Netch.Servers.V2ray.Models; -using Netch.Servers.VMess.Form; -using Netch.Utils; using System; using System.Collections.Generic; using System.Text.Encodings.Web; using System.Text.Json; using System.Text.Json.Serialization; +using Netch.Interfaces; +using Netch.Models; +using Netch.Servers.V2ray; +using Netch.Servers.V2ray.Models; +using Netch.Servers.VMess.Form; +using Netch.Utils; namespace Netch.Servers.VMess { diff --git a/Netch/Utils/ModeHelper.cs b/Netch/Utils/ModeHelper.cs index 54edc5c3..e2c0458c 100644 --- a/Netch/Utils/ModeHelper.cs +++ b/Netch/Utils/ModeHelper.cs @@ -1,10 +1,11 @@ -using Netch.Controllers; -using Netch.Models; -using Netch.Servers.Shadowsocks; -using Netch.Servers.Socks5; using System; using System.IO; using System.Linq; +using Netch.Controllers; +using Netch.Interfaces; +using Netch.Models; +using Netch.Servers.Shadowsocks; +using Netch.Servers.Socks5; namespace Netch.Utils { diff --git a/Netch/Utils/PortHelper.cs b/Netch/Utils/PortHelper.cs index d8683904..5edd09bf 100644 --- a/Netch/Utils/PortHelper.cs +++ b/Netch/Utils/PortHelper.cs @@ -3,16 +3,16 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Net.NetworkInformation; +using Netch.Models; using static Vanara.PInvoke.IpHlpApi; using static Vanara.PInvoke.Ws2_32; -using Range = Netch.Models.Range; namespace Netch.Utils { public static class PortHelper { - private static readonly List TCPReservedRanges = new(); - private static readonly List UDPReservedRanges = new(); + private static readonly List TCPReservedRanges = new(); + private static readonly List UDPReservedRanges = new(); private static readonly IPGlobalProperties NetInfo = IPGlobalProperties.GetIPGlobalProperties(); static PortHelper() @@ -38,7 +38,7 @@ namespace Netch.Utils return row.Select(r => Process.GetProcessById((int)r.dwOwningPid)); } - private static void GetReservedPortRange(PortType portType, ref List targetList) + private static void GetReservedPortRange(PortType portType, ref List targetList) { var process = new Process { @@ -64,7 +64,7 @@ namespace Netch.Utils if (!ushort.TryParse(value[0], out var start) || !ushort.TryParse(value[1], out var end)) continue; - targetList.Add(new Range(start, end)); + targetList.Add(new NumberRange(start, end)); } } diff --git a/Netch/Utils/ServerHelper.cs b/Netch/Utils/ServerHelper.cs index 235ec7c5..841fd5e3 100644 --- a/Netch/Utils/ServerHelper.cs +++ b/Netch/Utils/ServerHelper.cs @@ -1,11 +1,11 @@ -using Netch.Models; using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Threading.Tasks; using System.Timers; -using Range = Netch.Models.Range; +using Netch.Interfaces; +using Netch.Models; namespace Netch.Utils { @@ -32,7 +32,7 @@ namespace Netch.Utils private static readonly Timer Timer; private static bool _mux; - public static readonly Range Range = new(0, int.MaxValue / 1000); + public static readonly NumberRange Range = new(0, int.MaxValue / 1000); static DelayTestHelper() { diff --git a/Netch/Utils/Utils.cs b/Netch/Utils/Utils.cs index 591c909d..f9ae9adf 100644 --- a/Netch/Utils/Utils.cs +++ b/Netch/Utils/Utils.cs @@ -1,5 +1,3 @@ -using MaxMind.GeoIP2; -using Microsoft.Win32.TaskScheduler; using System; using System.ComponentModel; using System.Diagnostics; @@ -13,6 +11,8 @@ using System.Security.Cryptography; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; +using MaxMind.GeoIP2; +using Microsoft.Win32.TaskScheduler; using Task = System.Threading.Tasks.Task; namespace Netch.Utils @@ -254,7 +254,7 @@ namespace Netch.Utils Console.Write(error); } - p.WaitForExit(); + await p.WaitForExitAsync(); } public static int SubnetToCidr(string value)