Skip to content

Commit 3e81f60

Browse files
committed
Make UeberBackend::handle even more opaque. NFCI
Signed-off-by: Miod Vallat <[email protected]>
1 parent 9dd451f commit 3e81f60

File tree

2 files changed

+43
-26
lines changed

2 files changed

+43
-26
lines changed

pdns/ueberbackend.cc

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,8 @@ UeberBackend::UeberBackend(const string& pname)
715715
d_negcache_ttl = ::arg().asNum("negquery-cache-ttl");
716716

717717
backends = BackendMakers().all(pname == "key-only");
718+
719+
d_handle.setParent(this);
718720
}
719721

720722
// returns -1 for miss, 0 for negative match, 1 for hit
@@ -806,22 +808,15 @@ void UeberBackend::lookup(const QType& qtype, const DNSName& qname, domainid_t z
806808

807809
d_qtype = qtype.getCode();
808810

809-
d_handle.parent = this;
810-
d_handle.backendIndex = 0;
811-
d_handle.qtype = s_doANYLookupsOnly ? QType::ANY : qtype;
812-
d_handle.qname = qname;
813-
d_handle.zoneId = zoneId;
814-
d_handle.pkt_p = pkt_p;
811+
d_handle.lookup(qtype, qname, zoneId, pkt_p);
815812

816813
if (backends.empty()) {
817814
g_log << Logger::Error << "No database backends available - unable to answer questions." << endl;
818815
d_stale = true; // please recycle us!
819816
throw PDNSException("We are stale, please recycle");
820817
}
821818

822-
d_question.qtype = d_handle.qtype;
823-
d_question.qname = qname;
824-
d_question.zoneId = d_handle.zoneId;
819+
d_handle.setupQuestion(d_question);
825820

826821
auto cacheResult = cacheHas(d_question, d_answers);
827822
if (cacheResult == CacheResult::Miss) { // nothing
@@ -1063,14 +1058,30 @@ void UeberBackend::flush()
10631058
}
10641059
}
10651060

1061+
void UeberBackend::handle::lookup(const QType& qtype, const DNSName& qname, domainid_t zoneId, DNSPacket* pkt_p)
1062+
{
1063+
d_backendIndex = 0;
1064+
d_qtype = s_doANYLookupsOnly ? QType::ANY : qtype;
1065+
d_qname = qname;
1066+
d_zoneId = zoneId;
1067+
d_pkt_p = pkt_p;
1068+
}
1069+
1070+
void UeberBackend::handle::setupQuestion(UeberBackend::Question& question) const
1071+
{
1072+
question.qtype = d_qtype;
1073+
question.qname = d_qname;
1074+
question.zoneId = d_zoneId;
1075+
}
1076+
10661077
// Set d_hinterBackend to the next available backend from the parents list,
10671078
// reset it to nullptr if the whole list has been processed.
10681079
// Invokes lookup on behalf of the newly picked backend if successful.
10691080
void UeberBackend::handle::selectNextBackend()
10701081
{
1071-
if (backendIndex < parent->backends.size()) {
1072-
d_hinterBackend = parent->backends[backendIndex++].get();
1073-
d_hinterBackend->lookup(qtype, qname, zoneId, pkt_p);
1082+
if (d_backendIndex < d_parent->backends.size()) {
1083+
d_hinterBackend = d_parent->backends[d_backendIndex++].get();
1084+
d_hinterBackend->lookup(d_qtype, d_qname, d_zoneId, d_pkt_p);
10741085
++(*s_backendQueries);
10751086
}
10761087
else {
@@ -1082,11 +1093,11 @@ bool UeberBackend::handle::get(DNSZoneRecord& record)
10821093
{
10831094
DLOG(g_log << "Ueber get() was called for a " << qtype << " record" << endl);
10841095
while (d_hinterBackend != nullptr && !(d_hinterBackend->get(record))) { // this backend is out of answers
1085-
DLOG(g_log << "Backend #" << backendIndex << " of " << parent->backends.size()
1096+
DLOG(g_log << "Backend #" << d_backendIndex << " of " << d_parent->backends.size()
10861097
<< " out of answers, trying next" << endl);
10871098
selectNextBackend();
10881099
if (d_hinterBackend != nullptr) {
1089-
DLOG(g_log << "Now asking backend #" << backendIndex << endl);
1100+
DLOG(g_log << "Now asking backend #" << d_backendIndex << endl);
10901101
}
10911102
}
10921103

@@ -1096,7 +1107,7 @@ bool UeberBackend::handle::get(DNSZoneRecord& record)
10961107
}
10971108

10981109
DLOG(g_log << "Found an answering backend - will not try another one" << endl);
1099-
backendIndex = parent->backends.size(); // don't go on to the next backend
1110+
d_backendIndex = d_parent->backends.size(); // don't go on to the next backend
11001111
return true;
11011112
}
11021113

pdns/ueberbackend.hh

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,30 +62,36 @@ public:
6262
new modules are loaded */
6363
vector<std::unique_ptr<DNSBackend>> backends;
6464

65+
struct Question;
66+
6567
//! the very magic handle for UeberBackend questions
6668
class handle
6769
{
6870
public:
71+
void setParent(UeberBackend* parent) { d_parent = parent; }
72+
void selectNextBackend();
73+
74+
void setupQuestion(Question& question) const;
75+
void lookup(const QType& qtype, const DNSName& qname, domainid_t zoneId, DNSPacket* pkt_p);
6976
bool get(DNSZoneRecord& record);
7077
void lookupEnd() const;
7178

79+
private:
7280
//! The UeberBackend class where this handle belongs to
73-
UeberBackend* parent{nullptr};
81+
UeberBackend* d_parent{nullptr};
7482

75-
//! DNSPacket who asked this question
76-
DNSPacket* pkt_p{nullptr};
77-
DNSName qname;
83+
//! The currently selected real backend, which is answering questions
84+
DNSBackend* d_hinterBackend{nullptr};
7885

7986
//! Index of the current backend within the backends vector
80-
size_t backendIndex{0};
81-
QType qtype;
82-
domainid_t zoneId{UnknownDomainID};
87+
size_t d_backendIndex{0};
8388

84-
void selectNextBackend();
89+
//! DNSPacket who asked this question
90+
DNSPacket* d_pkt_p{nullptr};
91+
DNSName d_qname;
8592

86-
private:
87-
//! The currently selected real backend, which is answering questions
88-
DNSBackend* d_hinterBackend{nullptr};
93+
QType d_qtype;
94+
domainid_t d_zoneId{UnknownDomainID};
8995
};
9096

9197
void lookup(const QType& qtype, const DNSName& qname, domainid_t zoneId, DNSPacket* pkt_p = nullptr);

0 commit comments

Comments
 (0)