+ if (i->parent != IPAddr(0))
+ {
+#ifdef DEBUG_RESOLV
+ std::cerr << "resolv_direct found (al padre): "
+ << i->parent << "\n";
+#endif
+ ResolvProtoResponse rpr(ResolvProtoResponse::R_NS, i->ttl);
+ rpr.ips.push_back(i->parent);
+ return rpr;
+ }
+ }
+ }
+#ifdef DEBUG_RESOLV
+ std::cerr << "resolv_direct NOT FOUND (no hay padre)\n";
+#endif
+ // No hay padre, no puedo hacer nada más
+ return ResolvProtoResponse(ResolvProtoResponse::R_NOTFOUND);
+}
+
+/// Resuelve un nombre de forma recursiva
+ResolvProtoResponse NameServer::resolv_recursive(const Name& n)
+{
+ ResolvProtoResponse rpr = resolv_direct(n);
+ switch (rpr.ret)
+ {
+ case ResolvProtoResponse::R_NS:
+#ifdef DEBUG_RESOLV
+ std::cerr << "resolv_recursive -> redirect a " << rpr << "\n";
+#endif
+ return resolv_recursive_r(n, rpr); // Sigo "bajando"
+ case ResolvProtoResponse::R_A:
+#ifdef DEBUG_RESOLV
+ std::cerr << "resolv_recursive -> gotcha! " << rpr << "\n";
+#endif
+ // TODO agregar a cache
+ break;
+ }
+ return rpr; // Devuelvo el A o NOTFOUND
+}
+
+/// Resuelve un nombre de forma recursiva entrando a otros ns
+ResolvProtoResponse NameServer::resolv_recursive_r(const Name& n,
+ ResolvProtoResponse rpr)
+{
+ ResolvProtoResponse r;
+ for (ResolvProtoResponse::ipvec_t::const_iterator ip = rpr.ips.begin();
+ ip != rpr.ips.end(); ++ip)
+ {
+ r = query(n, *ip);
+ switch (r.ret)
+ {
+ case ResolvProtoResponse::R_NS:
+#ifdef DEBUG_RESOLV
+ std::cerr << "resolv_recursive_r -> redirect a " << r << "\n";
+#endif
+ return resolv_recursive_r(n, r); // Sigo "bajando"
+ case ResolvProtoResponse::R_NOTFOUND:
+#ifdef DEBUG_RESOLV
+ std::cerr << "resolv_recursive_r -> NOT FOUND en " << *ip
+ << ", sigo probando\n";
+#endif
+ break; // Sigo probando del mismo nivel
+ case ResolvProtoResponse::R_A:
+#ifdef DEBUG_RESOLV
+ std::cerr << "resolv_recursive_r -> gotcha! " << r << "\n";
+#endif
+ // TODO agregar a cache
+ return r; // Gotcha!
+ }