]> git.llucax.com Git - z.facultad/75.74/practicos.git/blobdiff - practicas/pipi/src/nameserver.cpp
Bugfix al mostrar request/response para debug en send_loop().
[z.facultad/75.74/practicos.git] / practicas / pipi / src / nameserver.cpp
index 23a2e237c938c35f1af773956a532c536c985801..b7346b7e28d7332331d01ecaa3febd5e90ec0d87 100644 (file)
@@ -309,7 +309,6 @@ ResolvProtoResponse NameServer::resolv_recursive(const Name& n)
             std::cerr << "NameServer::resolv_recursive -> gotcha! "
                 << rpr << "\n";
 #endif
             std::cerr << "NameServer::resolv_recursive -> gotcha! "
                 << rpr << "\n";
 #endif
-            // TODO agregar a cache
             break;
     }
     return rpr; // Devuelvo el A o NOTFOUND
             break;
     }
     return rpr; // Devuelvo el A o NOTFOUND
@@ -346,7 +345,6 @@ ResolvProtoResponse NameServer::resolv_recursive_r(const Name& n,
                 std::cerr << "NameServer::resolv_recursive_r -> gotcha! "
                     << r << "\n";
 #endif
                 std::cerr << "NameServer::resolv_recursive_r -> gotcha! "
                     << r << "\n";
 #endif
-                // TODO agregar a cache
                 return r; // Gotcha!
         }
     }
                 return r; // Gotcha!
         }
     }
@@ -376,6 +374,9 @@ ResolvProtoResponse NameServer::query(const Name& n, const IPAddr& ip)
     std::cerr << "NameServer::query -> recibido " << resp << " de "
         << ip << "\n";
 #endif
     std::cerr << "NameServer::query -> recibido " << resp << " de "
         << ip << "\n";
 #endif
+    // Agrego a cache
+    if (resp.ret == RP_RES_A)
+        cache[n] = CacheRecord(time(NULL) + resp.ttl, resp.ips);
     return resp;
 }
 
     return resp;
 }
 
@@ -429,8 +430,13 @@ void NameServer::send_loop()
         Dev::mac_type mac = 0;
         std::string buf = snd_que.receive(mac);
 #ifdef DEBUG_RESOLV
         Dev::mac_type mac = 0;
         std::string buf = snd_que.receive(mac);
 #ifdef DEBUG_RESOLV
-        std::cout << "NameServer::send_loop() -> envío request "
-            << ResolvProtoResponse(buf) << "\n";
+        uint8_t type;
+        memcpy(&type, s.data(), sizeof(uint8_t));
+        std::cout << "NameServer::send_loop() -> envío "
+        if (type == RP_REQ_DIRECT || type == RP_REQ_RECURSIVE)
+            std::cout << "request " << ResolvProtoRequest(buf) << "\n";
+        else
+            std::cout << "response " << ResolvProtoResponse(buf) << "\n";
 #endif
         ipout.send(buf, RESOLV_PROTO, IPAddr(mac));
     }
 #endif
         ipout.send(buf, RESOLV_PROTO, IPAddr(mac));
     }