mirror of
https://github.com/FastTunnel/FastTunnel.git
synced 2025-02-08 10:59:31 +08:00
Merge branch 'v2' of https://github.com/FastTunnel/FastTunnel into v2
This commit is contained in:
commit
98d2b82653
|
@ -1,11 +1,11 @@
|
|||
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
|
||||
WORKDIR /app
|
||||
EXPOSE 80
|
||||
EXPOSE 443
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
|
||||
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
|
||||
WORKDIR /src
|
||||
COPY ["FastTunnel.Server/FastTunnel.Server.csproj", "FastTunnel.Server/"]
|
||||
COPY ["FastTunnel.Core/FastTunnel.Core.csproj", "FastTunnel.Core/"]
|
||||
|
|
|
@ -18,6 +18,11 @@
|
|||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<PackageReleaseNotes>FastTunnel.Core</PackageReleaseNotes>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="Listener\PortProxyListenerV2.cs" />
|
||||
<Compile Remove="Listener\TcpServerHandler.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="5.0.0" />
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
using FastTunnel.Core.Client;
|
||||
using FastTunnel.Core.Exceptions;
|
||||
using FastTunnel.Core.Extensions;
|
||||
using FastTunnel.Core.Listener;
|
||||
using FastTunnel.Core.Models;
|
||||
using FastTunnel.Core.Sockets;
|
||||
using Microsoft.AspNetCore.Hosting.Server;
|
||||
|
@ -41,7 +42,7 @@ namespace FastTunnel.Core.Handlers.Server
|
|||
/// <param name="_socket">用户请求</param>
|
||||
/// <param name="client">FastTunnel客户端</param>
|
||||
/// <returns></returns>
|
||||
public async Task DispatchAsync(Socket _socket, WebSocket client)
|
||||
public async Task DispatchAsync(Socket _socket, WebSocket client, PortProxyListener listener)
|
||||
{
|
||||
var msgId = Guid.NewGuid().ToString().Replace("-", "");
|
||||
|
||||
|
@ -51,7 +52,6 @@ namespace FastTunnel.Core.Handlers.Server
|
|||
logger.LogDebug($"[Forward]Swap开始 {msgId}|{_config.RemotePort}=>{_config.LocalIp}:{_config.LocalPort}");
|
||||
|
||||
var tcs = new TaskCompletionSource<Stream>();
|
||||
tcs.SetTimeOut(10000, () => { logger.LogDebug($"[Dispatch TimeOut]:{msgId}"); });
|
||||
|
||||
_server.ResponseTasks.TryAdd(msgId, (tcs, CancellationToken.None));
|
||||
|
||||
|
@ -76,13 +76,11 @@ namespace FastTunnel.Core.Handlers.Server
|
|||
return;
|
||||
}
|
||||
|
||||
using (var stream1 = await tcs.Task)
|
||||
using (var stream1 = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(10)))
|
||||
using (var stream2 = new NetworkStream(_socket, true) { ReadTimeout = 1000 * 60 * 10 })
|
||||
{
|
||||
await Task.WhenAny(stream1.CopyToAsync(stream2), stream2.CopyToAsync(stream1));
|
||||
}
|
||||
|
||||
logger.LogDebug($"[Forward]Swap OK {msgId}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -90,7 +88,9 @@ namespace FastTunnel.Core.Handlers.Server
|
|||
}
|
||||
finally
|
||||
{
|
||||
logger.LogDebug($"[Forward]Swap结束 {msgId}");
|
||||
_server.ResponseTasks.TryRemove(msgId, out _);
|
||||
listener.DecrementClients();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -74,19 +74,16 @@ namespace FastTunnel.Core.Listener
|
|||
}
|
||||
}
|
||||
|
||||
private void ProcessAcceptAsync(SocketAsyncEventArgs e)
|
||||
private async void ProcessAcceptAsync(SocketAsyncEventArgs e)
|
||||
{
|
||||
if (e.SocketError == SocketError.Success)
|
||||
{
|
||||
var accept = e.AcceptSocket;
|
||||
|
||||
Interlocked.Increment(ref m_numConnectedSockets);
|
||||
|
||||
_logerr.LogInformation($"【{ListenIp}:{ListenPort}】Accepted. There are {{0}} clients connected to the port",
|
||||
m_numConnectedSockets);
|
||||
IncrementClients();
|
||||
|
||||
// 将此客户端交由Dispatcher进行管理
|
||||
_requestDispatcher.DispatchAsync(accept, client);
|
||||
_requestDispatcher.DispatchAsync(accept, client, this);
|
||||
|
||||
// Accept the next connection request
|
||||
StartAccept(e);
|
||||
|
@ -123,5 +120,19 @@ namespace FastTunnel.Core.Listener
|
|||
listenSocket.Close();
|
||||
}
|
||||
}
|
||||
|
||||
internal void IncrementClients()
|
||||
{
|
||||
Interlocked.Increment(ref m_numConnectedSockets);
|
||||
_logerr.LogInformation($"[Listener:{ListenPort}] Accepted. There are {{0}} clients connected", m_numConnectedSockets);
|
||||
|
||||
}
|
||||
|
||||
internal void DecrementClients()
|
||||
{
|
||||
Interlocked.Decrement(ref m_numConnectedSockets);
|
||||
_logerr.LogInformation($"[Listener:{ListenPort}] DisConnet. There are {{0}} clients connecting", m_numConnectedSockets);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user