OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 COMPONENTS_CERTIFICATE_TRANSPARENCY_LOG_DNS_CLIENT_H_ | 5 #ifndef COMPONENTS_CERTIFICATE_TRANSPARENCY_LOG_DNS_CLIENT_H_ |
6 #define COMPONENTS_CERTIFICATE_TRANSPARENCY_LOG_DNS_CLIENT_H_ | 6 #define COMPONENTS_CERTIFICATE_TRANSPARENCY_LOG_DNS_CLIENT_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <list> | 10 #include <list> |
(...skipping 23 matching lines...) Expand all Loading... | |
34 public: | 34 public: |
35 // Invoked when an audit proof query completes. | 35 // Invoked when an audit proof query completes. |
36 // If an error occurred, |net_error| will be a net::Error code, otherwise it | 36 // If an error occurred, |net_error| will be a net::Error code, otherwise it |
37 // will be net::OK and |proof| will be the audit proof that was received. | 37 // will be net::OK and |proof| will be the audit proof that was received. |
38 // The log ID of |proof| will not be set, as that is not known by this class, | 38 // The log ID of |proof| will not be set, as that is not known by this class, |
39 // but the leaf index will be set. | 39 // but the leaf index will be set. |
40 using AuditProofCallback = | 40 using AuditProofCallback = |
41 base::Callback<void(net::Error result, | 41 base::Callback<void(net::Error result, |
42 std::unique_ptr<net::ct::MerkleAuditProof> proof)>; | 42 std::unique_ptr<net::ct::MerkleAuditProof> proof)>; |
43 | 43 |
44 // Invoked when the number of concurrent queries drops below the limit. | |
45 // The limit is set by |max_concurrent_queries| (passed to the constructor). | |
46 using NotThrottledCallback = | |
47 base::Callback<void(base::WeakPtr<LogDnsClient> sender)>; | |
Ryan Sleevi
2016/10/03 23:56:04
From an API design standpoint, it's never desirabl
Rob Percival
2016/10/04 18:53:03
Done.
| |
48 | |
44 // Creates a log client that will take ownership of |dns_client| and use it | 49 // Creates a log client that will take ownership of |dns_client| and use it |
45 // to perform DNS queries. Queries will be logged to |net_log|. | 50 // to perform DNS queries. Queries will be logged to |net_log|. |
46 // The |dns_client| does not need to be configured first - this will be done | 51 // The |dns_client| does not need to be configured first - this will be done |
47 // automatically as needed. | 52 // automatically as needed. |
48 // A limit can be set on the number of concurrent DNS queries by providing a | 53 // A limit can be set on the number of concurrent DNS queries by providing a |
49 // positive value for |max_concurrent_queries|. Queries that would exceed this | 54 // positive value for |max_concurrent_queries|. Queries that would exceed this |
50 // limit will fail with net::TEMPORARILY_THROTTLED. Setting this to 0 will | 55 // limit will fail with net::TEMPORARILY_THROTTLED. Setting this to 0 will |
51 // disable this limit. | 56 // disable this limit. |
52 LogDnsClient(std::unique_ptr<net::DnsClient> dns_client, | 57 LogDnsClient(std::unique_ptr<net::DnsClient> dns_client, |
53 const net::NetLogWithSource& net_log, | 58 const net::NetLogWithSource& net_log, |
54 size_t max_concurrent_queries); | 59 size_t max_concurrent_queries); |
55 // Must be deleted on the same thread that it was created on. | 60 // Must be deleted on the same thread that it was created on. |
56 ~LogDnsClient() override; | 61 ~LogDnsClient() override; |
57 | 62 |
58 // Called by NetworkChangeNotifier when the DNS config changes. | 63 // Called by NetworkChangeNotifier when the DNS config changes. |
59 // The DnsClient's config will be updated in response. | 64 // The DnsClient's config will be updated in response. |
60 void OnDNSChanged() override; | 65 void OnDNSChanged() override; |
61 | 66 |
62 // Called by NetworkChangeNotifier when the DNS config is first read. | 67 // Called by NetworkChangeNotifier when the DNS config is first read. |
63 // The DnsClient's config will be updated in response. | 68 // The DnsClient's config will be updated in response. |
64 void OnInitialDNSConfigRead() override; | 69 void OnInitialDNSConfigRead() override; |
65 | 70 |
71 // Registers a callback to be invoked when the number of concurrent queries | |
72 // falls below the limit defined by |max_concurrent_queries| (passed to the | |
73 // constructor of LogDnsClient). This callback will fire once and then be | |
74 // unregistered. Should only be used if QueryAuditProof() returns | |
75 // net::ERR_TEMPORARILY_THROTTLED. | |
76 void NotifyWhenNotThrottled(const NotThrottledCallback& callback); | |
77 | |
66 // Queries a CT log to retrieve an audit proof for the leaf with |leaf_hash|. | 78 // Queries a CT log to retrieve an audit proof for the leaf with |leaf_hash|. |
67 // The log is identified by |domain_for_log|, which is the DNS name used as a | 79 // The log is identified by |domain_for_log|, which is the DNS name used as a |
68 // suffix for all queries. | 80 // suffix for all queries. |
69 // The |leaf_hash| is the SHA-256 Merkle leaf hash (see RFC6962, section 2.1). | 81 // The |leaf_hash| is the SHA-256 Merkle leaf hash (see RFC6962, section 2.1). |
70 // The size of the CT log tree, for which the proof is requested, must be | 82 // The size of the CT log tree, for which the proof is requested, must be |
71 // provided in |tree_size|. | 83 // provided in |tree_size|. |
72 // The |callback| is invoked when the query is complete, or an asynchronous | 84 // The |callback| is invoked when the query is complete, or an asynchronous |
73 // error occurs. It will only be invoked if this method returns | 85 // error occurs. It will only be invoked if this method returns |
74 // net::ERR_IO_PENDING. | 86 // net::ERR_IO_PENDING. |
75 // Returns: | 87 // Returns: |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 // Used to perform DNS queries. | 124 // Used to perform DNS queries. |
113 std::unique_ptr<net::DnsClient> dns_client_; | 125 std::unique_ptr<net::DnsClient> dns_client_; |
114 // Passed to the DNS client for logging. | 126 // Passed to the DNS client for logging. |
115 net::NetLogWithSource net_log_; | 127 net::NetLogWithSource net_log_; |
116 // A FIFO queue of ongoing queries. Since entries will always be appended to | 128 // A FIFO queue of ongoing queries. Since entries will always be appended to |
117 // the end and lookups will typically yield entries at the beginning, | 129 // the end and lookups will typically yield entries at the beginning, |
118 // std::list is an efficient choice. | 130 // std::list is an efficient choice. |
119 std::list<std::unique_ptr<AuditProofQuery>> audit_proof_queries_; | 131 std::list<std::unique_ptr<AuditProofQuery>> audit_proof_queries_; |
120 // The maximum number of queries that can be in flight at one time. | 132 // The maximum number of queries that can be in flight at one time. |
121 size_t max_concurrent_queries_; | 133 size_t max_concurrent_queries_; |
134 // Callbacks to invoke when the number of concurrent queries is at its limit. | |
135 std::list<NotThrottledCallback> not_throttled_callbacks_; | |
122 // Creates weak_ptrs to this, for callback purposes. | 136 // Creates weak_ptrs to this, for callback purposes. |
123 base::WeakPtrFactory<LogDnsClient> weak_ptr_factory_; | 137 base::WeakPtrFactory<LogDnsClient> weak_ptr_factory_; |
124 | 138 |
125 DISALLOW_COPY_AND_ASSIGN(LogDnsClient); | 139 DISALLOW_COPY_AND_ASSIGN(LogDnsClient); |
126 }; | 140 }; |
127 | 141 |
128 } // namespace certificate_transparency | 142 } // namespace certificate_transparency |
129 #endif // COMPONENTS_CERTIFICATE_TRANSPARENCY_LOG_DNS_CLIENT_H_ | 143 #endif // COMPONENTS_CERTIFICATE_TRANSPARENCY_LOG_DNS_CLIENT_H_ |
OLD | NEW |