Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| 6 #define NET_DNS_DNS_CLIENT_H_ | 6 #ifndef NET_DNS_DNS_TRANSACTION_H_ |
|
cbentzel
2012/01/13 22:17:25
This needs to move file names for these guards to
| |
| 7 #define NET_DNS_DNS_TRANSACTION_H_ | |
| 7 #pragma once | 8 #pragma once |
| 8 | 9 |
| 9 #include <string> | 10 #include <string> |
| 10 | 11 |
| 11 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 12 #include "base/callback.h" | 13 #include "base/callback_forward.h" |
| 13 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/string_piece.h" | |
| 15 #include "net/base/net_export.h" | 15 #include "net/base/net_export.h" |
| 16 | 16 |
| 17 namespace net { | 17 namespace net { |
| 18 | 18 |
| 19 class BoundNetLog; | 19 class BoundNetLog; |
| 20 class ClientSocketFactory; | |
| 21 class DnsResponse; | 20 class DnsResponse; |
| 22 class DnsSession; | 21 class DnsSession; |
| 23 | 22 |
| 24 // DnsClient performs asynchronous DNS queries. DnsClient takes care of | 23 // DnsTransaction implements a stub DNS resolver as defined in RFC 1034. |
| 25 // retransmissions, DNS server fallback (or round-robin), suffix search, and | 24 // The DnsTransaction takes care of retransmissions, name server fallback (or |
| 26 // simple response validation ("does it match the query") to fight poisoning. | 25 // round-robin), suffix search, and simple response validation ("does it match |
| 27 // It does NOT perform caching, aggregation or prioritization of requests. | 26 // the query") to fight poisoning. |
|
cbentzel
2012/01/13 22:17:25
I'd move the "It does not do caching" comment up h
| |
| 28 // | 27 // |
| 29 // Destroying DnsClient does NOT affect any already created Requests. | 28 // Destroying DnsTransaction cancels the underlying network effort. |
| 29 class NET_EXPORT_PRIVATE DnsTransaction { | |
| 30 public: | |
| 31 virtual ~DnsTransaction() {} | |
| 32 | |
| 33 // Returns the original |hostname|. | |
| 34 virtual const std::string& GetHostname() const = 0; | |
| 35 | |
| 36 // Returns the |qtype|. | |
| 37 virtual uint16 GetType() const = 0; | |
| 38 | |
| 39 // Starts the transaction. Returns the net error on synchronous failure or | |
| 40 // ERR_IO_PENDING in which case the result will be passed via the callback. | |
|
cbentzel
2012/01/13 22:17:25
"The callback" isn't really defined as part of the
szym
2012/01/13 22:32:44
I'm fine either way. The benefit of having it in t
| |
| 41 virtual int Start() = 0; | |
| 42 }; | |
| 43 | |
| 44 // Creates DnsTransaction which performs asynchronous DNS search. | |
| 45 // It does NOT perform caching, aggregation or prioritization of transactions. | |
| 30 // | 46 // |
| 31 // TODO(szym): consider adding flags to MakeRequest to indicate options: | 47 // Destroying the factory does NOT affect any already created DnsTransactions. |
| 32 // -- don't perform suffix search | 48 class NET_EXPORT_PRIVATE DnsTransactionFactory { |
| 33 // -- query both A and AAAA at once | |
| 34 // -- accept truncated response (and/or forbid TCP) | |
| 35 class NET_EXPORT_PRIVATE DnsClient { | |
| 36 public: | 49 public: |
| 37 class Request; | 50 // Called with the response or NULL if no matching response was received. |
| 38 // Callback for complete requests. Note that DnsResponse might be NULL if | 51 // Note that the |GetDottedName()| of the response may be different than the |
| 39 // the DNS server(s) could not be reached. | 52 // original |hostname| as a result of suffix search. |
| 40 typedef base::Callback<void(Request* req, | 53 typedef base::Callback<void(DnsTransaction* transaction, |
| 41 int result, | 54 int neterror, |
| 42 const DnsResponse* resp)> RequestCallback; | 55 const DnsResponse* response)> CallbackType; |
| 43 | 56 |
| 44 // A data-holder for a request made to the DnsClient. | 57 virtual ~DnsTransactionFactory() {} |
| 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 | 58 |
| 53 const std::string& qname() const { return qname_; } | 59 // Creates DnsTransaction for the given |hostname| and |qtype| (assuming |
| 54 | 60 // QCLASS is IN). |hostname| should be in the dotted form. A dot at the end |
| 55 uint16 qtype() const { return qtype_; } | 61 // implies the domain name is fully-qualified and will be exempt from suffix |
| 56 | 62 // search. |hostname| should not be an IP literal. |
| 57 virtual int Start() = 0; | 63 // |
| 58 | 64 // The transaction will run |callback| upon asynchronous completion. |
| 59 void DoCallback(int result, const DnsResponse* response) { | 65 // The source of |source_net_log| is used as source dependency in log. |
| 60 callback_.Run(this, result, response); | 66 virtual scoped_ptr<DnsTransaction> CreateTransaction( |
| 61 } | 67 const std::string& hostname, |
| 62 | |
| 63 private: | |
| 64 std::string qname_; | |
| 65 uint16 qtype_; | |
| 66 RequestCallback callback_; | |
| 67 | |
| 68 DISALLOW_COPY_AND_ASSIGN(Request); | |
| 69 }; | |
| 70 | |
| 71 virtual ~DnsClient() {} | |
| 72 | |
| 73 // Makes asynchronous DNS query for the given |qname| and |qtype| (assuming | |
| 74 // QCLASS == IN). The caller is responsible for destroying the returned | |
| 75 // request whether to cancel it or after its completion. | |
| 76 // (Destroying DnsClient does not abort the requests.) | |
| 77 virtual Request* CreateRequest( | |
| 78 const base::StringPiece& qname, | |
| 79 uint16 qtype, | 68 uint16 qtype, |
| 80 const RequestCallback& callback, | 69 const CallbackType& callback, |
| 81 const BoundNetLog& source_net_log) WARN_UNUSED_RESULT = 0; | 70 const BoundNetLog& source_net_log) WARN_UNUSED_RESULT = 0; |
| 82 | 71 |
| 83 // Creates a socket-based DnsClient using the |session|. | 72 // Creates a DnsTransactionFactory which creates DnsTransactionImpl using the |
| 84 static DnsClient* CreateClient(DnsSession* session) WARN_UNUSED_RESULT; | 73 // |session|. |
| 74 static scoped_ptr<DnsTransactionFactory> CreateFactory( | |
| 75 DnsSession* session) WARN_UNUSED_RESULT; | |
| 85 }; | 76 }; |
| 86 | 77 |
| 87 } // namespace net | 78 } // namespace net |
| 88 | 79 |
| 89 #endif // NET_DNS_DNS_CLIENT_H_ | 80 #endif // NET_DNS_DNS_TRANSACTION_H_ |
| 90 | 81 |
| OLD | NEW |