-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e15049
commit b01a740
Showing
10 changed files
with
64 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using Ae.Dns.Protocol; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Ae.Dns.Client | ||
{ | ||
/// <summary> | ||
/// A client consisting of multiple <see cref="IDnsClient"/> instances which are picked at random. | ||
/// </summary> | ||
public sealed class DnsRandomClient : IDnsClient | ||
{ | ||
private readonly IReadOnlyCollection<IDnsClient> _dnsClients; | ||
|
||
/// <summary> | ||
/// Create a new random DNS client selector using the specified <see cref="IDnsClient"/> instances to delegate to. | ||
/// </summary> | ||
/// <param name="dnsClients">The enumerable of DNS clients to use.</param> | ||
public DnsRandomClient(IEnumerable<IDnsClient> dnsClients) => _dnsClients = dnsClients.ToList(); | ||
|
||
/// <summary> | ||
/// Create a new random DNS client selector using the specified <see cref="IDnsClient"/> instances to delegate to. | ||
/// </summary> | ||
/// <param name="dnsClients">The array of DNS clients to use.</param> | ||
public DnsRandomClient(params IDnsClient[] dnsClients) => _dnsClients = dnsClients; | ||
|
||
private IDnsClient GetRandomClient() => _dnsClients.OrderBy(x => Guid.NewGuid()).First(); | ||
|
||
/// <inheritdoc/> | ||
public Task<DnsMessage> Query(DnsMessage query, CancellationToken token) => GetRandomClient().Query(query, token); | ||
|
||
/// <inheritdoc/> | ||
public void Dispose() | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters