if(cmd=="dump-failedservers")
return doDumpFailedServers(begin, end);
+ if(cmd=="dump-throttlemap")
+ return doDumpThrottleMap(begin, end);
+
if(cmd=="dump-rpz") {
return doDumpRPZ(begin, end);
}
return count;
}
+uint64_t SyncRes::doDumpThrottleMap(int fd)
+{
+ auto fp = std::unique_ptr<FILE, int(*)(FILE*)>(fdopen(dup(fd), "w"), fclose);
+ if(!fp)
+ return 0;
+ fprintf(fp.get(), "; throttle map dump follows\n");
+ fprintf(fp.get(), "; remote IP\tqname\tqtype\tcount\tttd\n");
+ uint64_t count=0;
+
+ const auto& throttleMap = t_sstorage.throttle.getThrottleMap();
+ for(const auto& i : throttleMap)
+ {
+ count++;
+ char tmp[26];
+ // remote IP, dns name, qtype, count, ttd
+ fprintf(fp.get(), "%s\t%s\t%d\t%u\t%s", i.first.get<0>().toString().c_str(), i.first.get<1>().toLogString().c_str(), i.first.get<2>(), i.second.count, ctime_r(&i.second.ttd, tmp));
+ }
+
+ return count;
+}
+
uint64_t SyncRes::doDumpFailedServers(int fd)
{
auto fp = std::unique_ptr<FILE, int(*)(FILE*)>(fdopen(dup(fd), "w"), fclose);
template<class Thing> class Throttle : public boost::noncopyable
{
public:
+ struct entry
+ {
+ time_t ttd;
+ unsigned int count;
+ };
+ typedef map<Thing,entry> cont_t;
Throttle()
{
d_limit=3;
return (unsigned int)d_cont.size();
}
+ const cont_t& getThrottleMap() const
+ {
+ return d_cont;
+ }
+
void clear()
{
d_cont.clear();
unsigned int d_limit;
time_t d_ttl;
time_t d_last_clean;
- struct entry
- {
- time_t ttd;
- unsigned int count;
- };
- typedef map<Thing,entry> cont_t;
cont_t d_cont;
};