mirror of
https://github.com/snltty/linker.git
synced 2025-10-15 21:50:42 +08:00
sync
This commit is contained in:
@@ -32,12 +32,12 @@ namespace linker.tunnel.connection
|
||||
|
||||
public byte BufferSize { get; init; } = 3;
|
||||
|
||||
public bool Connected => Stream != null && Stream.CanWrite && LastTicks > 0;
|
||||
public bool Connected => Stream != null && Stream.CanWrite && LastTicks.NotEqual(0);
|
||||
public int Delay { get; private set; }
|
||||
public long SendBytes { get; private set; }
|
||||
public long ReceiveBytes { get; private set; }
|
||||
|
||||
public long LastTicks { get; private set; } = Environment.TickCount64;
|
||||
public LastTicksManager LastTicks { get; private set; } = new LastTicksManager();
|
||||
|
||||
[JsonIgnore]
|
||||
public QuicStream Stream { get; init; }
|
||||
@@ -56,7 +56,7 @@ namespace linker.tunnel.connection
|
||||
private bool framing;
|
||||
private ReceiveDataBuffer bufferCache = new ReceiveDataBuffer();
|
||||
|
||||
private long pingStart = Environment.TickCount64;
|
||||
private LastTicksManager pingTicks = new();
|
||||
private byte[] pingBytes = Encoding.UTF8.GetBytes($"{Helper.GlobalString}.tcp.ping");
|
||||
private byte[] pongBytes = Encoding.UTF8.GetBytes($"{Helper.GlobalString}.tcp.pong");
|
||||
private bool pong = true;
|
||||
@@ -148,7 +148,7 @@ namespace linker.tunnel.connection
|
||||
private async Task CallbackPacket(Memory<byte> packet)
|
||||
{
|
||||
ReceiveBytes += packet.Length;
|
||||
LastTicks = Environment.TickCount64;
|
||||
LastTicks.Update();
|
||||
if (packet.Length == pingBytes.Length && (packet.Span.SequenceEqual(pingBytes) || packet.Span.SequenceEqual(pongBytes)))
|
||||
{
|
||||
if (packet.Span.SequenceEqual(pingBytes))
|
||||
@@ -157,7 +157,7 @@ namespace linker.tunnel.connection
|
||||
}
|
||||
else if (packet.Span.SequenceEqual(pongBytes))
|
||||
{
|
||||
Delay = (int)(Environment.TickCount64 - pingStart);
|
||||
Delay = (int)pingTicks.Diff();
|
||||
pong = true;
|
||||
}
|
||||
}
|
||||
@@ -179,9 +179,9 @@ namespace linker.tunnel.connection
|
||||
{
|
||||
while (cancellationTokenSource.IsCancellationRequested == false)
|
||||
{
|
||||
if (Environment.TickCount64 - LastTicks > 3000)
|
||||
if (LastTicks.Greater(3000))
|
||||
{
|
||||
pingStart = Environment.TickCount64;
|
||||
pingTicks.Update();
|
||||
await SendPingPong(pingBytes).ConfigureAwait(false);
|
||||
}
|
||||
await Task.Delay(3000).ConfigureAwait(false);
|
||||
@@ -223,7 +223,7 @@ namespace linker.tunnel.connection
|
||||
{
|
||||
if (pong == false) return;
|
||||
pong = false;
|
||||
pingStart = Environment.TickCount64;
|
||||
pingTicks.Update();
|
||||
await SendPingPong(pingBytes).ConfigureAwait(false);
|
||||
}
|
||||
private SemaphoreSlim semaphoreSlim = new SemaphoreSlim(1);
|
||||
@@ -254,7 +254,7 @@ namespace linker.tunnel.connection
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
LastTicks = 0;
|
||||
LastTicks.Clear();
|
||||
|
||||
if (LoggerHelper.Instance.LoggerLevel <= LoggerTypes.DEBUG)
|
||||
LoggerHelper.Instance.Error($"tunnel connection writer offline {ToString()}");
|
||||
|
Reference in New Issue
Block a user