Commit 45abf5a0 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

merged trac #301


git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@3132 e5f2f494-b856-4b98-b285-d166d9295462
parents 18cd6dd2 e2b2f49b
......@@ -64,24 +64,50 @@ IOAddress::toText() const {
return (asio_address_.to_string());
}
// Note: this implementation is optimized for the case where this object
// is created from an ASIO endpoint object in a receiving code path
// by avoiding to make a copy of the base endpoint. For TCP it may not be
// a big deal, but when we receive UDP packets at a high rate, the copy
// overhead might be significant.
/// \brief The \c TCPEndpoint class is a concrete derived class of
/// \c IOEndpoint that represents an endpoint of a TCP connection.
///
/// In the current implementation, an object of this class is always
/// instantiated within the wrapper routines. Applications are expected to
/// get access to the object via the abstract base class, \c IOEndpoint.
/// This design may be changed when we generalize the wrapper interface.
///
/// Note: this implementation is optimized for the case where this object
/// is created from an ASIO endpoint object in a receiving code path
/// by avoiding to make a copy of the base endpoint. For TCP it may not be
/// a big deal, but when we receive UDP packets at a high rate, the copy
/// overhead might be significant.
class TCPEndpoint : public IOEndpoint {
public:
///
/// \name Constructors and Destructor
///
//@{
/// \brief Constructor from a pair of address and port.
///
/// \param address The IP address of the endpoint.
/// \param port The TCP port number of the endpoint.
TCPEndpoint(const IOAddress& address, const unsigned short port) :
asio_endpoint_placeholder_(
new tcp::endpoint(ip::address::from_string(address.toText()),
port)),
asio_endpoint_(*asio_endpoint_placeholder_)
{}
/// \brief Constructor from an ASIO TCP endpoint.
///
/// This constructor is designed to be an efficient wrapper for the
/// corresponding ASIO class, \c tcp::endpoint.
///
/// \param asio_endpoint The ASIO representation of the TCP endpoint.
TCPEndpoint(const tcp::endpoint& asio_endpoint) :
asio_endpoint_placeholder_(NULL), asio_endpoint_(asio_endpoint)
{}
/// \brief The destructor.
~TCPEndpoint() { delete asio_endpoint_placeholder_; }
//@}
virtual IOAddress getAddress() const {
return (asio_endpoint_.address());
}
......@@ -90,18 +116,41 @@ private:
const tcp::endpoint& asio_endpoint_;
};
/// \brief The \c UDPEndpoint class is a concrete derived class of
/// \c IOEndpoint that represents an endpoint of a UDP packet.
///
/// Other notes about \c TCPEndpoint applies to this class, too.
class UDPEndpoint : public IOEndpoint {
public:
///
/// \name Constructors and Destructor.
///
//@{
/// \brief Constructor from a pair of address and port.
///
/// \param address The IP address of the endpoint.
/// \param port The UDP port number of the endpoint.
UDPEndpoint(const IOAddress& address, const unsigned short port) :
asio_endpoint_placeholder_(
new udp::endpoint(ip::address::from_string(address.toText()),
port)),
asio_endpoint_(*asio_endpoint_placeholder_)
{}
/// \brief Constructor from an ASIO UDP endpoint.
///
/// This constructor is designed to be an efficient wrapper for the
/// corresponding ASIO class, \c udp::endpoint.
///
/// \param asio_endpoint The ASIO representation of the UDP endpoint.
UDPEndpoint(const udp::endpoint& asio_endpoint) :
asio_endpoint_placeholder_(NULL), asio_endpoint_(asio_endpoint)
{}
/// \brief The destructor.
~UDPEndpoint() { delete asio_endpoint_placeholder_; }
//@}
virtual IOAddress getAddress() const {
return (asio_endpoint_.address());
}
......@@ -124,37 +173,74 @@ IOEndpoint::create(const int protocol, const IOAddress& address,
protocol);
}
/// \brief The \c TCPSocket class is a concrete derived class of
/// \c IOSocket that represents a TCP socket.
///
/// In the current implementation, an object of this class is always
/// instantiated within the wrapper routines. Applications are expected to
/// get access to the object via the abstract base class, \c IOSocket.
/// This design may be changed when we generalize the wrapper interface.
class TCPSocket : public IOSocket {
private:
TCPSocket(const TCPSocket& source);
TCPSocket& operator=(const TCPSocket& source);
public:
/// \brief Constructor from an ASIO TCP socket.
///
/// \param socket The ASIO representation of the TCP socket.
TCPSocket(tcp::socket& socket) : socket_(socket) {}
virtual int getNative() const { return (socket_.native()); }
virtual int getProtocol() const { return (IPPROTO_TCP); }
private:
tcp::socket& socket_;
};
/// \brief The \c UDPSocket class is a concrete derived class of
/// \c IOSocket that represents a UDP socket.
///
/// Other notes about \c TCPSocket applies to this class, too.
class UDPSocket : public IOSocket {
private:
UDPSocket(const UDPSocket& source);
UDPSocket& operator=(const UDPSocket& source);
public:
/// \brief Constructor from an ASIO UDP socket.
///
/// \param socket The ASIO representation of the UDP socket.
UDPSocket(udp::socket& socket) : socket_(socket) {}
virtual int getNative() const { return (socket_.native()); }
virtual int getProtocol() const { return (IPPROTO_UDP); }
private:
udp::socket& socket_;
};
/// \brief The \c DummySocket class is a concrete derived class of
/// \c IOSocket that is not associated with any real socket.
///
/// This main purpose of this class is tests, where it may be desirable to
/// instantiate an \c IOSocket object without involving system resource
/// allocation such as real network sockets.
class DummySocket : public IOSocket {
private:
DummySocket(const DummySocket& source);
DummySocket& operator=(const DummySocket& source);
public:
/// \brief Constructor from the protocol number.
///
/// The protocol must validly identify a standard network protocol.
/// For example, to specify TCP \c protocol must be \c IPPROTO_TCP.
///
/// \param protocol The network protocol number for the socket.
DummySocket(const int protocol) : protocol_(protocol) {}
/// \brief A dummy derived method of \c IOSocket::getNative().
///
/// This version of method always returns -1 as the object is not
/// associated with a real (native) socket.
virtual int getNative() const { return (-1); }
virtual int getProtocol() const { return (protocol_); }
private:
const int protocol_;
......@@ -197,8 +283,8 @@ public:
void start() {
// Check for queued configuration commands
if (auth_server_ != NULL &&
auth_server_->configSession()->hasQueuedMsgs()) {
auth_server_->configSession()->checkCommand();
auth_server_->getConfigSession()->hasQueuedMsgs()) {
auth_server_->getConfigSession()->checkCommand();
}
async_read(socket_, asio::buffer(data_, TCP_MESSAGE_LENGTHSIZE),
boost::bind(&TCPClient::headerRead, this,
......@@ -385,8 +471,8 @@ public:
{
// Check for queued configuration commands
if (auth_server_ != NULL &&
auth_server_->configSession()->hasQueuedMsgs()) {
auth_server_->configSession()->checkCommand();
auth_server_->getConfigSession()->hasQueuedMsgs()) {
auth_server_->getConfigSession()->checkCommand();
}
if (!error && bytes_recvd > 0) {
const UDPEndpoint remote_endpoint(sender_endpoint_);
......
......@@ -215,7 +215,7 @@ AuthSrv::setConfigSession(ModuleCCSession* config_session) {
}
ModuleCCSession*
AuthSrv::configSession() const {
AuthSrv::getConfigSession() const {
return (impl_->config_session_);
}
......
......@@ -38,8 +38,30 @@ namespace asio_link {
class IOMessage;
}
/// \brief The implementation class for the \c AuthSrv class using the pimpl
/// idiom.
class AuthSrvImpl;
/// \brief The authoritative nameserver class.
///
/// \c AuthSrv is a concrete class that implements authoritative DNS server
/// protocol processing.
/// An \c AuthSrv object is primarily responsible for handling incoming DNS
/// requests: It parses the request and dispatches subsequent processing to
/// the corresponding module (which may be an internal library or a separate
/// process) depending on the request type. For normal queries, the
/// \c AuthSrv object searches configured data sources for the answer to the
/// query, and builds a response containing the answer.
///
/// This class uses the "pimpl" idiom, and hides detailed implementation
/// through the \c impl_ pointer (which points to an instance of the
/// \c AuthSrvImpl class). An \c AuthSrv object is supposed to exist for quite
/// a long period, and only a few \c AuthSrv objects will be created (in fact,
/// in this current implementation there will only be one object), so the
/// construction overhead of this approach should be acceptable.
///
/// The design of this class is still in flux. It's quite likely to change
/// in future versions.
class AuthSrv {
///
/// \name Constructors, Assignment Operator and Destructor.
......@@ -67,10 +89,77 @@ public:
bool processMessage(const asio_link::IOMessage& io_message,
isc::dns::Message& message,
isc::dns::MessageRenderer& response_renderer);
void setVerbose(bool on);
/// \brief Enable or disable verbose logging.
///
/// This method never throws an exception.
///
/// \param on \c true to enable verbose logging; \c false to disable
/// verbose logging.
void setVerbose(const bool on);
/// \brief Returns the logging verbosity of the \c AuthSrv object.
///
/// This method never throws an exception.
///
/// \return \c true if verbose logging is enabled; otherwise \c false.
bool getVerbose() const;
/// \brief Updates the data source for the \c AuthSrv object.
///
/// This method installs or replaces the data source that the \c AuthSrv
/// object refers to for query processing.
/// Although the method name is generic, the only thing it does is to
/// update the data source information.
/// If there is a data source installed, it will be replaced with the
/// new one.
///
/// In the current implementation, the SQLite data source is assumed.
/// The \c config parameter will simply be passed to the initialization
/// routine of the \c Sqlite3DataSrc class.
///
/// On success this method returns a data \c Element (in the form of a
/// pointer like object) indicating the successful result,
/// i.e., {"result": [0]}.
/// Otherwise, it returns a data \c Element explaining the error:
/// {"result": [1, <error-description>]}.
///
/// This method is mostly exception free (error conditions are represented
/// via the return value). But it may still throw a standard exception
/// if memory allocation fails inside the method.
/// When a standard exception is thrown or an implementation specific
/// exception is triggered and caught internally, this function provides
/// the strong exception guarantee: Unless everything succeeds, currently
/// installed data source (if any) won't be replaced.
///
/// \param config An immutable pointer-like object to a data \c Element,
/// possibly containing the data source information to be used.
/// \return An immutable pointer-like object to a data \c Element
/// containing the result of the update operation.
isc::data::ConstElementPtr updateConfig(isc::data::ConstElementPtr config);
isc::config::ModuleCCSession* configSession() const;
/// \param Returns the command and configuration session for the
/// \c AuthSrv.
///
/// This method never throws an exception.
///
/// \return A pointer to \c ModuleCCSession object stored in the
/// \c AuthSrv object. In this implementation it could be NULL.
isc::config::ModuleCCSession* getConfigSession() const;
/// \brief Set the command and configuration session for the \c AuthSrv.
///
/// Note: this interface is tentative. We'll revisit the ASIO and session
/// frameworks, at which point the session will probably be passed on
/// construction of the server.
/// In the current implementation, this method is expected to be called
/// exactly once as part of initialization. If this method is called
/// multiple times, previously specified session is silently overridden.
///
/// This method never throws an exception.
///
/// \param config_session A pointer to \c ModuleCCSession object to receive
/// control commands and configuration updates.
void setConfigSession(isc::config::ModuleCCSession* config_session);
/// \brief Set or update the size (number of slots) of hot spot cache.
......@@ -93,6 +182,8 @@ public:
/// \return The current number of cache slots.
size_t getCacheSlots() const;
/// \brief Set the communication session with a separate process for
/// outgoing zone transfers.
///
/// Note: this interface is tentative. We'll revisit the ASIO and session
/// frameworks, at which point the session will probably be passed on
......@@ -105,6 +196,7 @@ public:
/// Ownership isn't transferred: the caller is responsible for keeping
/// this object to be valid while the server object is working and for
/// disconnecting the session and destroying the object when the server
/// is shutdown.
///
void setXfrinSession(isc::cc::AbstractSession* xfrin_session);
private:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment