protected override bool Receive(object message)
{
var resolve = message as Dns.Resolve;
if (resolve != null)
{
var answer = _cache.Cached(resolve.Name);
if (answer == null)
{
try
{
//TODO: IP6
answer = Dns.Resolved.Create(resolve.Name, System.Net.Dns.GetHostEntry(resolve.Name).AddressList.Where(x => x.AddressFamily == AddressFamily.InterNetwork));
_cache.Put(answer, _positiveTtl);
}
catch (SocketException ex)
{
if (ex.SocketErrorCode != SocketError.HostNotFound) throw;
answer = new Dns.Resolved(resolve.Name, Enumerable.Empty<IPAddress>(), Enumerable.Empty<IPAddress>());
_cache.Put(answer, _negativeTtl);
}
}
Sender.Tell(answer);
return true;
}
return false;
}
}