From aaa75c3d64ff89b17ccab9e160fcaf3309a3dee9 Mon Sep 17 00:00:00 2001 From: "Gui.H" Date: Sat, 3 Dec 2022 21:29:17 +0800 Subject: [PATCH] publish 2.1.2 --- FastTunnel.Client/Program.cs | 10 +- .../FastTunnel.Core.Client.csproj | 4 +- FastTunnel.Core/FastTunnel.Core.csproj | 4 +- FastTunnel.Core/Listener/PortProxyListener.cs | 33 +++--- .../Listener/PortProxyListenerV2.cs | 106 ------------------ FastTunnel.Core/Listener/TcpServerHandler.cs | 67 ----------- FastTunnel.Server/Program.cs | 20 +++- FastTunnel.Server/config/appsettings.json | 30 ++--- 8 files changed, 67 insertions(+), 207 deletions(-) delete mode 100644 FastTunnel.Core/Listener/PortProxyListenerV2.cs delete mode 100644 FastTunnel.Core/Listener/TcpServerHandler.cs diff --git a/FastTunnel.Client/Program.cs b/FastTunnel.Client/Program.cs index cf20d95..0c75e01 100644 --- a/FastTunnel.Client/Program.cs +++ b/FastTunnel.Client/Program.cs @@ -10,6 +10,7 @@ using System; using Microsoft.Extensions.Configuration; using Serilog; using FastTunnel.Core.Client.Extensions; +using Serilog.Events; namespace FastTunnel.Client; @@ -17,13 +18,20 @@ class Program { public static void Main(string[] args) { + Log.Logger = new LoggerConfiguration() + .MinimumLevel.Override("Microsoft", LogEventLevel.Information) + .Enrich.FromLogContext() + .WriteTo.Console().WriteTo.File("Logs/log-.log", rollingInterval: RollingInterval.Day) + .CreateBootstrapLogger(); + try { CreateHostBuilder(args).Build().Run(); } catch (Exception ex) { - Console.WriteLine(ex.Message); + Log.Fatal(ex, "致命异常"); + throw; } } diff --git a/FastTunnel.Core.Client/FastTunnel.Core.Client.csproj b/FastTunnel.Core.Client/FastTunnel.Core.Client.csproj index 39b4643..c7089b0 100644 --- a/FastTunnel.Core.Client/FastTunnel.Core.Client.csproj +++ b/FastTunnel.Core.Client/FastTunnel.Core.Client.csproj @@ -1,7 +1,7 @@ - + - 2.1.1 + 2.1.2 netcoreapp3.1;net5.0;net6.0;net7.0; enable preview diff --git a/FastTunnel.Core/FastTunnel.Core.csproj b/FastTunnel.Core/FastTunnel.Core.csproj index 0da9f0e..51a4684 100644 --- a/FastTunnel.Core/FastTunnel.Core.csproj +++ b/FastTunnel.Core/FastTunnel.Core.csproj @@ -2,7 +2,7 @@ net6.0;net7.0 - 2.1.1 + 2.1.2 https://github.com/SpringHgui/FastTunnel MIT FastTunnel @@ -27,7 +27,7 @@ - + diff --git a/FastTunnel.Core/Listener/PortProxyListener.cs b/FastTunnel.Core/Listener/PortProxyListener.cs index 3fef3bd..e27e9de 100644 --- a/FastTunnel.Core/Listener/PortProxyListener.cs +++ b/FastTunnel.Core/Listener/PortProxyListener.cs @@ -55,22 +55,29 @@ namespace FastTunnel.Core.Listener private void StartAccept(SocketAsyncEventArgs acceptEventArg) { - _logerr.LogDebug($"【{ListenIp}:{ListenPort}】: StartAccept"); - if (acceptEventArg == null) + try { - acceptEventArg = new SocketAsyncEventArgs(); - acceptEventArg.Completed += new EventHandler(AcceptEventArg_Completed); - } - else - { - // socket must be cleared since the context object is being reused - acceptEventArg.AcceptSocket = null; - } + _logerr.LogDebug($"【{ListenIp}:{ListenPort}】: StartAccept"); + if (acceptEventArg == null) + { + acceptEventArg = new SocketAsyncEventArgs(); + acceptEventArg.Completed += new EventHandler(AcceptEventArg_Completed); + } + else + { + // socket must be cleared since the context object is being reused + acceptEventArg.AcceptSocket = null; + } - bool willRaiseEvent = listenSocket.AcceptAsync(acceptEventArg); - if (!willRaiseEvent) + bool willRaiseEvent = listenSocket.AcceptAsync(acceptEventArg); + if (!willRaiseEvent) + { + ProcessAcceptAsync(acceptEventArg); + } + } + catch (Exception ex) { - ProcessAcceptAsync(acceptEventArg); + _logerr.LogError(ex, "待处理异常"); } } diff --git a/FastTunnel.Core/Listener/PortProxyListenerV2.cs b/FastTunnel.Core/Listener/PortProxyListenerV2.cs deleted file mode 100644 index b19076d..0000000 --- a/FastTunnel.Core/Listener/PortProxyListenerV2.cs +++ /dev/null @@ -1,106 +0,0 @@ -// Licensed under the Apache License, Version 2.0 (the "License"). -// You may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// https://github.com/FastTunnel/FastTunnel/edit/v2/LICENSE -// Copyright (c) 2019 Gui.H - -using BeetleX; -using BeetleX.EventArgs; -using FastTunnel.Core.Handlers.Server; -using Microsoft.AspNetCore.Hosting.Server; -using Microsoft.Extensions.Logging; -using System; -using System.Net; -using System.Net.Sockets; -using System.Net.WebSockets; -using System.Threading; -using IServer = BeetleX.IServer; - -namespace FastTunnel.Core.Listener -{ - public class PortProxyListenerV2 - { - ILogger _logerr; - - public string ListenIp { get; private set; } - - public int ListenPort { get; private set; } - - public IServer Server { get; set; } - - int m_numConnectedSockets; - - private IServer server; - - bool shutdown; - ForwardDispatcher _requestDispatcher; - WebSocket client; - - // string ip, int port, ILogger logerr, WebSocket client - public PortProxyListenerV2() - { - //IPAddress ipa = IPAddress.Parse(ListenIp); - //IPEndPoint localEndPoint = new IPEndPoint(ipa, ListenPort); - } - - public void Start(ForwardDispatcher requestDispatcher, string host, int port, ILogger logger, WebSocket webSocket) - { - this.client = webSocket; - this._logerr = logger; - this.ListenIp = host; - this.ListenPort = port; - - shutdown = false; - _requestDispatcher = requestDispatcher; - - server = SocketFactory.CreateTcpServer(); - var handler = server.Handler as TcpServerHandler; - handler.Sethanler(this); - server.Options.DefaultListen.Port = port; - server.Options.DefaultListen.Host = host; - server.Open(); - } - - //protected override void OnReceiveMessage(IServer server, ISession session, object message) - //{ - // base.OnReceiveMessage(server, session, message); - //} - - private void ProcessAcceptAsync(SocketAsyncEventArgs e) - { - // 将此客户端交由Dispatcher进行管理 - } - - internal async void Process(SessionReceiveEventArgs e) - { - //var pipeStream = e.Session.Stream.ToPipeStream(); - //if (pipeStream.TryReadLine(out string name)) - //{ - // Console.WriteLine(name); - // e.Stream.ToPipeStream().WriteLine("hello " + name); - // e.Stream.Flush(); - //} - - await _requestDispatcher.DispatchAsync(e.Stream, client); - } - - public void Stop() - { - if (shutdown) - return; - - try - { - server.Dispose(); - } - catch (Exception) - { - } - finally - { - - } - } - - } -} diff --git a/FastTunnel.Core/Listener/TcpServerHandler.cs b/FastTunnel.Core/Listener/TcpServerHandler.cs deleted file mode 100644 index 6233c33..0000000 --- a/FastTunnel.Core/Listener/TcpServerHandler.cs +++ /dev/null @@ -1,67 +0,0 @@ -// Licensed under the Apache License, Version 2.0 (the "License"). -// You may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// https://github.com/FastTunnel/FastTunnel/edit/v2/LICENSE -// Copyright (c) 2019 Gui.H - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using BeetleX; -using BeetleX.EventArgs; - -namespace FastTunnel.Core.Listener; - -internal class TcpServerHandler : ServerHandlerBase -{ - PortProxyListenerV2 proxyListenerV2; - - public override void Connected(IServer server, ConnectedEventArgs e) - { - Console.WriteLine("[Connected]"); - } - - public override void Connecting(IServer server, ConnectingEventArgs e) - { - Console.WriteLine("[Connecting]"); - } - - public override void Disconnect(IServer server, SessionEventArgs e) - { - Console.WriteLine("[Disconnect]"); - } - - public override void Error(IServer server, ServerErrorEventArgs e) - { - Console.WriteLine("[Error]"); - } - - public override void Opened(IServer server) - { - Console.WriteLine("[Opened]"); - } - - public override void SessionDetection(IServer server, SessionDetectionEventArgs e) - { - Console.WriteLine("[SessionDetection]"); - } - - public override void SessionPacketDecodeCompleted(IServer server, PacketDecodeCompletedEventArgs e) - { - Console.WriteLine("[SessionPacketDecodeCompleted]"); - } - - public override void SessionReceive(IServer server, SessionReceiveEventArgs e) - { - Console.WriteLine("[SessionReceive]"); - - proxyListenerV2.Process(e); - } - - internal void Sethanler(PortProxyListenerV2 portProxyListenerV2) - { - this.proxyListenerV2 = portProxyListenerV2; - } -} diff --git a/FastTunnel.Server/Program.cs b/FastTunnel.Server/Program.cs index ce41f81..1f9574e 100644 --- a/FastTunnel.Server/Program.cs +++ b/FastTunnel.Server/Program.cs @@ -4,11 +4,14 @@ // https://github.com/FastTunnel/FastTunnel/edit/v2/LICENSE // Copyright (c) 2019 Gui.H +using System.Net.Http; +using System.Net.Sockets; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Serilog; +using Serilog.Events; namespace FastTunnel.Server; @@ -16,7 +19,22 @@ public class Program { public static void Main(string[] args) { - CreateHostBuilder(args).Build().Run(); + Log.Logger = new LoggerConfiguration() + .MinimumLevel.Override("Microsoft", LogEventLevel.Information) + .Enrich.FromLogContext() + .WriteTo.Console().WriteTo.File("Logs/log-.log", rollingInterval: RollingInterval.Day) + .CreateBootstrapLogger(); + + try + { + CreateHostBuilder(args).Build().Run(); + + } + catch (System.Exception ex) + { + Log.Fatal(ex, "致命异常"); + throw; + } } public static IHostBuilder CreateHostBuilder(string[] args) diff --git a/FastTunnel.Server/config/appsettings.json b/FastTunnel.Server/config/appsettings.json index 0c9fd29..8ab6754 100644 --- a/FastTunnel.Server/config/appsettings.json +++ b/FastTunnel.Server/config/appsettings.json @@ -41,20 +41,20 @@ /** * 访问api接口的JWT配置 */ - "Api": { - "JWT": { - "ClockSkew": 10, - "ValidAudience": "https://suidao.io", - "ValidIssuer": "FastTunnel", - "IssuerSigningKey": "This is IssuerSigningKey", - "Expires": 120 - }, - "Accounts": [ - { - "Name": "admin", - "Password": "admin123" - } - ] - } + //"Api": { + // "JWT": { + // "ClockSkew": 10, + // "ValidAudience": "https://suidao.io", + // "ValidIssuer": "FastTunnel", + // "IssuerSigningKey": "This is IssuerSigningKey", + // "Expires": 120 + // }, + // "Accounts": [ + // { + // "Name": "admin", + // "Password": "admin123" + // } + // ] + //} } }