]> git.llucax.com Git - z.facultad/75.74/practicos.git/commitdiff
Se verifica si expiró el cache y se lo elimina si así fuere.
authorLeandro Lucarella <llucax@gmail.com>
Tue, 4 Jul 2006 15:00:54 +0000 (15:00 +0000)
committerLeandro Lucarella <llucax@gmail.com>
Tue, 4 Jul 2006 15:00:54 +0000 (15:00 +0000)
practicas/pipi/src/Makefile
practicas/pipi/src/nameserver.cpp

index c543be5cbdd40c9f17c26ce6f7b00a09f9fa1171..8ae2d0488a010acffafefe4e9027bcf676b67ecb 100644 (file)
@@ -24,7 +24,7 @@ ifdef debug
 #CFLAGS += -DDEBUG_QUE
 #CFLAGS += -DDEBUG_NAME
 #CFLAGS += -DDEBUG_ROUTE
 #CFLAGS += -DDEBUG_QUE
 #CFLAGS += -DDEBUG_NAME
 #CFLAGS += -DDEBUG_ROUTE
-CFLAGS += -DDEBUG_TRACE
+#CFLAGS += -DDEBUG_TRACE
 CFLAGS += -DDEBUG_RESOLV
 #CFLAGS += -DDEBUG_LIBTCP
 endif
 CFLAGS += -DDEBUG_RESOLV
 #CFLAGS += -DDEBUG_LIBTCP
 endif
index 886a2fc4cae3433e205b758b9333a728a8d004a7..959286a3ee6dde5a029828c55334f7d80158dd56 100644 (file)
@@ -250,16 +250,26 @@ ResolvProtoResponse NameServer::resolv_direct(const Name& n)
 #endif
         return ResolvProtoResponse(RP_RES_NOTFOUND);
     }
 #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())
     {
     if (i != cache.end())
     {
+        const CacheRecord& cr = i->second;
 #ifdef DEBUG_RESOLV
         std::cerr << "NameServer::resolv_direct -> found (en cache): "
 #ifdef DEBUG_RESOLV
         std::cerr << "NameServer::resolv_direct -> found (en cache): "
-            << i->second << "\n";
+            << cr << "\n";
 #endif
 #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())
     {
     }
     if (zones.size())
     {
@@ -449,6 +459,9 @@ void NameServer::req_loop()
 #endif
     while (true)
     {
 #endif
     while (true)
     {
+#ifdef DEBUG_RESOLV
+        std::cout << "----------------------------------------------------\n";
+#endif
         Dev::mac_type mac = 0;
         ResolvProtoRequest req(req_que.receive(mac));
 #ifdef DEBUG_RESOLV
         Dev::mac_type mac = 0;
         ResolvProtoRequest req(req_que.receive(mac));
 #ifdef DEBUG_RESOLV
@@ -494,7 +507,8 @@ std::ostream& operator<< (std::ostream& os, const NameServer::Zone& z)
 
 std::ostream& operator<< (std::ostream& os, const NameServer::CacheRecord& cr)
 {
 
 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 << ")";
     std::copy(cr.ips.begin(), cr.ips.end(),
             std::ostream_iterator< IPAddr >(os, ","));
     return os << ")";