]>
Commit | Line | Data |
---|---|---|
6264512b | 1 | #include "statnode.hh" |
2 | ||
431c4359 | 3 | StatNode::Stat StatNode::print(unsigned int depth, Stat newstat, bool silent) const |
6264512b | 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 | if(children.size()>1024 && !silent) { | |
16 | cout<<string(depth, ' ')<<name<<": too many to print"<<endl; | |
17 | } | |
18 | for(const children_t::value_type& child : children) { | |
19 | childstat=child.second.print(depth+8, childstat, silent || children.size()>1024); | |
20 | } | |
21 | if(!silent || children.size()>1) | |
22 | cout<<string(depth, ' ')<<childstat.queries<<" queries, " << | |
23 | childstat.noerrors<<" noerrors, "<< | |
24 | childstat.nxdomains<<" nxdomains, "<< | |
25 | childstat.servfails<<" servfails, "<< | |
26 | childstat.drops<<" drops"<<endl; | |
27 | ||
28 | newstat+=childstat; | |
29 | ||
30 | return newstat; | |
31 | } | |
32 | ||
33 | ||
431c4359 | 34 | void StatNode::visit(visitor_t visitor, Stat &newstat, unsigned int depth) const |
6264512b | 35 | { |
36 | Stat childstat; | |
37 | childstat.queries += s.queries; | |
38 | childstat.noerrors += s.noerrors; | |
39 | childstat.nxdomains += s.nxdomains; | |
40 | childstat.servfails += s.servfails; | |
41 | childstat.drops += s.drops; | |
7d07129c | 42 | childstat.remotes = s.remotes; |
6264512b | 43 | |
c5983d8d | 44 | Stat selfstat(childstat); |
6264512b | 45 | |
46 | for(const children_t::value_type& child : children) { | |
47 | child.second.visit(visitor, childstat, depth+8); | |
48 | } | |
49 | ||
50 | visitor(this, selfstat, childstat); | |
51 | ||
52 | newstat+=childstat; | |
53 | } | |
54 | ||
55 | ||
7d07129c | 56 | void StatNode::submit(const DNSName& domain, int rcode, boost::optional<const ComboAddress&> remote) |
6264512b | 57 | { |
58 | // cerr<<"FIRST submit called on '"<<domain<<"'"<<endl; | |
1b7c449b | 59 | std::vector<string> tmp = domain.getRawLabels(); |
6264512b | 60 | if(tmp.empty()) |
61 | return; | |
62 | ||
1b7c449b RG |
63 | auto last = tmp.end() - 1; |
64 | children[*last].submit(last, tmp.begin(), "", rcode, remote, 1); | |
6264512b | 65 | } |
66 | ||
67 | /* www.powerdns.com. -> | |
68 | . <- fullnames | |
69 | com. | |
70 | powerdns.com | |
71 | www.powerdns.com. | |
72 | */ | |
73 | ||
7d07129c | 74 | void StatNode::submit(std::vector<string>::const_iterator end, std::vector<string>::const_iterator begin, const std::string& domain, int rcode, boost::optional<const ComboAddress&> remote, unsigned int count) |
6264512b | 75 | { |
6264512b | 76 | // cerr<<"Submit called for domain='"<<domain<<"': "; |
77 | // for(const std::string& n : labels) | |
78 | // cerr<<n<<"."; | |
79 | // cerr<<endl; | |
80 | if(name.empty()) { | |
81 | ||
1b7c449b | 82 | name=*end; |
6264512b | 83 | // cerr<<"Set short name to '"<<name<<"'"<<endl; |
84 | } | |
2010ac95 RG |
85 | else { |
86 | // cerr<<"Short name was already set to '"<<name<<"'"<<endl; | |
87 | } | |
6264512b | 88 | |
1b7c449b | 89 | if(end == begin) { |
431c4359 RG |
90 | if (fullname.empty()) { |
91 | fullname=name+"."+domain; | |
92 | labelsCount = count; | |
93 | } | |
6264512b | 94 | // cerr<<"Hit the end, set our fullname to '"<<fullname<<"'"<<endl<<endl; |
95 | s.queries++; | |
96 | if(rcode<0) | |
97 | s.drops++; | |
98 | else if(rcode==0) | |
99 | s.noerrors++; | |
100 | else if(rcode==2) | |
101 | s.servfails++; | |
102 | else if(rcode==3) | |
103 | s.nxdomains++; | |
7d07129c RG |
104 | |
105 | if (remote) { | |
106 | s.remotes[*remote]++; | |
107 | } | |
6264512b | 108 | } |
109 | else { | |
431c4359 RG |
110 | if (fullname.empty()) { |
111 | fullname=name+"."+domain; | |
112 | labelsCount = count; | |
113 | } | |
6264512b | 114 | // cerr<<"Not yet end, set our fullname to '"<<fullname<<"', recursing"<<endl; |
4b5da564 | 115 | --end; |
1b7c449b | 116 | children[*end].submit(end, begin, fullname, rcode, remote, count+1); |
6264512b | 117 | } |
118 | } | |
119 |