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 @@
-
+
@@ -87,17 +87,26 @@ import { computed, onMounted, reactive } from 'vue'
export default {
setup(props) {
const globalData = injectGlobalData();
+ const list = ((globalData.value.config.Running.Tunnel || {Servers:[]}).Servers || []).sort((a,b)=>a.Disabled - b.Disabled);
const state = reactive({
- list:((globalData.value.config.Running.Tunnel || {Servers:[]}).Servers || []).sort((a,b)=>a.Disabled - b.Disabled),
+ list:list,
types:[],
height: computed(()=>globalData.value.height-130),
- sync:true,
- protocolTypes:{1:'tcp',2:'udp'},
+ sync:true
});
const _getTunnelTypes = ()=>{
getTunnelTypes().then((res)=>{
state.types = res;
+ initProtocols(state.list);
+ });
+ }
+ const initProtocols = (list)=>{
+ list.forEach(c=>{
+ c.Protocols = state.types.filter(d=>d.Value == c.Type)[0].Protocols;
+ if(!c.Protocols[c.ProtocolType]){
+ c.ProtocolType = +Object.keys(c.Protocols)[0];
+ }
});
}
@@ -105,6 +114,7 @@ export default {
handleEdit(row, column.property);
}
const handleEdit = (row, p) => {
+ initProtocols([row])
state.list.forEach(c => {
c[`NameEditing`] = false;
c[`TypeEditing`] = false;
@@ -114,6 +124,7 @@ export default {
row[`${p}Editing`] = true;
}
const handleEditBlur = (row, p) => {
+ initProtocols([row])
row[`${p}Editing`] = false;
handleSave();
}
@@ -126,7 +137,10 @@ export default {
if(state.list.filter(c=>c.Host == '' || c.Name == '').length > 0){
return;
}
- state.list.splice(index+1,0,{Name:'',Host:'',Type:0,Disabled:false,ProtocolType:2});
+ const row = {Name:'',Host:'',Type:0,Disabled:false,ProtocolType:2};
+ initProtocols([row]);
+ state.list.splice(index+1,0,row);
+
handleSave();
}
diff --git a/linker/linker.csproj b/linker/linker.csproj
index e81c9404..3270360d 100644
--- a/linker/linker.csproj
+++ b/linker/linker.csproj
@@ -25,8 +25,8 @@
https://github.com/snltty/linker
https://github.com/snltty/linker
linker
- 1.1.1.1
- 1.1.1.1
+ 1.1.1.2
+ 1.1.1.2
diff --git a/linker/plugins/tunnel/TunnelAdapter.cs b/linker/plugins/tunnel/TunnelAdapter.cs
index 910329e1..883fb345 100644
--- a/linker/plugins/tunnel/TunnelAdapter.cs
+++ b/linker/plugins/tunnel/TunnelAdapter.cs
@@ -42,11 +42,11 @@ namespace linker.plugins.tunnel
public List GetTunnelWanPortProtocols()
{
- return running.Data.Tunnel.Servers.ToList();
+ return running.Data.Tunnel.Servers;
}
public void SetTunnelWanPortProtocols(List compacts)
{
- running.Data.Tunnel.Servers = compacts.ToArray();
+ running.Data.Tunnel.Servers = compacts;
running.Data.Update();
}
diff --git a/linker/plugins/tunnel/TunnelApiController.cs b/linker/plugins/tunnel/TunnelApiController.cs
index 7e62bb04..7ed0ac5e 100644
--- a/linker/plugins/tunnel/TunnelApiController.cs
+++ b/linker/plugins/tunnel/TunnelApiController.cs
@@ -82,7 +82,7 @@ namespace linker.plugins.tunnel
{
SetServersParamInfo info = param.Content.DeJson();
- tunnelMessengerAdapter.SetTunnelWanPortProtocols(info.List.ToList());
+ tunnelMessengerAdapter.SetTunnelWanPortProtocols(info.List);
if (info.Sync)
{
await messengerSender.SendOnly(new MessageRequestWrap
@@ -179,7 +179,7 @@ namespace linker.plugins.tunnel
public sealed class SetServersParamInfo
{
public bool Sync { get; set; }
- public TunnelWanPortInfo[] List { get; set; } = Array.Empty();
+ public List List { get; set; } =new List();
}
public sealed class SetTransportsParamInfo
diff --git a/linker/plugins/tunnel/TunnelConfigTransfer.cs b/linker/plugins/tunnel/TunnelConfigTransfer.cs
index 2e378e9d..66e57b93 100644
--- a/linker/plugins/tunnel/TunnelConfigTransfer.cs
+++ b/linker/plugins/tunnel/TunnelConfigTransfer.cs
@@ -33,17 +33,27 @@ namespace linker.plugins.tunnel
GetRemoveRouteLevel();
};
- if (running.Data.Tunnel.Servers.Length == 0)
+ if (running.Data.Tunnel.Servers.FirstOrDefault(c => c.Type == TunnelWanPortType.Linker && c.ProtocolType == TunnelWanPortProtocolType.Udp) == null)
{
- running.Data.Tunnel.Servers = new TunnelWanPortInfo[]
+ running.Data.Tunnel.Servers.Add(new TunnelWanPortInfo
{
- new TunnelWanPortInfo{
- Name="Linker Udp",
- Type= TunnelWanPortType.Linker,
- Disabled = false,
- Host = running.Data.Client.Servers.FirstOrDefault().Host,
- }
- };
+ Name = "Linker Udp",
+ Type = TunnelWanPortType.Linker,
+ ProtocolType = TunnelWanPortProtocolType.Udp,
+ Disabled = false,
+ Host = running.Data.Client.Servers.FirstOrDefault().Host,
+ });
+ }
+ if (running.Data.Tunnel.Servers.FirstOrDefault(c => c.Type == TunnelWanPortType.Linker && c.ProtocolType == TunnelWanPortProtocolType.Tcp) == null)
+ {
+ running.Data.Tunnel.Servers.Add(new TunnelWanPortInfo
+ {
+ Name = "Linker Tcp",
+ Type = TunnelWanPortType.Linker,
+ ProtocolType = TunnelWanPortProtocolType.Tcp,
+ Disabled = false,
+ Host = running.Data.Client.Servers.FirstOrDefault().Host,
+ });
}
}
diff --git a/linker/plugins/tunnel/TunnelStartup.cs b/linker/plugins/tunnel/TunnelStartup.cs
index 811bcb55..fd4caa46 100644
--- a/linker/plugins/tunnel/TunnelStartup.cs
+++ b/linker/plugins/tunnel/TunnelStartup.cs
@@ -34,6 +34,8 @@ namespace linker.plugins.tunnel
MemoryPackFormatterProvider.Register(new TunnelTransportWanPortInfoFormatter());
MemoryPackFormatterProvider.Register(new TunnelTransportItemInfoFormatter());
MemoryPackFormatterProvider.Register(new TunnelTransportInfoFormatter());
+ MemoryPackFormatterProvider.Register(new TunnelWanPortProtocolInfoFormatter());
+
//管理接口
serviceCollection.AddSingleton();
@@ -43,6 +45,7 @@ namespace linker.plugins.tunnel
//外网端口协议
serviceCollection.AddSingleton();
serviceCollection.AddSingleton();
+ serviceCollection.AddSingleton();
serviceCollection.AddSingleton();
//打洞协议
@@ -69,6 +72,7 @@ namespace linker.plugins.tunnel
MemoryPackFormatterProvider.Register(new TunnelTransportWanPortInfoFormatter());
MemoryPackFormatterProvider.Register(new TunnelTransportItemInfoFormatter());
MemoryPackFormatterProvider.Register(new TunnelTransportInfoFormatter());
+ MemoryPackFormatterProvider.Register(new TunnelWanPortProtocolInfoFormatter());
serviceCollection.AddSingleton();
}
diff --git a/linker/plugins/tunnel/config/Config.cs b/linker/plugins/tunnel/config/Config.cs
index 4b34f83b..02acf2de 100644
--- a/linker/plugins/tunnel/config/Config.cs
+++ b/linker/plugins/tunnel/config/Config.cs
@@ -19,7 +19,7 @@ namespace linker.client.config
public sealed class TunnelRunningInfo
{
public ObjectId Id { get; set; }
- public TunnelWanPortInfo[] Servers { get; set; } = Array.Empty();
+ public List Servers { get; set; } = new List();
public int RouteLevelPlus { get; set; } = 0;
public ExcludeIPItem[] ExcludeIPs { get; set; } = Array.Empty();
@@ -128,6 +128,9 @@ namespace linker.config
[MemoryPackInclude]
TunnelWanPortType Type => tunnelCompactInfo.Type;
+ [MemoryPackInclude]
+ TunnelWanPortProtocolType ProtocolType => tunnelCompactInfo.ProtocolType;
+
[MemoryPackInclude]
string Host => tunnelCompactInfo.Host;
@@ -135,9 +138,9 @@ namespace linker.config
bool Disabled => tunnelCompactInfo.Disabled;
[MemoryPackConstructor]
- SerializableTunnelWanPortInfo(string name, TunnelWanPortType type, string host, bool disabled)
+ SerializableTunnelWanPortInfo(string name, TunnelWanPortType type, TunnelWanPortProtocolType protocolType, string host, bool disabled)
{
- var tunnelCompactInfo = new TunnelWanPortInfo { Name = name, Type = type, Host = host, Disabled = disabled };
+ var tunnelCompactInfo = new TunnelWanPortInfo { Name = name, Type = type, ProtocolType = protocolType, Host = host, Disabled = disabled };
this.tunnelCompactInfo = tunnelCompactInfo;
}
diff --git a/linker/plugins/tunnel/messenger/TunnelMessenger.cs b/linker/plugins/tunnel/messenger/TunnelMessenger.cs
index c3cffa19..963ced30 100644
--- a/linker/plugins/tunnel/messenger/TunnelMessenger.cs
+++ b/linker/plugins/tunnel/messenger/TunnelMessenger.cs
@@ -95,8 +95,8 @@ namespace linker.plugins.tunnel.messenger
[MessengerId((ushort)TunnelMessengerIds.Servers)]
public void Servers(IConnection connection)
{
- TunnelWanPortInfo[] servers = MemoryPackSerializer.Deserialize(connection.ReceiveRequestWrap.Payload.Span);
- tunnelMessengerAdapter.SetTunnelWanPortProtocols(servers.ToList());
+ List servers = MemoryPackSerializer.Deserialize>(connection.ReceiveRequestWrap.Payload.Span);
+ tunnelMessengerAdapter.SetTunnelWanPortProtocols(servers);
}
[MessengerId((ushort)TunnelMessengerIds.ExcludeIPs)]