| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 // The log ID of |proof| will not be set, as that is not known by this class, | 45 // The log ID of |proof| will not be set, as that is not known by this class, |
| 46 // but the leaf index will be set. | 46 // but the leaf index will be set. |
| 47 using AuditProofCallback = | 47 using AuditProofCallback = |
| 48 base::Callback<void(int net_error, | 48 base::Callback<void(int net_error, |
| 49 std::unique_ptr<net::ct::MerkleAuditProof> proof)>; | 49 std::unique_ptr<net::ct::MerkleAuditProof> proof)>; |
| 50 | 50 |
| 51 // Creates a log client that will take ownership of |dns_client| and use it | 51 // Creates a log client that will take ownership of |dns_client| and use it |
| 52 // to perform DNS queries. Queries will be logged to |net_log|. | 52 // to perform DNS queries. Queries will be logged to |net_log|. |
| 53 // The |dns_client| does not need to be configured first - this will be done | 53 // The |dns_client| does not need to be configured first - this will be done |
| 54 // automatically as needed. | 54 // automatically as needed. |
| 55 // A limit can be set on the number of concurrent DNS queries by providing a |
| 56 // positive value for |max_concurrent_queries|. Queries that would exceed this |
| 57 // limit will fail with net::TEMPORARILY_THROTTLED. Setting this to 0 will |
| 58 // disable this limit. |
| 55 LogDnsClient(std::unique_ptr<net::DnsClient> dns_client, | 59 LogDnsClient(std::unique_ptr<net::DnsClient> dns_client, |
| 56 const net::NetLogWithSource& net_log); | 60 const net::NetLogWithSource& net_log, |
| 61 size_t max_concurrent_queries); |
| 57 // Must be deleted on the same thread that it was created on. | 62 // Must be deleted on the same thread that it was created on. |
| 58 ~LogDnsClient() override; | 63 ~LogDnsClient() override; |
| 59 | 64 |
| 60 // Called by NetworkChangeNotifier when the DNS config changes. | 65 // Called by NetworkChangeNotifier when the DNS config changes. |
| 61 // The DnsClient's config will be updated in response. | 66 // The DnsClient's config will be updated in response. |
| 62 void OnDNSChanged() override; | 67 void OnDNSChanged() override; |
| 63 | 68 |
| 64 // Called by NetworkChangeNotifier when the DNS config is first read. | 69 // Called by NetworkChangeNotifier when the DNS config is first read. |
| 65 // The DnsClient's config will be updated in response. | 70 // The DnsClient's config will be updated in response. |
| 66 void OnInitialDNSConfigRead() override; | 71 void OnInitialDNSConfigRead() override; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 const AuditProofCallback& callback); | 106 const AuditProofCallback& callback); |
| 102 | 107 |
| 103 void QueryAuditProofNodesComplete( | 108 void QueryAuditProofNodesComplete( |
| 104 std::unique_ptr<net::ct::MerkleAuditProof> proof, | 109 std::unique_ptr<net::ct::MerkleAuditProof> proof, |
| 105 base::StringPiece domain_for_log, | 110 base::StringPiece domain_for_log, |
| 106 uint64_t tree_size, | 111 uint64_t tree_size, |
| 107 net::DnsTransaction* transaction, | 112 net::DnsTransaction* transaction, |
| 108 int net_error, | 113 int net_error, |
| 109 const net::DnsResponse* response); | 114 const net::DnsResponse* response); |
| 110 | 115 |
| 116 // Returns true if the maximum number of queries are currently in flight. |
| 117 // If the maximum number of concurrency queries is set to 0, this will always |
| 118 // return false. |
| 119 bool HasMaxConcurrentQueriesInProgress() const; |
| 120 |
| 111 // Updates the |dns_client_| config using NetworkChangeNotifier. | 121 // Updates the |dns_client_| config using NetworkChangeNotifier. |
| 112 void UpdateDnsConfig(); | 122 void UpdateDnsConfig(); |
| 113 | 123 |
| 114 // A DNS query that is in flight. | 124 // A DNS query that is in flight. |
| 115 template <typename CallbackType> | 125 template <typename CallbackType> |
| 116 struct Query { | 126 struct Query { |
| 117 std::unique_ptr<net::DnsTransaction> transaction; | 127 std::unique_ptr<net::DnsTransaction> transaction; |
| 118 CallbackType callback; | 128 CallbackType callback; |
| 119 }; | 129 }; |
| 120 | 130 |
| 121 // Used to perform DNS queries. | 131 // Used to perform DNS queries. |
| 122 std::unique_ptr<net::DnsClient> dns_client_; | 132 std::unique_ptr<net::DnsClient> dns_client_; |
| 123 // Passed to the DNS client for logging. | 133 // Passed to the DNS client for logging. |
| 124 net::NetLogWithSource net_log_; | 134 net::NetLogWithSource net_log_; |
| 125 // Leaf index queries that haven't completed yet. | 135 // Leaf index queries that haven't completed yet. |
| 126 std::list<Query<LeafIndexCallback>> leaf_index_queries_; | 136 std::list<Query<LeafIndexCallback>> leaf_index_queries_; |
| 127 // Audit proof queries that haven't completed yet. | 137 // Audit proof queries that haven't completed yet. |
| 128 std::list<Query<AuditProofCallback>> audit_proof_queries_; | 138 std::list<Query<AuditProofCallback>> audit_proof_queries_; |
| 139 // The maximum number of queries that can be in flight at one time. |
| 140 size_t max_concurrent_queries_; |
| 129 // Creates weak_ptrs to this, for callback purposes. | 141 // Creates weak_ptrs to this, for callback purposes. |
| 130 base::WeakPtrFactory<LogDnsClient> weak_ptr_factory_; | 142 base::WeakPtrFactory<LogDnsClient> weak_ptr_factory_; |
| 131 | 143 |
| 132 DISALLOW_COPY_AND_ASSIGN(LogDnsClient); | 144 DISALLOW_COPY_AND_ASSIGN(LogDnsClient); |
| 133 }; | 145 }; |
| 134 | 146 |
| 135 } // namespace certificate_transparency | 147 } // namespace certificate_transparency |
| 136 #endif // COMPONENTS_CERTIFICATE_TRANSPARENCY_LOG_DNS_CLIENT_H_ | 148 #endif // COMPONENTS_CERTIFICATE_TRANSPARENCY_LOG_DNS_CLIENT_H_ |
| OLD | NEW |