diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index d701f7ae..4ac02a6f 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -37,7 +37,7 @@ jobs: release_name: v1.5.0.${{ steps.date.outputs.today }} draft: false prerelease: false - body: "1. 新增多分组管理,方便分组切换\r\n2. 增加分组密码,提高分组隔离安全性\r\n3. 优化配置同步,可自由选择同步哪些信息\r\n4. 自动分配虚拟网卡IP\r\n5. 线程池优化\r\n6. 一些UI优化\r\n7. 测试中,不要更新,不要更新,不要更新,请使用v1.4.9" + body: "1. 新增多分组管理,方便分组切换\r\n2. 增加分组密码,提高分组隔离安全性\r\n3. 优化配置同步,可自由选择同步哪些信息\r\n4. 自动分配虚拟网卡IP\r\n5. 线程池优化\r\n6. 一些UI优化\r\n7. 减少很多耦合,更方便自由组合各个组件\r\n8. 测试中,不要更新,不要更新,不要更新,请使用v1.4.9" - name: upload-win-x86-oss id: upload-win-x86-oss uses: tvrcgo/oss-action@v0.1.1 diff --git a/linker.libs/api/ApiServer.cs b/linker.libs/api/ApiServer.cs index c2915216..2ab9795e 100644 --- a/linker.libs/api/ApiServer.cs +++ b/linker.libs/api/ApiServer.cs @@ -92,7 +92,7 @@ namespace linker.libs.api { return new ApiControllerResponseInfo { - Content = "not exists this path", + Content = $"{model.Path} not exists", RequestId = model.RequestId, Path = model.Path, Code = ApiControllerResponseCodes.NotFound diff --git a/linker.tunnel/TunnelTransfer.cs b/linker.tunnel/TunnelTransfer.cs index fd531531..ebc908d7 100644 --- a/linker.tunnel/TunnelTransfer.cs +++ b/linker.tunnel/TunnelTransfer.cs @@ -150,11 +150,11 @@ namespace linker.tunnel continue; } - foreach (var wanPortProtocol in tunnelAdapter.GetTunnelWanPortProtocols().Where(c => c.Disabled == false && string.IsNullOrWhiteSpace(c.Host) == false)) + foreach (var wanPortProtocol in compactTransfer.Protocols) { //这个打洞协议不支持这个外网端口协议 - if ((transport.AllowWanPortProtocolType & wanPortProtocol.ProtocolType) != wanPortProtocol.ProtocolType) + if ((transport.AllowWanPortProtocolType & wanPortProtocol) != wanPortProtocol) { continue; } @@ -172,8 +172,7 @@ namespace linker.tunnel Task remoteInfo = tunnelAdapter.GetRemoteWanPort(new TunnelWanPortProtocolInfo { MachineId = remoteMachineId, - ProtocolType = wanPortProtocol.ProtocolType, - Type = wanPortProtocol.Type, + ProtocolType = wanPortProtocol }); await Task.WhenAll(localInfo, remoteInfo).ConfigureAwait(false); @@ -305,18 +304,16 @@ 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); + return await GetLocalInfo(_info.ProtocolType).ConfigureAwait(false); } /// /// 获取自己的外网IP /// /// - private async Task GetLocalInfo(TunnelWanPortInfo info) + private async Task GetLocalInfo(TunnelWanPortProtocolType tunnelWanPortProtocolType) { - TunnelWanPortEndPoint ip = await compactTransfer.GetWanPortAsync(tunnelAdapter.LocalIP, info).ConfigureAwait(false); + TunnelWanPortEndPoint ip = await compactTransfer.GetWanPortAsync(tunnelAdapter.LocalIP, tunnelWanPortProtocolType).ConfigureAwait(false); if (ip != null) { MapInfo portMapInfo = TunnelUpnpTransfer.PortMap ?? new MapInfo { PrivatePort = 0, PublicPort = 0 }; diff --git a/linker.tunnel/adapter/ITunnelAdapter.cs b/linker.tunnel/adapter/ITunnelAdapter.cs index 4e639e19..6ec7ef94 100644 --- a/linker.tunnel/adapter/ITunnelAdapter.cs +++ b/linker.tunnel/adapter/ITunnelAdapter.cs @@ -12,22 +12,17 @@ namespace linker.tunnel.adapter /// public IPAddress LocalIP { get; } + /// + /// 服务器地址 + /// + public string ServerHost { get; } + /// /// ssl加密证书,没有证书则无法加密通信 /// public X509Certificate2 Certificate { get; } - /// - /// 获取外网端口协议列表 - /// - /// - public List GetTunnelWanPortProtocols(); - /// - /// 保存外网端口协议列表 - /// - /// - public void SetTunnelWanPortProtocols(List protocols, bool updateVersion); - + /// /// 获取打洞协议列表 /// @@ -96,10 +91,6 @@ namespace linker.tunnel.adapter public sealed class TunnelWanPortProtocolInfo { - /// - /// 类别 - /// - public TunnelWanPortType Type { get; set; } /// /// 协议 /// diff --git a/linker.tunnel/wanport/ITunnelWanPortProtocol.cs b/linker.tunnel/wanport/ITunnelWanPortProtocol.cs index 35194c18..6938afdd 100644 --- a/linker.tunnel/wanport/ITunnelWanPortProtocol.cs +++ b/linker.tunnel/wanport/ITunnelWanPortProtocol.cs @@ -8,7 +8,6 @@ namespace linker.tunnel.wanport public interface ITunnelWanPortProtocol { public string Name { get; } - public TunnelWanPortType Type { get; } public TunnelWanPortProtocolType ProtocolType { get; } /// /// 获取外网端口 @@ -31,65 +30,10 @@ namespace linker.tunnel.wanport public IPEndPoint Remote { get; set; } } - public sealed partial class TunnelWanPortInfo - { - public TunnelWanPortInfo() { } - /// - /// 名称 - /// - public string Name { get; set; } = string.Empty; - /// - /// 协议类别 - /// - public TunnelWanPortType Type { get; set; } - /// - /// 协议 - /// - public TunnelWanPortProtocolType ProtocolType { get; set; } = TunnelWanPortProtocolType.Udp; - - /// - /// 地址 - /// - public string Host { get; set; } = string.Empty; - /// - /// 是否禁用 - /// - public bool Disabled { get; set; } - } - - public enum TunnelWanPortType : byte - { - Linker = 0, - Stun = 1, - Other = 255, - } - [Flags] public enum TunnelWanPortProtocolType : byte { Tcp = 1, Udp = 2, } - - public sealed class TunnelWanPortTypeInfo - { - public TunnelWanPortType Value { get; set; } - public string Name { get; set; } - public Dictionary Protocols { get; set; } = new Dictionary(); - } - - public sealed class TunnelWanPortTypeInfoEqualityComparer : IEqualityComparer - { - public bool Equals(TunnelWanPortTypeInfo x, TunnelWanPortTypeInfo y) - { - return x.Value == y.Value; - } - - public int GetHashCode(TunnelWanPortTypeInfo obj) - { - return obj.Value.GetHashCode(); - } - } - - } diff --git a/linker.tunnel/wanport/TunnelWanPortProtocolLinker.cs b/linker.tunnel/wanport/TunnelWanPortProtocolLinker.cs index 5b95e0b4..359bac60 100644 --- a/linker.tunnel/wanport/TunnelWanPortProtocolLinker.cs +++ b/linker.tunnel/wanport/TunnelWanPortProtocolLinker.cs @@ -9,7 +9,6 @@ namespace linker.tunnel.wanport public sealed class TunnelWanPortProtocolLinkerUdp : ITunnelWanPortProtocol { public string Name => "Linker Udp"; - public TunnelWanPortType Type => TunnelWanPortType.Linker; public TunnelWanPortProtocolType ProtocolType => TunnelWanPortProtocolType.Udp; @@ -73,7 +72,6 @@ namespace linker.tunnel.wanport public sealed class TunnelWanPortProtocolLinkerTcp : ITunnelWanPortProtocol { public string Name => "Linker Tcp"; - public TunnelWanPortType Type => TunnelWanPortType.Linker; public TunnelWanPortProtocolType ProtocolType => TunnelWanPortProtocolType.Tcp; diff --git a/linker.tunnel/wanport/TunnelWanPortProtocolStun.cs b/linker.tunnel/wanport/TunnelWanPortProtocolStun.cs index 3dcc97b0..9a5c2197 100644 --- a/linker.tunnel/wanport/TunnelWanPortProtocolStun.cs +++ b/linker.tunnel/wanport/TunnelWanPortProtocolStun.cs @@ -8,7 +8,6 @@ namespace linker.tunnel.wanport public sealed class TunnelWanPortProtocolStun : ITunnelWanPortProtocol { public string Name => "Stun Udp"; - public TunnelWanPortType Type => TunnelWanPortType.Stun; public TunnelWanPortProtocolType ProtocolType => TunnelWanPortProtocolType.Udp; diff --git a/linker.tunnel/wanport/TunnelWanPortTransfer.cs b/linker.tunnel/wanport/TunnelWanPortTransfer.cs index 81233a0c..d04b6c4e 100644 --- a/linker.tunnel/wanport/TunnelWanPortTransfer.cs +++ b/linker.tunnel/wanport/TunnelWanPortTransfer.cs @@ -1,4 +1,5 @@ using linker.libs; +using linker.tunnel.adapter; using System.Net; namespace linker.tunnel.wanport @@ -8,13 +9,18 @@ namespace linker.tunnel.wanport /// public sealed class TunnelWanPortTransfer { - private List tunnelWanPorts; + private List tunnelWanPorts = new List(); - public TunnelWanPortTransfer() + public List Protocols => tunnelWanPorts.Select(p => p.ProtocolType).ToList(); + + private readonly ITunnelAdapter tunnelAdapter; + public TunnelWanPortTransfer(ITunnelAdapter tunnelAdapter) { - + this.tunnelAdapter = tunnelAdapter; } + + /// /// 加载所有外网端口协议 /// @@ -25,35 +31,23 @@ namespace linker.tunnel.wanport LoggerHelper.Instance.Info($"load tunnel wanport compacts:{string.Join(",", tunnelWanPorts.Select(c => c.Name))}"); } - public List GetTypes() - { - 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; - } /// /// 获取外网端口 /// /// 你的局域网IP /// - public async Task GetWanPortAsync(IPAddress localIP, TunnelWanPortInfo info) + public async Task GetWanPortAsync(IPAddress localIP, TunnelWanPortProtocolType protocolType) { - if (info == null) return null; - var tunnelWanPort = tunnelWanPorts.FirstOrDefault(c => c.Type == info.Type && c.ProtocolType == info.ProtocolType); + var tunnelWanPort = tunnelWanPorts.FirstOrDefault(c => c.ProtocolType == protocolType); if (tunnelWanPort == null) return null; try { if (LoggerHelper.Instance.LoggerLevel <= LoggerTypes.DEBUG) - LoggerHelper.Instance.Debug($"get domain ip {info.Host}"); - IPEndPoint server = NetworkHelper.GetEndPoint(info.Host, 3478); + LoggerHelper.Instance.Debug($"get domain ip {tunnelAdapter.ServerHost}"); + IPEndPoint server = NetworkHelper.GetEndPoint(tunnelAdapter.ServerHost, 3478); if (LoggerHelper.Instance.LoggerLevel <= LoggerTypes.DEBUG) - LoggerHelper.Instance.Debug($"got domain ip {info.Host}->{server}"); + LoggerHelper.Instance.Debug($"got domain ip {tunnelAdapter.ServerHost}->{server}"); if (server == null) return null; TunnelWanPortEndPoint wanPort = await tunnelWanPort.GetAsync(localIP, server).ConfigureAwait(false); if (wanPort != null) diff --git a/linker.web/src/apis/relay.js b/linker.web/src/apis/relay.js index e3c12333..ee5daed1 100644 --- a/linker.web/src/apis/relay.js +++ b/linker.web/src/apis/relay.js @@ -1,8 +1,5 @@ import { sendWebsocketMsg } from './request' -export const getRelayTypes = () => { - return sendWebsocketMsg('relay/gettypes'); -} export const setRelayServers = (servers) => { return sendWebsocketMsg('relay/SetServers', servers); } diff --git a/linker.web/src/apis/tunnel.js b/linker.web/src/apis/tunnel.js index 0d12b06e..7a1f0862 100644 --- a/linker.web/src/apis/tunnel.js +++ b/linker.web/src/apis/tunnel.js @@ -1,12 +1,5 @@ import { sendWebsocketMsg } from './request' -export const getTunnelTypes = () => { - return sendWebsocketMsg('tunnel/gettypes'); -} -export const setTunnelServers = (servers) => { - return sendWebsocketMsg('tunnel/SetServers', servers); -} - export const getTunnelInfo = (hashcode = '0') => { return sendWebsocketMsg('tunnel/get', hashcode); } @@ -25,19 +18,6 @@ export const setTunnelTransports = (data) => { return sendWebsocketMsg('tunnel/SetTransports', data); } -export const getTunnelExcludeIPs = () => { - return sendWebsocketMsg('tunnel/GetExcludeIPs'); -} -export const setTunnelExcludeIPs = (data) => { - return sendWebsocketMsg('tunnel/SetExcludeIPs', data); -} - -export const getInterfaces = () => { - return sendWebsocketMsg('tunnel/GeInterfaces'); -} -export const setInterface = (ip) => { - return sendWebsocketMsg('tunnel/SetInterface', ip); -} export const getTunnelRecords = () => { return sendWebsocketMsg('tunnel/Records'); } \ No newline at end of file diff --git a/linker.web/src/views/full/action/Index.vue b/linker.web/src/views/full/action/Index.vue index 9e6ccd54..a596b91e 100644 --- a/linker.web/src/views/full/action/Index.vue +++ b/linker.web/src/views/full/action/Index.vue @@ -1,25 +1,23 @@ \ No newline at end of file diff --git a/linker.web/src/views/full/logger/Index.vue b/linker.web/src/views/full/logger/Index.vue index d8a483e3..1ed24b3d 100644 --- a/linker.web/src/views/full/logger/Index.vue +++ b/linker.web/src/views/full/logger/Index.vue @@ -19,7 +19,7 @@
- +