From 7d8251a896fb605deaea8b0138d5a20c699803f6 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Mon, 3 Jul 2006 23:21:57 +0000 Subject: [PATCH] Bugfix en mensajes de debug (y emprolijamiento). --- practicas/pipi/src/Makefile | 2 +- practicas/pipi/src/nameserver.cpp | 59 ++++++++++++++++++------------- 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/practicas/pipi/src/Makefile b/practicas/pipi/src/Makefile index 8ae2d04..c543be5 100644 --- a/practicas/pipi/src/Makefile +++ b/practicas/pipi/src/Makefile @@ -24,7 +24,7 @@ ifdef debug #CFLAGS += -DDEBUG_QUE #CFLAGS += -DDEBUG_NAME #CFLAGS += -DDEBUG_ROUTE -#CFLAGS += -DDEBUG_TRACE +CFLAGS += -DDEBUG_TRACE CFLAGS += -DDEBUG_RESOLV #CFLAGS += -DDEBUG_LIBTCP endif diff --git a/practicas/pipi/src/nameserver.cpp b/practicas/pipi/src/nameserver.cpp index f04b4ab..23a2e23 100644 --- a/practicas/pipi/src/nameserver.cpp +++ b/practicas/pipi/src/nameserver.cpp @@ -46,7 +46,7 @@ static std::istream& parsezone(std::istream& is, NameServer::Zone& z) throw std::runtime_error("Error al parsear"); z.name = sname; #ifdef DEBUG_PARSER - std::cerr << "parsezone: IP = " << ip << "\n\n"; + std::cerr << "NameServer::parsezone: IP = " << ip << "\n\n"; #endif z.parent = IPAddr(ip); // un record por linea, sin líneas vacías @@ -60,13 +60,13 @@ static std::istream& parsezone(std::istream& is, NameServer::Zone& z) throw std::runtime_error("Error al parsear"); typedef NameServer::Record Rec; #ifdef DEBUG_PARSER - std::cerr << "parsezone: IP = " << ip << "\n\n"; + std::cerr << "NameServer::parsezone: IP = " << ip << "\n\n"; #endif Rec r((type == "NS") ? Rec::NS : Rec::A, IPAddr(ip)); z.records.insert(NameServer::Zone::records_t::value_type(key, r)); } #ifdef DEBUG_PARSER - std::cerr << "parsezone: " << z << "\n\n"; + std::cerr << "NameServer::parsezone: " << z << "\n\n"; #endif return is; } @@ -106,12 +106,12 @@ NameServer::NameServer(std::istream& is, IPIn& ipin, IPOut& ipout, zones.push_back(z); z.clear(); #ifdef DEBUG_PARSER - std::cerr << "NameServer: " << z << "\n\n"; + std::cerr << "NameServer::NameServer: " << z << "\n\n"; #endif } #ifdef DEBUG_RESOLV - std::cout << "NameServer: req_que_id = " << req_que.que_id + std::cout << "NameServer::NameServer: req_que_id = " << req_que.que_id << ", res_que_id = " << res_que.que_id << ", snd_que_id = " << snd_que.que_id << "\n"; #endif @@ -142,7 +142,8 @@ name_split(NameServer::Name n, NameServer::Name m) r.push_back(n[i++]); std::reverse(r.begin(), r.end()); #ifdef DEBUG_NAME - std::cerr << "name_split(" << n << ", " << m << ") -> " << r << "\n"; + std::cerr << "NameServer::name_split(" << n << ", " << m << ") -> " + << r << "\n"; #endif return r; } @@ -225,7 +226,8 @@ ResolvProtoResponse NameServer::resolv_direct(const Name& n) std::cout << "NameServer::resolv_direct()\n"; #endif #ifdef DEBUG_RESOLV - std::cerr << "resolv_direct -> tratando de resolver: " << n << "\n"; + std::cerr << "NameServer::resolv_direct -> tratando de resolver: " + << n << "\n"; #endif search_zone zs(n); bool found; @@ -235,14 +237,16 @@ ResolvProtoResponse NameServer::resolv_direct(const Name& n) if (found) { #ifdef DEBUG_RESOLV - std::cerr << "resolv_direct found (local/hijo): " << zs.resp << "\n"; + std::cerr << "NameServer::resolv_direct -> found (local/hijo): " + << zs.resp << "\n"; #endif return zs.resp; } if (zs.local) { #ifdef DEBUG_RESOLV - std::cerr << "resolv_direct NOT FOUND (es local pero no existe)\n"; + std::cerr << "NameServer::resolv_direct -> NOT FOUND (es local pero " + "no existe)\n"; #endif return ResolvProtoResponse(RP_RES_NOTFOUND); } @@ -251,7 +255,8 @@ ResolvProtoResponse NameServer::resolv_direct(const Name& n) if (i != cache.end()) { #ifdef DEBUG_RESOLV - std::cerr << "resolv_direct found (en cache): " << i->second << "\n"; + std::cerr << "NameServer::resolv_direct -> found (en cache): " + << i->second << "\n"; #endif const CacheRecord& cr = i->second; return ResolvProtoResponse(RP_RES_A, cr.ttl, cr.ips); @@ -262,13 +267,13 @@ ResolvProtoResponse NameServer::resolv_direct(const Name& n) for (zones_t::const_iterator i = zones.begin(); i != zones.end(); ++i) { #ifdef DEBUG_RESOLV - std::cerr << "resolv_direct -> evaluando padre " << i->parent - << "\n"; + std::cerr << "NameServer::resolv_direct -> evaluando padre " + << i->parent << "\n"; #endif if (i->parent != IPAddr(0)) { #ifdef DEBUG_RESOLV - std::cerr << "resolv_direct found (al padre): " + std::cerr << "NameServer::resolv_direct -> found (al padre): " << i->parent << "\n"; #endif ResolvProtoResponse rpr(RP_RES_NS, i->ttl); @@ -278,7 +283,7 @@ ResolvProtoResponse NameServer::resolv_direct(const Name& n) } } #ifdef DEBUG_RESOLV - std::cerr << "resolv_direct NOT FOUND (no hay padre)\n"; + std::cerr << "NameServer::resolv_direct -> NOT FOUND (no hay padre)\n"; #endif // No hay padre, no puedo hacer nada más return ResolvProtoResponse(RP_RES_NOTFOUND); @@ -295,12 +300,14 @@ ResolvProtoResponse NameServer::resolv_recursive(const Name& n) { case RP_RES_NS: #ifdef DEBUG_RESOLV - std::cerr << "resolv_recursive -> redirect a " << rpr << "\n"; + std::cerr << "NameServer::resolv_recursive -> redirect a " + << rpr << "\n"; #endif return resolv_recursive_r(n, rpr); // Sigo "bajando" case RP_RES_A: #ifdef DEBUG_RESOLV - std::cerr << "resolv_recursive -> gotcha! " << rpr << "\n"; + std::cerr << "NameServer::resolv_recursive -> gotcha! " + << rpr << "\n"; #endif // TODO agregar a cache break; @@ -324,25 +331,28 @@ ResolvProtoResponse NameServer::resolv_recursive_r(const Name& n, { case RP_RES_NS: #ifdef DEBUG_RESOLV - std::cerr << "resolv_recursive_r -> redirect a " << r << "\n"; + std::cerr << "NameServer::resolv_recursive_r -> redirect a " + << r << "\n"; #endif return resolv_recursive_r(n, r); // Sigo "bajando" case RP_RES_NOTFOUND: #ifdef DEBUG_RESOLV - std::cerr << "resolv_recursive_r -> NOT FOUND en " << *ip - << ", sigo probando\n"; + std::cerr << "NameServer::resolv_recursive_r -> NOT FOUND en " + << *ip << ", sigo probando\n"; #endif break; // Sigo probando del mismo nivel case RP_RES_A: #ifdef DEBUG_RESOLV - std::cerr << "resolv_recursive_r -> gotcha! " << r << "\n"; + std::cerr << "NameServer::resolv_recursive_r -> gotcha! " + << r << "\n"; #endif // TODO agregar a cache return r; // Gotcha! } } #ifdef DEBUG_RESOLV - std::cerr << "resolv_recursive_r -> NOT FOUND, no hay más por hacer\n"; + std::cerr << "NameServer::resolv_recursive_r -> NOT FOUND, no hay más " + "por hacer\n"; #endif return r; // NOTFOUND } @@ -355,7 +365,7 @@ ResolvProtoResponse NameServer::query(const Name& n, const IPAddr& ip) #endif ResolvProtoRequest r(std::string(n), RP_REQ_DIRECT); #ifdef DEBUG_RESOLV - std::cerr << "query -> pidiendo " << r << " a " << ip << "\n"; + std::cerr << "NameServer::query -> pidiendo " << r << " a " << ip << "\n"; #endif // Envía a través de la cola de envío snd_que.transmit(std::string(r), ip); @@ -363,7 +373,8 @@ ResolvProtoResponse NameServer::query(const Name& n, const IPAddr& ip) std::string buf = res_que.receive(mac); ResolvProtoResponse resp(buf); #ifdef DEBUG_RESOLV - std::cerr << "query -> recibido " << resp << " de " << ip << "\n"; + std::cerr << "NameServer::query -> recibido " << resp << " de " + << ip << "\n"; #endif return resp; } @@ -419,7 +430,7 @@ void NameServer::send_loop() std::string buf = snd_que.receive(mac); #ifdef DEBUG_RESOLV std::cout << "NameServer::send_loop() -> envío request " - << ResolvProtoRequest(buf) << "\n"; + << ResolvProtoResponse(buf) << "\n"; #endif ipout.send(buf, RESOLV_PROTO, IPAddr(mac)); } -- 2.43.0