From: bert hubert Date: Sat, 22 Mar 2014 20:11:48 +0000 (+0100) Subject: oops, committed all the wrong stuff for dnsreplay.cc in 15c01debce267a442e136ea34dca1... X-Git-Tag: rec-3.6.0-rc1~112 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1451ac8a790d5302f176e149a844b346021841f0;p=thirdparty%2Fpdns.git oops, committed all the wrong stuff for dnsreplay.cc in 15c01debce267a442e136ea34dca190c1357c35b - revert the wrong bits. --- diff --git a/pdns/dnsreplay.cc b/pdns/dnsreplay.cc index a4a64fc60f..04cbfe3ab2 100644 --- a/pdns/dnsreplay.cc +++ b/pdns/dnsreplay.cc @@ -21,7 +21,6 @@ There is one central object, which has (when complete) What to do with timeouts. We keep around at most 65536 outstanding answers. */ - /* mental_clock=0; for(;;) { @@ -98,8 +97,11 @@ const struct timeval operator*(float fact, const struct timeval& rhs) return ret; } - - +bool g_pleaseQuit; +void pleaseQuitHandler(int) +{ + g_pleaseQuit=true; +} class DNSIDManager : public boost::noncopyable { @@ -108,7 +110,6 @@ public: { for(unsigned int i=0; i < 65536; ++i) d_available.push_back(i); - } uint16_t peakID() @@ -140,6 +141,31 @@ private: } s_idmanager; +void setSocketBuffer(int fd, int optname, uint32_t size) +{ + uint32_t psize=0; + socklen_t len=sizeof(psize); + + if(!getsockopt(fd, SOL_SOCKET, optname, (char*)&psize, &len) && psize > size) { + cerr<<"Not decreasing socket buffer size from "< qids_t; qids_t qids; - - bool g_throttled; unsigned int s_questions, s_origanswers, s_weanswers, s_wetimedout, s_perfect, s_mostly, s_origtimedout; @@ -176,7 +200,6 @@ unsigned int s_webetter, s_origbetter, s_norecursionavailable; unsigned int s_weunmatched, s_origunmatched; unsigned int s_wednserrors, s_origdnserrors, s_duplicates; - double DiffTime(const struct timeval& first, const struct timeval& second) { int seconds=second.tv_sec - first.tv_sec; @@ -260,16 +283,60 @@ bool isRootReferral(const MOADNSParser::answers_t& answers) return ok; } -void measureResultAndClean(const QuestionIdentifier& qi) +vector flightTimes; +void accountFlightTime(qids_t::const_iterator iter) +{ + if(flightTimes.empty()) + flightTimes.resize(2050); + + struct timeval now; + gettimeofday(&now, 0); + unsigned int mdiff = 1000*DiffTime(iter->d_resentTime, now); + if(mdiff > flightTimes.size()-2) + mdiff= flightTimes.size()-1; + + flightTimes[mdiff]++; +} + +uint64_t countLessThan(unsigned int msec) +{ + uint64_t ret=0; + for(unsigned int i = 0 ; i < msec && i < flightTimes.size() ; ++i) { + ret += flightTimes[i]; + } + return ret; +} + +void emitFlightTimes() { - QuestionData qd=*qids.find(qi); + uint64_t totals = countLessThan(flightTimes.size()); + unsigned int limits[]={1, 2, 3, 4, 5, 10, 20, 30, 40, 50, 100, 200, 500, 1000, flightTimes.size()}; + uint64_t sofar=0; + cout.setf(std::ios::fixed); + cout.precision(2); + for(unsigned int i =0 ; i < sizeof(limits)/sizeof(limits[0]); ++i) { + if(limits[i]!=flightTimes.size()) + cout<<"Within "< canonicOrig, canonicNew; compactAnswerSet(qd.d_origAnswers, canonicOrig); compactAnswerSet(qd.d_newAnswers, canonicNew); if(!g_quiet) { - cout<d_qi; - QuestionData qd=*found; - + + QuestionData qd=*found; // we have to make a copy because we reinsert below qd.d_newAnswers=mdp.d_answers; qd.d_newRcode=mdp.d_header.rcode; idindex.replace(found, qd); if(qd.d_origRcode!=-1) { - // cout<<"Removing entry "<first<<", is done [in socket]"<(found); + measureResultAndClean(iter); } } catch(MOADNSException &e) @@ -374,16 +440,15 @@ try s_wednserrors++; } } - } catch(std::exception& e) { - cerr<<"Receiver thread died: "<qr) { - qd.d_assignedID = s_idmanager.peakID(); + // yes, we send out ALWAYS. Even if we don't do anything with it later, + if(!dh->qr) { // this is to stress out the reference server with all the pain + qd.d_assignedID = s_idmanager.getID(); uint16_t tmp=dh->id; dh->id=htons(qd.d_assignedID); - s_socket->sendTo(string(pr.d_payload, pr.d_payload + pr.d_len), remote); + s_socket->sendTo((const char*)pr.d_payload, pr.d_len, remote); sent=true; dh->id=tmp; } MOADNSParser mdp((const char*)pr.d_payload, pr.d_len); QuestionIdentifier qi=QuestionIdentifier::create(pr.getSource(), pr.getDest(), mdp); - + if(!mdp.d_header.qr) { s_questions++; if(qids.count(qi)) { if(!g_quiet) - cout<<"Saw an exact duplicate question, "<(); + signal(SIGINT, pleaseQuitHandler); float speedup=g_vm["speedup"].as(); g_timeoutMsec=g_vm["timeout-msec"].as(); @@ -610,7 +671,9 @@ try s_socket= new Socket(InterNetwork, Datagram); s_socket->setNonBlocking(); - + setSocketReceiveBuffer(s_socket->getHandle(), 2000000); + setSocketSendBuffer(s_socket->getHandle(), 2000000); + ComboAddress remote(g_vm["target-ip"].as(), g_vm["target-port"].as()); @@ -625,6 +688,10 @@ try unsigned int count=0; for(;;) { + if(g_pleaseQuit) { + cerr<<"Interrupted from terminal"<