mirror of
https://github.com/snltty/linker.git
synced 2026-03-02 04:00:52 +08:00
关闭端口
This commit is contained in:
@@ -6,7 +6,7 @@ is_docker_running () {
|
||||
DOCKER_NAME="linker"
|
||||
|
||||
if [ -f "$FILE_PATH" ]; then
|
||||
DOCKER_NAME=$(cat $FILE_PATH | grep "linker" | awk -F ':' '{print $2}' | xargs)
|
||||
DOCKER_NAME=$(cat $FILE_PATH | grep "container_name" | awk -F ':' '{print $2}' | xargs)
|
||||
echo "DOCKER_NAME is set to: $DOCKER_NAME"
|
||||
fi
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
v1.9.9
|
||||
2026-02-03 22:40:58
|
||||
2026-02-11 15:21:13
|
||||
1. 一些累计更新,一些BUG修复
|
||||
2. 国家级别的连接限制
|
||||
3. 修复一些地方未能正确释放端口的问题
|
||||
|
||||
@@ -267,8 +267,8 @@ namespace linker.tunnel.transport
|
||||
}
|
||||
try
|
||||
{
|
||||
remoteUdp?.Close();
|
||||
remoteUdp?.Close();
|
||||
remoteUdp?.SafeClose();
|
||||
remoteUdp?.SafeClose();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
@@ -166,13 +166,13 @@ namespace linker.tunnel.transport
|
||||
|
||||
targetSocket.KeepAlive();
|
||||
targetSocket.IPv6Only(ep.AddressFamily, false);
|
||||
targetSocket.ReuseBind(new IPEndPoint(ep.AddressFamily == AddressFamily.InterNetwork ? IPAddress.Any : IPAddress.IPv6Any, tunnelTransportInfo.Local.Local.Port));
|
||||
targetSocket.ReuseBind(new IPEndPoint(ep.AddressFamily == AddressFamily.InterNetwork ? IPAddress.Any : IPAddress.IPv6Any, tunnelTransportInfo.Local.Local.Port));
|
||||
|
||||
if (LoggerHelper.Instance.LoggerLevel <= LoggerTypes.DEBUG)
|
||||
{
|
||||
LoggerHelper.Instance.Warning($"{Name} connect to {tunnelTransportInfo.Remote.MachineId}->{tunnelTransportInfo.Remote.MachineName} {ep}");
|
||||
}
|
||||
await targetSocket.ConnectAsync(ep,cts.Token).ConfigureAwait(false);
|
||||
await targetSocket.ConnectAsync(ep, cts.Token).ConfigureAwait(false);
|
||||
|
||||
//需要ssl
|
||||
SslStream sslStream = null;
|
||||
@@ -180,7 +180,8 @@ namespace linker.tunnel.transport
|
||||
{
|
||||
sslStream = new SslStream(new NetworkStream(targetSocket, false), false, ValidateServerCertificate, null);
|
||||
#pragma warning disable SYSLIB0039 // 类型或成员已过时
|
||||
await sslStream.AuthenticateAsClientAsync(new SslClientAuthenticationOptions {
|
||||
await sslStream.AuthenticateAsClientAsync(new SslClientAuthenticationOptions
|
||||
{
|
||||
EnabledSslProtocols = SslProtocols.Tls13 | SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls,
|
||||
CertificateRevocationCheckMode = X509RevocationMode.NoCheck,
|
||||
ClientCertificates = new X509CertificateCollection { certificate }
|
||||
@@ -236,7 +237,7 @@ namespace linker.tunnel.transport
|
||||
}
|
||||
return null;
|
||||
});
|
||||
foreach (Socket item in sockets.Where(c => c != null && c.Connected == false))
|
||||
foreach (Socket item in sockets.Where(c => c != null))
|
||||
{
|
||||
item.SafeClose();
|
||||
}
|
||||
@@ -282,7 +283,7 @@ namespace linker.tunnel.transport
|
||||
return;
|
||||
}
|
||||
|
||||
sslStream = new SslStream(new NetworkStream(socket, false), false, ValidateServerCertificate,null);
|
||||
sslStream = new SslStream(new NetworkStream(socket, false), false, ValidateServerCertificate, null);
|
||||
#pragma warning disable SYSLIB0039 // 类型或成员已过时
|
||||
await sslStream.AuthenticateAsServerAsync(certificate, OperatingSystem.IsAndroid(), SslProtocols.Tls13 | SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls, false).ConfigureAwait(false);
|
||||
#pragma warning restore SYSLIB0039 // 类型或成员已过时
|
||||
|
||||
@@ -145,6 +145,7 @@ namespace linker.tunnel.transport
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
socket.SafeClose();
|
||||
if (LoggerHelper.Instance.LoggerLevel <= LoggerTypes.DEBUG)
|
||||
{
|
||||
LoggerHelper.Instance.Error(ex);
|
||||
|
||||
@@ -113,18 +113,16 @@ namespace linker.tunnel.wanport
|
||||
{
|
||||
byte[] buffer = ArrayPool<byte>.Shared.Rent(1024);
|
||||
using CancellationTokenSource cts = new CancellationTokenSource(5000);
|
||||
Socket socket = new Socket(server.AddressFamily, SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);
|
||||
socket.ReuseBind(new IPEndPoint(IPAddress.Any, 0));
|
||||
try
|
||||
{
|
||||
Socket socket = new Socket(server.AddressFamily, SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);
|
||||
socket.ReuseBind(new IPEndPoint(IPAddress.Any, 0));
|
||||
await socket.ConnectAsync(server, cts.Token).ConfigureAwait(false);
|
||||
|
||||
await socket.SendAsync(BuildSendData(buffer, (byte)new Random().Next(0, 255))).ConfigureAwait(false);
|
||||
|
||||
int length = await socket.ReceiveAsync(buffer.AsMemory(), SocketFlags.None, cts.Token).ConfigureAwait(false);
|
||||
IPEndPoint localEP = socket.LocalEndPoint as IPEndPoint;
|
||||
socket.Close();
|
||||
|
||||
|
||||
return new TunnelWanPortEndPoint { Local = localEP, Remote = UnpackRecvData(buffer, length) };
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -134,6 +132,7 @@ namespace linker.tunnel.wanport
|
||||
}
|
||||
finally
|
||||
{
|
||||
socket.SafeClose();
|
||||
ArrayPool<byte>.Shared.Return(buffer);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user