Skip to content

Commit

Permalink
修复异常IP问题
Browse files Browse the repository at this point in the history
升级.net8
  • Loading branch information
LuoCore committed Dec 21, 2023
1 parent a2aa48d commit e90dc34
Show file tree
Hide file tree
Showing 19 changed files with 1,162 additions and 57 deletions.
1,021 changes: 1,021 additions & 0 deletions .vs/LuoCoreFastGithub/config/applicationhost.config

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.2" />
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.0" />
</ItemGroup>

</Project>
18 changes: 13 additions & 5 deletions LuoCoreFastGithub.DomainResolve/IPAddressService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,19 @@ private async Task<AddressElapsed> GetAddressElapsedAsync(IPEndPoint endPoint, C
{
using var timeoutTokenSource = new CancellationTokenSource(this.connectTimeout);
using var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, timeoutTokenSource.Token);
using var socket = new Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
await socket.ConnectAsync(endPoint, linkedTokenSource.Token);

addressElapsed = new AddressElapsed(endPoint.Address, stopWatch.Elapsed);
return this.addressElapsedCache.Set(endPoint, addressElapsed, this.normalElapsedExpiration);
if (Enum.IsDefined(typeof(AddressFamily), endPoint.AddressFamily))
{
using var socket = new Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
await socket.ConnectAsync(endPoint, linkedTokenSource.Token);
addressElapsed = new AddressElapsed(endPoint.Address, stopWatch.Elapsed);
return this.addressElapsedCache.Set(endPoint, addressElapsed, this.normalElapsedExpiration);
}
else
{
return addressElapsed;
}


}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="PInvoke.AdvApi32" Version="0.7.124" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
<PackageReference Include="DNS" Version="7.0.0" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.49-beta">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="PInvoke.AdvApi32" Version="0.7.124" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Tommy" Version="3.1.2" />
<ProjectReference Include="..\LuoCoreFastGithub.Configuration\LuoCoreFastGithub.Configuration.csproj" />
</ItemGroup>


<ItemGroup>
<None Include="../@dnscrypt-proxy/*" Link="dnscrypt-proxy/%(Filename)%(Extension)">
<None Include="..\%40dnscrypt-proxy\*" Link="dnscrypt-proxy\%(Filename)%(Extension)">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="../@dnscrypt-proxy/$(RuntimeIdentifier)/*" Link="dnscrypt-proxy/%(Filename)%(Extension)">
<None Include="..\%40dnscrypt-proxy\$(RuntimeIdentifier)\*" Link="dnscrypt-proxy\%(Filename)%(Extension)">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="..\%40dnscrypt-proxy\$(RuntimeIdentifier)\win-x64\dnscrypt-proxy.exe" Link="dnscrypt-proxy\%(Filename)%(Extension)">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>



</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
Expand Down
2 changes: 1 addition & 1 deletion LuoCoreFastGithub.Http/LuoCoreFastGithub.Http.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\LuoCoreFastGithub.DomainResolve\LuoCoreFastGithub.DomainResolve.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public async Task InvokeAsync(HttpContext context, RequestDelegate next)
{
var proxyPac = this.CreateProxyPac(context.Request.Host);
context.Response.ContentType = "application/x-ns-proxy-autoconfig";
context.Response.Headers.Add("Content-Disposition", $"attachment;filename=proxy.pac");
context.Response.Headers.Append("Content-Disposition", $"attachment;filename=proxy.pac");
await context.Response.WriteAsync(proxyPac);
}
else
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Yarp.ReverseProxy" Version="1.1.1" />
<PackageReference Include="Yarp.ReverseProxy" Version="2.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<!--<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>-->
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand Down
10 changes: 8 additions & 2 deletions LuoCoreFastGithub.UI/LuoCoreFastGithub.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
<UseWindowsForms>true</UseWindowsForms>
<OutputType>WinExe</OutputType>
<LangVersion>8.0</LangVersion>
<TargetFramework>net7.0-windows</TargetFramework>
<TargetFramework>net8.0-windows</TargetFramework>
<ApplicationIcon>app.ico</ApplicationIcon>
<ApplicationManifest>app.manifest</ApplicationManifest>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<AutoGenerateBindingRedirects>False</AutoGenerateBindingRedirects>
<StartupObject></StartupObject>
<BaseOutputPath>D:\CodeRepository\Git\LuoCoreFastGithub\Resources</BaseOutputPath>
Expand All @@ -18,6 +17,13 @@
<Resource Include="Resource\*.*" />
</ItemGroup>

