diff --git a/linker.libs/linker.libs.csproj b/linker.libs/linker.libs.csproj index 6e966cfc..da11ff5f 100644 --- a/linker.libs/linker.libs.csproj +++ b/linker.libs/linker.libs.csproj @@ -15,8 +15,8 @@ https://github.com/snltty/linker https://github.com/snltty/linker 1.1.1 - 1.1.1.1 - 1.1.1.1 + 1.1.1.2 + 1.1.1.2 DEBUG;TRACE diff --git a/linker.service/linker.service.csproj b/linker.service/linker.service.csproj index 2a3d532e..e28d95a0 100644 --- a/linker.service/linker.service.csproj +++ b/linker.service/linker.service.csproj @@ -14,6 +14,16 @@ true true true + 1.1.1 + snltty + snltty + snltty + snltty + https://github.com/snltty/linker + https://github.com/snltty/linker + snltty service + 1.1.1.2 + 1.1.1.2 diff --git a/linker.tunnel/TunnelTransfer.cs b/linker.tunnel/TunnelTransfer.cs index 0b45fdfc..5964dfa6 100644 --- a/linker.tunnel/TunnelTransfer.cs +++ b/linker.tunnel/TunnelTransfer.cs @@ -170,8 +170,8 @@ namespace linker.tunnel LoggerHelper.Instance.Error($"tunnel {transport.Name} get remote {remoteMachineId} external ip fail "); break; } - LoggerHelper.Instance.Info($"tunnel {transport.Name} got local external ip {localInfo.ToJson()}"); - LoggerHelper.Instance.Info($"tunnel {transport.Name} got remote external ip {remoteInfo.ToJson()}"); + LoggerHelper.Instance.Info($"tunnel {transport.Name} got local external ip {localInfo.Result.ToJson()}"); + LoggerHelper.Instance.Info($"tunnel {transport.Name} got remote external ip {remoteInfo.Result.ToJson()}"); tunnelTransportInfo = new TunnelTransportInfo @@ -265,10 +265,7 @@ namespace linker.tunnel public void OnFail(TunnelTransportInfo tunnelTransportInfo) { ITunnelTransport _transports = transports.FirstOrDefault(c => c.Name == tunnelTransportInfo.TransportName && c.ProtocolType == tunnelTransportInfo.TransportType); - if (_transports != null) - { - _transports.OnFail(tunnelTransportInfo); - } + _transports?.OnFail(tunnelTransportInfo); } /// /// 收到对方发来的连接成功的消息 @@ -277,10 +274,7 @@ namespace linker.tunnel public void OnSuccess(TunnelTransportInfo tunnelTransportInfo) { ITunnelTransport _transports = transports.FirstOrDefault(c => c.Name == tunnelTransportInfo.TransportName && c.ProtocolType == tunnelTransportInfo.TransportType); - if (_transports != null) - { - _transports.OnSuccess(tunnelTransportInfo); - } + _transports?.OnSuccess(tunnelTransportInfo); } /// @@ -290,6 +284,7 @@ namespace linker.tunnel public async Task GetWanPort(TunnelWanPortProtocolInfo _info) { TunnelWanPortInfo info = tunnelAdapter.GetTunnelWanPortProtocols().FirstOrDefault(c => c.Type == _info.Type && c.ProtocolType == _info.ProtocolType); + if (info == null) return null; return await GetLocalInfo(info).ConfigureAwait(false); } diff --git a/linker.tunnel/linker.tunnel.csproj b/linker.tunnel/linker.tunnel.csproj index d867d31a..c30ca2a6 100644 --- a/linker.tunnel/linker.tunnel.csproj +++ b/linker.tunnel/linker.tunnel.csproj @@ -17,8 +17,8 @@ https://github.com/snltty/linker https://github.com/snltty/linker linker tunnel - 1.1.1.1 - 1.1.1.1 + 1.1.1.2 + 1.1.1.2 diff --git a/linker.tunnel/proxy/TunnelProxyTcp.cs b/linker.tunnel/proxy/TunnelProxyTcp.cs index 9fd8bf08..aa1ceb9d 100644 --- a/linker.tunnel/proxy/TunnelProxyTcp.cs +++ b/linker.tunnel/proxy/TunnelProxyTcp.cs @@ -224,11 +224,6 @@ namespace linker.tunnel.proxy { if (token.Proxy.TargetEP == null) return; - if (LoggerHelper.Instance.LoggerLevel <= LoggerTypes.DEBUG) - { - LoggerHelper.Instance.Warning($"connect {token.Proxy.ConnectId} {token.Proxy.TargetEP}"); - } - Socket socket = new Socket(token.Proxy.TargetEP.AddressFamily, SocketType.Stream, ProtocolType.Tcp); socket.KeepAlive(); @@ -258,11 +253,7 @@ namespace linker.tunnel.proxy token.Socket.EndConnect(result); token.Socket.KeepAlive(); - if (LoggerHelper.Instance.LoggerLevel <= LoggerTypes.DEBUG) - { - LoggerHelper.Instance.Warning($"connect {token.Proxy.ConnectId} {token.Proxy.TargetEP} success"); - } - + if (state.Data.Length > 0) { await token.Socket.SendAsync(state.Data.AsMemory(0, state.Length), SocketFlags.None).ConfigureAwait(false); diff --git a/linker.tunnel/transport/TransportTcpP2PNAT.cs b/linker.tunnel/transport/TransportTcpP2PNAT.cs index b416ebea..92b63513 100644 --- a/linker.tunnel/transport/TransportTcpP2PNAT.cs +++ b/linker.tunnel/transport/TransportTcpP2PNAT.cs @@ -18,9 +18,9 @@ namespace linker.tunnel.transport public string Label => "TCP、同时打开"; public TunnelProtocolType ProtocolType => TunnelProtocolType.Tcp; public TunnelWanPortProtocolType AllowWanPortProtocolType => TunnelWanPortProtocolType.Tcp; - public bool Reverse => false; + public bool Reverse => true; - public bool DisableReverse => true; + public bool DisableReverse => false; public bool SSL => true; @@ -65,7 +65,10 @@ namespace linker.tunnel.transport { return null; } - await Task.Delay(50).ConfigureAwait(false); + if(tunnelTransportInfo.Direction == TunnelDirection.Reverse) + { + await Task.Delay(50).ConfigureAwait(false); + } ITunnelConnection connection = await ConnectForward(tunnelTransportInfo, TunnelMode.Client).ConfigureAwait(false); if (connection != null) { diff --git a/linker.tunnel/wanport/ITunnelWanPortProtocol.cs b/linker.tunnel/wanport/ITunnelWanPortProtocol.cs index 072ec031..5c037626 100644 --- a/linker.tunnel/wanport/ITunnelWanPortProtocol.cs +++ b/linker.tunnel/wanport/ITunnelWanPortProtocol.cs @@ -68,6 +68,7 @@ namespace linker.tunnel.wanport { public TunnelWanPortType Value { get; set; } public string Name { get; set; } + public Dictionary Protocols { get; set; } = new Dictionary(); } public sealed class TunnelWanPortTypeInfoEqualityComparer : IEqualityComparer diff --git a/linker.tunnel/wanport/TunnelWanPortProtocolLinker.cs b/linker.tunnel/wanport/TunnelWanPortProtocolLinker.cs index 3c16a78e..41b0d615 100644 --- a/linker.tunnel/wanport/TunnelWanPortProtocolLinker.cs +++ b/linker.tunnel/wanport/TunnelWanPortProtocolLinker.cs @@ -75,8 +75,8 @@ namespace linker.tunnel.wanport try { Socket socket = new Socket(server.AddressFamily, SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp); + socket.Reuse(true); await socket.ConnectAsync(server).ConfigureAwait(false); - await socket.SendAsync(new byte[] { 0 }); int length = await socket.ReceiveAsync(buffer.AsMemory(), SocketFlags.None).ConfigureAwait(false); diff --git a/linker.tunnel/wanport/TunnelWanPortTransfer.cs b/linker.tunnel/wanport/TunnelWanPortTransfer.cs index 8ee579d7..716ccc51 100644 --- a/linker.tunnel/wanport/TunnelWanPortTransfer.cs +++ b/linker.tunnel/wanport/TunnelWanPortTransfer.cs @@ -1,4 +1,5 @@ using linker.libs; +using linker.libs.extends; using System.Diagnostics; using System.Net; @@ -27,7 +28,14 @@ namespace linker.tunnel.wanport public List GetTypes() { - return tunnelWanPorts.Select(c => new TunnelWanPortTypeInfo { Value = c.Type, Name = c.Type.ToString() }).Distinct(new TunnelWanPortTypeInfoEqualityComparer()).ToList(); + List res = tunnelWanPorts.Select(c => new TunnelWanPortTypeInfo + { + Value = c.Type, + Name = c.Type.ToString(), + Protocols = tunnelWanPorts + .Where(d => d.Type == c.Type).ToList().Select(d => d.ProtocolType).Distinct().ToDictionary(c => (int)c, d => d.ToString()), + }).Distinct(new TunnelWanPortTypeInfoEqualityComparer()).ToList(); + return res; } /// @@ -39,6 +47,7 @@ namespace linker.tunnel.wanport { if (info == null) return null; var tunnelWanPort = tunnelWanPorts.FirstOrDefault(c => c.Type == info.Type && c.ProtocolType == info.ProtocolType); + if (tunnelWanPort == null) return null; try { Stopwatch sw = new Stopwatch(); @@ -49,11 +58,11 @@ namespace linker.tunnel.wanport { LoggerHelper.Instance.Warning($"get domain ip time:{sw.ElapsedMilliseconds}ms"); } - TunnelWanPortEndPoint WanPort = await tunnelWanPort.GetAsync(server).ConfigureAwait(false); - if (WanPort != null) + TunnelWanPortEndPoint wanPort = await tunnelWanPort.GetAsync(server).ConfigureAwait(false); + if (wanPort != null) { - WanPort.Local.Address = localIP; - return WanPort; + wanPort.Local.Address = localIP; + return wanPort; } } catch (Exception ex) diff --git a/linker.web/src/views/settings/TunnelServers.vue b/linker.web/src/views/settings/TunnelServers.vue index 712e18c0..406dd4f1 100644 --- a/linker.web/src/views/settings/TunnelServers.vue +++ b/linker.web/src/views/settings/TunnelServers.vue @@ -21,7 +21,7 @@