#endif
return ResolvProtoResponse(RP_RES_NOTFOUND);
}
- cache_t::const_iterator i = cache.find(n);
- // TODO TTL!?!
+ cache_t::iterator i = cache.find(n);
if (i != cache.end())
{
+ const CacheRecord& cr = i->second;
#ifdef DEBUG_RESOLV
std::cerr << "NameServer::resolv_direct -> found (en cache): "
- << i->second << "\n";
+ << cr << "\n";
#endif
- const CacheRecord& cr = i->second;
- return ResolvProtoResponse(RP_RES_A, cr.ttl, cr.ips);
+ if (unsigned(time(NULL)) > cr.expire) // Expiró
+ {
+ cache.erase(i);
+#ifdef DEBUG_RESOLV
+ std::cerr << " -> pero no sirve, expiró "
+ "hace unos " << (time(NULL) - cr.expire) << " segundos\n";
+#endif
+ }
+ else
+ {
+ return ResolvProtoResponse(RP_RES_A, cr.ttl, cr.ips);
+ }
}
if (zones.size())
{
#endif
while (true)
{
+#ifdef DEBUG_RESOLV
+ std::cout << "----------------------------------------------------\n";
+#endif
Dev::mac_type mac = 0;
ResolvProtoRequest req(req_que.receive(mac));
#ifdef DEBUG_RESOLV
std::ostream& operator<< (std::ostream& os, const NameServer::CacheRecord& cr)
{
- os << "CacheRecord(ttl=" << cr.ttl << ", records=";
+ os << "CacheRecord(expire=" << cr.expire << " [now=" << time(NULL)
+ << "], ttl=" << cr.ttl << ", records=";
std::copy(cr.ips.begin(), cr.ips.end(),
std::ostream_iterator< IPAddr >(os, ","));
return os << ")";