防火墙

This commit is contained in:
snltty
2025-05-11 18:26:11 +08:00
parent bf2c3a5050
commit 24418ee37f
10 changed files with 43 additions and 29 deletions

View File

@@ -37,7 +37,7 @@ jobs:
release_name: v1.7.9.${{ steps.date.outputs.today }} release_name: v1.7.9.${{ steps.date.outputs.today }}
draft: false draft: false
prerelease: false prerelease: false
body: "1. 一些累计更新\r\n2. 优化安卓APP\r\n3. 新增防火墙用于网卡、端口转发、和socks5\r\n4. 检测密钥是否正确\r\n5. 如果你设备很多,请尝试升级其中一个成功重启后再升级其它" body: "1. 一些累计更新\r\n2. 优化安卓APP\r\n3. 新增防火墙用于网卡、端口转发、和socks5\r\n4. 优化重启清理数据,优化了网卡自启动问题\r\n5. 检测密钥是否正确\r\n6. 如果你设备很多,请尝试升级其中一个成功重启后再升级其它"
- name: publish projects - name: publish projects
run: ./publish.bat "C:\\Android\\android-sdk" run: ./publish.bat "C:\\Android\\android-sdk"
- name: upload-win-x86-oss - name: upload-win-x86-oss

View File

@@ -25,10 +25,19 @@ namespace linker.libs
public static async Task Await() public static async Task Await()
{ {
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
AppDomain.CurrentDomain.ProcessExit += (sender, e) => cancellationTokenSource.Cancel();
Console.CancelKeyPress += (sender, e) => cancellationTokenSource.Cancel(); AppDomain.CurrentDomain.ProcessExit += (sender, e) => Exit(cancellationTokenSource);
Console.CancelKeyPress += (sender, e) => Exit(cancellationTokenSource);
await Task.Delay(-1, cancellationTokenSource.Token).ConfigureAwait(false); await Task.Delay(-1, cancellationTokenSource.Token).ConfigureAwait(false);
} }
private static void Exit(CancellationTokenSource cancellationTokenSource)
{
if(cancellationTokenSource.IsCancellationRequested == false)
{
cancellationTokenSource.Cancel();
AppExit(0);
}
}
private delegate bool ConsoleCtrlDelegate(int ctrlType); private delegate bool ConsoleCtrlDelegate(int ctrlType);
private static ConsoleCtrlDelegate handler; private static ConsoleCtrlDelegate handler;

View File

@@ -1,4 +1,5 @@
using System.Net; using linker.libs;
using System.Net;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
namespace linker.messenger.signin namespace linker.messenger.signin
{ {
@@ -10,11 +11,12 @@ namespace linker.messenger.signin
public SignInClientState() public SignInClientState()
{ {
if (OperatingSystem.IsAndroid() == false) Helper.OnAppExit += Helper_OnAppExit;
{ }
AppDomain.CurrentDomain.ProcessExit += (s, e) => Disponse();
Console.CancelKeyPress += (s, e) => Disponse(); private void Helper_OnAppExit(object sender, EventArgs e)
} {
Disponse();
} }
/// <summary> /// <summary>

View File

@@ -33,6 +33,7 @@ namespace linker.messenger.store.file
private void Helper_OnAppExit(object sender, EventArgs e) private void Helper_OnAppExit(object sender, EventArgs e)
{ {
Save(); Save();
dBfactory.Dispose();
} }
private void Load() private void Load()

View File

@@ -4,7 +4,6 @@ using linker.libs.timer;
using linker.tunnel.connection; using linker.tunnel.connection;
using LiteDB; using LiteDB;
using System.Net; using System.Net;
using System.Runtime.ExceptionServices;
namespace linker.messenger.store.file namespace linker.messenger.store.file
{ {
@@ -47,12 +46,6 @@ namespace linker.messenger.store.file
//让服务自动重启 //让服务自动重启
Helper.AppExit(1); Helper.AppExit(1);
} }
if (OperatingSystem.IsAndroid() == false)
{
AppDomain.CurrentDomain.ProcessExit += (s, e) => { database.Checkpoint(); database.Dispose(); };
Console.CancelKeyPress += (s, e) => { database.Checkpoint(); database.Dispose(); };
}
TimerHelper.SetIntervalLong(database.Checkpoint, 3000); TimerHelper.SetIntervalLong(database.Checkpoint, 3000);
} }
@@ -60,6 +53,12 @@ namespace linker.messenger.store.file
{ {
return database.GetCollection<T>(name); return database.GetCollection<T>(name);
} }
public void Dispose()
{
database.Checkpoint();
database.Dispose();
}
} }
} }

