private static async Task DoResolveAsync(IDnsResolverStrategy dnsResolverStrategy, DnsQuestion dnsQuestion, IWriteDnsContext dnsWriteContext, CancellationToken cancellationToken) { var answer = await dnsResolverStrategy .ResolveAsync(dnsQuestion, cancellationToken) .ConfigureAwait(false); var response = (DnsMessage)dnsWriteContext.Response; response.AnswerRecords.AddRange(answer.Cast <DnsRecordBase>()); }
private static async Task DoStrategyAsync(IDnsResolverStrategy dnsResolverStrategy, DnsQuestion dnsQuestion, IWriteDnsContext dnsWriteContext, CancellationToken joinedGlobalCtx) { if (!dnsWriteContext.Response.AnswerRecords.Any() && dnsResolverStrategy != null) { try { if (!dnsResolverStrategy.NeedsQueryTimeout) { await DoResolveAsync(dnsResolverStrategy, dnsQuestion, dnsWriteContext, joinedGlobalCtx).ConfigureAwait(false); } else { using (var strategyQueryTimeoutCts = new CancellationTokenSource(dnsResolverStrategy.Rule.QueryTimeout * 2)) using (var joinedStrategyCts = CancellationTokenSource.CreateLinkedTokenSource(strategyQueryTimeoutCts.Token, joinedGlobalCtx)) { await DoResolveAsync(dnsResolverStrategy, dnsQuestion, dnsWriteContext, joinedStrategyCts.Token).ConfigureAwait(false); } } } catch (ArgumentOutOfRangeException aoore) { dnsWriteContext.Logger.LogWarning(aoore, "A mapping is not supported [{0}] for that dns question! >> [{1}]", aoore.ActualValue, aoore.Message); } catch (Exception e) { dnsWriteContext.Logger.LogError(e, "A strategy error for the dns question {0} with the error message >> [{1}]", dnsQuestion?.Name?.ToString(), e.Message); } } else { dnsWriteContext.Logger.LogInformation("Query is found! {0}", dnsResolverStrategy?.GetType()?.ToString()); } }