OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/dns/mdns_client_impl.h" | 5 #include "net/dns/mdns_client_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop_proxy.h" | 8 #include "base/message_loop/message_loop_proxy.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/time/default_clock.h" | 10 #include "base/time/default_clock.h" |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 | 195 |
196 void MDnsClientImpl::Core::HandlePacket(DnsResponse* response, | 196 void MDnsClientImpl::Core::HandlePacket(DnsResponse* response, |
197 int bytes_read) { | 197 int bytes_read) { |
198 unsigned offset; | 198 unsigned offset; |
199 // Note: We store cache keys rather than record pointers to avoid | 199 // Note: We store cache keys rather than record pointers to avoid |
200 // erroneous behavior in case a packet contains multiple exclusive | 200 // erroneous behavior in case a packet contains multiple exclusive |
201 // records with the same type and name. | 201 // records with the same type and name. |
202 std::map<MDnsCache::Key, MDnsCache::UpdateType> update_keys; | 202 std::map<MDnsCache::Key, MDnsCache::UpdateType> update_keys; |
203 | 203 |
204 if (!response->InitParseWithoutQuery(bytes_read)) { | 204 if (!response->InitParseWithoutQuery(bytes_read)) { |
205 LOG(WARNING) << "Could not understand an mDNS packet."; | 205 DVLOG(1) << "Could not understand an mDNS packet."; |
206 return; // Message is unreadable. | 206 return; // Message is unreadable. |
207 } | 207 } |
208 | 208 |
209 // TODO(noamsml): duplicate query suppression. | 209 // TODO(noamsml): duplicate query suppression. |
210 if (!(response->flags() & dns_protocol::kFlagResponse)) | 210 if (!(response->flags() & dns_protocol::kFlagResponse)) |
211 return; // Message is a query. ignore it. | 211 return; // Message is a query. ignore it. |
212 | 212 |
213 DnsRecordParser parser = response->Parser(); | 213 DnsRecordParser parser = response->Parser(); |
214 unsigned answer_count = response->answer_count() + | 214 unsigned answer_count = response->answer_count() + |
215 response->additional_answer_count(); | 215 response->additional_answer_count(); |
216 | 216 |
217 for (unsigned i = 0; i < answer_count; i++) { | 217 for (unsigned i = 0; i < answer_count; i++) { |
218 offset = parser.GetOffset(); | 218 offset = parser.GetOffset(); |
219 scoped_ptr<const RecordParsed> record = RecordParsed::CreateFrom( | 219 scoped_ptr<const RecordParsed> record = RecordParsed::CreateFrom( |
220 &parser, base::Time::Now()); | 220 &parser, base::Time::Now()); |
221 | 221 |
222 if (!record) { | 222 if (!record) { |
223 LOG(WARNING) << "Could not understand an mDNS record."; | 223 DVLOG(1) << "Could not understand an mDNS record."; |
224 | 224 |
225 if (offset == parser.GetOffset()) { | 225 if (offset == parser.GetOffset()) { |
226 LOG(WARNING) << "Abandoned parsing the rest of the packet."; | 226 DVLOG(1) << "Abandoned parsing the rest of the packet."; |
227 return; // The parser did not advance, abort reading the packet. | 227 return; // The parser did not advance, abort reading the packet. |
228 } else { | 228 } else { |
229 continue; // We may be able to extract other records from the packet. | 229 continue; // We may be able to extract other records from the packet. |
230 } | 230 } |
231 } | 231 } |
232 | 232 |
233 if ((record->klass() & dns_protocol::kMDnsClassMask) != | 233 if ((record->klass() & dns_protocol::kMDnsClassMask) != |
234 dns_protocol::kClassIN) { | 234 dns_protocol::kClassIN) { |
235 LOG(WARNING) << "Received an mDNS record with non-IN class. Ignoring."; | 235 DVLOG(1) << "Received an mDNS record with non-IN class. Ignoring."; |
236 continue; // Ignore all records not in the IN class. | 236 continue; // Ignore all records not in the IN class. |
237 } | 237 } |
238 | 238 |
239 MDnsCache::Key update_key = MDnsCache::Key::CreateFor(record.get()); | 239 MDnsCache::Key update_key = MDnsCache::Key::CreateFor(record.get()); |
240 MDnsCache::UpdateType update = cache_.UpdateDnsRecord(record.Pass()); | 240 MDnsCache::UpdateType update = cache_.UpdateDnsRecord(record.Pass()); |
241 | 241 |
242 // Cleanup time may have changed. | 242 // Cleanup time may have changed. |
243 ScheduleCleanup(cache_.next_expiration()); | 243 ScheduleCleanup(cache_.next_expiration()); |
244 | 244 |
245 update_keys.insert(std::make_pair(update_key, update)); | 245 update_keys.insert(std::make_pair(update_key, update)); |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 | 701 |
702 void MDnsTransactionImpl::OnNsecRecord(const std::string& name, unsigned type) { | 702 void MDnsTransactionImpl::OnNsecRecord(const std::string& name, unsigned type) { |
703 TriggerCallback(RESULT_NSEC, NULL); | 703 TriggerCallback(RESULT_NSEC, NULL); |
704 } | 704 } |
705 | 705 |
706 void MDnsTransactionImpl::OnCachePurged() { | 706 void MDnsTransactionImpl::OnCachePurged() { |
707 // TODO(noamsml): Cache purge situations not yet implemented | 707 // TODO(noamsml): Cache purge situations not yet implemented |
708 } | 708 } |
709 | 709 |
710 } // namespace net | 710 } // namespace net |
OLD | NEW |