X-Git-Url: https://git.llucax.com/z.facultad/75.74/practicos.git/blobdiff_plain/c1b28b595a388df043997c87faf75c06959405d0..c26a92b22080c9c6cbec81ad6b49f2899864e5aa:/practicas/pipi/src/nameserver.h?ds=inline diff --git a/practicas/pipi/src/nameserver.h b/practicas/pipi/src/nameserver.h index 686fb52..dbaecf7 100644 --- a/practicas/pipi/src/nameserver.h +++ b/practicas/pipi/src/nameserver.h @@ -2,7 +2,7 @@ #define _NAMESERVER_H_ #include "ipaddr.h" -//XXX#include "resolvproto.h" +#include "resolvproto.h" #include #include #include @@ -15,7 +15,13 @@ struct NameServer { /// Nombre de un dominio dividido en tokens - typedef std::vector< std::string > name_t; + struct Name: std::vector< std::string > + { + /// Constructor + Name() {} + Name(const std::string& name); + operator std::string (); + }; /// Registro de una zona struct Record @@ -33,7 +39,7 @@ struct NameServer struct Zone { /// Nombre - name_t name; + Name name; /// Time to live size_t ttl; /// Nodo padre @@ -49,21 +55,53 @@ struct NameServer void clear(); }; - //TODO cache de _records_ (no zonas) - /// Zonas para las que este servidor de nombres es autoridad typedef std::vector< Zone > zones_t; zones_t zones; + /// Cache de un registro + struct CacheRecord + { + /// Time to live + size_t ttl; + /// Dirección IP del registro + typedef ResolvProtoResponse::ipvec_t ipvec_t; + ipvec_t ips; + /// Constructor + CacheRecord(): ttl(0) {} + CacheRecord(size_t ttl, const ipvec_t& ips): + ttl(ttl), ips(ips) {} + }; + + /// Cache de records + typedef std::map< Name, CacheRecord > cache_t; + cache_t cache; + /// Constructor NameServer(std::istream& is) throw (std::runtime_error); + /// Resuelve un nombre de forma directa (no recursiva) + ResolvProtoResponse resolv_direct(const Name& n); + + /// Resuelve un nombre de forma recursiva + ResolvProtoResponse resolv_recursive(const Name& n); + + /// Consulta a otro name server sobre un nombre + ResolvProtoResponse query(const Name&n, const IPAddr& ip); + + private: + /// Resuelve un nombre de forma recursiva entrando a otros ns + ResolvProtoResponse resolv_recursive_r(const Name& n, + ResolvProtoResponse rpr); + }; /// Impresión (para debug) std::ostream& operator<< (std::ostream& os, const NameServer& ns); +std::ostream& operator<< (std::ostream& os, const NameServer::Name& name); std::ostream& operator<< (std::ostream& os, const NameServer::Record& r); std::ostream& operator<< (std::ostream& os, const NameServer::Zone& z); +std::ostream& operator<< (std::ostream& os, const NameServer::CacheRecord& cr); #endif // _NAMESERVER_H_