Commit bc6b92a8 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[1539] make sure ddns forwarder establishes connection only once.

parent 7433c00e
......@@ -110,6 +110,27 @@ public:
private:
MessageRenderer& renderer_;
};
/// TBD document it.
class SocketSessionForwarderHolder {
public:
SocketSessionForwarderHolder(BaseSocketSessionForwarder& forwarder) :
forwarder_(forwarder), connected_(false)
{}
~SocketSessionForwarderHolder() {}
void connect() {
if (!connected_) {
forwarder_.connectToReceiver();
connected_ = true;
}
}
BaseSocketSessionForwarder& forwarder_;
private:
bool connected_;
};
}
class AuthSrvImpl {
......@@ -196,7 +217,7 @@ private:
bool xfrout_connected_;
AbstractXfroutClient& xfrout_client_;
BaseSocketSessionForwarder& ddns_forwarder_;
SocketSessionForwarderHolder ddns_forwarder_;
/// Increment query counter
void incCounter(const int protocol);
......@@ -763,7 +784,8 @@ AuthSrvImpl::processUpdate(const IOMessage& /*io_message*/,
std::auto_ptr<TSIGContext> /*tsig_context*/)
{
// hardcode for initial test
ddns_forwarder_.connectToReceiver();
ddns_forwarder_.connect();
return (false);
}
......
......@@ -1392,14 +1392,19 @@ TEST_F(AuthSrvTest, queryWithThrowingInToWire) {
TEST_F(AuthSrvTest, DDNSForward) {
EXPECT_FALSE(ddns_forwarder.isConnected());
UnitTestUtil::createRequestMessage(request_message, Opcode::UPDATE(),
default_qid, Name("example.com"),
RRClass::IN(), RRType::SOA());
createRequestPacket(request_message, IPPROTO_UDP);
server.processMessage(*io_message, *parse_message, *response_obuffer,
&dnsserv);
EXPECT_FALSE(dnsserv.hasAnswer());
EXPECT_TRUE(ddns_forwarder.isConnected());
// Repeat sending an update request two times. By doing that we'll
// confirm the forwarder connection will be established exactly once,
// and kept established.
for (size_t i = 0; i < 2; ++i) {
UnitTestUtil::createRequestMessage(request_message, Opcode::UPDATE(),
default_qid, Name("example.com"),
RRClass::IN(), RRType::SOA());
createRequestPacket(request_message, IPPROTO_UDP);
server.processMessage(*io_message, *parse_message, *response_obuffer,
&dnsserv);
EXPECT_FALSE(dnsserv.hasAnswer());
EXPECT_TRUE(ddns_forwarder.isConnected());
}
}
}
......@@ -218,6 +218,9 @@ public:
isc_throw(isc::util::io::SocketSessionError, "socket session "
"forwarding connection disabled for test");
}
if (is_connected_) {
isc_throw(isc::util::io::SocketSessionError, "duplicate connect");
}
is_connected_ = true;
}
virtual void close() {}
......
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