tdns/Tesses.Dns/Server.cs

32 lines
792 B
C#
Raw Normal View History

2022-07-24 20:09:33 +00:00
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