同步命名空间

This commit is contained in:
Gui.H 2022-06-29 15:48:53 +08:00
parent e795e46fd5
commit 9b96dbaef3
17 changed files with 75 additions and 62 deletions

View File

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net5.0;net6.0</TargetFrameworks> <TargetFrameworks>net6.0</TargetFrameworks>
<Version>1.1.0</Version> <Version>1.1.0</Version>
<PackageProjectUrl>https://github.com/FastTunnel/FastTunnel/tree/v2/FastTunnel.Api</PackageProjectUrl> <PackageProjectUrl>https://github.com/FastTunnel/FastTunnel/tree/v2/FastTunnel.Api</PackageProjectUrl>
<RepositoryUrl>https://github.com/FastTunnel/FastTunnel/tree/v2/FastTunnel.Api</RepositoryUrl> <RepositoryUrl>https://github.com/FastTunnel/FastTunnel/tree/v2/FastTunnel.Api</RepositoryUrl>

View File

@ -8,9 +8,9 @@ using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System; using System;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using FastTunnel.Core;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Serilog; using Serilog;
using FastTunnel.Core.Extensions;
namespace FastTunnel.Client; namespace FastTunnel.Client;

View File

@ -12,7 +12,7 @@
"ClientSettings": { "ClientSettings": {
"Server": { "Server": {
// [] ip/urls // [] ip/urls
"ServerAddr": "test.cc", "ServerAddr": "127.0.0.1",
// [] urls // [] urls
"ServerPort": 1270 "ServerPort": 1270
}, },

View File

@ -1,4 +1,4 @@
// Licensed under the Apache License, Version 2.0 (the "License"). // Licensed under the Apache License, Version 2.0 (the "License").
// You may not use this file except in compliance with the License. // You may not use this file except in compliance with the License.
// You may obtain a copy of the License at // You may obtain a copy of the License at
// https://github.com/FastTunnel/FastTunnel/edit/v2/LICENSE // https://github.com/FastTunnel/FastTunnel/edit/v2/LICENSE
@ -16,6 +16,7 @@ using FastTunnel.Core.Handlers.Client;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using System.Net.WebSockets; using System.Net.WebSockets;
using FastTunnel.Core.Utilitys; using FastTunnel.Core.Utilitys;
using FastTunnel.Core.Models.Massage;
namespace FastTunnel.Core.Client namespace FastTunnel.Core.Client
{ {

View File

@ -9,12 +9,10 @@ using FastTunnel.Core.Config;
using FastTunnel.Core.Forwarder.MiddleWare; using FastTunnel.Core.Forwarder.MiddleWare;
using FastTunnel.Core.Forwarder; using FastTunnel.Core.Forwarder;
using FastTunnel.Core.Handlers.Client; using FastTunnel.Core.Handlers.Client;
using FastTunnel.Core.MiddleWares;
using FastTunnel.Core.Services; using FastTunnel.Core.Services;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Yarp.ReverseProxy.Forwarder; using Yarp.ReverseProxy.Forwarder;
using Yarp.Sample;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using FastTunnel.Core.Filters; using FastTunnel.Core.Filters;
using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.Filters;
@ -24,9 +22,23 @@ using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Threading; using System.Threading;
/* FastTunnel.Core (net5.0)
:
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
namespace FastTunnel.Core namespace FastTunnel.Core
:
using Microsoft.AspNetCore.Http;
using FastTunnel.Core.Extensions;
using FastTunnel;
using FastTunnel.Core;
namespace FastTunnel.Core
*/
using Microsoft.AspNetCore.Http;
namespace FastTunnel.Core.Extensions
{ {
public static class ServicesExtensions public static class ServicesExtensions
{ {

View File

@ -5,6 +5,7 @@
// Copyright (c) 2019 Gui.H // Copyright (c) 2019 Gui.H
using FastTunnel.Core.Models; using FastTunnel.Core.Models;
using FastTunnel.Core.Models.Massage;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Net.Sockets; using System.Net.Sockets;

View File

@ -1,43 +1,45 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net5.0;net6.0</TargetFrameworks> <TargetFrameworks>net6.0</TargetFrameworks>
<Version>2.1.0</Version> <Version>2.1.0</Version>
<PackageProjectUrl>https://github.com/SpringHgui/FastTunnel</PackageProjectUrl> <PackageProjectUrl>https://github.com/SpringHgui/FastTunnel</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression> <PackageLicenseExpression>MIT</PackageLicenseExpression>
<Copyright>FastTunnel</Copyright> <Copyright>FastTunnel</Copyright>
<Description>expose a local server behind a NAT or firewall to the internet like ngrok and frp</Description> <Description>expose a local server behind a NAT or firewall to the internet like ngrok and frp</Description>
<Authors>Gui.H</Authors> <Authors>Gui.H</Authors>
<Company>FastTunnel</Company> <Company>FastTunnel</Company>
<Product>FastTunnel</Product> <Product>FastTunnel</Product>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance> <PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<RepositoryUrl>https://github.com/SpringHgui/FastTunnel</RepositoryUrl> <RepositoryUrl>https://github.com/SpringHgui/FastTunnel</RepositoryUrl>
<RepositoryType>git</RepositoryType> <RepositoryType>git</RepositoryType>
<PackageTags>FastTunnel.Core</PackageTags> <PackageTags>FastTunnel.Core</PackageTags>
<GenerateDocumentationFile>true</GenerateDocumentationFile> <GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageReleaseNotes>FastTunnel.Core</PackageReleaseNotes> <PackageReleaseNotes>FastTunnel.Core</PackageReleaseNotes>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="5.0.0" />
<PackageReference Include="Yarp.ReverseProxy" Version="1.1.0" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" /> <Compile Update="TunnelResource.Designer.cs">
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="5.0.0" /> <DesignTime>True</DesignTime>
<PackageReference Include="Yarp.ReverseProxy" Version="1.1.0" /> <AutoGen>True</AutoGen>
</ItemGroup> <DependentUpon>TunnelResource.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Update="TunnelResource.Designer.cs"> <EmbeddedResource Update="TunnelResource.resx">
<DesignTime>True</DesignTime> <Generator>PublicResXFileCodeGenerator</Generator>
<AutoGen>True</AutoGen> <LastGenOutput>TunnelResource.Designer.cs</LastGenOutput>
<DependentUpon>TunnelResource.resx</DependentUpon> </EmbeddedResource>
</Compile> </ItemGroup>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="TunnelResource.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>TunnelResource.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project> </Project>

View File

@ -9,7 +9,7 @@ using Microsoft.Extensions.Primitives;
using Yarp.ReverseProxy.Configuration; using Yarp.ReverseProxy.Configuration;
using System.Linq; using System.Linq;
namespace Yarp.Sample namespace FastTunnel.Core.Forwarder
{ {
/// <summary> /// <summary>
/// Extends the IReverseProxyBuilder to support the InMemoryConfigProvider /// Extends the IReverseProxyBuilder to support the InMemoryConfigProvider
@ -19,7 +19,7 @@ namespace Yarp.Sample
public static IReverseProxyBuilder LoadFromMemory(this IReverseProxyBuilder builder) public static IReverseProxyBuilder LoadFromMemory(this IReverseProxyBuilder builder)
{ {
builder.Services.AddSingleton<IProxyConfigProvider>( builder.Services.AddSingleton<IProxyConfigProvider>(
new InMemoryConfigProvider(Array.Empty<RouteConfig>(), Array.Empty<ClusterConfig>())); new FastTunnelInMemoryConfigProvider(Array.Empty<RouteConfig>(), Array.Empty<ClusterConfig>()));
return builder; return builder;
} }
@ -28,13 +28,13 @@ namespace Yarp.Sample
/// <summary> /// <summary>
/// Provides an implementation of IProxyConfigProvider to support config being generated by code. /// Provides an implementation of IProxyConfigProvider to support config being generated by code.
/// </summary> /// </summary>
public class InMemoryConfigProvider : IProxyConfigProvider public class FastTunnelInMemoryConfigProvider : IProxyConfigProvider
{ {
// Marked as volatile so that updates are atomic // Marked as volatile so that updates are atomic
private volatile InMemoryConfig _config; private volatile InMemoryConfig _config;
private object locker = new object(); private object locker = new object();
public InMemoryConfigProvider(IReadOnlyList<RouteConfig> routes, IReadOnlyList<ClusterConfig> clusters) public FastTunnelInMemoryConfigProvider(IReadOnlyList<RouteConfig> routes, IReadOnlyList<ClusterConfig> clusters)
{ {
_config = new InMemoryConfig(routes, clusters); _config = new InMemoryConfig(routes, clusters);
} }

View File

@ -1,4 +1,4 @@
// Copyright (c) 2019-2022 Gui.H. https://github.com/FastTunnel/FastTunnel // Copyright (c) 2019-2022 Gui.H. https://github.com/FastTunnel/FastTunnel
// The FastTunnel licenses this file to you under the Apache License Version 2.0. // The FastTunnel licenses this file to you under the Apache License Version 2.0.
// For more details,You may obtain License file at: https://github.com/FastTunnel/FastTunnel/blob/v2/LICENSE // For more details,You may obtain License file at: https://github.com/FastTunnel/FastTunnel/blob/v2/LICENSE
@ -13,7 +13,7 @@ using System.Net.WebSockets;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FastTunnel.Core.MiddleWares namespace FastTunnel.Core.Forwarder.MiddleWare
{ {
public class FastTunnelClientHandler public class FastTunnelClientHandler
{ {
@ -91,7 +91,7 @@ namespace FastTunnel.Core.MiddleWares
private bool checkToken(HttpContext context) private bool checkToken(HttpContext context)
{ {
bool checkToken = false; var checkToken = false;
if (fastTunnelServer.ServerOption.CurrentValue.Tokens != null && fastTunnelServer.ServerOption.CurrentValue.Tokens.Count != 0) if (fastTunnelServer.ServerOption.CurrentValue.Tokens != null && fastTunnelServer.ServerOption.CurrentValue.Tokens.Count != 0)
{ {
checkToken = true; checkToken = true;

View File

@ -1,6 +1,5 @@
using FastTunnel.Core.Client; using FastTunnel.Core.Client;
using FastTunnel.Core.Extensions; using FastTunnel.Core.Extensions;
using FastTunnel.Core.MiddleWares;
using Microsoft.AspNetCore.Connections.Features; using Microsoft.AspNetCore.Connections.Features;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;

View File

@ -5,7 +5,6 @@
// Copyright (c) 2019 Gui.H // Copyright (c) 2019 Gui.H
using FastTunnel.Core.Client; using FastTunnel.Core.Client;
using FastTunnel.Core.Dispatchers;
using FastTunnel.Core.Exceptions; using FastTunnel.Core.Exceptions;
using FastTunnel.Core.Extensions; using FastTunnel.Core.Extensions;
using FastTunnel.Core.Models; using FastTunnel.Core.Models;
@ -21,7 +20,7 @@ using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FastTunnel.Core.Dispatchers namespace FastTunnel.Core.Handlers.Server
{ {
public class ForwardDispatcher public class ForwardDispatcher
{ {

View File

@ -13,7 +13,7 @@ using System.Net.WebSockets;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FastTunnel.Core.Handlers namespace FastTunnel.Core.Handlers.Server
{ {
public interface IClientMessageHandler public interface IClientMessageHandler
{ {

View File

@ -5,10 +5,11 @@
// Copyright (c) 2019 Gui.H // Copyright (c) 2019 Gui.H
using FastTunnel.Core.Client; using FastTunnel.Core.Client;
using FastTunnel.Core.Dispatchers;
using FastTunnel.Core.Extensions; using FastTunnel.Core.Extensions;
using FastTunnel.Core.Forwarder;
using FastTunnel.Core.Listener; using FastTunnel.Core.Listener;
using FastTunnel.Core.Models; using FastTunnel.Core.Models;
using FastTunnel.Core.Models.Massage;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System; using System;
using System.Linq; using System.Linq;
@ -16,7 +17,6 @@ using System.Text.Json;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Yarp.ReverseProxy.Configuration; using Yarp.ReverseProxy.Configuration;
using Yarp.Sample;
namespace FastTunnel.Core.Handlers.Server namespace FastTunnel.Core.Handlers.Server
{ {
@ -49,7 +49,7 @@ namespace FastTunnel.Core.Handlers.Server
logger.LogDebug($"new domain '{hostName}'"); logger.LogDebug($"new domain '{hostName}'");
server.WebList.AddOrUpdate(hostName, info, (key, oldInfo) => { return info; }); server.WebList.AddOrUpdate(hostName, info, (key, oldInfo) => { return info; });
(proxyConfig as InMemoryConfigProvider).AddWeb(hostName); (proxyConfig as FastTunnelInMemoryConfigProvider).AddWeb(hostName);
await client.webSocket.SendCmdAsync(MessageType.Log, $" HTTP | http://{hostName}:{client.ConnectionPort} => {item.LocalIp}:{item.LocalPort}", CancellationToken.None); await client.webSocket.SendCmdAsync(MessageType.Log, $" HTTP | http://{hostName}:{client.ConnectionPort} => {item.LocalIp}:{item.LocalPort}", CancellationToken.None);
client.AddWeb(info); client.AddWeb(info);
@ -61,7 +61,7 @@ namespace FastTunnel.Core.Handlers.Server
// TODO:validateDomain // TODO:validateDomain
hostName = www.Trim().ToLower(); hostName = www.Trim().ToLower();
server.WebList.AddOrUpdate(www, info, (key, oldInfo) => { return info; }); server.WebList.AddOrUpdate(www, info, (key, oldInfo) => { return info; });
(proxyConfig as InMemoryConfigProvider).AddWeb(www); (proxyConfig as FastTunnelInMemoryConfigProvider).AddWeb(www);
await client.webSocket.SendCmdAsync(MessageType.Log, $" HTTP | http://{www}:{client.ConnectionPort} => {item.LocalIp}:{item.LocalPort}", CancellationToken.None); await client.webSocket.SendCmdAsync(MessageType.Log, $" HTTP | http://{www}:{client.ConnectionPort} => {item.LocalIp}:{item.LocalPort}", CancellationToken.None);
client.AddWeb(info); client.AddWeb(info);

View File

@ -4,7 +4,7 @@
// https://github.com/FastTunnel/FastTunnel/edit/v2/LICENSE // https://github.com/FastTunnel/FastTunnel/edit/v2/LICENSE
// Copyright (c) 2019 Gui.H // Copyright (c) 2019 Gui.H
using FastTunnel.Core.Dispatchers; using FastTunnel.Core.Handlers.Server;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System; using System;
using System.Net; using System.Net;

View File

@ -6,7 +6,7 @@
using System.Collections.Generic; using System.Collections.Generic;
namespace FastTunnel.Core.Models namespace FastTunnel.Core.Models.Massage
{ {
public class LogInMassage : TunnelMassage public class LogInMassage : TunnelMassage
{ {

View File

@ -4,7 +4,7 @@
// https://github.com/FastTunnel/FastTunnel/edit/v2/LICENSE // https://github.com/FastTunnel/FastTunnel/edit/v2/LICENSE
// Copyright (c) 2019 Gui.H // Copyright (c) 2019 Gui.H
namespace FastTunnel.Core.Models namespace FastTunnel.Core.Models.Massage
{ {
public class TunnelMassage public class TunnelMassage
{ {

View File

@ -4,7 +4,6 @@
// https://github.com/FastTunnel/FastTunnel/edit/v2/LICENSE // https://github.com/FastTunnel/FastTunnel/edit/v2/LICENSE
// Copyright (c) 2019 Gui.H // Copyright (c) 2019 Gui.H
using FastTunnel.Core;
using FastTunnel.Core.Extensions; using FastTunnel.Core.Extensions;
using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;