mirror of
https://github.com/snltty/linker.git
synced 2025-12-20 10:26:45 +08:00
修复一些问题
This commit is contained in:
@@ -27,7 +27,7 @@ namespace cmonitor.tunnel.connection
|
||||
public IPEndPoint IPEndPoint { get; init; }
|
||||
public bool SSL { get; init; }
|
||||
|
||||
public bool Connected => Socket != null && Socket.Poll(-1, SelectMode.SelectWrite) && Socket.Connected;
|
||||
public bool Connected => Socket != null && Environment.TickCount64 - ticks < 15000;
|
||||
public int Delay { get; private set; }
|
||||
public long SendBytes { get; private set; }
|
||||
public long ReceiveBytes { get; private set; }
|
||||
@@ -85,6 +85,7 @@ namespace cmonitor.tunnel.connection
|
||||
length = await Stream.ReadAsync(buffer);
|
||||
if (length == 0) break;
|
||||
ReceiveBytes += length;
|
||||
ticks = Environment.TickCount64;
|
||||
await ReadPacket(buffer.AsMemory(0, length));
|
||||
}
|
||||
else
|
||||
@@ -92,6 +93,7 @@ namespace cmonitor.tunnel.connection
|
||||
length = await Socket.ReceiveAsync(buffer, SocketFlags.None);
|
||||
if (length == 0) break;
|
||||
ReceiveBytes += length;
|
||||
ticks = Environment.TickCount64;
|
||||
await ReadPacket(buffer.AsMemory(0, length));
|
||||
|
||||
while (Socket.Available > 0)
|
||||
@@ -99,6 +101,7 @@ namespace cmonitor.tunnel.connection
|
||||
length = Socket.Receive(buffer);
|
||||
if (length == 0) break;
|
||||
ReceiveBytes += length;
|
||||
ticks = Environment.TickCount64;
|
||||
await ReadPacket(buffer.AsMemory(0, length));
|
||||
}
|
||||
}
|
||||
@@ -154,6 +157,7 @@ namespace cmonitor.tunnel.connection
|
||||
}
|
||||
private async Task CallbackPacket(Memory<byte> packet)
|
||||
{
|
||||
|
||||
if (packet.Length == pingBytes.Length && (packet.Span.SequenceEqual(pingBytes) || packet.Span.SequenceEqual(pongBytes)))
|
||||
{
|
||||
if (packet.Span.SequenceEqual(pingBytes))
|
||||
|
||||
@@ -4,6 +4,7 @@ using common.libs.extends;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
|
||||
namespace cmonitor.tunnel.proxy
|
||||
{
|
||||
@@ -109,10 +110,7 @@ namespace cmonitor.tunnel.proxy
|
||||
byte[] connectData = token.Proxy.ToBytes(out int length);
|
||||
try
|
||||
{
|
||||
foreach (var connection in token.Connections)
|
||||
{
|
||||
await connection.SendAsync(connectData.AsMemory(0, length)).ConfigureAwait(false);
|
||||
}
|
||||
await Task.WhenAll(token.Connections.Select(c => c.SendAsync(connectData.AsMemory(0, length)).AsTask())).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
@@ -134,7 +132,6 @@ namespace cmonitor.tunnel.proxy
|
||||
await ValueTask.CompletedTask;
|
||||
}
|
||||
|
||||
UdpClient broadcastUdp;
|
||||
private async Task SendToSocketUdp(AsyncUserTunnelToken tunnelToken)
|
||||
{
|
||||
|
||||
@@ -143,19 +140,20 @@ namespace cmonitor.tunnel.proxy
|
||||
ConnectIdUdp connectId = new ConnectIdUdp(tunnelToken.Proxy.ConnectId, tunnelToken.Proxy.SourceEP, tunnelToken.Connection.GetHashCode());
|
||||
try
|
||||
{
|
||||
if (tunnelToken.Proxy.TargetEP.Address.GetAddressBytes()[3] == 255)
|
||||
IPEndPoint target = new IPEndPoint(tunnelToken.Proxy.TargetEP.Address, tunnelToken.Proxy.TargetEP.Port);
|
||||
if (target.Address.GetAddressBytes()[3] == 255)
|
||||
{
|
||||
tunnelToken.Proxy.TargetEP.Address = IPAddress.Loopback;
|
||||
target.Address = IPAddress.Loopback;
|
||||
}
|
||||
|
||||
if (udpConnections.TryGetValue(connectId, out AsyncUserUdpTokenTarget token))
|
||||
{
|
||||
token.Connection = tunnelToken.Connection;
|
||||
await token.TargetSocket.SendAsync(tunnelToken.Proxy.Data, tunnelToken.Proxy.TargetEP);
|
||||
await token.TargetSocket.SendAsync(tunnelToken.Proxy.Data, target);
|
||||
token.Update();
|
||||
return;
|
||||
}
|
||||
_ = ConnectUdp(tunnelToken);
|
||||
_ = ConnectUdp(tunnelToken, target);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -191,7 +189,7 @@ namespace cmonitor.tunnel.proxy
|
||||
}
|
||||
}
|
||||
}
|
||||
private async Task ConnectUdp(AsyncUserTunnelToken tunnelToken)
|
||||
private async Task ConnectUdp(AsyncUserTunnelToken tunnelToken, IPEndPoint target)
|
||||
{
|
||||
ConnectIdUdp connectId = new ConnectIdUdp(tunnelToken.Proxy.ConnectId, tunnelToken.Proxy.SourceEP, tunnelToken.Connection.GetHashCode());
|
||||
|
||||
@@ -216,7 +214,7 @@ namespace cmonitor.tunnel.proxy
|
||||
udpToken.Proxy.Direction = ProxyDirection.Reverse;
|
||||
udpConnections.AddOrUpdate(connectId, udpToken, (a, b) => udpToken);
|
||||
|
||||
await udpClient.SendAsync(tunnelToken.Proxy.Data, tunnelToken.Proxy.TargetEP);
|
||||
await udpClient.SendAsync(tunnelToken.Proxy.Data, target);
|
||||
try
|
||||
{
|
||||
while (true)
|
||||
|
||||
@@ -280,7 +280,7 @@ export default {
|
||||
res.List[j].showDel = machineId.value != res.List[j].MachineId && res.List[j].Connected == false;
|
||||
res.List[j].isSelf = machineId.value == res.List[j].MachineId;
|
||||
}
|
||||
state.page.List = res.List.sort((a,b)=>a.Connected - b.Connected);
|
||||
state.page.List = res.List.sort((a,b)=>b.Connected - a.Connected);
|
||||
}).catch((err) => { });
|
||||
}
|
||||
const _getSignList1 = () => {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
using cmonitor.db;
|
||||
using common.libs;
|
||||
using LiteDB;
|
||||
using SharpDX.DXGI;
|
||||
using System.Reflection;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace cmonitor.client.config
|
||||
|
||||
@@ -112,7 +112,7 @@ namespace cmonitor.plugins.relay.messenger
|
||||
|
||||
IConnection targetConnection = await tcsWrap.Tcs.Task.WaitAsync(TimeSpan.FromMilliseconds(3000));
|
||||
|
||||
Relay(connection, targetConnection, info.SecretKey);
|
||||
_ = Relay(connection, targetConnection, info.SecretKey);
|
||||
|
||||
connection.Write(Helper.TrueArray);
|
||||
}
|
||||
@@ -140,8 +140,9 @@ namespace cmonitor.plugins.relay.messenger
|
||||
}
|
||||
}
|
||||
|
||||
private void Relay(IConnection source, IConnection target, string secretKey)
|
||||
private async Task Relay(IConnection source, IConnection target, string secretKey)
|
||||
{
|
||||
await Task.Delay(100);
|
||||
int limit = 0;
|
||||
source.TargetStream = target.SourceStream;
|
||||
source.TargetSocket = target.SourceSocket;
|
||||
@@ -154,8 +155,10 @@ namespace cmonitor.plugins.relay.messenger
|
||||
|
||||
source.Cancel();
|
||||
target.Cancel();
|
||||
_ = source.RelayAsync();
|
||||
_ = target.RelayAsync();
|
||||
|
||||
await Task.Delay(200);
|
||||
|
||||
await Task.WhenAll(source.RelayAsync(), target.RelayAsync());
|
||||
}
|
||||
|
||||
public sealed class TcsWrap
|
||||
|
||||
@@ -5,7 +5,6 @@ using cmonitor.tunnel.connection;
|
||||
using common.libs;
|
||||
using common.libs.extends;
|
||||
using MemoryPack;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Net;
|
||||
using System.Net.Security;
|
||||
using System.Net.Sockets;
|
||||
@@ -69,7 +68,6 @@ namespace cmonitor.plugins.relay.transport
|
||||
await sslStream.AuthenticateAsClientAsync(new SslClientAuthenticationOptions { EnabledSslProtocols = SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12 | SslProtocols.Tls13 });
|
||||
}
|
||||
|
||||
Console.WriteLine($"socket:{socket.Connected}");
|
||||
return new TunnelConnectionTcp
|
||||
{
|
||||
Direction = TunnelDirection.Forward,
|
||||
@@ -130,7 +128,6 @@ namespace cmonitor.plugins.relay.transport
|
||||
sslStream = new SslStream(connection.SourceNetworkStream, false);
|
||||
await sslStream.AuthenticateAsServerAsync(certificate, false, SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12 | SslProtocols.Tls13, false);
|
||||
}
|
||||
Console.WriteLine($"socket:{socket.Connected}");
|
||||
return new TunnelConnectionTcp
|
||||
{
|
||||
Direction = TunnelDirection.Reverse,
|
||||
|
||||
@@ -12,6 +12,7 @@ using System.Buffers.Binary;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
|
||||
namespace cmonitor.plugins.tuntap.proxy
|
||||
{
|
||||
@@ -158,13 +159,18 @@ namespace cmonitor.plugins.tuntap.proxy
|
||||
|
||||
protected override async ValueTask<bool> ConnectionReceiveUdp(AsyncUserTunnelToken token, AsyncUserUdpToken asyncUserUdpToken)
|
||||
{
|
||||
//Console.WriteLine($"receive send {token.Proxy.TargetEP} -> {token.Proxy.SourceEP} {Encoding.UTF8.GetString(token.Proxy.Data.Span)}");
|
||||
byte[] data = Socks5Parser.MakeUdpResponse(token.Proxy.TargetEP, token.Proxy.Data, out int length);
|
||||
try
|
||||
{
|
||||
await asyncUserUdpToken.SourceSocket.SendAsync(data.AsMemory(0, length), token.Proxy.SourceEP);
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (Logger.Instance.LoggerLevel <= LoggerTypes.DEBUG)
|
||||
{
|
||||
Logger.Instance.Error(ex);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
@@ -262,6 +262,7 @@ namespace cmonitor.server
|
||||
break;
|
||||
}
|
||||
ReceiveBytes += length;
|
||||
ticks = Environment.TickCount64;
|
||||
await ReadPacket(buffer.AsMemory(0, length));
|
||||
}
|
||||
}
|
||||
@@ -279,6 +280,10 @@ namespace cmonitor.server
|
||||
finally
|
||||
{
|
||||
ArrayPool<byte>.Shared.Return(buffer);
|
||||
SourceStream?.Close();
|
||||
SourceStream?.Dispose();
|
||||
TargetStream?.Close();
|
||||
TargetStream?.Dispose();
|
||||
}
|
||||
}
|
||||
private async Task ReadPacket(Memory<byte> buffer)
|
||||
@@ -447,7 +452,6 @@ namespace cmonitor.server
|
||||
}
|
||||
private async Task CopyToAsync(NetworkStream source, NetworkStream destination)
|
||||
{
|
||||
await Task.Delay(500);
|
||||
byte[] buffer = ArrayPool<byte>.Shared.Rent(16 * 1024);
|
||||
try
|
||||
{
|
||||
@@ -508,6 +512,7 @@ namespace cmonitor.server
|
||||
userToken = null;
|
||||
cancellationTokenSource?.Cancel();
|
||||
bufferCache.Clear(true);
|
||||
|
||||
}
|
||||
public override void Disponse(int value = 0)
|
||||
{
|
||||
@@ -517,10 +522,10 @@ namespace cmonitor.server
|
||||
|
||||
try
|
||||
{
|
||||
SourceStream?.Close();
|
||||
SourceStream?.Dispose();
|
||||
TargetStream?.Close();
|
||||
TargetStream?.Dispose();
|
||||
SourceNetworkStream?.Close();
|
||||
SourceNetworkStream?.Dispose();
|
||||
TargetNetworkStream?.Close();
|
||||
TargetNetworkStream?.Dispose();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
@@ -4,13 +4,9 @@ for %%r in (win-x64,win-arm64,linux-x64,linux-arm64,osx-x64,osx-arm64) do (
|
||||
for %%c in (ReleaseMonitor,ReleaseNetwork) do (
|
||||
|
||||
dotnet publish ./cmonitor -c %%c -f net8.0 -o ./public/publish/%%c/%%r/single -r %%r -p:PublishTrimmed=true -p:TrimMode=partial --self-contained true -p:TieredPGO=true -p:DebugType=none -p:DebugSymbols=false -p:PublishSingleFile=true -p:EnableCompressionInSingleFile=true -p:DebuggerSupport=false -p:EnableUnsafeBinaryFormatterSerialization=false -p:EnableUnsafeUTF7Encoding=false -p:HttpActivityPropagationSupport=false -p:InvariantGlobalization=true -p:MetadataUpdaterSupport=false -p:UseSystemResourceKeys=true
|
||||
dotnet publish ./cmonitor -c %%c -f net8.0 -r %%r -o ./public/publish/%%c/%%r/any/ -p:PublishSingleFile=true --self-contained false
|
||||
|
||||
echo F|xcopy "public\\extends\\%%c\\%%r\\*" "public\\publish\\%%c\\%%r\\single\\*" /s /f /h /y
|
||||
echo F|xcopy "public\\extends\\%%c\\%%r\\*" "public\\publish\\%%c\\%%r\\any\\*" /s /f /h /y
|
||||
|
||||
echo F|xcopy "public\\extends\\%%c\\any\\*" "public\\publish\\%%c\\%%r\\single\\*" /s /f /h /y
|
||||
echo F|xcopy "public\\extends\\%%c\\any\\*" "public\\publish\\%%c\\%%r\\any\\*" /s /f /h /y
|
||||
|
||||
7z a -tzip ./public/publish-zip/%%c-%%r.zip ./public/publish/%%c/%%r/*
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user