mirror of
https://github.com/FastTunnel/FastTunnel.git
synced 2025-02-08 02:39:29 +08:00
publish 2.1.2
This commit is contained in:
parent
8422fa8043
commit
aaa75c3d64
|
@ -10,6 +10,7 @@ using System;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
using FastTunnel.Core.Client.Extensions;
|
using FastTunnel.Core.Client.Extensions;
|
||||||
|
using Serilog.Events;
|
||||||
|
|
||||||
namespace FastTunnel.Client;
|
namespace FastTunnel.Client;
|
||||||
|
|
||||||
|
@ -17,13 +18,20 @@ class Program
|
||||||
{
|
{
|
||||||
public static void Main(string[] args)
|
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
|
try
|
||||||
{
|
{
|
||||||
CreateHostBuilder(args).Build().Run();
|
CreateHostBuilder(args).Build().Run();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Console.WriteLine(ex.Message);
|
Log.Fatal(ex, "致命异常");
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Version>2.1.1</Version>
|
<Version>2.1.2</Version>
|
||||||
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net7.0;</TargetFrameworks>
|
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net7.0;</TargetFrameworks>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<LangVersion>preview</LangVersion>
|
<LangVersion>preview</LangVersion>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
|
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
|
||||||
<Version>2.1.1</Version>
|
<Version>2.1.2</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>
|
||||||
|
@ -27,7 +27,7 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="5.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="5.0.0" />
|
||||||
<PackageReference Include="Yarp.ReverseProxy" Version="1.1.0" />
|
<PackageReference Include="Yarp.ReverseProxy" Version="1.1.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -55,22 +55,29 @@ namespace FastTunnel.Core.Listener
|
||||||
|
|
||||||
private void StartAccept(SocketAsyncEventArgs acceptEventArg)
|
private void StartAccept(SocketAsyncEventArgs acceptEventArg)
|
||||||
{
|
{
|
||||||
_logerr.LogDebug($"【{ListenIp}:{ListenPort}】: StartAccept");
|
try
|
||||||
if (acceptEventArg == null)
|
|
||||||
{
|
{
|
||||||
acceptEventArg = new SocketAsyncEventArgs();
|
_logerr.LogDebug($"【{ListenIp}:{ListenPort}】: StartAccept");
|
||||||
acceptEventArg.Completed += new EventHandler<SocketAsyncEventArgs>(AcceptEventArg_Completed);
|
if (acceptEventArg == null)
|
||||||
}
|
{
|
||||||
else
|
acceptEventArg = new SocketAsyncEventArgs();
|
||||||
{
|
acceptEventArg.Completed += new EventHandler<SocketAsyncEventArgs>(AcceptEventArg_Completed);
|
||||||
// socket must be cleared since the context object is being reused
|
}
|
||||||
acceptEventArg.AcceptSocket = null;
|
else
|
||||||
}
|
{
|
||||||
|
// socket must be cleared since the context object is being reused
|
||||||
|
acceptEventArg.AcceptSocket = null;
|
||||||
|
}
|
||||||
|
|
||||||
bool willRaiseEvent = listenSocket.AcceptAsync(acceptEventArg);
|
bool willRaiseEvent = listenSocket.AcceptAsync(acceptEventArg);
|
||||||
if (!willRaiseEvent)
|
if (!willRaiseEvent)
|
||||||
|
{
|
||||||
|
ProcessAcceptAsync(acceptEventArg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
ProcessAcceptAsync(acceptEventArg);
|
_logerr.LogError(ex, "待处理异常");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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<TcpServerHandler>();
|
|
||||||
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
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -4,11 +4,14 @@
|
||||||
// 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 System.Net.Http;
|
||||||
|
using System.Net.Sockets;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
using Serilog.Events;
|
||||||
|
|
||||||
namespace FastTunnel.Server;
|
namespace FastTunnel.Server;
|
||||||
|
|
||||||
|
@ -16,7 +19,22 @@ public class Program
|
||||||
{
|
{
|
||||||
public static void Main(string[] args)
|
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)
|
public static IHostBuilder CreateHostBuilder(string[] args)
|
||||||
|
|
|
@ -41,20 +41,20 @@
|
||||||
/**
|
/**
|
||||||
* 访问api接口的JWT配置
|
* 访问api接口的JWT配置
|
||||||
*/
|
*/
|
||||||
"Api": {
|
//"Api": {
|
||||||
"JWT": {
|
// "JWT": {
|
||||||
"ClockSkew": 10,
|
// "ClockSkew": 10,
|
||||||
"ValidAudience": "https://suidao.io",
|
// "ValidAudience": "https://suidao.io",
|
||||||
"ValidIssuer": "FastTunnel",
|
// "ValidIssuer": "FastTunnel",
|
||||||
"IssuerSigningKey": "This is IssuerSigningKey",
|
// "IssuerSigningKey": "This is IssuerSigningKey",
|
||||||
"Expires": 120
|
// "Expires": 120
|
||||||
},
|
// },
|
||||||
"Accounts": [
|
// "Accounts": [
|
||||||
{
|
// {
|
||||||
"Name": "admin",
|
// "Name": "admin",
|
||||||
"Password": "admin123"
|
// "Password": "admin123"
|
||||||
}
|
// }
|
||||||
]
|
// ]
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user