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

Side by Side Diff: net/dns/dns_client.h

Issue 9190031: DnsClient refactoring + features (timeout, suffix search, server rotation). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added comments. Fixed tests. 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 #ifndef NET_DNS_DNS_CLIENT_H_ 5 #ifndef NET_DNS_DNS_CLIENT_H_
6 #define NET_DNS_DNS_CLIENT_H_ 6 #define NET_DNS_DNS_CLIENT_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/callback.h" 12 #include "base/callback_forward.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/string_piece.h"
15 #include "net/base/net_export.h" 14 #include "net/base/net_export.h"
16 15
17 namespace net { 16 namespace net {
18 17
19 class BoundNetLog; 18 class BoundNetLog;
20 class ClientSocketFactory;
21 class DnsResponse; 19 class DnsResponse;
22 class DnsSession; 20 class DnsSession;
23 21
24 // DnsClient performs asynchronous DNS queries. DnsClient takes care of 22 // The DnsTransaction takes care of retransmissions, DNS server fallback (or
25 // retransmissions, DNS server fallback (or round-robin), suffix search, and 23 // round-robin), suffix search, and simple response validation ("does it match
26 // simple response validation ("does it match the query") to fight poisoning. 24 // the query") to fight poisoning.
25 //
26 // Destroying DnsTransaction cancels the underlying network effort.
27 class NET_EXPORT_PRIVATE DnsTransaction {
28 public:
29 virtual ~DnsTransaction() {}
30
31 // Returns the original |hostname|.
32 virtual const std::string& GetHostname() const = 0;
33 // Returns the |qtype|.
cbentzel 2012/01/13 13:39:54 Nit: extra newline before this comment.
34 virtual uint16 GetType() const = 0;
35 };
36
37 // Creates DnsTransaction which performs asynchronous DNS search.
27 // It does NOT perform caching, aggregation or prioritization of requests. 38 // It does NOT perform caching, aggregation or prioritization of requests.
28 // 39 //
29 // Destroying DnsClient does NOT affect any already created Requests. 40 // Destroying DnsClient does NOT affect any already created DnsTransactions.
30 //
31 // TODO(szym): consider adding flags to MakeRequest to indicate options:
32 // -- don't perform suffix search
33 // -- query both A and AAAA at once
34 // -- accept truncated response (and/or forbid TCP)
35 class NET_EXPORT_PRIVATE DnsClient { 41 class NET_EXPORT_PRIVATE DnsClient {
cbentzel 2012/01/13 13:39:54 I wonder if this should just be called DnsTransact
36 public: 42 public:
37 class Request; 43 // Called with the response or NULL if no matching response was received.
38 // Callback for complete requests. Note that DnsResponse might be NULL if 44 // Note that the |qname| of the response may be different than |hostname|
39 // the DNS server(s) could not be reached. 45 // as a result of suffix search.
40 typedef base::Callback<void(Request* req, 46 typedef base::Callback<void(DnsTransaction* transaction,
41 int result, 47 int neterror,
42 const DnsResponse* resp)> RequestCallback; 48 const DnsResponse* response)> CallbackType;
43
44 // A data-holder for a request made to the DnsClient.
45 // Destroying the request cancels the underlying network effort.
46 class NET_EXPORT_PRIVATE Request {
47 public:
48 Request(const base::StringPiece& qname,
49 uint16 qtype,
50 const RequestCallback& callback);
51 virtual ~Request();
52
53 const std::string& qname() const { return qname_; }
54
55 uint16 qtype() const { return qtype_; }
56
57 virtual int Start() = 0;
58
59 void DoCallback(int result, const DnsResponse* response) {
60 callback_.Run(this, result, response);
61 }
62
63 private:
64 std::string qname_;
65 uint16 qtype_;
66 RequestCallback callback_;
67
68 DISALLOW_COPY_AND_ASSIGN(Request);
69 };
70 49
71 virtual ~DnsClient() {} 50 virtual ~DnsClient() {}
72 51
73 // Makes asynchronous DNS query for the given |qname| and |qtype| (assuming 52 // Creates DnsTransaction for the given |hostname| and |qtype| (assuming
74 // QCLASS == IN). The caller is responsible for destroying the returned 53 // QCLASS is IN). The transaction will run |callback| upon asynchronous
75 // request whether to cancel it or after its completion. 54 // completion. Uses the source of |source_net_log| as source dependency.
cbentzel 2012/01/13 13:39:54 It would be worth pointing out that |hostname| mus
szym 2012/01/13 15:43:40 I'll add DCHECKs. For requests that can complete s
76 // (Destroying DnsClient does not abort the requests.) 55 virtual scoped_ptr<DnsTransaction> CreateTransaction(
77 virtual Request* CreateRequest( 56 const std::string& hostname,
78 const base::StringPiece& qname,
79 uint16 qtype, 57 uint16 qtype,
80 const RequestCallback& callback, 58 const CallbackType& callback,
81 const BoundNetLog& source_net_log) WARN_UNUSED_RESULT = 0; 59 const BoundNetLog& source_net_log) WARN_UNUSED_RESULT = 0;
82 60
83 // Creates a socket-based DnsClient using the |session|. 61 // Creates a socket-based DnsClient using the |session|.
84 static DnsClient* CreateClient(DnsSession* session) WARN_UNUSED_RESULT; 62 static scoped_ptr<DnsClient> CreateClient(
63 DnsSession* session) WARN_UNUSED_RESULT;
85 }; 64 };
86 65
87 } // namespace net 66 } // namespace net
88 67
89 #endif // NET_DNS_DNS_CLIENT_H_ 68 #endif // NET_DNS_DNS_CLIENT_H_
90 69
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698