Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(854)

Side by Side Diff: net/dns/dns_transaction.cc

Issue 9369045: [net] HostResolverImpl + DnsTransaction + DnsConfigService = Asynchronous DNS ready for experiments. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased to master. Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/dns_transaction.h" 5 #include "net/dns/dns_transaction.h"
6 6
7 #include <deque> 7 #include <deque>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 71
72 class ResponseParameters : public NetLog::EventParameters { 72 class ResponseParameters : public NetLog::EventParameters {
73 public: 73 public:
74 ResponseParameters(int rcode, int answer_count, const NetLog::Source& source) 74 ResponseParameters(int rcode, int answer_count, const NetLog::Source& source)
75 : rcode_(rcode), answer_count_(answer_count), source_(source) {} 75 : rcode_(rcode), answer_count_(answer_count), source_(source) {}
76 76
77 virtual Value* ToValue() const OVERRIDE { 77 virtual Value* ToValue() const OVERRIDE {
78 DictionaryValue* dict = new DictionaryValue(); 78 DictionaryValue* dict = new DictionaryValue();
79 dict->SetInteger("rcode", rcode_); 79 dict->SetInteger("rcode", rcode_);
80 dict->SetInteger("answer_count", answer_count_); 80 dict->SetInteger("answer_count", answer_count_);
81 dict->Set("socket_source", source_.ToValue()); 81 dict->Set("source_dependency", source_.ToValue());
82 return dict; 82 return dict;
83 } 83 }
84 84
85 private: 85 private:
86 const int rcode_; 86 const int rcode_;
87 const int answer_count_; 87 const int answer_count_;
88 const NetLog::Source source_; 88 const NetLog::Source source_;
89 }; 89 };
90 90
91 // ---------------------------------------------------------------------------- 91 // ----------------------------------------------------------------------------
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 base::Bind(&DnsUDPAttempt::OnIOComplete, 204 base::Bind(&DnsUDPAttempt::OnIOComplete,
205 base::Unretained(this))); 205 base::Unretained(this)));
206 } 206 }
207 207
208 int DoReadResponseComplete(int rv) { 208 int DoReadResponseComplete(int rv) {
209 DCHECK_NE(ERR_IO_PENDING, rv); 209 DCHECK_NE(ERR_IO_PENDING, rv);
210 if (rv < 0) 210 if (rv < 0)
211 return rv; 211 return rv;
212 212
213 DCHECK(rv); 213 DCHECK(rv);
214 if (!response_->InitParse(rv, *query_)) 214 if (!response_->InitParse(rv, *query_)) {
215 // TODO(szym): Consider making this reaction less aggressive.
216 // Other implementations simply ignore mismatched responses. Since each
217 // DnsUDPAttempt binds to a different port, we might find that responses
218 // to previously timed out queries lead to failures in the future.
219 // http://crbug.com/107413
215 return ERR_DNS_MALFORMED_RESPONSE; 220 return ERR_DNS_MALFORMED_RESPONSE;
221 }
216 if (response_->flags() & dns_protocol::kFlagTC) 222 if (response_->flags() & dns_protocol::kFlagTC)
217 return ERR_DNS_SERVER_REQUIRES_TCP; 223 return ERR_DNS_SERVER_REQUIRES_TCP;
218 if (response_->rcode() != dns_protocol::kRcodeNOERROR && 224 if (response_->rcode() != dns_protocol::kRcodeNOERROR &&
219 response_->rcode() != dns_protocol::kRcodeNXDOMAIN) { 225 response_->rcode() != dns_protocol::kRcodeNXDOMAIN) {
220 return ERR_DNS_SERVER_FAILED; 226 return ERR_DNS_SERVER_FAILED;
221 } 227 }
222 if (response_->answer_count() == 0) 228 if (response_->answer_count() == 0)
223 return ERR_NAME_NOT_RESOLVED; 229 return ERR_NAME_NOT_RESOLVED;
224 230
225 return OK; 231 return OK;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 } 302 }
297 303
298 virtual int Start() OVERRIDE { 304 virtual int Start() OVERRIDE {
299 int rv = PrepareSearch(); 305 int rv = PrepareSearch();
300 if (rv == OK) 306 if (rv == OK)
301 rv = StartQuery(); 307 rv = StartQuery();
302 DCHECK_NE(OK, rv); 308 DCHECK_NE(OK, rv);
303 return rv; 309 return rv;
304 } 310 }
305 311
312 virtual const BoundNetLog& net_log() const {
mmenke 2012/02/15 19:54:16 nit: OVERRIDE
313 return net_log_;
314 }
315
306 private: 316 private:
307 // Prepares |qnames_| according to the DnsConfig. 317 // Prepares |qnames_| according to the DnsConfig.
308 int PrepareSearch() { 318 int PrepareSearch() {
309 const DnsConfig& config = session_->config(); 319 const DnsConfig& config = session_->config();
310 320
311 std::string labeled_hostname; 321 std::string labeled_hostname;
312 if (!DNSDomainFromDot(hostname_, &labeled_hostname)) 322 if (!DNSDomainFromDot(hostname_, &labeled_hostname))
313 return ERR_INVALID_ARGUMENT; 323 return ERR_INVALID_ARGUMENT;
314 324
315 if (hostname_[hostname_.size() - 1] == '.') { 325 if (hostname_[hostname_.size() - 1] == '.') {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 390
381 uint16 id = session_->NextQueryId(); 391 uint16 id = session_->NextQueryId();
382 scoped_ptr<DnsQuery> query; 392 scoped_ptr<DnsQuery> query;
383 if (attempts_.empty()) { 393 if (attempts_.empty()) {
384 query.reset(new DnsQuery(id, qnames_.front(), qtype_)); 394 query.reset(new DnsQuery(id, qnames_.front(), qtype_));
385 } else { 395 } else {
386 query.reset(attempts_[0]->query()->CloneWithNewId(id)); 396 query.reset(attempts_[0]->query()->CloneWithNewId(id));
387 } 397 }
388 398
389 net_log_.AddEvent(NetLog::TYPE_DNS_TRANSACTION_ATTEMPT, make_scoped_refptr( 399 net_log_.AddEvent(NetLog::TYPE_DNS_TRANSACTION_ATTEMPT, make_scoped_refptr(
390 new NetLogSourceParameter("socket_source", socket->NetLog().source()))); 400 new NetLogSourceParameter("source_dependency",
401 socket->NetLog().source())));
391 402
392 const DnsConfig& config = session_->config(); 403 const DnsConfig& config = session_->config();
393 404
394 unsigned server_index = first_server_index_ + 405 unsigned server_index = first_server_index_ +
395 (attempt_number % config.nameservers.size()); 406 (attempt_number % config.nameservers.size());
396 407
397 DnsUDPAttempt* attempt = new DnsUDPAttempt( 408 DnsUDPAttempt* attempt = new DnsUDPAttempt(
398 socket.Pass(), 409 socket.Pass(),
399 config.nameservers[server_index], 410 config.nameservers[server_index],
400 query.Pass(), 411 query.Pass(),
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 qnames_.pop_front(); 455 qnames_.pop_front();
445 if (qnames_.empty()) 456 if (qnames_.empty())
446 rv = ERR_NAME_NOT_RESOLVED; 457 rv = ERR_NAME_NOT_RESOLVED;
447 else 458 else
448 rv = StartQuery(); 459 rv = StartQuery();
449 break; 460 break;
450 case OK: 461 case OK:
451 DoCallback(rv, attempt); 462 DoCallback(rv, attempt);
452 return; 463 return;
453 default: 464 default:
454 // TODO(szym): Some nameservers could fail so try the next one. 465 // Some nameservers could fail so try the next one.
455 const DnsConfig& config = session_->config(); 466 const DnsConfig& config = session_->config();
456 if (attempts_.size() < config.attempts * config.nameservers.size()) { 467 if (attempts_.size() < config.attempts * config.nameservers.size()) {
457 rv = MakeAttempt(); 468 rv = MakeAttempt();
458 } else { 469 } else {
459 // TODO(szym): Should this be different than the timeout case? 470 // TODO(szym): Should this be different than the timeout case?
460 rv = ERR_DNS_SERVER_FAILED; 471 rv = ERR_DNS_SERVER_FAILED;
461 } 472 }
462 break; 473 break;
463 } 474 }
464 if (rv != ERR_IO_PENDING) 475 if (rv != ERR_IO_PENDING)
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 539
529 // static 540 // static
530 scoped_ptr<DnsTransactionFactory> DnsTransactionFactory::CreateFactory( 541 scoped_ptr<DnsTransactionFactory> DnsTransactionFactory::CreateFactory(
531 DnsSession* session) { 542 DnsSession* session) {
532 return scoped_ptr<DnsTransactionFactory>( 543 return scoped_ptr<DnsTransactionFactory>(
533 new DnsTransactionFactoryImpl(session)); 544 new DnsTransactionFactoryImpl(session));
534 } 545 }
535 546
536 } // namespace net 547 } // namespace net
537 548
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698