recursor.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // Copyright (C) 2009 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. // $Id$
  15. #ifndef __RECURSOR_H
  16. #define __RECURSOR_H 1
  17. #include <string>
  18. #include <vector>
  19. #include <utility>
  20. #include <cc/data.h>
  21. #include <config/ccsession.h>
  22. #include <asiolink/asiolink.h>
  23. class RecursorImpl;
  24. class Recursor {
  25. ///
  26. /// \name Constructors, Assignment Operator and Destructor.
  27. ///
  28. /// Note: The copy constructor and the assignment operator are
  29. /// intentionally defined as private.
  30. //@{
  31. private:
  32. Recursor(const Recursor& source);
  33. Recursor& operator=(const Recursor& source);
  34. public:
  35. /// The constructor.
  36. Recursor();
  37. ~Recursor();
  38. //@}
  39. /// \brief Process an incoming DNS message, then signal 'server' to resume
  40. ///
  41. /// A DNS query (or other message) has been received by a \c DNSServer
  42. /// object. Find an answer, then post the \c DNSServer object on the
  43. /// I/O service queue and return. When the server resumes, it can
  44. /// send the reply.
  45. ///
  46. /// \param io_message The I/O service queue
  47. /// \param message Pointer to the \c Message object
  48. /// \param buffer Pointer to an \c OutputBuffer for the resposne
  49. /// \param server Pointer to the \c DNSServer
  50. void processMessage(const asiolink::IOMessage& io_message,
  51. isc::dns::MessagePtr message,
  52. isc::dns::OutputBufferPtr buffer,
  53. asiolink::DNSServer* server);
  54. /// \brief Set verbose flag
  55. ///
  56. /// \param on The new value of the verbose flag
  57. void setVerbose(bool on);
  58. /// \brief Get the current value of the verbose flag
  59. bool getVerbose() const;
  60. /// \brief Set and get the config session
  61. isc::config::ModuleCCSession* getConfigSession() const;
  62. void setConfigSession(isc::config::ModuleCCSession* config_session);
  63. /// \brief Handle commands from the config session
  64. isc::data::ConstElementPtr updateConfig(isc::data::ConstElementPtr config);
  65. /// \brief Assign an ASIO IO Service queue to this Recursor object
  66. void setIOService(asiolink::IOService& ios);
  67. /// \brief Return this object's ASIO IO Service queue
  68. asiolink::IOService& getIOService() const { return (*io_); }
  69. /// \brief Return pointer to the DNS Lookup callback function
  70. asiolink::DNSLookup* getDNSLookupProvider() { return (dns_lookup_); }
  71. /// \brief Return pointer to the DNS Answer callback function
  72. asiolink::DNSAnswer* getDNSAnswerProvider() { return (dns_answer_); }
  73. /// \brief Return pointer to the Checkin callback function
  74. asiolink::SimpleCallback* getCheckinProvider() { return (checkin_); }
  75. /**
  76. * \brief Specify the list of upstream servers.
  77. *
  78. * Specify the list off addresses of upstream servers to forward queries
  79. * to. If the list is empty, this server is set to full recursive mode.
  80. * If it is non-empty, it switches to forwarder.
  81. *
  82. * @param addresses The list of addresses to use (each one is the address
  83. * and port pair).
  84. */
  85. void setForwardAddresses(const std::vector<std::pair<std::string,
  86. uint16_t> >& addresses);
  87. /**
  88. * \short Get list of upstream addresses.
  89. *
  90. * \see setForwardAddresses.
  91. */
  92. std::vector<std::pair<std::string, uint16_t> > getForwardAddresses() const;
  93. /// Return if we are in forwarding mode (if not, we are in fully recursive)
  94. bool isForwarding() const;
  95. private:
  96. RecursorImpl* impl_;
  97. asiolink::IOService* io_;
  98. asiolink::SimpleCallback* checkin_;
  99. asiolink::DNSLookup* dns_lookup_;
  100. asiolink::DNSAnswer* dns_answer_;
  101. };
  102. #endif // __RECURSOR_H
  103. // Local Variables:
  104. // mode: c++
  105. // End: