Skip to content

Commit

Permalink
Refactor: name, namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
chsbuffer committed Apr 30, 2021
1 parent 258880e commit fb64951
Show file tree
Hide file tree
Showing 33 changed files with 133 additions and 111 deletions.
3 changes: 2 additions & 1 deletion Netch/Controllers/DNSController.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
7 changes: 4 additions & 3 deletions Netch/Controllers/MainController.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
15 changes: 8 additions & 7 deletions Netch/Controllers/NFController.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
5 changes: 3 additions & 2 deletions Netch/Controllers/NTTController.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
10 changes: 6 additions & 4 deletions Netch/Controllers/PcapController.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
20 changes: 11 additions & 9 deletions Netch/Controllers/TUNController.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -98,7 +100,7 @@ public void Start(in Mode mode)
break;
}

NativeMethods.CreateUnicastIP(AddressFamily.InterNetwork,
RouteHelper.CreateUnicastIP(AddressFamily.InterNetwork,
Global.Settings.TUNTAP.Address,
(byte) Utils.Utils.SubnetToCidr(Global.Settings.TUNTAP.Netmask),
_tunAdapter.InterfaceIndex);
Expand Down Expand Up @@ -268,13 +270,13 @@ private bool RouteAction(Action action, in string ipNetwork, RouteType routeType
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);
Expand Down
2 changes: 1 addition & 1 deletion Netch/Models/IAdapter.cs → Netch/Interfaces/IAdapter.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Net;
using System.Net.NetworkInformation;

namespace Netch.Models
namespace Netch.Interfaces
{
public interface IAdapter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Netch.Controllers
namespace Netch.Interfaces
{
public interface IController
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Netch.Models;

namespace Netch.Controllers
namespace Netch.Interfaces
{
public interface IModeController : IController
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Netch.Models;

namespace Netch.Controllers
namespace Netch.Interfaces
{
public interface IServerController : IController
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Netch.Interops
{
public static class AioDNSInterops
public static class AioDNS
{
private const string aiodns_bin = "aiodns.bin";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Netch.Interops
{
public static class RedirectorInterop
public static class Redirector
{
public enum NameList
{
Expand Down
26 changes: 26 additions & 0 deletions Netch/Interops/RouteHelper.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Netch.Interops
{
public static class TUNInterop
public static class tun2socks
{
public enum NameList
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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);

Expand Down
4 changes: 2 additions & 2 deletions Netch/Models/Range.cs → Netch/Models/NumberRange.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
21 changes: 1 addition & 20 deletions Netch/NativeMethods.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,10 @@
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;

namespace Netch
{
public static class NativeMethods
{
[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);
}
}
3 changes: 2 additions & 1 deletion Netch/Servers/Shadowsocks/SSController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using Netch.Controllers;
using Netch.Interfaces;
using Netch.Models;
using System.Collections.Generic;

namespace Netch.Servers.Shadowsocks
{
Expand Down
12 changes: 6 additions & 6 deletions Netch/Servers/Shadowsocks/SSUtil.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
3 changes: 2 additions & 1 deletion Netch/Servers/ShadowsocksR/SSRController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using Netch.Controllers;
using Netch.Interfaces;
using Netch.Models;
using System.Collections.Generic;

namespace Netch.Servers.ShadowsocksR
{
Expand Down
8 changes: 4 additions & 4 deletions Netch/Servers/ShadowsocksR/SSRUtil.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
8 changes: 4 additions & 4 deletions Netch/Servers/Socks5/S5Util.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
9 changes: 5 additions & 4 deletions Netch/Servers/Trojan/TrojanController.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
Loading

0 comments on commit fb64951

Please sign in to comment.