]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/statnode.cc
pkcs11signers: Use emplace_back for attributes
[thirdparty/pdns.git] / pdns / statnode.cc
1 #include "statnode.hh"
2
3 StatNode::Stat StatNode::print(unsigned int depth, Stat newstat, bool silent) const
4 {
5 if(!silent) {
6 cout<<string(depth, ' ');
7 cout<<name<<": "<<endl;
8 }
9 Stat childstat;
10 childstat.queries += s.queries;
11 childstat.noerrors += s.noerrors;
12 childstat.nxdomains += s.nxdomains;
13 childstat.servfails += s.servfails;
14 childstat.drops += s.drops;
15 childstat.bytes += s.bytes;
16 childstat.hits += s.hits;
17
18 if(children.size()>1024 && !silent) {
19 cout<<string(depth, ' ')<<name<<": too many to print"<<endl;
20 }
21 for(const children_t::value_type& child : children) {
22 childstat=child.second.print(depth+8, childstat, silent || children.size()>1024);
23 }
24 if(!silent || children.size()>1)
25 cout<<string(depth, ' ')<<childstat.queries<<" queries, " <<
26 childstat.noerrors<<" noerrors, "<<
27 childstat.nxdomains<<" nxdomains, "<<
28 childstat.servfails<<" servfails, "<<
29 childstat.drops<<" drops, "<<
30 childstat.bytes<<" bytes, "<<
31 childstat.hits<<" hits"<<endl;
32
33 newstat+=childstat;
34
35 return newstat;
36 }
37
38
39 void StatNode::visit(visitor_t visitor, Stat &newstat, unsigned int depth) const
40 {
41 Stat childstat(s);
42
43 for (const auto& child : children) {
44 child.second.visit(visitor, childstat, depth+8);
45 }
46
47 visitor(this, s, childstat);
48
49 newstat += childstat;
50 }
51
52
53 void StatNode::submit(const DNSName& domain, int rcode, unsigned int bytes, bool hit, boost::optional<const ComboAddress&> remote)
54 {
55 // cerr<<"FIRST submit called on '"<<domain<<"'"<<endl;
56 std::vector<string> tmp = domain.getRawLabels();
57 if (tmp.empty()) {
58 return;
59 }
60
61 auto last = tmp.end() - 1;
62 children[*last].submit(last, tmp.begin(), "", rcode, bytes, remote, 1, hit);
63 }
64
65 /* www.powerdns.com. ->
66 . <- fullnames
67 com.
68 powerdns.com
69 www.powerdns.com.
70 */
71
72 void StatNode::submit(std::vector<string>::const_iterator end, std::vector<string>::const_iterator begin, const std::string& domain, int rcode, unsigned int bytes, boost::optional<const ComboAddress&> remote, unsigned int count, bool hit)
73 {
74 // cerr<<"Submit called for domain='"<<domain<<"': ";
75 // for(const std::string& n : labels)
76 // cerr<<n<<".";
77 // cerr<<endl;
78 if (name.empty()) {
79
80 name=*end;
81 // cerr<<"Set short name to '"<<name<<"'"<<endl;
82 }
83 else {
84 // cerr<<"Short name was already set to '"<<name<<"'"<<endl;
85 }
86
87 if (end == begin) {
88 if (fullname.empty()) {
89 size_t needed = name.size() + 1 + domain.size();
90 if (fullname.capacity() < needed) {
91 fullname.reserve(needed);
92 }
93 fullname = name;
94 fullname.append(".");
95 fullname.append(domain);
96 labelsCount = count;
97 }
98 // cerr<<"Hit the end, set our fullname to '"<<fullname<<"'"<<endl<<endl;
99 s.queries++;
100 s.bytes += bytes;
101 if (rcode < 0) {
102 s.drops++;
103 }
104 else if (rcode == RCode::NoError) {
105 s.noerrors++;
106 }
107 else if (rcode == RCode::ServFail) {
108 s.servfails++;
109 }
110 else if (rcode == RCode::NXDomain) {
111 s.nxdomains++;
112 }
113
114 if (remote) {
115 s.remotes[*remote]++;
116 }
117
118 if (hit) {
119 ++s.hits;
120 }
121 }
122 else {
123 if (fullname.empty()) {
124 size_t needed = name.size() + 1 + domain.size();
125 if (fullname.capacity() < needed) {
126 fullname.reserve(needed);
127 }
128 fullname = name;
129 fullname.append(".");
130 fullname.append(domain);
131 labelsCount = count;
132 }
133 // cerr<<"Not yet end, set our fullname to '"<<fullname<<"', recursing"<<endl;
134 --end;
135 children[*end].submit(end, begin, fullname, rcode, bytes, remote, count+1, hit);
136 }
137 }