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

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

Issue 9190031: DnsClient refactoring + features (timeout, suffix search, server rotation). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed code review. Created 8 years, 11 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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. BUG=110197
cbentzel 2012/01/21 03:41:16 Nit: direct link to crbug.com is more common than
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698