<ItemGroup>
<Compile Remove="bin\**" />
<EmbeddedResource Remove="bin\**" />
<None Remove="bin\**" />
<Page Remove="bin\**" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="LiveCharts.Wpf.Core" Version="0.9.8" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3">
Expand Down
2 changes: 1 addition & 1 deletion LuoCoreFastGithub.UI/LuoCoreFastGithub.UI.csproj.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<_LastSelectedProfileId>D:\Work\gitCode\LuoCoreFastGithub\LuoCoreFastGithub.UI\Properties\PublishProfiles\FolderProfile.pubxml</_LastSelectedProfileId>
<_LastSelectedProfileId>D:\CodeRepository\Git\LuoCoreFastGithub\LuoCoreFastGithub.UI\Properties\PublishProfiles\FolderProfile1.pubxml</_LastSelectedProfileId>
</PropertyGroup>
</Project>
31 changes: 27 additions & 4 deletions LuoCoreFastGithub.UI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,33 @@
</Grid>
</TabItem>

<TabItem Style="{StaticResource TabItemExWithUnderLineStyle}" Header="打赏" Height="40" Width="60" Margin="5 0" FontSize="18">
<Grid Background="#f7f7f7">
<Image Source="/Resource/zfbSH.jpg" Margin="16" />
</Grid>


<TabItem Style="{StaticResource TabItemExWithUnderLineStyle}" Header="支持" Height="40" Width="60" Margin="5 0" FontSize="18">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<Grid Background="#f7f7f7">
<StackPanel>
<TextBlock Text="扫描领取红包,然后打赏支持一下" HorizontalAlignment="Center"/>
<StackPanel HorizontalAlignment="Center" Margin="0 10">
<StackPanel>
<Image Source="/Resource/zfb_HB.jpg" Margin="16" Width="300" Height="400"/>
<TextBlock Text="支付宝红包" HorizontalAlignment="Center"/>
</StackPanel>
</StackPanel>

