diff --git a/FastTunnel.Client/FastTunnel.Client.csproj b/FastTunnel.Client/FastTunnel.Client.csproj
index 39204f2..01bd184 100644
--- a/FastTunnel.Client/FastTunnel.Client.csproj
+++ b/FastTunnel.Client/FastTunnel.Client.csproj
@@ -1,15 +1,18 @@
- net7.0
+ net8.0
Exe
+ enable
+ enable
+ true
-
-
-
-
-
+
+
+
+
+
diff --git a/FastTunnel.Client/Program.cs b/FastTunnel.Client/Program.cs
index 0c75e01..d104235 100644
--- a/FastTunnel.Client/Program.cs
+++ b/FastTunnel.Client/Program.cs
@@ -11,6 +11,8 @@ using Microsoft.Extensions.Configuration;
using Serilog;
using FastTunnel.Core.Client.Extensions;
using Serilog.Events;
+using Microsoft.Extensions.DependencyInjection;
+using FastTunnel.Core.Config;
namespace FastTunnel.Client;
diff --git a/FastTunnel.Core.Client/DefaultClientConfig.cs b/FastTunnel.Core.Client/DefaultClientConfig.cs
index 5f7afa3..0507d2a 100644
--- a/FastTunnel.Core.Client/DefaultClientConfig.cs
+++ b/FastTunnel.Core.Client/DefaultClientConfig.cs
@@ -12,6 +12,7 @@ namespace FastTunnel.Core.Config
{
public class DefaultClientConfig : IClientConfig
{
+ public DefaultClientConfig() { }
public SuiDaoServer Server { get; set; }
public string Token { get; set; }
diff --git a/FastTunnel.Core.Client/Extensions/ServicesExtensions.cs b/FastTunnel.Core.Client/Extensions/ServicesExtensions.cs
index 84f15f1..f2515ff 100644
--- a/FastTunnel.Core.Client/Extensions/ServicesExtensions.cs
+++ b/FastTunnel.Core.Client/Extensions/ServicesExtensions.cs
@@ -10,24 +10,23 @@ using FastTunnel.Core.Services;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
-namespace FastTunnel.Core.Client.Extensions
+namespace FastTunnel.Core.Client.Extensions;
+
+public static class ServicesExtensions
{
- public static class ServicesExtensions
+ ///
+ /// 客户端依赖及HostedService
+ ///
+ ///
+ public static void AddFastTunnelClient(this IServiceCollection services, IConfigurationSection configurationSection)
{
- ///
- /// 客户端依赖及HostedService
- ///
- ///
- public static void AddFastTunnelClient(this IServiceCollection services, IConfigurationSection configurationSection)
- {
- services.Configure(configurationSection);
+ services.Configure(configurationSection);
- services.AddTransient()
- .AddSingleton()
- .AddSingleton();
-
- services.AddHostedService();
- }
+ services.AddTransient()
+ .AddSingleton()
+ .AddSingleton();
+ services.AddHostedService();
}
}
+
diff --git a/FastTunnel.Core.Client/Extensions/SocketExtensions.cs b/FastTunnel.Core.Client/Extensions/SocketExtensions.cs
deleted file mode 100644
index 565b32f..0000000
--- a/FastTunnel.Core.Client/Extensions/SocketExtensions.cs
+++ /dev/null
@@ -1,24 +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 FastTunnel.Core.Models;
-using FastTunnel.Core.Models.Massage;
-using System;
-using System.Collections.Generic;
-using System.Net.Sockets;
-using System.Text;
-
-namespace FastTunnel.Core.Extensions
-{
- public static class SocketExtensions
- {
- public static void SendCmd(this Socket socket, Message message)
- where T : TunnelMassage
- {
- socket.Send(Encoding.UTF8.GetBytes(message.ToJson() + "\n"));
- }
- }
-}
diff --git a/FastTunnel.Core.Client/FastTunnel.Core.Client.csproj b/FastTunnel.Core.Client/FastTunnel.Core.Client.csproj
index 510552e..e30426c 100644
--- a/FastTunnel.Core.Client/FastTunnel.Core.Client.csproj
+++ b/FastTunnel.Core.Client/FastTunnel.Core.Client.csproj
@@ -2,15 +2,15 @@
2.1.2
- netcoreapp3.1;net5.0;net6.0;net7.0;
+ netcoreapp3.1;net5.0;net6.0;net7.0;net8.0
enable
preview
+
-
@@ -22,14 +22,13 @@
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
diff --git a/FastTunnel.Core.Client/FastTunnelClient.cs b/FastTunnel.Core.Client/FastTunnelClient.cs
index aab6a37..acafa57 100644
--- a/FastTunnel.Core.Client/FastTunnelClient.cs
+++ b/FastTunnel.Core.Client/FastTunnelClient.cs
@@ -9,6 +9,8 @@ using System.Buffers;
using System.Net.Sockets;
using System.Net.WebSockets;
using System.Text;
+using System.Text.Json;
+using System.Text.Json.Serialization;
using System.Threading;
using System.Threading.Tasks;
using FastTunnel.Core.Config;
@@ -22,6 +24,15 @@ using Microsoft.Extensions.Options;
namespace FastTunnel.Core.Client;
+#if NET6_0_OR_GREATER
+[JsonSourceGenerationOptions(WriteIndented = false)]
+[JsonSerializable(typeof(LogInMassage))]
+[JsonSerializable(typeof(Message))]
+public partial class SourceGenerationContext : JsonSerializerContext
+{
+}
+#endif
+
public class FastTunnelClient : IFastTunnelClient
{
private ClientWebSocket socket;
@@ -99,14 +110,25 @@ public class FastTunnelClient : IFastTunnelClient
await socket.SendCmdAsync(MessageType.LogIn, logMsg, cancellationToken);
}
+
protected virtual string GetLoginMsg(CancellationToken cancellationToken)
{
Server = ClientConfig.Server;
+
+# if NET8_0_OR_GREATER
+ return new LogInMassage
+ {
+ Webs = ClientConfig.Webs,
+ Forwards = ClientConfig.Forwards,
+ }.ToJson(jsonTypeInfo: SourceGenerationContext.Default.LogInMassage);
+
+#else
return new LogInMassage
{
Webs = ClientConfig.Webs,
Forwards = ClientConfig.Forwards,
}.ToJson();
+#endif
}
diff --git a/FastTunnel.Core/Extensions/ObjectExtensions.cs b/FastTunnel.Core/Extensions/ObjectExtensions.cs
index b251527..c42b184 100644
--- a/FastTunnel.Core/Extensions/ObjectExtensions.cs
+++ b/FastTunnel.Core/Extensions/ObjectExtensions.cs
@@ -5,10 +5,25 @@
// Copyright (c) 2019 Gui.H
using System.Text.Json;
+#if NET8_0_OR_GREATER
+using System.Text.Json.Serialization.Metadata;
+#endif
+
namespace FastTunnel.Core.Extensions
{
public static class ObjectExtensions
{
+#if NET8_0_OR_GREATER
+ public static string ToJson(this T message, JsonTypeInfo jsonTypeInfo)
+ {
+ if (message == null)
+ {
+ return null;
+ }
+
+ return JsonSerializer.Serialize(message, jsonTypeInfo: jsonTypeInfo);
+ }
+#else
public static string ToJson(this object message)
{
if (message == null)
@@ -19,5 +34,6 @@ namespace FastTunnel.Core.Extensions
var jsonOptions = new JsonSerializerOptions { WriteIndented = false };
return JsonSerializer.Serialize(message, message.GetType(), jsonOptions);
}
+#endif
}
}
diff --git a/FastTunnel.Core/FastTunnel.Core.csproj b/FastTunnel.Core/FastTunnel.Core.csproj
index cad8180..a9700f1 100644
--- a/FastTunnel.Core/FastTunnel.Core.csproj
+++ b/FastTunnel.Core/FastTunnel.Core.csproj
@@ -1,7 +1,7 @@
- net6.0;net7.0
+ net6.0;net7.0;net8.0
2.1.2
https://github.com/SpringHgui/FastTunnel
MIT
@@ -24,17 +24,13 @@
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
True
diff --git a/FastTunnel.Core/Handlers/LoginHandler.cs b/FastTunnel.Core/Handlers/LoginHandler.cs
index 69cb211..00942bc 100644
--- a/FastTunnel.Core/Handlers/LoginHandler.cs
+++ b/FastTunnel.Core/Handlers/LoginHandler.cs
@@ -8,6 +8,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
+using System.Text.Json.Serialization;
using System.Threading;
using System.Threading.Tasks;
using FastTunnel.Core.Client;
@@ -21,6 +22,13 @@ using Yarp.ReverseProxy.Configuration;
namespace FastTunnel.Core.Handlers.Server;
+
+[JsonSourceGenerationOptions(WriteIndented = false)]
+[JsonSerializable(typeof(LogInMassage))]
+internal partial class SourceGenerationContext : JsonSerializerContext
+{
+}
+
public class LoginHandler : ILoginHandler
{
private readonly ILogger logger;
@@ -133,9 +141,11 @@ public class LoginHandler : ILoginHandler
await client.webSocket.SendCmdAsync(MessageType.Log, TunnelResource.NoTunnel, CancellationToken.None);
}
+
public virtual async Task HandlerMsg(FastTunnelServer fastTunnelServer, TunnelClient tunnelClient, string lineCmd, CancellationToken cancellationToken)
{
- var msg = JsonSerializer.Deserialize(lineCmd);
+ var msg = JsonSerializer.Deserialize(lineCmd, SourceGenerationContext.Default.LogInMassage);
+
await HandleLoginAsync(fastTunnelServer, tunnelClient, msg, cancellationToken);
return NeedRecive;
}
diff --git a/FastTunnel.Server/FastTunnel.Server.csproj b/FastTunnel.Server/FastTunnel.Server.csproj
index 78bd29b..4288c14 100644
--- a/FastTunnel.Server/FastTunnel.Server.csproj
+++ b/FastTunnel.Server/FastTunnel.Server.csproj
@@ -1,7 +1,10 @@
- net7.0
+ net8.0
+ enable
+ enable
+ true
@@ -12,17 +15,17 @@
-
-
-
-
-
+
+
+
+
+
-
+
diff --git a/FastTunnel.Server/Program.cs b/FastTunnel.Server/Program.cs
index 79e3a8d..a49a826 100644
--- a/FastTunnel.Server/Program.cs
+++ b/FastTunnel.Server/Program.cs
@@ -5,6 +5,7 @@
// Copyright (c) 2019 Gui.H
using System;
+using System.Diagnostics.CodeAnalysis;
using System.Net.Http;
using System.Net.Sockets;
using System.Text;
@@ -28,17 +29,18 @@ namespace FastTunnel.Server;
public class Program
{
+ [RequiresUnreferencedCode("")]
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();
+ .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
+ .Enrich.FromLogContext()
+ .WriteTo.Console().WriteTo.File("Logs/log-.log", rollingInterval: RollingInterval.Day)
+ .CreateBootstrapLogger();
try
{
- var builder = WebApplication.CreateBuilder(new WebApplicationOptions
+ var builder = WebApplication.CreateSlimBuilder(new WebApplicationOptions
{
Args = args
});
@@ -48,9 +50,9 @@ public class Program
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
-#if DEBUG
- builder.Services.AddSwaggerGen();
-#endif
+ //#if DEBUG
+ // builder.Services.AddSwaggerGen();
+ //#endif
builder.Services.AddCors(options =>
{
options.AddPolicy("corsPolicy", policy =>
@@ -111,10 +113,10 @@ public class Program
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
-#if DEBUG
- app.UseSwagger();
- app.UseSwaggerUI();
-#endif
+ //#if DEBUG
+ // app.UseSwagger();
+ // app.UseSwaggerUI();
+ //#endif
}
app.UseCors("corsPolicy");
diff --git a/FastTunnel.Server/Properties/PublishProfiles/FolderProfile.pubxml b/FastTunnel.Server/Properties/PublishProfiles/FolderProfile.pubxml
index 040b013..0c9a117 100644
--- a/FastTunnel.Server/Properties/PublishProfiles/FolderProfile.pubxml
+++ b/FastTunnel.Server/Properties/PublishProfiles/FolderProfile.pubxml
@@ -4,13 +4,17 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
-->
- False
- False
- True
+ false
+ false
+ true
Release
Any CPU
FileSystem
bin\Release\net5.0\publish\
FileSystem
+
+ net8.0
+ def2e322-9075-4c3f-9967-7eaf0ee28ceb
+ false
\ No newline at end of file
diff --git a/FastTunnel.Server/Properties/launchSettings.json b/FastTunnel.Server/Properties/launchSettings.json
index 86dc5a8..4336146 100644
--- a/FastTunnel.Server/Properties/launchSettings.json
+++ b/FastTunnel.Server/Properties/launchSettings.json
@@ -11,7 +11,7 @@
"profiles": {
"FastTunnel.Server": {
"commandName": "Project",
- "launchBrowser": true,
+ "launchBrowser": false,
"launchUrl": "http://localhost:1270/swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"