Changeset 925
- Timestamp:
- 12/14/06 21:10:48 (2 years ago)
- Files:
-
- trunk/pdns/pdns/dnswriter.cc (modified) (6 diffs)
- trunk/pdns/pdns/dnswriter.hh (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/pdns/pdns/dnswriter.cc
r803 r925 42 42 43 43 d_stuff=0xffff; 44 d_labelmap.reserve(16); 44 45 } 45 46 … … 64 65 d_rollbackmarker=d_content.size(); 65 66 66 xfrLabel(d_recordqname, true); 67 d_content.insert(d_content.end(), d_record.begin(), d_record.end()); 68 d_record.clear(); 69 67 if(d_qname == d_recordqname) { // don't do the whole label compression thing if we *know* we can get away with "see question" 68 static char marker[2]={0xc0, 0x0c}; 69 d_content.insert(d_content.end(), &marker[0], &marker[2]); 70 } 71 else { 72 xfrLabel(d_recordqname, true); 73 d_content.insert(d_content.end(), d_record.begin(), d_record.end()); 74 d_record.clear(); 75 } 76 70 77 d_stuff = sizeof(dnsrecordheader); // this is needed to get compressed label offsets right, the dnsrecordheader will be interspersed 71 78 d_sor=d_content.size() + d_stuff; // start of real record … … 115 122 } 116 123 117 // this is the absolute hottest function in the pdns recursor 124 DNSPacketWriter::lmap_t::iterator find(DNSPacketWriter::lmap_t& lmap, const string& label) 125 { 126 DNSPacketWriter::lmap_t::iterator ret; 127 for(ret=lmap.begin(); ret != lmap.end(); ++ret) 128 if(ret->first == label) 129 break; 130 return ret; 131 } 132 133 // this is the absolute hottest function in the pdns recursor 118 134 void DNSPacketWriter::xfrLabel(const string& label, bool compress) 119 135 { … … 128 144 for(parts_t::const_iterator i=parts.begin(); i!=parts.end(); ++i) { 129 145 // cerr<<"chopped: '"<<chopped<<"'\n"; 130 map<string, uint16_t>::iterator li=d_labelmap.end();146 lmap_t::iterator li=d_labelmap.end(); 131 147 // see if we've written out this domain before 132 if(compress && (li= d_labelmap.find(chopped))!=d_labelmap.end()) {148 if(compress && (li=find(d_labelmap, chopped))!=d_labelmap.end()) { 133 149 uint16_t offset=li->second; 134 150 offset|=0xc000; … … 139 155 140 156 if(li==d_labelmap.end() && pos< 16384) 141 d_labelmap [chopped]=pos; // if untrue, we need to count - also, don't store offsets > 16384, won't work142 157 d_labelmap.push_back(make_pair(chopped, pos)); // if untrue, we need to count - also, don't store offsets > 16384, won't work 158 143 159 d_record.push_back((char)(i->second - i->first)); 144 160 unsigned int len=d_record.size(); … … 147 163 // cerr<<"Added: '"<<string(label.c_str() + i->first, i->second - i->first) <<"'\n"; 148 164 pos+=(i->second - i->first)+1; 149 chopOff(chopped); // www.powerdns.com. -> powerdns.com. -> com. -> . 165 166 if(i+1 != parts.end()) 167 chopOff(chopped); // www.powerdns.com. -> powerdns.com. -> com. -> . 150 168 } 151 169 d_record.push_back(0); trunk/pdns/pdns/dnswriter.hh
r802 r925 41 41 class DNSPacketWriter 42 42 { 43 43 44 public: 45 typedef vector<pair<string, uint16_t> > lmap_t; 44 46 enum Place {ANSWER=1, AUTHORITY=2, ADDITIONAL=3}; 45 47 … … 99 101 uint16_t d_recordqtype, d_recordqclass; 100 102 uint32_t d_recordttl; 101 map<string, uint16_t>d_labelmap;103 lmap_t d_labelmap; 102 104 uint16_t d_stuff; 103 105 uint16_t d_sor;