<StackPanel Orientation="Horizontal" Margin="0 10">
<StackPanel>
<Image Source="/Resource/zfbSH.jpg" Margin="16" Width="260" Height="260"/>
<TextBlock Text="支付宝打赏" HorizontalAlignment="Center"/>
</StackPanel>
<StackPanel>
<Image Source="/Resource/wx_GZH.jpg" Margin="16" Width="260" Height="260"/>
<TextBlock Text="微信公众号" HorizontalAlignment="Center"/>
</StackPanel>
</StackPanel>
</StackPanel>
</Grid>
</ScrollViewer>
</TabItem>
</TabControl>
</Grid>
Expand Down
Binary file added LuoCoreFastGithub.UI/Resource/wx_GZH.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added LuoCoreFastGithub.UI/Resource/zfb_HB.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion LuoCoreFastGithub/AppHostedService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public AppHostedService(
public override Task StartAsync(CancellationToken cancellationToken)
{
var version = ProductionVersion.Current;
this.logger.LogInformation($"{nameof(LuoCoreFastGithub)}启动完成,当前版本为v{version},访问 https://github.com/dotnetcore/LuoCoreFastGithub 关注新版本");
this.logger.LogInformation($"{nameof(LuoCoreFastGithub)}启动完成,当前版本为v{version},访问 https://github.com/LuoCore/LuoCoreFastGithub 关注新版本");
return base.StartAsync(cancellationToken);
}

Expand Down
14 changes: 8 additions & 6 deletions LuoCoreFastGithub/LuoCoreFastGithub.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,30 @@
<ApplicationManifest>app.manifest</ApplicationManifest>
<EnableCompressionInSingleFile>true</EnableCompressionInSingleFile>

<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>

<Version>2.0.0</Version>
<BaseOutputPath>D:\CodeRepository\Git\LuoCoreFastGithub\Resources</BaseOutputPath>
</PropertyGroup>




<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="7.0.0-rc*" />
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="7.0.0-rc*" />
<PackageReference Include="DnsCrypt.Blacklist" Version="0.1.1" />
<PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Network" Version="2.0.2.68" />
<ProjectReference Include="..\LuoCoreFastGithub.DomainResolve\LuoCoreFastGithub.DomainResolve.csproj" />
<ProjectReference Include="..\LuoCoreFastGithub.HttpServer\LuoCoreFastGithub.HttpServer.csproj" />
<ProjectReference Include="..\LuoCoreFastGithub.PacketIntercept\LuoCoreFastGithub.PacketIntercept.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Serilog.Extensions.Hosting" Version="5.0.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.4.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion LuoCoreFastGithub/LuoCoreFastGithub.csproj.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<NameOfLastUsedPublishProfile>D:\Work\gitCode\LuoCoreFastGithub\LuoCoreFastGithub\Properties\PublishProfiles\FolderProfile.pubxml</NameOfLastUsedPublishProfile>
<NameOfLastUsedPublishProfile>D:\CodeRepository\Git\LuoCoreFastGithub\LuoCoreFastGithub\Properties\PublishProfiles\FolderProfile1.pubxml</NameOfLastUsedPublishProfile>
</PropertyGroup>
</Project>
40 changes: 31 additions & 9 deletions LuoCoreFastGithub/ProductionVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,26 @@ namespace LuoCoreFastGithub
/// </summary>
public class ProductionVersion : IComparable<ProductionVersion>
{
private static readonly string? productionVersion = Assembly
.GetEntryAssembly()?
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?
.InformationalVersion;
private static string? productionVersion;


/// <summary>
/// 获取当前应用程序的产品版本
/// </summary>
public static ProductionVersion? Current { get; } = productionVersion == null ? null : Parse(productionVersion);


public static ProductionVersion? Current
{
get
{
if (productionVersion == null)
{
productionVersion = Assembly
.GetEntryAssembly()?
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?
.InformationalVersion;
}
return productionVersion == null ? null : Parse(productionVersion);
}
}
/// <summary>
/// 版本
/// </summary>
Expand Down Expand Up @@ -94,8 +103,21 @@ public override string ToString()
/// <returns></returns>
public static ProductionVersion Parse(string productionVersion)
{
const string VERSION = @"^\d+\.(\d+.){0,2}\d+";
var verion = Regex.Match(productionVersion, VERSION).Value;
if (string.IsNullOrEmpty(productionVersion))
{
throw new ArgumentException("productionVersion cannot be null or empty");
}

const string VERSION = @"^\d+\.\d+\.\d+"; // 匹配 X.X.X 格式的版本号
var match = Regex.Match(productionVersion, VERSION);
var verion = match.Success ? match.Value : "";


if (string.IsNullOrEmpty(verion))
{
throw new FormatException("Invalid productionVersion format");
}

var subVersion = productionVersion[verion.Length..];
return new ProductionVersion(Version.Parse(verion), subVersion);
}
Expand Down
39 changes: 26 additions & 13 deletions LuoCoreFastGithub/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
{
// 新增的子配置文件appsettings.*.json,重启应用程序才生效
"LuoCoreFastGithub": {
"HttpProxyPort": 38457, // http代理端口,linux/osx平台使用
"FallbackDns": [ // 以下dns必须要支持tcp
// http代理端口,linux/osx平台使用
"HttpProxyPort": 38457,
// 以下dns必须要支持tcp
"FallbackDns": [
"8.8.8.8:53",
"119.29.29.29:53",
"114.114.114.114:53"
],
"DomainConfigs": {
"*.LuoCoreFastGithub.com": { // 域名的*表示除.之外0到多个任意字符
"TlsSni": false, // 指示tls握手时是否发送SNI
"TlsSniPattern": null, // SNI表达式,@domain变量表示取域名值 @ipaddress变量表示取ip @random变量表示取随机值,其它字符保留不替换
"TlsIgnoreNameMismatch": false, // 是否忽略服务器证书域名不匹配,当不发送SNI时服务器可能发回域名不匹配的证书,默认为false
"Timeout": null, // 请求超时时长,格式为"00:02:00",默认为null
"IPAddress": null, // 请求的ip,默认为null
"Destination": null, // 请求目的地,格式为绝对或相对Uri,默认null
"Response": { // 阻断请求直接响应,设置了Response其它配置都不起作用了
"StatusCode": 404, // 响应的状态码
"ContentType": "text/plain;charset=utf-8", // 如果有ContentValue,就要指示ContentType
"ContentValue": "这是一个用于示范配置的域名" // 自定义返回的内容,这是可选的
// 域名的*表示除.之外0到多个任意字符
"*.LuoCoreFastGithub.com": {
// 指示tls握手时是否发送SNI
"TlsSni": false,
// SNI表达式,@domain变量表示取域名值 @ipaddress变量表示取ip @random变量表示取随机值,其它字符保留不替换
"TlsSniPattern": null,
// 是否忽略服务器证书域名不匹配,当不发送SNI时服务器可能发回域名不匹配的证书,默认为false
"TlsIgnoreNameMismatch": false,
// 请求超时时长,格式为"00:02:00",默认为null
"Timeout": null,
// 请求的ip,默认为null
"IPAddress": null,
// 请求目的地,格式为绝对或相对Uri,默认null
"Destination": null,
// 阻断请求直接响应,设置了Response其它配置都不起作用了
"Response": {
// 响应的状态码
"StatusCode": 404,
// 如果有ContentValue,就要指示ContentType
"ContentType": "text/plain;charset=utf-8",
// 自定义返回的内容,这是可选的
"ContentValue": "这是一个用于示范配置的域名"
}
}
}
Expand Down

0 comments on commit e90dc34

Please sign in to comment.