Changeset 701

Show
Ignore:
Timestamp:
04/14/06 17:43:31 (4 years ago)
Author:
ahu
Message:

make it work

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/pdns/pdns/dnsreplay-mindex.cc

    r608 r701  
    114114  } 
    115115 
    116   uint16_t getID() 
     116  uint16_t peakID() 
    117117  { 
    118118    uint16_t ret; 
    119119    if(!d_available.empty()) { 
    120120      ret=d_available.front(); 
    121       d_available.pop_front(); 
    122121      return ret; 
    123122    } 
    124123    else 
    125124      throw runtime_error("out of ids!"); // XXX FIXME 
     125  } 
     126 
     127  uint16_t getID() 
     128  { 
     129    uint16_t ret=peakID(); 
     130    d_available.pop_front(); 
     131    return ret; 
    126132  } 
    127133 
     
    326332      qids_by_id_index_t::const_iterator found=idindex.find(ntohs(mdp.d_header.id)); 
    327333      if(found == idindex.end()) { 
    328         cout<<"Received an answer ("<<mdp.d_qname<<") from reference nameserver with id "<<mdp.d_header.id<<" which we can't match to a question!"<<endl; 
     334//      cout<<"Received an answer ("<<mdp.d_qname<<") from reference nameserver with id "<<mdp.d_header.id<<" which we can't match to a question!"<<endl; 
    329335        s_weunmatched++; 
    330336        continue; 
     
    453459  if((ntohs(pr.d_udp->uh_dport)!=53 && ntohs(pr.d_udp->uh_sport)!=53) || !dh->rd || (unsigned int)pr.d_len <= sizeof(HEADER)) 
    454460    return; 
    455    
     461  QuestionData qd; 
    456462  try { 
     463    dnsheader* dh=(dnsheader*)pr.d_payload; 
     464    if(!dh->qr) { 
     465      qd.d_assignedID = s_idmanager.peakID(); 
     466      uint16_t tmp=dh->id; 
     467      dh->id=htons(qd.d_assignedID); 
     468      s_socket->sendTo(string(pr.d_payload, pr.d_payload + pr.d_len), remote); 
     469      dh->id=tmp; 
     470    } 
    457471    MOADNSParser mdp((const char*)pr.d_payload, pr.d_len); 
    458472    QuestionIdentifier qi=QuestionIdentifier::create(pr.d_ip, pr.d_udp, mdp); 
     
    465479        return; 
    466480      } 
    467        
    468481      // new question! 
    469  
    470       QuestionData qd; 
    471482      qd.d_qi=qi; 
    472483      gettimeofday(&qd.d_resentTime,0); 
    473        
    474484      qd.d_assignedID = s_idmanager.getID(); 
    475        
    476485      qids.insert(qd); 
    477  
    478       dh->id=htons(qd.d_assignedID); 
    479  
    480 #if 0 
    481       if(lastsent.tv_sec && (!(s_questions%25))) { 
    482         double seconds=pr.d_pheader.ts.tv_sec - lastsent.tv_sec; 
    483         double useconds=(pr.d_pheader.ts.tv_usec - lastsent.tv_usec); 
    484          
    485         if(useconds < 0) { 
    486           seconds-=1; 
    487           useconds+=1000000; 
    488         } 
    489          
    490         double factor=10; 
    491          
    492         seconds/=factor; 
    493         useconds/=factor; 
    494          
    495         long long nanoseconds=(long long)(1000000000ULL*seconds + useconds * 1000); 
    496          
    497         struct timespec tosleep; 
    498         tosleep.tv_sec=nanoseconds/1000000000UL; 
    499         tosleep.tv_nsec=nanoseconds%1000000000UL; 
    500          
    501         nanosleep(&tosleep, 0); 
    502         lastsent=pr.d_pheader.ts; 
    503       } 
    504       if(!lastsent.tv_sec) 
    505         lastsent=pr.d_pheader.ts; 
    506        
    507       //        cout<<"sending!"<<endl; 
    508 #endif 
    509       s_socket->sendTo(string(pr.d_payload, pr.d_payload + pr.d_len), remote); 
    510486    } 
    511487    else { 
     
    600576    gettimeofday(&now, 0); 
    601577 
    602     mental_time= mental_time + 3*(now-then); 
     578    mental_time= mental_time + 1*(now-then); 
    603579  } 
    604580 out:;