Skip to content

Commit

Permalink
中间件重命名
Browse files Browse the repository at this point in the history
  • Loading branch information
xljiulang committed Jun 11, 2021
1 parent ea70ddd commit a2ea783
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 77 deletions.
2 changes: 1 addition & 1 deletion FastGithub/GithubOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ class GithubOptions

public TimeSpan PortScanTimeout { get; set; } = TimeSpan.FromSeconds(1d);

public TimeSpan HttpTestTimeout { get; set; } = TimeSpan.FromSeconds(5d);
public TimeSpan HttpsScanTimeout { get; set; } = TimeSpan.FromSeconds(5d);
}
}
13 changes: 12 additions & 1 deletion FastGithub/IPv4CIDR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public IPv4CIDR(IPAddress ipAddress, int mask)
{
this.IPAddress = ipAddress;
this.Mask = mask;
this.Size = (int)(uint.MaxValue << mask >> mask);
this.Size = Math.Abs((int)(uint.MaxValue << mask >> mask));
}

public IEnumerable<IPAddress> GetAllIPAddress()
Expand All @@ -45,6 +45,17 @@ private static IPAddress Add(IPAddress ip, int value)
return new IPAddress(span);
}

public static IEnumerable<IPv4CIDR> From(IEnumerable<string> cidrs)
{
foreach (var item in cidrs)
{
if (TryParse(item, out var value))
{
yield return value;
}
}
}

public static bool TryParse(ReadOnlySpan<char> cidr, [MaybeNullWhen(false)] out IPv4CIDR value)
{
value = null;
Expand Down
19 changes: 7 additions & 12 deletions FastGithub/Meta.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text.Json.Serialization;

Expand Down Expand Up @@ -37,25 +38,19 @@ class Meta

public IEnumerable<DomainAddress> ToDomainAddress()
{
foreach (var item in this.Web)
foreach (var cidr in IPv4CIDR.From(this.Web).OrderBy(item => item.Size))
{
if (IPv4CIDR.TryParse(item, out var cidr))
foreach (var address in cidr.GetAllIPAddress())
{
foreach (var address in cidr.GetAllIPAddress())
{
yield return new DomainAddress("github.com", address);
}
yield return new DomainAddress("github.com", address);
}
}

foreach (var item in this.Api)
foreach (var cidr in IPv4CIDR.From(this.Api).OrderBy(item => item.Size))
{
if (IPv4CIDR.TryParse(item, out var cidr))
foreach (var address in cidr.GetAllIPAddress())
{
foreach (var address in cidr.GetAllIPAddress())
{
yield return new DomainAddress("api.github.com", address);
}
yield return new DomainAddress("api.github.com", address);
}
}
}
Expand Down
60 changes: 0 additions & 60 deletions FastGithub/Middlewares/HttpTestMiddleware.cs

This file was deleted.

4 changes: 2 additions & 2 deletions FastGithub/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ public static IHostBuilder CreateHostBuilder(string[] args)
.AddTransient<GithubService>()

.AddSingleton<PortScanMiddleware>()
.AddSingleton<HttpTestMiddleware>()
.AddSingleton<HttpsScanMiddleware>()
.AddSingleton<ConcurrentMiddleware>()
.AddSingleton(serviceProvider =>
{
return new GithubBuilder(serviceProvider, ctx => Task.CompletedTask)
.Use<ConcurrentMiddleware>()
.Use<PortScanMiddleware>()
.Use<HttpTestMiddleware>()
.Use<HttpsScanMiddleware>()
.Build();
})
.AddHostedService<GithubHostedService>()
Expand Down
2 changes: 1 addition & 1 deletion FastGithub/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Github": {
"MetaUri": "https://gitee.com/jiulang/fast-github/raw/master/FastGithub/meta.json", // ip资源文件uri
"PortScanTimeout": "00:00:01", // 端口扫描超时时间
"HttpTestTimeout": "00:00:05" // http测试超时时间
"HttpsScanTimeout": "00:00:05" // https扫描超时时间
},
"Logging": {
"LogLevel": {
Expand Down

0 comments on commit a2ea783

Please sign in to comment.