View File

@@ -29,11 +29,6 @@ namespace linker.messenger.tuntap
this.linkerTunDeviceAdapter = linkerTunDeviceAdapter; this.linkerTunDeviceAdapter = linkerTunDeviceAdapter;
linkerTunDeviceAdapter.AddHooks(new List<ILinkerTunPacketHook> { tuntapFirewall }); linkerTunDeviceAdapter.AddHooks(new List<ILinkerTunPacketHook> { tuntapFirewall });
Helper.OnAppExit += Helper_OnAppExit; Helper.OnAppExit += Helper_OnAppExit;
if (OperatingSystem.IsAndroid() == false)
{
AppDomain.CurrentDomain.ProcessExit += (s, e) => Shutdown();
Console.CancelKeyPress += (s, e) => Shutdown();
}
} }
private void Helper_OnAppExit(object sender, EventArgs e) private void Helper_OnAppExit(object sender, EventArgs e)

View File

@@ -16,8 +16,13 @@ namespace linker.tun
public LanSnat() public LanSnat()
{ {
} }
private void Helper_OnAppExit(object sender, EventArgs e)
{
Shutdown();
}
public void Setup(IPAddress address, byte prefixLength, LinkerTunAppNatItemInfo[] items, ref string error) public void Setup(IPAddress address, byte prefixLength, LinkerTunAppNatItemInfo[] items, ref string error)
{ {
if (OperatingSystem.IsWindows() == false) return; if (OperatingSystem.IsWindows() == false) return;

View File

@@ -156,6 +156,7 @@ namespace linker.tun
cancellationTokenSource?.Cancel(); cancellationTokenSource?.Cancel();
linkerTunDevice.Shutdown(); linkerTunDevice.Shutdown();
linkerTunDevice.RemoveNat(out string error); linkerTunDevice.RemoveNat(out string error);
lanSnat.Shutdown();
} }
catch (Exception) catch (Exception)
{ {
@@ -289,7 +290,7 @@ namespace linker.tun
List<ILinkerTunPacketHook> list = this.hooks.ToList(); List<ILinkerTunPacketHook> list = this.hooks.ToList();
list.AddRange(hooks); list.AddRange(hooks);
this.hooks = list.Distinct().OrderBy(c=>c.Level).ToArray(); this.hooks = list.Distinct().OrderBy(c => c.Level).ToArray();
} }
private void Read() private void Read()
@@ -334,7 +335,7 @@ namespace linker.tun
/// </summary> /// </summary>
/// <param name="buffer"></param> /// <param name="buffer"></param>
/// <returns></returns> /// <returns></returns>
public bool Write(string srcId,ReadOnlyMemory<byte> buffer) public bool Write(string srcId, ReadOnlyMemory<byte> buffer)
{ {
if (linkerTunDevice == null || Status != LinkerTunDeviceStatus.Running) return false; if (linkerTunDevice == null || Status != LinkerTunDeviceStatus.Running) return false;

View File

@@ -23,8 +23,9 @@
<Description>1. 一些累计更新 <Description>1. 一些累计更新
2. 优化安卓APP 2. 优化安卓APP
3. 新增防火墙用于网卡、端口转发、和socks5 3. 新增防火墙用于网卡、端口转发、和socks5
4. 检测密钥是否正确 4. 优化重启清理数据,优化了网卡自启动问题
5. 如果你设备很多,请尝试升级其中一个成功重启后再升级其它</Description> 5. 检测密钥是否正确
6. 如果你设备很多,请尝试升级其中一个成功重启后再升级其它</Description>
<Copyright>snltty</Copyright> <Copyright>snltty</Copyright>
<PackageProjectUrl>https://github.com/snltty/linker</PackageProjectUrl> <PackageProjectUrl>https://github.com/snltty/linker</PackageProjectUrl>
<RepositoryUrl>https://github.com/snltty/linker</RepositoryUrl> <RepositoryUrl>https://github.com/snltty/linker</RepositoryUrl>

View File

@@ -1,7 +1,8 @@
v1.7.9 v1.7.9
2025-05-11 18:02:02 2025-05-11 18:26:11
1. 一些累计更新 1. 一些累计更新
2. 优化安卓APP 2. 优化安卓APP
3. 新增防火墙用于网卡、端口转发、和socks5 3. 新增防火墙用于网卡、端口转发、和socks5
4. 检测密钥是否正确 4. 优化重启清理数据,优化了网卡自启动问题
5. 如果你设备很多,请尝试升级其中一个成功重启后再升级其它 5. 检测密钥是否正确
6. 如果你设备很多,请尝试升级其中一个成功重启后再升级其它