移除api.github.com的扫描

This commit is contained in:
xljiulang 2021-06-16 21:36:59 +08:00
parent 52f73f8790
commit 988d1d5399
4 changed files with 23 additions and 23 deletions

View File

@ -27,7 +27,7 @@ namespace FastGithub.Scanner
this.metaService = metaService; this.metaService = metaService;
this.contextCollection = contextCollection; this.contextCollection = contextCollection;
this.logger = logger; this.logger = logger;
; ;
this.fullScanDelegate = new PipelineBuilder<GithubContext>(appService, ctx => Task.CompletedTask) this.fullScanDelegate = new PipelineBuilder<GithubContext>(appService, ctx => Task.CompletedTask)
.Use<ConcurrentMiddleware>() .Use<ConcurrentMiddleware>()
.Use<ScanOkLogMiddleware>() .Use<ScanOkLogMiddleware>()
@ -46,29 +46,30 @@ namespace FastGithub.Scanner
public async Task ScanAllAsync(CancellationToken cancellationToken = default) public async Task ScanAllAsync(CancellationToken cancellationToken = default)
{ {
this.logger.LogInformation("完整扫描开始"); this.logger.LogInformation("完整扫描开始..");
var meta = await this.metaService.GetMetaAsync(cancellationToken); var meta = await this.metaService.GetMetaAsync(cancellationToken);
if (meta != null) if (meta != null)
{ {
var scanTasks = meta.ToGithubContexts().Select(ctx => ScanAsync(ctx)); var scanTasks = meta.ToGithubContexts().Select(ctx => ScanAsync(ctx));
await Task.WhenAll(scanTasks); var results = await Task.WhenAll(scanTasks);
var successCount = results.Count(item => item);
this.logger.LogInformation($"完整扫描结束,成功{successCount}条共{results.Length}条");
} }
this.logger.LogInformation("完整扫描结束"); async Task<bool> ScanAsync(GithubContext context)
async Task ScanAsync(GithubContext context)
{ {
await this.fullScanDelegate(context); await this.fullScanDelegate(context);
if (context.Available == true) if (context.Available == true)
{ {
this.contextCollection.Add(context); this.contextCollection.Add(context);
} }
return context.Available;
} }
} }
public async Task ScanResultAsync() public async Task ScanResultAsync()
{ {
this.logger.LogInformation("结果扫描开始"); this.logger.LogInformation("结果扫描开始..");
var contexts = this.contextCollection.ToArray(); var contexts = this.contextCollection.ToArray();
foreach (var context in contexts) foreach (var context in contexts)
@ -76,7 +77,7 @@ namespace FastGithub.Scanner
await this.resultScanDelegate(context); await this.resultScanDelegate(context);
} }
this.logger.LogInformation("结果扫描结束"); this.logger.LogInformation($"结果扫描结束,共扫描{contexts.Length}条记录");
} }
} }
} }

View File

@ -47,18 +47,7 @@ namespace FastGithub.Scanner
yield return new GithubContext("github.com", address); yield return new GithubContext("github.com", address);
} }
} }
} }
foreach (var range in IPRange.From(this.Api).OrderBy(item => item.Size))
{
if (range.AddressFamily == AddressFamily.InterNetwork)
{
foreach (var address in range)
{
yield return new GithubContext("api.github.com", address);
}
}
}
} }
} }
} }

View File

@ -12,8 +12,8 @@ namespace FastGithub.Scanner.Middlewares
public ConcurrentMiddleware() public ConcurrentMiddleware()
{ {
var initialCount = Environment.ProcessorCount; var currentCount = Environment.ProcessorCount * 4;
this.semaphoreSlim = new SemaphoreSlim(initialCount, initialCount * 4); this.semaphoreSlim = new SemaphoreSlim(currentCount, currentCount);
} }
public async Task InvokeAsync(GithubContext context, Func<Task> next) public async Task InvokeAsync(GithubContext context, Func<Task> next)

View File

@ -57,8 +57,18 @@ namespace FastGithub.Scanner.Middlewares
} }
catch (Exception ex) catch (Exception ex)
{ {
this.logger.LogTrace($"{context.Domain} {context.Address} {ex.Message}"); var message = GetInnerMessage(ex);
this.logger.LogTrace($"{context.Domain} {context.Address} {message}");
} }
} }
private string GetInnerMessage(Exception ex)
{
while (ex.InnerException != null)
{
return GetInnerMessage(ex.InnerException);
}
return ex.Message;
}
} }
} }