mirror of
https://github.com/FastTunnel/FastTunnel.git
synced 2025-02-08 02:39:29 +08:00
3.0.0 beta2
This commit is contained in:
parent
a2f0ba1e12
commit
7dc576304d
|
@ -50,7 +50,7 @@ csharp_new_line_before_members_in_object_initializers = true
|
|||
csharp_new_line_before_members_in_anonymous_types = true
|
||||
|
||||
# Namespace settings
|
||||
csharp_style_namespace_declarations = file_scoped
|
||||
csharp_style_namespace_declarations = file_scoped:silent
|
||||
|
||||
[*.{xml,config,*proj,nuspec,props,resx,targets,yml,tasks}]
|
||||
indent_size = 2
|
||||
|
@ -213,6 +213,16 @@ file_header_template = Licensed under the Apache License, Version 2.0 (the "Lice
|
|||
|
||||
# IDE0161: Convert to file-scoped namespace
|
||||
dotnet_diagnostic.IDE0161.severity = warning
|
||||
end_of_line = crlf
|
||||
dotnet_style_qualification_for_field = false:suggestion
|
||||
dotnet_style_qualification_for_property = false:suggestion
|
||||
dotnet_style_qualification_for_method = false:silent
|
||||
dotnet_style_qualification_for_event = false:silent
|
||||
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
|
||||
dotnet_code_quality_unused_parameters = all:suggestion
|
||||
dotnet_style_readonly_field = true:suggestion
|
||||
tab_width = 4
|
||||
indent_size = 4
|
||||
|
||||
[**/{test,samples,perf}/**.{cs,vb}]
|
||||
# CA1018: Mark attributes with AttributeUsageAttribute
|
||||
|
@ -309,6 +319,23 @@ dotnet_naming_style.pascal_case.required_prefix =
|
|||
dotnet_naming_style.pascal_case.required_suffix =
|
||||
dotnet_naming_style.pascal_case.word_separator =
|
||||
dotnet_naming_style.pascal_case.capitalization = pascal_case
|
||||
csharp_using_directive_placement = outside_namespace:silent
|
||||
csharp_style_expression_bodied_methods = false:silent
|
||||
csharp_style_expression_bodied_constructors = false:silent
|
||||
csharp_style_expression_bodied_operators = false:silent
|
||||
csharp_style_expression_bodied_properties = true:silent
|
||||
csharp_style_expression_bodied_indexers = true:silent
|
||||
csharp_style_expression_bodied_accessors = true:silent
|
||||
csharp_style_expression_bodied_lambdas = true:silent
|
||||
csharp_style_expression_bodied_local_functions = false:silent
|
||||
csharp_style_conditional_delegate_call = true:suggestion
|
||||
csharp_prefer_simple_using_statement = true:suggestion
|
||||
csharp_prefer_braces = true:silent
|
||||
csharp_style_prefer_method_group_conversion = true:silent
|
||||
csharp_style_prefer_top_level_statements = true:silent
|
||||
csharp_prefer_static_local_function = true:suggestion
|
||||
csharp_space_around_binary_operators = before_and_after
|
||||
csharp_indent_labels = one_less_than_current
|
||||
|
||||
[*.vb]
|
||||
#### ÃüÃûÑùʽ ####
|
||||
|
|
|
@ -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.Api/FastTunnel.Api.csproj", "FastTunnel.Api/"]
|
||||
|
|
|
@ -4,17 +4,17 @@
|
|||
// https://github.com/FastTunnel/FastTunnel/edit/v2/LICENSE
|
||||
// Copyright (c) 2019 Gui.H
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using FastTunnel.Api.Models;
|
||||
using FastTunnel.Core.Config;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace FastTunnel.Api.Controllers
|
||||
{
|
||||
|
|
|
@ -4,14 +4,11 @@
|
|||
// https://github.com/FastTunnel/FastTunnel/edit/v2/LICENSE
|
||||
// Copyright (c) 2019 Gui.H
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using FastTunnel.Api.Models;
|
||||
using FastTunnel.Core.Server;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FastTunnel.Api.Controllers
|
||||
{
|
||||
|
|
|
@ -5,22 +5,17 @@
|
|||
// Copyright (c) 2019 Gui.H
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using FastTunnel.Api;
|
||||
using FastTunnel.Api.Filters;
|
||||
using FastTunnel.Core.Config;
|
||||
using FastTunnel.Core.Extensions;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
|
||||
[assembly: HostingStartup(typeof(FastTunnelApiHostingStartup))]
|
||||
|
|
|
@ -4,6 +4,16 @@
|
|||
<TargetFramework>net7.0</TargetFramework>
|
||||
<OutputType>Exe</OutputType>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<None Remove="appsettings.Development.json" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="appsettings.Development.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="7.0.0-preview.3.22175.4" />
|
||||
|
|
|
@ -4,13 +4,11 @@
|
|||
// https://github.com/FastTunnel/FastTunnel/edit/v2/LICENSE
|
||||
// Copyright (c) 2019 Gui.H
|
||||
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Serilog;
|
||||
using FastTunnel.Core.Extensions;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Serilog;
|
||||
|
||||
namespace FastTunnel.Client;
|
||||
|
||||
|
@ -49,12 +47,12 @@ class Program
|
|||
Host.CreateDefaultBuilder(args)
|
||||
.UseWindowsService()
|
||||
.UseSerilog((context, services, configuration) => configuration
|
||||
.WriteTo.File("logs/log-.txt", rollingInterval: RollingInterval.Day)
|
||||
.WriteTo.Console())
|
||||
.ReadFrom.Configuration(context.Configuration)
|
||||
.WriteTo.Console())
|
||||
.ConfigureServices((hostContext, services) =>
|
||||
{
|
||||
// -------------------FastTunnel START------------------
|
||||
services.AddFastTunnelClient(hostContext.Configuration.GetSection("ClientSettings"));
|
||||
services.AddFastTunnelClient(hostContext.Configuration.GetSection("FastTunnel"));
|
||||
// -------------------FastTunnel EDN--------------------
|
||||
});
|
||||
}
|
||||
|
|
7
FastTunnel.Client/appsettings.Development.json
Normal file
7
FastTunnel.Client/appsettings.Development.json
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"Serilog": {
|
||||
"MinimumLevel": {
|
||||
"Default": "Debug"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,15 +1,24 @@
|
|||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
// Trace Debug Information Warning Error
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
"Serilog": {
|
||||
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
|
||||
"MinimumLevel": {
|
||||
"Default": "Debug",
|
||||
"Override": {
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"WriteTo": [
|
||||
//{
|
||||
// "Name": "File",
|
||||
// "Args": {
|
||||
// "path": "Logs/log-.log",
|
||||
// "rollingInterval": 3
|
||||
// }
|
||||
//}
|
||||
]
|
||||
},
|
||||
// 是否启用文件日志输出
|
||||
"EnableFileLog": false,
|
||||
"ClientSettings": {
|
||||
"FastTunnel": {
|
||||
"Server": {
|
||||
// [必选] 服务端ip/域名(来自服务端配置文件的urls参数)
|
||||
"ServerAddr": "test.cc",
|
||||
|
|
|
@ -20,6 +20,9 @@ using Microsoft.Extensions.Options;
|
|||
|
||||
namespace FastTunnel.Core.Client;
|
||||
|
||||
/// <summary>
|
||||
/// 客户端
|
||||
/// </summary>
|
||||
public class FastTunnelClient : IFastTunnelClient
|
||||
{
|
||||
private ClientWebSocket socket;
|
||||
|
@ -48,8 +51,7 @@ public class FastTunnelClient : IFastTunnelClient
|
|||
/// <summary>
|
||||
/// 启动客户端
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="customLoginMsg">自定义登录信息,可进行扩展业务</param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
public async void StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
_logger.LogInformation("===== FastTunnel Client Start =====");
|
||||
|
|
|
@ -6,10 +6,7 @@
|
|||
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using System.IO.Pipelines;
|
||||
using System.Linq;
|
||||
using System.Reflection.PortableExecutable;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using FastTunnel.Core.Forwarder.Kestrel.Features;
|
||||
|
@ -17,7 +14,6 @@ using FastTunnel.Core.Models;
|
|||
using FastTunnel.Core.Protocol;
|
||||
using FastTunnel.Core.Server;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.Extensions.FileSystemGlobbing;
|
||||
|
||||
namespace FastTunnel.Core.Forwarder;
|
||||
|
||||
|
|
|
@ -4,11 +4,7 @@
|
|||
// 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 FastTunnel.Core.Models;
|
||||
|
||||
namespace FastTunnel.Core.Forwarder.Kestrel.Features;
|
||||
|
|
|
@ -4,13 +4,8 @@
|
|||
// 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 FastTunnel.Core.Models;
|
||||
using FastTunnel.Core.Protocol;
|
||||
|
||||
namespace FastTunnel.Core.Forwarder.Kestrel.Features;
|
||||
|
||||
|
|
|
@ -5,24 +5,18 @@
|
|||
// Copyright (c) 2019 Gui.H
|
||||
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.IO;
|
||||
using System.IO.Pipelines;
|
||||
using System.Net.WebSockets;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using FastTunnel.Core.Exceptions;
|
||||
using FastTunnel.Core.Extensions;
|
||||
using FastTunnel.Core.Forwarder.Kestrel;
|
||||
using FastTunnel.Core.Forwarder.Kestrel.Features;
|
||||
using FastTunnel.Core.Forwarder.Streams;
|
||||
using FastTunnel.Core.Models.Massage;
|
||||
using FastTunnel.Core.Protocol;
|
||||
using FastTunnel.Core.Server;
|
||||
using FastTunnel.Core.Utilitys;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Connections.Features;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FastTunnel.Core.Forwarder.Kestrel.MiddleWare;
|
||||
|
@ -132,7 +126,7 @@ internal class ForwarderMiddleware
|
|||
finally
|
||||
{
|
||||
Interlocked.Decrement(ref UserCount);
|
||||
logger.LogDebug($"=========USER END {requestId}===========");
|
||||
logger.LogDebug($"=========USER END {requestId} {UserCount}===========");
|
||||
fastTunnelServer.ResponseTasks.TryRemove(requestId, out _);
|
||||
|
||||
await context.Transport.Input.CompleteAsync();
|
||||
|
@ -183,7 +177,7 @@ internal class ForwarderMiddleware
|
|||
finally
|
||||
{
|
||||
Interlocked.Decrement(ref ClientCount);
|
||||
logger.LogDebug($"=========CLINET END {requestId}===========");
|
||||
logger.LogDebug($"=========CLINET END {requestId} {ClientCount}===========");
|
||||
await context.Transport.Input.CompleteAsync();
|
||||
await context.Transport.Output.CompleteAsync();
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
// Copyright (c) 2019 Gui.H
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using FastTunnel.Core.Forwarder.Kestrel;
|
||||
using FastTunnel.Core.Server;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
|
|
@ -9,7 +9,6 @@ using System.Buffers;
|
|||
using System.IO;
|
||||
using System.IO.Pipelines;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using FastTunnel.Core.Extensions;
|
||||
|
|
|
@ -5,11 +5,8 @@
|
|||
// Copyright (c) 2019 Gui.H
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO.Pipelines;
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FastTunnel.Core.Forwarder.Streams;
|
||||
|
|
|
@ -46,8 +46,6 @@ public class SwapHandler : IClientHandler
|
|||
var taskY = localStream.CopyToAsync(serverStream, cancellationToken);
|
||||
|
||||
await Task.WhenAny(taskX, taskY).WaitAsync(cancellationToken);
|
||||
|
||||
_logger.LogDebug($"[HandlerMsgAsync] success {requestId}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -56,7 +54,7 @@ public class SwapHandler : IClientHandler
|
|||
finally
|
||||
{
|
||||
Interlocked.Decrement(ref SwapCount);
|
||||
_logger.LogDebug($"========Swap End:{requestId}==========");
|
||||
_logger.LogDebug($"========Swap End:{requestId} {SwapCount}==========");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,14 +6,12 @@
|
|||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.IO.Pipelines;
|
||||
using System.Net.Sockets;
|
||||
using System.Net.WebSockets;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using FastTunnel.Core.Exceptions;
|
||||
using FastTunnel.Core.Extensions;
|
||||
using FastTunnel.Core.Forwarder.Streams;
|
||||
using FastTunnel.Core.Models;
|
||||
using FastTunnel.Core.Models.Massage;
|
||||
using FastTunnel.Core.Server;
|
||||
|
@ -34,6 +32,8 @@ public class ForwardDispatcher
|
|||
_config = config;
|
||||
}
|
||||
|
||||
int SwapCount;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
@ -46,6 +46,8 @@ public class ForwardDispatcher
|
|||
|
||||
(Stream Stream, CancellationTokenSource TokenSource) res = default;
|
||||
|
||||
Interlocked.Increment(ref SwapCount);
|
||||
|
||||
try
|
||||
{
|
||||
logger.LogDebug($"[Forward]Swap开始 {msgId}|{_config.RemotePort}=>{_config.LocalIp}:{_config.LocalPort}");
|
||||
|
@ -53,7 +55,10 @@ public class ForwardDispatcher
|
|||
var tcs = new TaskCompletionSource<(Stream Stream, CancellationTokenSource TokenSource)>();
|
||||
tcs.SetTimeOut(10000, () => { logger.LogDebug($"[Dispatch TimeOut]:{msgId}"); });
|
||||
|
||||
_server.ResponseTasks.TryAdd(msgId, tcs);
|
||||
if (!_server.ResponseTasks.TryAdd(msgId, tcs))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -88,8 +93,9 @@ public class ForwardDispatcher
|
|||
}
|
||||
finally
|
||||
{
|
||||
Interlocked.Decrement(ref SwapCount);
|
||||
res.TokenSource?.Cancel();
|
||||
logger.LogDebug($"[Forward]Swap OK {msgId}");
|
||||
logger.LogDebug($"[Forward]Swap OK {msgId} {SwapCount}");
|
||||
_server.ResponseTasks.TryRemove(msgId, out _);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ public class LoginHandler : ILoginHandler
|
|||
var hostName = $"{item.SubDomain}.{server.ServerOption.CurrentValue.WebDomain}".Trim().ToLower();
|
||||
var info = new WebInfo { Socket = client.webSocket, WebConfig = item };
|
||||
|
||||
logger.LogDebug($"new domain '{hostName}'");
|
||||
logger.LogDebug($"New Http '{hostName}'");
|
||||
server.WebList.AddOrUpdate(hostName, info, (key, oldInfo) => { return info; });
|
||||
|
||||
await client.webSocket.SendCmdAsync(MessageType.Log, $" HTTP | http://{hostName}:{client.ConnectionPort} => {item.LocalIp}:{item.LocalPort}", CancellationToken.None);
|
||||
|
|
|
@ -54,7 +54,6 @@ public class PortProxyListener
|
|||
|
||||
private void StartAccept(SocketAsyncEventArgs acceptEventArg)
|
||||
{
|
||||
_logerr.LogDebug($"【{ListenIp}:{ListenPort}】: StartAccept");
|
||||
if (acceptEventArg == null)
|
||||
{
|
||||
acceptEventArg = new SocketAsyncEventArgs();
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
// https://github.com/FastTunnel/FastTunnel/edit/v2/LICENSE
|
||||
// Copyright (c) 2019 Gui.H
|
||||
|
||||
using System;
|
||||
using System.Net.WebSockets;
|
||||
|
||||
namespace FastTunnel.Core.Models;
|
||||
|
|
|
@ -1,173 +0,0 @@
|
|||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.IO;
|
||||
using System.IO.Pipelines;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using FastTunnel.Core.Extensions;
|
||||
using Microsoft.AspNetCore.Internal;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace FastTunnel.Core.Refs;
|
||||
|
||||
internal class DuplexPipeStream : Stream
|
||||
{
|
||||
private readonly PipeReader _input;
|
||||
private readonly PipeWriter _output;
|
||||
private readonly bool _throwOnCancelled;
|
||||
private volatile bool _cancelCalled;
|
||||
|
||||
public DuplexPipeStream(PipeReader input, PipeWriter output, bool throwOnCancelled = false)
|
||||
{
|
||||
_input = input;
|
||||
_output = output;
|
||||
_throwOnCancelled = throwOnCancelled;
|
||||
}
|
||||
|
||||
public void CancelPendingRead()
|
||||
{
|
||||
_cancelCalled = true;
|
||||
_input.CancelPendingRead();
|
||||
}
|
||||
|
||||
public override bool CanRead => true;
|
||||
|
||||
public override bool CanSeek => false;
|
||||
|
||||
public override bool CanWrite => true;
|
||||
|
||||
public override long Length
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
public override long Position
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
set
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
public override long Seek(long offset, SeekOrigin origin)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override void SetLength(long value)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
{
|
||||
var vt = ReadAsyncInternal(new Memory<byte>(buffer, offset, count), default);
|
||||
return vt.IsCompleted ?
|
||||
vt.Result :
|
||||
vt.AsTask().GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return ReadAsyncInternal(new Memory<byte>(buffer, offset, count), cancellationToken).AsTask();
|
||||
}
|
||||
|
||||
public override ValueTask<int> ReadAsync(Memory<byte> destination, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return ReadAsyncInternal(destination, cancellationToken);
|
||||
}
|
||||
|
||||
public override void Write(byte[] buffer, int offset, int count)
|
||||
{
|
||||
WriteAsync(buffer, offset, count).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
public override Task WriteAsync(byte[]? buffer, int offset, int count, CancellationToken cancellationToken)
|
||||
{
|
||||
return _output.WriteAsync(buffer.AsMemory(offset, count), cancellationToken).GetAsTask();
|
||||
}
|
||||
|
||||
public override ValueTask WriteAsync(ReadOnlyMemory<byte> source, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return _output.WriteAsync(source, cancellationToken).GetAsValueTask();
|
||||
}
|
||||
|
||||
public override void Flush()
|
||||
{
|
||||
FlushAsync(CancellationToken.None).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
public override Task FlushAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return _output.FlushAsync(cancellationToken).GetAsTask();
|
||||
}
|
||||
|
||||
[AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder<>))]
|
||||
private async ValueTask<int> ReadAsyncInternal(Memory<byte> destination, CancellationToken cancellationToken)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
var result = await _input.ReadAsync(cancellationToken);
|
||||
var readableBuffer = result.Buffer;
|
||||
try
|
||||
{
|
||||
if (_throwOnCancelled && result.IsCanceled && _cancelCalled)
|
||||
{
|
||||
// Reset the bool
|
||||
_cancelCalled = false;
|
||||
throw new OperationCanceledException();
|
||||
}
|
||||
|
||||
if (!readableBuffer.IsEmpty)
|
||||
{
|
||||
// buffer.Count is int
|
||||
var count = (int)Math.Min(readableBuffer.Length, destination.Length);
|
||||
readableBuffer = readableBuffer.Slice(0, count);
|
||||
readableBuffer.CopyTo(destination.Span);
|
||||
return count;
|
||||
}
|
||||
|
||||
if (result.IsCompleted)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_input.AdvanceTo(readableBuffer.End, readableBuffer.End);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state)
|
||||
{
|
||||
return TaskToApm.Begin(ReadAsync(buffer, offset, count), callback, state);
|
||||
}
|
||||
|
||||
public override int EndRead(IAsyncResult asyncResult)
|
||||
{
|
||||
return TaskToApm.End<int>(asyncResult);
|
||||
}
|
||||
|
||||
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state)
|
||||
{
|
||||
return TaskToApm.Begin(WriteAsync(buffer, offset, count), callback, state);
|
||||
}
|
||||
|
||||
public override void EndWrite(IAsyncResult asyncResult)
|
||||
{
|
||||
TaskToApm.End(asyncResult);
|
||||
}
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.IO.Pipelines;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FastTunnel.Core.Refs;
|
||||
|
||||
/// <summary>
|
||||
/// A helper for wrapping a Stream decorator from an <see cref="IDuplexPipe"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="TStream"></typeparam>
|
||||
internal class DuplexPipeStreamAdapter<TStream> : DuplexPipeStream, IDuplexPipe where TStream : Stream
|
||||
{
|
||||
private bool _disposed;
|
||||
private readonly object _disposeLock = new object();
|
||||
|
||||
public DuplexPipeStreamAdapter(IDuplexPipe duplexPipe, Func<Stream, TStream> createStream) :
|
||||
this(duplexPipe, new StreamPipeReaderOptions(leaveOpen: true), new StreamPipeWriterOptions(leaveOpen: true), createStream)
|
||||
{
|
||||
}
|
||||
|
||||
public DuplexPipeStreamAdapter(IDuplexPipe duplexPipe, StreamPipeReaderOptions readerOptions, StreamPipeWriterOptions writerOptions, Func<Stream, TStream> createStream) :
|
||||
base(duplexPipe.Input, duplexPipe.Output)
|
||||
{
|
||||
var stream = createStream(this);
|
||||
Stream = stream;
|
||||
Input = PipeReader.Create(stream, readerOptions);
|
||||
Output = PipeWriter.Create(stream, writerOptions);
|
||||
}
|
||||
|
||||
public TStream Stream { get; }
|
||||
|
||||
public PipeReader Input { get; }
|
||||
|
||||
public PipeWriter Output { get; }
|
||||
|
||||
public override async ValueTask DisposeAsync()
|
||||
{
|
||||
lock (_disposeLock)
|
||||
{
|
||||
if (_disposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_disposed = true;
|
||||
}
|
||||
|
||||
await Input.CompleteAsync();
|
||||
await Output.CompleteAsync();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
|
@ -8,7 +8,6 @@ using System;
|
|||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Pipelines;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using FastTunnel.Core.Config;
|
||||
|
|
|
@ -4,12 +4,8 @@
|
|||
// https://github.com/FastTunnel/FastTunnel/edit/v2/LICENSE
|
||||
// Copyright (c) 2019 Gui.H
|
||||
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using System.IO.Pipelines;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
@ -40,7 +36,7 @@ internal class SwapUtility
|
|||
|
||||
result = await pipe.Input.ReadAsync(cancellationToken);
|
||||
readableBuffer = result.Buffer;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
// https://github.com/FastTunnel/FastTunnel/edit/v2/LICENSE
|
||||
// Copyright (c) 2019 Gui.H
|
||||
|
||||
using FastTunnel.Core.Extensions;
|
||||
using FastTunnel.Hosting;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using FastTunnel.Core.Extensions;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
[assembly: HostingStartup(typeof(FastTunnelHostingStartup))]
|
||||
|
@ -24,7 +24,7 @@ public class FastTunnelHostingStartup : IHostingStartup
|
|||
|
||||
builder.UseKestrel((context, options) =>
|
||||
{
|
||||
var basePort = context.Configuration.GetValue<int?>("FastTunnel:BasePort") ?? 1270;
|
||||
var basePort = context.Configuration.GetValue<int?>("FastTunnel:BinPort") ?? 1270;
|
||||
options.ListenAnyIP(basePort, listenOptions =>
|
||||
{
|
||||
listenOptions.UseConnectionFastTunnel();
|
||||
|
|
|
@ -35,6 +35,9 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="install.bat">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="uninstall.bat">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
|
|
|
@ -4,13 +4,11 @@
|
|||
// https://github.com/FastTunnel/FastTunnel/edit/v2/LICENSE
|
||||
// Copyright (c) 2019 Gui.H
|
||||
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using FastTunnel.Core.Extensions;
|
||||
using Serilog;
|
||||
using System;
|
||||
|
||||
namespace FastTunnel.Server;
|
||||
|
||||
|
@ -49,7 +47,9 @@ public class Program
|
|||
Host.CreateDefaultBuilder(args)
|
||||
.UseWindowsService()
|
||||
.UseSerilog((context, services, configuration) => configuration
|
||||
.WriteTo.File("logs/log-.txt", rollingInterval: RollingInterval.Day)
|
||||
.ReadFrom.Configuration(context.Configuration)
|
||||
.ReadFrom.Services(services)
|
||||
.Enrich.FromLogContext()
|
||||
.WriteTo.Console())
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
|
|
|
@ -5,16 +5,12 @@
|
|||
// Copyright (c) 2019 Gui.H
|
||||
|
||||
using FastTunnel.Core.Extensions;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using System;
|
||||
using FastTunnel.Core.Config;
|
||||
using System.Text;
|
||||
|
||||
#if DEBUG
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
// Trace Debug Information Warning Error
|
||||
"Default": "Debug",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
"Serilog": {
|
||||
"MinimumLevel": {
|
||||
"Default": "Debug"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"EnableFileLog": false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,30 @@
|
|||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
// Trace Debug Information Warning Error
|
||||
"Serilog": {
|
||||
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
|
||||
"MinimumLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
"Override": {
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"WriteTo": [
|
||||
//{
|
||||
// "Name": "File",
|
||||
// "Args": {
|
||||
// "path": "Logs/log-.log",
|
||||
// "rollingInterval": 3
|
||||
// }
|
||||
//}
|
||||
]
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
// Http&客户端通讯端口
|
||||
"urls": "http://*:1270",
|
||||
// 是否启用文件日志输出
|
||||
"EnableFileLog": false,
|
||||
"FastTunnel": {
|
||||
// 服务监听端口
|
||||
"BinPort": 1270,
|
||||
|
||||
// 可选,绑定的根域名,
|
||||
// 客户端需配置SubDomain,实现 ${SubDomain}.${WebDomain}访问内网的站点,注意:需要通过域名访问网站时必选。
|
||||
"WebDomain": "test.cc",
|
||||
|
|
|
@ -4,7 +4,7 @@ color 0e
|
|||
@echo ==================================
|
||||
@echo 提醒:请右键本文件,用管理员方式打开。
|
||||
@echo ==================================
|
||||
@echo Start Install ./../FastTunnel.Server
|
||||
@echo Start Install FastTunnel.Server
|
||||
|
||||
sc create FastTunnel.Server binPath=%~dp0\FastTunnel.Server.exe start= auto
|
||||
sc description FastTunnel.Server "FastTunnel-开源内网穿透服务,仓库地址:https://github.com/SpringHgui/FastTunnel star项目以支持作者"
|
|
@ -4,7 +4,7 @@ color 0e
|
|||
@echo ==================================
|
||||
@echo 提醒:请右键本文件,用管理员方式打开。
|
||||
@echo ==================================
|
||||
@echo Start Remove ./../FastTunnel.Server
|
||||
@echo Start Remove FastTunnel.Server
|
||||
|
||||
Net stop FastTunnel.Server
|
||||
sc delete FastTunnel.Server
|
Loading…
Reference in New Issue
Block a user