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

Side by Side Diff: components/certificate_transparency/log_dns_client.h

Issue 2331923003: Allow LogDnsClient queries to be rate-limited (Closed)
Patch Set: Created 4 years, 3 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
OLDNEW
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 LogDnsClient(std::unique_ptr<net::DnsClient> dns_client, 55 LogDnsClient(std::unique_ptr<net::DnsClient> dns_client,
56 const net::BoundNetLog& net_log); 56 const net::BoundNetLog& net_log);
57 // Must be deleted on the same thread that it was created on. 57 // Must be deleted on the same thread that it was created on.
58 ~LogDnsClient() override; 58 ~LogDnsClient() override;
59 59
60 // Gets the number of queries that can be in flight at any one time.
61 // If this returns 0, there is no limit.
62 size_t GetMaxConcurrentQueries() const { return max_concurrent_queries_; }
Eran Messeri 2016/09/12 13:26:48 Nit: What use do clients have for this method?
Rob Percival 2016/09/12 17:26:24 Probably none, so I'm happy to remove it.
63
64 // A limit can be set on the number of concurrent queries by providing a
65 // positive value for |max_concurrent_queries|. Queries that would exceed this
66 // limit will fail with net::TEMPORARILY_THROTTLED. Setting this to 0 will
67 // disable this limit.
68 void SetMaxConcurrentQueries(size_t max_queries) {
Eran Messeri 2016/09/12 13:26:48 Nit: I'd make the value a c'tor parameter so clien
Rob Percival 2016/09/12 17:26:24 Done.
69 max_concurrent_queries_ = max_queries;
70 }
71
60 // Called by NetworkChangeNotifier when the DNS config changes. 72 // Called by NetworkChangeNotifier when the DNS config changes.
61 // The DnsClient's config will be updated in response. 73 // The DnsClient's config will be updated in response.
62 void OnDNSChanged() override; 74 void OnDNSChanged() override;
63 75
64 // Called by NetworkChangeNotifier when the DNS config is first read. 76 // Called by NetworkChangeNotifier when the DNS config is first read.
65 // The DnsClient's config will be updated in response. 77 // The DnsClient's config will be updated in response.
66 void OnInitialDNSConfigRead() override; 78 void OnInitialDNSConfigRead() override;
67 79
68 // Queries a CT log to discover the index of the leaf with |leaf_hash|. 80 // Queries a CT log to discover the index of the leaf with |leaf_hash|.
69 // The log is identified by |domain_for_log|, which is the DNS name used as a 81 // The log is identified by |domain_for_log|, which is the DNS name used as a
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 const AuditProofCallback& callback); 113 const AuditProofCallback& callback);
102 114
103 void QueryAuditProofNodesComplete( 115 void QueryAuditProofNodesComplete(
104 std::unique_ptr<net::ct::MerkleAuditProof> proof, 116 std::unique_ptr<net::ct::MerkleAuditProof> proof,
105 base::StringPiece domain_for_log, 117 base::StringPiece domain_for_log,
106 uint64_t tree_size, 118 uint64_t tree_size,
107 net::DnsTransaction* transaction, 119 net::DnsTransaction* transaction,
108 int net_error, 120 int net_error,
109 const net::DnsResponse* response); 121 const net::DnsResponse* response);
110 122
123 // Returns true if the maximum number of queries are currently in flight.
124 // If the maximum number of concurrency queries is set to 0, this will always
125 // return false.
126 bool HasMaxConcurrentQueriesInProgress() const;
127
111 // Updates the |dns_client_| config using NetworkChangeNotifier. 128 // Updates the |dns_client_| config using NetworkChangeNotifier.
112 void UpdateDnsConfig(); 129 void UpdateDnsConfig();
113 130
114 // A DNS query that is in flight. 131 // A DNS query that is in flight.
115 template <typename CallbackType> 132 template <typename CallbackType>
116 struct Query { 133 struct Query {
117 std::unique_ptr<net::DnsTransaction> transaction; 134 std::unique_ptr<net::DnsTransaction> transaction;
118 CallbackType callback; 135 CallbackType callback;
119 }; 136 };
120 137
121 // Used to perform DNS queries. 138 // Used to perform DNS queries.
122 std::unique_ptr<net::DnsClient> dns_client_; 139 std::unique_ptr<net::DnsClient> dns_client_;
123 // Passed to the DNS client for logging. 140 // Passed to the DNS client for logging.
124 net::BoundNetLog net_log_; 141 net::BoundNetLog net_log_;
125 // Leaf index queries that haven't completed yet. 142 // Leaf index queries that haven't completed yet.
126 std::list<Query<LeafIndexCallback>> leaf_index_queries_; 143 std::list<Query<LeafIndexCallback>> leaf_index_queries_;
127 // Audit proof queries that haven't completed yet. 144 // Audit proof queries that haven't completed yet.
128 std::list<Query<AuditProofCallback>> audit_proof_queries_; 145 std::list<Query<AuditProofCallback>> audit_proof_queries_;
146 // The maximum number of queries that can be in flight at one time.
147 size_t max_concurrent_queries_;
129 // Creates weak_ptrs to this, for callback purposes. 148 // Creates weak_ptrs to this, for callback purposes.
130 base::WeakPtrFactory<LogDnsClient> weak_ptr_factory_; 149 base::WeakPtrFactory<LogDnsClient> weak_ptr_factory_;
131 150
132 DISALLOW_COPY_AND_ASSIGN(LogDnsClient); 151 DISALLOW_COPY_AND_ASSIGN(LogDnsClient);
133 }; 152 };
134 153
135 } // namespace certificate_transparency 154 } // namespace certificate_transparency
136 #endif // COMPONENTS_CERTIFICATE_TRANSPARENCY_LOG_DNS_CLIENT_H_ 155 #endif // COMPONENTS_CERTIFICATE_TRANSPARENCY_LOG_DNS_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698