| OLD | NEW |
| 1 // Copyright (c) 2011 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_session.h" | 5 #include "net/dns/dns_session.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "net/base/ip_endpoint.h" | 10 #include "net/base/ip_endpoint.h" |
| 11 #include "net/dns/dns_config_service.h" | 11 #include "net/dns/dns_config_service.h" |
| 12 #include "net/socket/client_socket_factory.h" | 12 #include "net/socket/client_socket_factory.h" |
| 13 | 13 |
| 14 namespace net { | 14 namespace net { |
| 15 | 15 |
| 16 DnsSession::DnsSession(const DnsConfig& config, | 16 DnsSession::DnsSession(const DnsConfig& config, |
| 17 ClientSocketFactory* factory, | 17 ClientSocketFactory* factory, |
| 18 const RandIntCallback& rand_int_callback, | 18 const RandIntCallback& rand_int_callback, |
| 19 NetLog* net_log) | 19 NetLog* net_log) |
| 20 : config_(config), | 20 : config_(config), |
| 21 socket_factory_(factory), | 21 socket_factory_(factory), |
| 22 rand_callback_(base::Bind(rand_int_callback, 0, kuint16max)), | 22 rand_callback_(base::Bind(rand_int_callback, 0, kuint16max)), |
| 23 net_log_(net_log), | 23 net_log_(net_log), |
| 24 server_index_(0) { | 24 server_index_(0) { |
| 25 } | 25 } |
| 26 | 26 |
| 27 int DnsSession::NextId() const { | 27 int DnsSession::NextQueryId() const { |
| 28 return rand_callback_.Run(); | 28 return rand_callback_.Run(); |
| 29 } | 29 } |
| 30 | 30 |
| 31 const IPEndPoint& DnsSession::NextServer() { | 31 int DnsSession::NextFirstServerIndex() { |
| 32 // TODO(szym): Rotate servers on failures. | 32 int index = server_index_; |
| 33 const IPEndPoint& ipe = config_.nameservers[server_index_]; | |
| 34 if (config_.rotate) | 33 if (config_.rotate) |
| 35 server_index_ = (server_index_ + 1) % config_.nameservers.size(); | 34 server_index_ = (server_index_ + 1) % config_.nameservers.size(); |
| 36 return ipe; | 35 return index; |
| 37 } | 36 } |
| 38 | 37 |
| 39 base::TimeDelta DnsSession::NextTimeout(int attempt) { | 38 base::TimeDelta DnsSession::NextTimeout(int attempt) { |
| 40 // TODO(szym): Adapt timeout to observed RTT. | 39 // The timeout doubles every full round (each nameserver once). |
| 41 return config_.timeout * (attempt + 1); | 40 // TODO(szym): Adapt timeout to observed RTT. http://crbug.com/110197 |
| 41 return config_.timeout * (1 << (attempt / config_.nameservers.size())); |
| 42 } | 42 } |
| 43 | 43 |
| 44 DnsSession::~DnsSession() {} | 44 DnsSession::~DnsSession() {} |
| 45 | 45 |
| 46 } // namespace net | 46 } // namespace net |
| 47 | 47 |
| OLD | NEW |