if(!fp)
return 0;
fprintf(fp, "; throttle map dump follows\n");
- fprintf(fp, "; remote IP, DNSName, QType\n");
+ fprintf(fp, "; remote IP\tqname\tqtype\tcount\tttd\n");
uint64_t count=0;
- for(const auto& i : t_sstorage.throttle.getThrottleTuples())
+ const auto& throttleMap = t_sstorage.throttle.getThrottleMap();
+ for(const auto& i : throttleMap)
{
count++;
- // remote IP, dns name, qtype
- fprintf(fp, "%s %s %d", i.get<0>().toLogString().c_str(), i.get<1>().toString().c_str(), i.get<2>());
- fprintf(fp, "\n");
+ // remote IP, dns name, qtype, count, ttd
+ fprintf(fp, "%s\t%s\t%d\t%d\t%s", i.first.get<0>().toString().c_str(), i.first.get<1>().toString().c_str(), i.first.get<2>(), i.second.count, ctime(&i.second.ttd));
}
fclose(fp);
return count;
d_ttl=60;
d_last_clean=time(0);
}
+
+ struct entry
+ {
+ time_t ttd;
+ unsigned int count;
+ };
+ typedef map<Thing,entry> cont_t;
+
bool shouldThrottle(time_t now, const Thing& t)
{
if(now > d_last_clean + 300 ) {
return (unsigned int)d_cont.size();
}
- typedef std::vector<boost::tuple<ComboAddress,DNSName,uint16_t> > throttles_t;
- throttles_t getThrottleTuples() {
- throttles_t ret;
- ret.reserve(d_cont.size());
-
- for(const auto& i : d_cont) {
- ret.push_back(i.first);
- }
-
- return ret;
+ const cont_t& getThrottleMap() const
+ {
+ return d_cont;
}
void 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;
};