diff --git a/FastGithub.Scanner/GithubScanService.cs b/FastGithub.Scanner/GithubScanService.cs index 3b89603..437c397 100644 --- a/FastGithub.Scanner/GithubScanService.cs +++ b/FastGithub.Scanner/GithubScanService.cs @@ -27,7 +27,7 @@ namespace FastGithub.Scanner this.metaService = metaService; this.contextCollection = contextCollection; this.logger = logger; - ; + ; this.fullScanDelegate = new PipelineBuilder(appService, ctx => Task.CompletedTask) .Use() .Use() @@ -46,29 +46,30 @@ namespace FastGithub.Scanner public async Task ScanAllAsync(CancellationToken cancellationToken = default) { - this.logger.LogInformation("完整扫描开始"); + this.logger.LogInformation("完整扫描开始.."); var meta = await this.metaService.GetMetaAsync(cancellationToken); if (meta != null) { 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 ScanAsync(GithubContext context) + async Task ScanAsync(GithubContext context) { await this.fullScanDelegate(context); if (context.Available == true) { this.contextCollection.Add(context); } + return context.Available; } } public async Task ScanResultAsync() { - this.logger.LogInformation("结果扫描开始"); + this.logger.LogInformation("结果扫描开始.."); var contexts = this.contextCollection.ToArray(); foreach (var context in contexts) @@ -76,7 +77,7 @@ namespace FastGithub.Scanner await this.resultScanDelegate(context); } - this.logger.LogInformation("结果扫描结束"); + this.logger.LogInformation($"结果扫描结束,共扫描{contexts.Length}条记录"); } } } diff --git a/FastGithub.Scanner/Meta.cs b/FastGithub.Scanner/Meta.cs index 94ceed1..10ee457 100644 --- a/FastGithub.Scanner/Meta.cs +++ b/FastGithub.Scanner/Meta.cs @@ -47,18 +47,7 @@ namespace FastGithub.Scanner 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); - } - } - } + } } } } diff --git a/FastGithub.Scanner/Middlewares/ConcurrentMiddleware.cs b/FastGithub.Scanner/Middlewares/ConcurrentMiddleware.cs index 053fcb8..1271f51 100644 --- a/FastGithub.Scanner/Middlewares/ConcurrentMiddleware.cs +++ b/FastGithub.Scanner/Middlewares/ConcurrentMiddleware.cs @@ -12,8 +12,8 @@ namespace FastGithub.Scanner.Middlewares public ConcurrentMiddleware() { - var initialCount = Environment.ProcessorCount; - this.semaphoreSlim = new SemaphoreSlim(initialCount, initialCount * 4); + var currentCount = Environment.ProcessorCount * 4; + this.semaphoreSlim = new SemaphoreSlim(currentCount, currentCount); } public async Task InvokeAsync(GithubContext context, Func next) diff --git a/FastGithub.Scanner/Middlewares/HttpsScanMiddleware.cs b/FastGithub.Scanner/Middlewares/HttpsScanMiddleware.cs index 6ceb89a..2ed1a78 100644 --- a/FastGithub.Scanner/Middlewares/HttpsScanMiddleware.cs +++ b/FastGithub.Scanner/Middlewares/HttpsScanMiddleware.cs @@ -57,8 +57,18 @@ namespace FastGithub.Scanner.Middlewares } 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; + } } }