32 lines
792 B
C#
32 lines
792 B
C#
using System.Net;
|
|
using DNS.Client.RequestResolver;
|
|
using DNS.Protocol;
|
|
using DNS.Protocol.ResourceRecords;
|
|
|
|
|
|
public class RequestResolver : IRequestResolver {
|
|
public RequestResolver(LiteDB.ILiteCollection<DNSEntry> db)
|
|
{
|
|
_db=db;
|
|
}
|
|
LiteDB.ILiteCollection<DNSEntry> _db;
|
|
|
|
public Task<IResponse> Resolve(IRequest request,CancellationToken token) {
|
|
IResponse response = Response.FromRequest(request);
|
|
|
|
|
|
foreach (Question question in response.Questions) {
|
|
var res= DNSEntry.GetDNSEntry(_db.FindAll(),question);
|
|
if(res != null)
|
|
{
|
|
response.AnswerRecords.Add(res);
|
|
}
|
|
}
|
|
|
|
|
|
return Task.FromResult(response);
|
|
}
|
|
}
|
|
|
|
// All dns requests received will be handled by the localhost request resolver
|