This commit is contained in:
ChsBuffer
2021-02-20 18:15:16 +08:00
parent 021f940957
commit ac0800ec56
79 changed files with 924 additions and 890 deletions

View File

@@ -67,7 +67,9 @@ namespace Netch.Controllers
{
try
{
if (Instance == null || Instance.HasExited) return;
if (Instance == null || Instance.HasExited)
return;
Instance.Kill();
Instance.WaitForExit();
}
@@ -134,7 +136,10 @@ namespace Netch.Controllers
Instance.Start();
if (priority != ProcessPriorityClass.Normal)
Instance.PriorityClass = priority;
if (!RedirectStd) return;
if (!RedirectStd)
return;
// 启动日志重定向
Instance.BeginOutputReadLine();
Instance.BeginErrorReadLine();

View File

@@ -45,6 +45,7 @@ namespace Netch.Controllers
Server = $"127.0.0.1:{Global.Settings.HTTPLocalPort}",
Bypass = string.Join(";", ProxyService.LanIp)
};
service.Global();
}
}
@@ -72,6 +73,7 @@ namespace Netch.Controllers
service.Bypass = prevBypass;
service.Global();
}
if (prevPAC != "")
{
service.AutoConfigUrl = prevPAC;
@@ -89,6 +91,7 @@ namespace Netch.Controllers
}
})
};
Task.WaitAll(tasks);
}

View File

@@ -175,6 +175,7 @@ namespace Netch.Controllers
Task.Run(() => ServerController?.Stop()),
Task.Run(() => ModeController?.Stop())
};
await Task.WhenAll(tasks);
ModeController = null;
ServerController = null;

View File

@@ -57,7 +57,8 @@ namespace Netch.Controllers
aio_dial((int) NameList.TYPE_FILTERLOOPBACK, "false");
aio_dial((int) NameList.TYPE_TCPLISN, Global.Settings.RedirectorTCPPort.ToString());
if (Global.Settings.ProcessNoProxyForUdp && Global.Settings.ProcessNoProxyForTcp) MessageBoxX.Show("");
if (Global.Settings.ProcessNoProxyForUdp && Global.Settings.ProcessNoProxyForTcp)
MessageBoxX.Show("");
//UDP
if (Global.Settings.ProcessNoProxyForUdp)
@@ -96,6 +97,7 @@ namespace Netch.Controllers
_sysDns = DNS.OutboundDNS;
if (string.IsNullOrWhiteSpace(Global.Settings.ModifiedDNS))
Global.Settings.ModifiedDNS = "1.1.1.1,8.8.8.8";
DNS.OutboundDNS = Global.Settings.ModifiedDNS;
}
@@ -138,6 +140,7 @@ namespace Netch.Controllers
{
if (r.StartsWith("!"))
return aio_dial((int) NameList.TYPE_ADDNAME, r.Substring(1));
return aio_dial((int) NameList.TYPE_ADDNAME, r);
}
finally
@@ -177,7 +180,8 @@ namespace Netch.Controllers
reinstallFlag = true;
}
if (!reinstallFlag) return;
if (!reinstallFlag)
return;
Logging.Info("更新驱动");
UninstallDriver();
@@ -352,7 +356,9 @@ namespace Netch.Controllers
// ignored
}
if (!File.Exists(SystemDriver)) return true;
if (!File.Exists(SystemDriver))
return true;
NFAPI.nf_unRegisterDriver("netfilter2");
File.Delete(SystemDriver);

View File

@@ -7,9 +7,15 @@ namespace Netch.Controllers
{
public class NTTController : Guard, IController
{
public override string Name { get; } = "NTT";
public override string MainFile { get; protected set; } = "NTT.exe";
public override string Name { get; } = "NTT";
public override void Stop()
{
StopInstance();
}
/// <summary>
/// 启动 NatTypeTester
/// </summary>
@@ -42,6 +48,7 @@ namespace Netch.Controllers
var str = line.Split(':').Select(s => s.Trim()).ToArray();
if (str.Length < 2)
continue;
var key = str[0];
var value = str[1];
switch (key)
@@ -70,6 +77,7 @@ namespace Netch.Controllers
if (bindingTest == "Fail")
result = "UdpBlocked";
return (result, localEnd, publicEnd);
}
catch (Exception e)
@@ -87,10 +95,5 @@ namespace Netch.Controllers
return (null, null, null);
}
}
public override void Stop()
{
StopInstance();
}
}
}

View File

@@ -48,6 +48,7 @@ namespace Netch.Controllers
// 查找并安装 TAP 适配器
if (string.IsNullOrEmpty(TUNTAP.GetComponentID()))
AddTap();
SearchTapAdapter();
SetupRouteTable(mode);
@@ -102,6 +103,7 @@ namespace Netch.Controllers
Task.Run(ClearRouteTable),
Task.Run(DNSController.Stop)
};
Task.WaitAll(tasks);
}
@@ -145,9 +147,7 @@ namespace Netch.Controllers
{
Logging.Info("代理 → 自定义 DNS");
if (Global.Settings.TUNTAP.UseCustomDNS)
RouteAction(Action.Create,
Global.Settings.TUNTAP.DNS.Select(ip => $"{ip}/32"),
RouteType.TUNTAP);
RouteAction(Action.Create, Global.Settings.TUNTAP.DNS.Select(ip => $"{ip}/32"), RouteType.TUNTAP);
else
RouteAction(Action.Create,
new[] {"1.1.1.1", "8.8.8.8", "9.9.9.9", "185.222.222.222"}.Select(ip => $"{ip}/32"),
@@ -160,14 +160,13 @@ namespace Netch.Controllers
// 将 TUN/TAP 网卡权重放到最高
Process.Start(new ProcessStartInfo
{
FileName = "netsh",
Arguments = $"interface ip set interface {Global.TUNTAP.Index} metric=0",
WindowStyle = ProcessWindowStyle.Hidden,
UseShellExecute = true,
CreateNoWindow = true
}
);
{
FileName = "netsh",
Arguments = $"interface ip set interface {Global.TUNTAP.Index} metric=0",
WindowStyle = ProcessWindowStyle.Hidden,
UseShellExecute = true,
CreateNoWindow = true
});
Logging.Info("绕行 → 规则 IP");
RouteAction(Action.Create, mode.FullRule, RouteType.Outbound);
@@ -256,8 +255,7 @@ namespace Netch.Controllers
return true;
}
private void RouteAction(Action action, in IEnumerable<string> ipNetworks, RouteType routeType,
int metric = 0)
private void RouteAction(Action action, in IEnumerable<string> ipNetworks, RouteType routeType, int metric = 0)
{
foreach (var address in ipNetworks)
RouteAction(action, address, routeType, metric);

View File

@@ -29,7 +29,9 @@ namespace Netch.Controllers
public static Release LatestRelease;
public static event EventHandler NewVersionFound;
public static event EventHandler NewVersionFoundFailed;
public static event EventHandler NewVersionNotFound;
public static async void Check(bool isPreRelease)