Stop preemptively generating an RSA key pair.
RSA isn't used by the Java binding, it isn't the default for Obj-C,
and this identity store class isn't used at all by Chrome. So in most
cases, preemptively generating an RSA key pair just wastes CPU cycles
and blocks the worker thread.
If a native C++ application really wants to preemptively generate an RSA
key pair, it can easily do this by passing in its own DtlsIdentityStoreImpl
and calling GenerateIdentity on it.
R=juberti@chromium.org
Review URL: https://codereview.webrtc.org/1907083005 .
Cr-Original-Commit-Position: refs/heads/master@{#12498}
Cr-Mirrored-From: https://chromium.googlesource.com/external/webrtc
Cr-Mirrored-Commit: 9cb23a3579990ff78e3ceb6b6a88a06912662d7b
diff --git a/api/dtlsidentitystore.cc b/api/dtlsidentitystore.cc
index a485188..a1a45b8 100644
--- a/api/dtlsidentitystore.cc
+++ b/api/dtlsidentitystore.cc
@@ -108,12 +108,6 @@
worker_thread_(worker_thread),
request_info_() {
RTC_DCHECK(signaling_thread_->IsCurrent());
- // Preemptively generate identities unless the worker thread and signaling
- // thread are the same (only do preemptive work in the background).
- if (worker_thread_ != signaling_thread_) {
- // Only necessary for RSA.
- GenerateIdentity(rtc::KT_RSA, nullptr);
- }
}
DtlsIdentityStoreImpl::~DtlsIdentityStoreImpl() {
@@ -226,7 +220,7 @@
if (worker_thread_ != signaling_thread_ && // Only do in background thread.
key_type == rtc::KT_RSA && // Only necessary for RSA.
!request_info_[key_type].free_identity_.get() &&
- request_info_[key_type].request_observers_.size() <=
+ request_info_[key_type].request_observers_.size() ==
request_info_[key_type].gen_in_progress_counts_) {
GenerateIdentity(key_type, nullptr);
}
diff --git a/api/dtlsidentitystore_unittest.cc b/api/dtlsidentitystore_unittest.cc
index 809e885..65428f2 100644
--- a/api/dtlsidentitystore_unittest.cc
+++ b/api/dtlsidentitystore_unittest.cc
@@ -83,8 +83,6 @@
};
TEST_F(DtlsIdentityStoreTest, RequestIdentitySuccessRSA) {
- EXPECT_TRUE_WAIT(store_->HasFreeIdentityForTesting(rtc::KT_RSA), kTimeoutMs);
-
store_->RequestIdentity(rtc::KeyParams(rtc::KT_RSA),
rtc::Optional<uint64_t>(),
observer_.get());
@@ -103,14 +101,14 @@
}
TEST_F(DtlsIdentityStoreTest, RequestIdentitySuccessECDSA) {
- // Since store currently does not preemptively generate free ECDSA identities
- // we do not invoke HasFreeIdentityForTesting between requests.
-
store_->RequestIdentity(rtc::KeyParams(rtc::KT_ECDSA),
rtc::Optional<uint64_t>(),
observer_.get());
EXPECT_TRUE_WAIT(observer_->LastRequestSucceeded(), kTimeoutMs);
+ // Since store currently does not preemptively generate free ECDSA identities
+ // we do not invoke HasFreeIdentityForTesting between requests.
+
observer_->Reset();
// Verifies that the callback is async when a free identity is ready.