diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml
index 54198536..44f7e485 100644
--- a/.github/workflows/dotnet.yml
+++ b/.github/workflows/dotnet.yml
@@ -37,7 +37,7 @@ jobs:
release_name: v1.4.5.${{ steps.date.outputs.today }}
draft: false
prerelease: false
- body: "1. 订阅消费,按需同步数据,减少流量消费\r\n2. 更详细的流量统计信息"
+ body: "1. 订阅消费,按需同步数据,减少流量消费\r\n2. 更详细的流量统计信息\r\n3. 修复路由表失效问题"
- name: upload-win-x86-oss
id: upload-win-x86-oss
uses: tvrcgo/oss-action@v0.1.1
diff --git a/linker.libs/LastTicksManager.cs b/linker.libs/LastTicksManager.cs
index eaf5f867..f318c6cf 100644
--- a/linker.libs/LastTicksManager.cs
+++ b/linker.libs/LastTicksManager.cs
@@ -6,37 +6,77 @@ namespace linker.libs
{
private long ticks = Environment.TickCount64;
+ ///
+ /// 当前值
+ ///
public long Value => ticks;
- public void Update()
- {
- ticks = Environment.TickCount64;
- }
- public bool Less(long ms)
+
+ ///
+ /// 差小于等于
+ ///
+ ///
+ ///
+ public bool DiffLessEqual(long ms)
{
return Environment.TickCount64 - ticks <= ms;
}
- public bool Greater(long ms)
+ ///
+ /// 差大于
+ ///
+ ///
+ ///
+ public bool DiffGreater(long ms)
{
return Environment.TickCount64 - ticks > ms;
}
+ ///
+ /// 等于
+ ///
+ ///
+ ///
public bool Equal(long ms)
{
return ticks == ms;
}
- public bool NotEqual(long ms)
- {
- return ticks != ms;
- }
+ ///
+ /// 差值
+ ///
+ ///
public long Diff()
{
return Environment.TickCount64 - ticks;
}
- public bool Timeout(long ms)
+ ///
+ /// 超时
+ ///
+ ///
+ ///
+ public bool Expired(long ms)
{
return ticks == 0 || Environment.TickCount64 - ticks > ms;
}
+ ///
+ /// 不等于
+ ///
+ ///
+ ///
+ public bool HasValue()
+ {
+ return ticks != 0;
+ }
+
+ ///
+ /// 更新值
+ ///
+ public void Update()
+ {
+ ticks = Environment.TickCount64;
+ }
+ ///
+ /// 清除值
+ ///
public void Clear()
{
ticks = 0;
diff --git a/linker.tunnel/connection/TunnelConnectionMsQuic.cs b/linker.tunnel/connection/TunnelConnectionMsQuic.cs
index 62a9134d..6928a54c 100644
--- a/linker.tunnel/connection/TunnelConnectionMsQuic.cs
+++ b/linker.tunnel/connection/TunnelConnectionMsQuic.cs
@@ -32,7 +32,7 @@ namespace linker.tunnel.connection
public byte BufferSize { get; init; } = 3;
- public bool Connected => Stream != null && Stream.CanWrite && LastTicks.NotEqual(0);
+ public bool Connected => Stream != null && Stream.CanWrite && LastTicks.HasValue();
public int Delay { get; private set; }
public long SendBytes { get; private set; }
public long ReceiveBytes { get; private set; }
@@ -179,7 +179,7 @@ namespace linker.tunnel.connection
{
while (cancellationTokenSource.IsCancellationRequested == false)
{
- if (LastTicks.Greater(3000))
+ if (LastTicks.DiffGreater(3000))
{
pingTicks.Update();
await SendPingPong(pingBytes).ConfigureAwait(false);
diff --git a/linker.tunnel/connection/TunnelConnectionTcp.cs b/linker.tunnel/connection/TunnelConnectionTcp.cs
index 77d3cd82..7662d00d 100644
--- a/linker.tunnel/connection/TunnelConnectionTcp.cs
+++ b/linker.tunnel/connection/TunnelConnectionTcp.cs
@@ -27,7 +27,7 @@ namespace linker.tunnel.connection
public IPEndPoint IPEndPoint { get; init; }
public bool SSL { get; init; }
public byte BufferSize { get; init; } = 3;
- public bool Connected => Socket != null && LastTicks.Timeout(15000) == false;
+ public bool Connected => Socket != null && LastTicks.Expired(15000) == false;
public int Delay { get; private set; }
public long SendBytes { get; private set; }
public long ReceiveBytes { get; private set; }
@@ -192,7 +192,7 @@ namespace linker.tunnel.connection
break;
}
- if (LastTicks.Greater(3000))
+ if (LastTicks.DiffGreater(3000))
{
pingTicks.Update();
await SendPingPong(pingBytes).ConfigureAwait(false);
diff --git a/linker.tunnel/connection/TunnelConnectionUdp.cs b/linker.tunnel/connection/TunnelConnectionUdp.cs
index df13518b..ae21e84f 100644
--- a/linker.tunnel/connection/TunnelConnectionUdp.cs
+++ b/linker.tunnel/connection/TunnelConnectionUdp.cs
@@ -27,7 +27,7 @@ namespace linker.tunnel.connection
public bool SSL { get; init; }
public byte BufferSize { get; init; } = 3;
- public bool Connected => UdpClient != null && LastTicks.Timeout(15000) == false;
+ public bool Connected => UdpClient != null && LastTicks.Expired(15000) == false;
public int Delay { get; private set; }
public long SendBytes { get; private set; }
public long ReceiveBytes { get; private set; }
@@ -178,7 +178,7 @@ namespace linker.tunnel.connection
break;
}
- if (LastTicks.Greater(3000))
+ if (LastTicks.DiffGreater(3000))
{
pingTicks.Update();
await SendPingPong(pingBytes).ConfigureAwait(false);
diff --git a/linker.tunnel/transport/TransportUdpPortMap.cs b/linker.tunnel/transport/TransportUdpPortMap.cs
index 0e97e243..3d82ff38 100644
--- a/linker.tunnel/transport/TransportUdpPortMap.cs
+++ b/linker.tunnel/transport/TransportUdpPortMap.cs
@@ -125,7 +125,7 @@ namespace linker.tunnel.transport
}
}
}
- catch (Exception ex)
+ catch (Exception)
{
socket.SafeClose();
break;
@@ -351,7 +351,7 @@ namespace linker.tunnel.transport
{
TimerHelper.SetInterval(() =>
{
- var keys = connectionsDic.Where(c => (c.Value.Connection == null && c.Value.LastTicks.Greater(5000)) || (c.Value.Connection != null && c.Value.Connection.Connected == false)).Select(c => c.Key).ToList();
+ var keys = connectionsDic.Where(c => (c.Value.Connection == null && c.Value.LastTicks.DiffGreater(5000)) || (c.Value.Connection != null && c.Value.Connection.Connected == false)).Select(c => c.Key).ToList();
foreach (var item in keys)
{
connectionsDic.TryRemove(item, out _);
diff --git a/linker/linker.csproj b/linker/linker.csproj
index 77e40e65..fd536745 100644
--- a/linker/linker.csproj
+++ b/linker/linker.csproj
@@ -20,7 +20,8 @@
snltty
snltty
1. 订阅消费,按需同步数据,减少流量消费
-2. 更详细的流量统计信息
+2. 更详细的流量统计信息
+3. 修复路由表失效问题
snltty
https://github.com/snltty/linker
https://github.com/snltty/linker
diff --git a/linker/plugins/flow/IFlow.cs b/linker/plugins/flow/IFlow.cs
index ccd0a32b..edba45bb 100644
--- a/linker/plugins/flow/IFlow.cs
+++ b/linker/plugins/flow/IFlow.cs
@@ -1,5 +1,4 @@
-using linker.libs;
-using MemoryPack;
+using MemoryPack;
using System.Text.Json.Serialization;
namespace linker.plugins.flow
diff --git a/linker/plugins/forward/proxy/ForwardProxyUdp.cs b/linker/plugins/forward/proxy/ForwardProxyUdp.cs
index 5e447f35..8cf61ab0 100644
--- a/linker/plugins/forward/proxy/ForwardProxyUdp.cs
+++ b/linker/plugins/forward/proxy/ForwardProxyUdp.cs
@@ -385,7 +385,7 @@ namespace linker.plugins.forward.proxy
public byte[] Buffer { get; set; }
public LastTicksManager LastTicks { get; set; } = new LastTicksManager();
- public bool Timeout => LastTicks.Timeout(60 * 60 * 1000);
+ public bool Timeout => LastTicks.Expired(60 * 1000);
public void Clear()
{
TargetSocket?.SafeClose();
diff --git a/linker/plugins/messenger/IConnection.cs b/linker/plugins/messenger/IConnection.cs
index 35884353..330d15c0 100644
--- a/linker/plugins/messenger/IConnection.cs
+++ b/linker/plugins/messenger/IConnection.cs
@@ -246,7 +246,7 @@ namespace linker.plugins.messenger
}
- public override bool Connected => SourceSocket != null && lastTicks.Timeout(15000) == false;
+ public override bool Connected => SourceSocket != null && lastTicks.Expired(15000) == false;
private IConnectionReceiveCallback callback;
@@ -257,7 +257,7 @@ namespace linker.plugins.messenger
private ReceiveDataBuffer bufferCache = new ReceiveDataBuffer();
private LastTicksManager lastTicks = new LastTicksManager();
- private LastTicksManager pingTicks =new LastTicksManager();
+ private LastTicksManager pingTicks = new LastTicksManager();
private static byte[] pingBytes = Encoding.UTF8.GetBytes($"{Helper.GlobalString}.tcp.ping");
private static byte[] pongBytes = Encoding.UTF8.GetBytes($"{Helper.GlobalString}.tcp.pong");
private bool pong = true;
@@ -384,9 +384,9 @@ namespace linker.plugins.messenger
{
while (cancellationTokenSource.IsCancellationRequested == false)
{
- if (lastTicks.Greater(3000))
+ if (lastTicks.DiffGreater(3000))
{
- pingTicks .Update();
+ pingTicks.Update();
await SendPingPong(pingBytes).ConfigureAwait(false);
}
diff --git a/linker/plugins/relay/RelayFlow.cs b/linker/plugins/relay/RelayFlow.cs
index d2856613..79f0727c 100644
--- a/linker/plugins/relay/RelayFlow.cs
+++ b/linker/plugins/relay/RelayFlow.cs
@@ -19,7 +19,7 @@ namespace linker.plugins.relay
{
TimerHelper.SetInterval(() =>
{
- if (lastTicksManager.Less(5000))
+ if (lastTicksManager.DiffLessEqual(5000))
{
foreach (var item in flows.Values)
{
diff --git a/linker/plugins/sforward/proxy/SForwardFlow.cs b/linker/plugins/sforward/proxy/SForwardFlow.cs
index 025fd675..5dab0ef6 100644
--- a/linker/plugins/sforward/proxy/SForwardFlow.cs
+++ b/linker/plugins/sforward/proxy/SForwardFlow.cs
@@ -19,7 +19,7 @@ namespace linker.plugins.sforward.proxy
{
TimerHelper.SetInterval(() =>
{
- if (lastTicksManager.Less(5000))
+ if (lastTicksManager.DiffLessEqual(5000))
{
foreach (var item in flows.Values)
{
diff --git a/linker/plugins/sforward/proxy/SForwardProxyUdp.cs b/linker/plugins/sforward/proxy/SForwardProxyUdp.cs
index 86ea58cd..358caca0 100644
--- a/linker/plugins/sforward/proxy/SForwardProxyUdp.cs
+++ b/linker/plugins/sforward/proxy/SForwardProxyUdp.cs
@@ -292,7 +292,7 @@ namespace linker.plugins.sforward.proxy
{
public IPEndPoint IPEndPoint { get; set; }
public LastTicksManager LastTicks { get; set; } = new LastTicksManager();
- public bool Timeout => LastTicks.Greater(5 * 60 * 1000);
+ public bool Timeout => LastTicks.DiffGreater(5 * 60 * 1000);
}
public sealed class UdpConnectedCache
@@ -300,7 +300,7 @@ namespace linker.plugins.sforward.proxy
public Socket SourceSocket { get; set; }
public Socket TargetSocket { get; set; }
public LastTicksManager LastTicks { get; set; } = new LastTicksManager();
- public bool Timeout => LastTicks.Greater(5 * 60 * 1000);
+ public bool Timeout => LastTicks.DiffGreater(5 * 60 * 1000);
public void Clear()
{
diff --git a/linker/plugins/tuntap/TuntapProxy.cs b/linker/plugins/tuntap/TuntapProxy.cs
index b8daf291..eb9be101 100644
--- a/linker/plugins/tuntap/TuntapProxy.cs
+++ b/linker/plugins/tuntap/TuntapProxy.cs
@@ -10,6 +10,7 @@ using System.Buffers.Binary;
using linker.plugins.client;
using linker.plugins.tunnel;
using System.Buffers;
+using linker.libs.extends;
namespace linker.plugins.tuntap
{
diff --git a/linker/plugins/tuntap/TuntapTransfer.cs b/linker/plugins/tuntap/TuntapTransfer.cs
index 3a173acc..829e6095 100644
--- a/linker/plugins/tuntap/TuntapTransfer.cs
+++ b/linker/plugins/tuntap/TuntapTransfer.cs
@@ -446,7 +446,7 @@ namespace linker.plugins.tuntap
return infos
//自己的ip不要
- .Where(c => c.IP.Equals(runningConfig.Data.Tuntap.IP) == false && c.LastTicks.Greater(0))
+ .Where(c => c.IP.Equals(runningConfig.Data.Tuntap.IP) == false && c.LastTicks.Value > 0)
.OrderByDescending(c => c.LastTicks.Value)
.Select(c =>
{
@@ -539,7 +539,7 @@ namespace linker.plugins.tuntap
{
TimerHelper.SetInterval(async () =>
{
- if (lastTicksManager.Less(5000))
+ if (lastTicksManager.DiffLessEqual(5000))
{
await Ping();
}
@@ -547,7 +547,7 @@ namespace linker.plugins.tuntap
}, 3000);
TimerHelper.SetInterval(async () =>
{
- if (lastTicksManager.Greater(15000))
+ if (lastTicksManager.DiffGreater(15000))
{
await Ping();
}
diff --git a/linker/plugins/updater/UpdaterClientTransfer.cs b/linker/plugins/updater/UpdaterClientTransfer.cs
index f5ba606e..c68653b7 100644
--- a/linker/plugins/updater/UpdaterClientTransfer.cs
+++ b/linker/plugins/updater/UpdaterClientTransfer.cs
@@ -87,7 +87,7 @@ namespace linker.plugins.updater
}
//距离上次订阅超过一分钟,需要立即更新一次
- bool needUpdate = lastTicksManager.Greater(60 * 1000);
+ bool needUpdate = lastTicksManager.DiffGreater(60 * 1000);
lastTicksManager.Update();
@@ -104,7 +104,7 @@ namespace linker.plugins.updater
if (updateInfo.Updated)
{
updateInfo.MachineId = fileConfig.Data.Client.Id;
- string[] machines = subscribes.Where(c => c.Value.Less(15000)).Select(c => c.Key).ToArray();
+ string[] machines = subscribes.Where(c => c.Value.DiffLessEqual(15000)).Select(c => c.Key).ToArray();
if (machines.Length > 0)
{
await messengerSender.SendOnly(new MessageRequestWrap
diff --git a/version.txt b/version.txt
index eb6fd73c..c5ea2a92 100644
--- a/version.txt
+++ b/version.txt
@@ -1,4 +1,5 @@
v1.4.5
-2024-09-28 13:31:54
+2024-09-28 14:56:27
1. 订阅消费,按需同步数据,减少流量消费
-2. 更详细的流量统计信息
\ No newline at end of file
+2. 更详细的流量统计信息
+3. 修复路由表失效问题
\ No newline at end of file