Commit f0a43d24 authored by Jelte Jansen's avatar Jelte Jansen

[trac494] change ResolverInterface::Callback to take Message

instead of AbstractRRset it will now take a MessagePtr in its success()
callback. needed to change a lot of test code for it to run again
parent a6f9d5cd
......@@ -347,9 +347,7 @@ Resolver::getConfigSession() const {
/* tmp for in-dev testing */
class MyCallback : public resolve::ResolverInterface::Callback {
public:
virtual void success(
const boost::shared_ptr<isc::dns::AbstractRRset>&
response) {
virtual void success(MessagePtr response) {
std::cout << "[XX] CALLBACK FOR LOOKUP!" << std::endl;
std::cout << "[XX] GOT: " << *response << std::endl;
std::cout << "[XX] END" << std::endl;
......@@ -381,6 +379,7 @@ Resolver::processMessage(const IOMessage& io_message,
OutputBufferPtr buffer,
DNSServer* server)
{
/*
std::cout << "[XX] remove this :p" << std::endl;
QuestionPtr q(new Question(Name("www.tjeb.nl"), RRClass::IN(), RRType::A()));
boost::shared_ptr<MyCallback> callback(new MyCallback());
......@@ -390,7 +389,7 @@ Resolver::processMessage(const IOMessage& io_message,
resolve(q, callback);
//resolve(q, callback);
std::cout << "[XX] up to here" << std::endl;
*/
dlog("Got a DNS message");
InputBuffer request_buffer(io_message.getData(), io_message.getDataSize());
// First, check the header part. If we fail even for the base header,
......
......@@ -30,6 +30,8 @@
#include <dns/name.h>
#include <dns/rrclass.h>
#include <dns/rrttl.h>
#include <dns/rcode.h>
#include <dns/opcode.h>
#include <dns/question.h>
#include <resolve/resolver_interface.h>
......@@ -214,11 +216,22 @@ class NameserverEntry::ResolverCallback :
* This extracts the addresses out from the response and puts them
* inside the entry. It tries to reuse the address entries from before (if there were any), to keep their RTTs.
*/
virtual void success(const boost::shared_ptr<AbstractRRset>& response) {
virtual void success(MessagePtr response_message) {
time_t now = time(NULL);
Lock lock(entry_->mutex_);
// TODO: find the correct RRset, not simply the first
if (!response_message ||
response_message->getRcode() != isc::dns::Rcode::NOERROR() ||
response_message->getRRCount(isc::dns::Message::SECTION_ANSWER) == 0) {
failureInternal(lock);
}
isc::dns::RRsetIterator rrsi =
response_message->beginSection(isc::dns::Message::SECTION_ANSWER);
const isc::dns::RRsetPtr response = *rrsi;
vector<AddressEntry> entries;
if (response->getType() != type_ ||
......
......@@ -86,7 +86,7 @@ public:
* if it is asked for by the resolver.
*/
void lookupAndAnswer(const string& name, const RRClass& class_code,
boost::shared_ptr<AbstractRRset> authority,
RRsetPtr authority,
boost::shared_ptr<AddressRequestCallback> callback)
{
size_t size(resolver_->requests.size());
......
......@@ -39,7 +39,7 @@ class NameserverEntrySample {
public:
NameserverEntrySample():
name_("example.org"),
rrv4_(new BasicRRset(name_, RRClass::IN(), RRType::A(), RRTTL(1200)))
rrv4_(new RRset(name_, RRClass::IN(), RRType::A(), RRTTL(1200)))
{
// Add some sample A records
rrv4_->addRdata(ConstRdataPtr(new RdataTest<A>("1.2.3.4")));
......@@ -50,7 +50,7 @@ public:
boost::shared_ptr<TestResolver> resolver(new TestResolver);
ns_->askIP(resolver, boost::shared_ptr<Callback>(new Callback), ANY_OK);
resolver->asksIPs(name_, 0, 1);
resolver->requests[0].second->success(rrv4_);
resolver->requests[0].second->success(createResponseMessage(rrv4_));
}
// Return the sample NameserverEntry
......@@ -73,7 +73,7 @@ public:
private:
Name name_; ///< Name of the sample
boost::shared_ptr<BasicRRset> rrv4_; ///< Standard RRSet - IN, A, lowercase name
RRsetPtr rrv4_; ///< Standard RRSet - IN, A, lowercase name
boost::shared_ptr<NameserverEntry> ns_; ///< Shared_ptr that points to a NameserverEntry object
class Callback : public NameserverEntry::Callback {
......
......@@ -69,10 +69,10 @@ private:
* as a failure.
*/
void fillSet(boost::shared_ptr<TestResolver> resolver, size_t index,
boost::shared_ptr<BasicRRset> set)
RRsetPtr set)
{
if (set) {
resolver->requests[index].second->success(set);
resolver->requests[index].second->success(createResponseMessage(set));
} else {
resolver->requests[index].second->failure();
}
......@@ -80,7 +80,7 @@ private:
protected:
/// Fills the nameserver entry with data trough ask IP
void fillNSEntry(boost::shared_ptr<NameserverEntry> entry,
boost::shared_ptr<BasicRRset> rrv4, boost::shared_ptr<BasicRRset> rrv6)
RRsetPtr rrv4, RRsetPtr rrv6)
{
// Prepare data to run askIP
boost::shared_ptr<TestResolver> resolver(new TestResolver);
......@@ -212,13 +212,13 @@ TEST_F(NameserverEntryTest, ExpirationTime) {
// Test where there is a single TTL
boost::shared_ptr<NameserverEntry> alpha(new NameserverEntry(EXAMPLE_CO_UK,
RRClass::IN()));
fillNSEntry(alpha, rrv4_, boost::shared_ptr<BasicRRset>());
fillNSEntry(alpha, rrv4_, RRsetPtr());
expiration = alpha->getExpiration();
EXPECT_EQ(expiration, curtime + rrv4_->getTTL().getValue());
boost::shared_ptr<NameserverEntry> beta(new NameserverEntry(EXAMPLE_CO_UK,
RRClass::IN()));
fillNSEntry(beta, boost::shared_ptr<BasicRRset>(), rrv6_);
fillNSEntry(beta, RRsetPtr(), rrv6_);
expiration = beta->getExpiration();
EXPECT_EQ(expiration, curtime + rrv6_->getTTL().getValue());
......@@ -237,7 +237,7 @@ TEST_F(NameserverEntryTest, ExpirationTime) {
boost::shared_ptr<NameserverEntry> delta(new NameserverEntry(EXAMPLE_CO_UK,
RRClass::IN()));
fillNSEntry(delta, rrv4_, boost::shared_ptr<BasicRRset>());
fillNSEntry(delta, rrv4_, RRsetPtr());
EXPECT_GT(delta->getExpiration(), rrv4_->getTTL().getValue());
}
......@@ -347,9 +347,9 @@ TEST_F(NameserverEntryTest, DirectAnswer) {
resolver->addPresetAnswer(Question(Name(EXAMPLE_CO_UK), RRClass::IN(),
RRType::AAAA()), rrv6_);
resolver->addPresetAnswer(Question(Name(EXAMPLE_NET), RRClass::IN(),
RRType::A()), boost::shared_ptr<AbstractRRset>());
RRType::A()), RRsetPtr());
resolver->addPresetAnswer(Question(Name(EXAMPLE_NET), RRClass::IN(),
RRType::AAAA()), boost::shared_ptr<AbstractRRset>());
RRType::AAAA()), RRsetPtr());
// A successfull test first
entry->askIP(resolver, callback, ANY_OK);
......
......@@ -25,10 +25,13 @@
#include <config.h>
#include <dns/message.h>
#include <dns/buffer.h>
#include <dns/rdata.h>
#include <dns/rrtype.h>
#include <dns/rrttl.h>
#include <dns/opcode.h>
#include <dns/rcode.h>
#include <dns/messagerenderer.h>
#include <dns/rdataclass.h>
#include <resolve/resolver_interface.h>
......@@ -37,6 +40,18 @@
using namespace isc::dns::rdata;
using namespace isc::dns;
namespace {
MessagePtr
createResponseMessage(RRsetPtr answer_rrset)
{
MessagePtr response(new Message(Message::RENDER));
response->setOpcode(Opcode::QUERY());
response->setRcode(Rcode::NOERROR());
response->addRRset(Message::SECTION_ANSWER, answer_rrset);
return response;
}
}
namespace isc {
namespace dns {
......@@ -223,7 +238,7 @@ class TestResolver : public isc::resolve::ResolverInterface {
return (requests.size() > index);
}
typedef std::map<isc::dns::Question, boost::shared_ptr<AbstractRRset> >
typedef std::map<isc::dns::Question, RRsetPtr >
PresetAnswers;
PresetAnswers answers_;
public:
......@@ -235,7 +250,7 @@ class TestResolver : public isc::resolve::ResolverInterface {
requests.push_back(Request(q, c));
} else {
if (it->second) {
c->success(it->second);
c->success(createResponseMessage(it->second));
} else {
c->failure();
}
......@@ -248,7 +263,7 @@ class TestResolver : public isc::resolve::ResolverInterface {
* it goes to requests and you can answer later.
*/
void addPresetAnswer(const isc::dns::Question& question,
boost::shared_ptr<AbstractRRset> answer)
RRsetPtr answer)
{
answers_[question] = answer;
}
......@@ -308,11 +323,11 @@ class TestResolver : public isc::resolve::ResolverInterface {
RRsetPtr set(new RRset(name, RRClass::IN(),
type, RRTTL(TTL)));
set->addRdata(rdata);
requests[index].second->success(set);
requests[index].second->success(createResponseMessage(set));
}
void provideNS(size_t index,
boost::shared_ptr<AbstractRRset> nameservers)
RRsetPtr nameservers)
{
if (index >= requests.size()) {
throw NoSuchRequest();
......@@ -322,7 +337,7 @@ class TestResolver : public isc::resolve::ResolverInterface {
{
throw DifferentRequest();
}
requests[index].second->success(nameservers);
requests[index].second->success(createResponseMessage(nameservers));
}
};
......
......@@ -460,7 +460,7 @@ TEST_F(ZoneEntryTest, DirectAnswer) {
// One unsuccessfull attempt, nameservers fail
resolver_->addPresetAnswer(Question(Name(EXAMPLE_CO_UK), RRClass::IN(),
RRType::NS()), boost::shared_ptr<AbstractRRset>());
RRType::NS()), RRsetPtr());
zone->addCallback(callback_, ANY_OK);
EXPECT_EQ(0, callback_->successes_.size());
EXPECT_EQ(1, callback_->unreachable_count_);
......@@ -494,9 +494,9 @@ TEST_F(ZoneEntryTest, DirectAnswer) {
callback_->successes_.clear();
// Now, pretend we do not have IP addresses
resolver_->addPresetAnswer(Question(ns_name, RRClass::IN(), RRType::A()),
boost::shared_ptr<AbstractRRset>());
RRsetPtr());
resolver_->addPresetAnswer(Question(ns_name, RRClass::IN(),
RRType::AAAA()), boost::shared_ptr<AbstractRRset>());
RRType::AAAA()), RRsetPtr());
// Get another zone and ask it again. It should fail.
// Clean the table first, though, so it does not find the old nameserver
nameserver_table_->remove(HashKey(ns_name.toText(), RRClass::IN()));
......
......@@ -22,6 +22,7 @@
#include <boost/foreach.hpp>
#include <boost/bind.hpp>
#include <dns/rrttl.h>
#include <dns/rcode.h>
#include <dns/rdataclass.h>
using namespace std;
......@@ -92,8 +93,21 @@ class ZoneEntry::ResolverCallback :
* examining them and seeing if some addresses are already there
* and to ask for the rest of them.
*/
virtual void success(const boost::shared_ptr<AbstractRRset>& answer) {
virtual void success(MessagePtr response_message) {
Lock lock(entry_->mutex_);
// TODO: find the correct RRset, not simply the first
if (!response_message ||
response_message->getRcode() != isc::dns::Rcode::NOERROR() ||
response_message->getRRCount(isc::dns::Message::SECTION_ANSWER) == 0) {
// todo: define this
failureInternal(300);
}
isc::dns::RRsetIterator rrsi =
response_message->beginSection(isc::dns::Message::SECTION_ANSWER);
const isc::dns::RRsetPtr answer = *rrsi;
RdataIteratorPtr iterator(answer->getRdataIterator());
// If there are no data
if (iterator->isLast()) {
......
......@@ -31,10 +31,13 @@ ResolverCallbackDirect::callback(bool result)
if (result &&
answer_message_->getRcode() == isc::dns::Rcode::NOERROR() &&
answer_message_->getRRCount(isc::dns::Message::SECTION_ANSWER) > 0) {
/*
std::cout << *answer_message_ << std::endl;
isc::dns::RRsetIterator rrsi = answer_message_->beginSection(isc::dns::Message::SECTION_ANSWER);
const isc::dns::RRsetPtr result = *rrsi;
callback_->success(result);
*/
callback_->success(answer_message_);
} else {
callback_->failure();
}
......
......@@ -46,9 +46,8 @@ class ResolverInterface {
class Callback {
public:
/// \short Some data arrived.
virtual void success(
const boost::shared_ptr<isc::dns::AbstractRRset>&
response) = 0;
virtual void success(isc::dns::MessagePtr response) = 0;
/**
* \short No data available.
*
......
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