OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 private: | 51 private: |
52 void GenerateIdentity_w() { | 52 void GenerateIdentity_w() { |
53 LOG(LS_INFO) << "Generating identity, using keytype " << key_type_; | 53 LOG(LS_INFO) << "Generating identity, using keytype " << key_type_; |
54 std::unique_ptr<rtc::SSLIdentity> identity( | 54 std::unique_ptr<rtc::SSLIdentity> identity( |
55 rtc::SSLIdentity::Generate(kIdentityName, key_type_)); | 55 rtc::SSLIdentity::Generate(kIdentityName, key_type_)); |
56 | 56 |
57 // Posting to |this| avoids touching |store_| on threads other than | 57 // Posting to |this| avoids touching |store_| on threads other than |
58 // |signaling_thread_| and thus avoids having to use locks. | 58 // |signaling_thread_| and thus avoids having to use locks. |
59 IdentityResultMessageData* msg = new IdentityResultMessageData( | 59 IdentityResultMessageData* msg = new IdentityResultMessageData( |
60 new IdentityResult(key_type_, std::move(identity))); | 60 new IdentityResult(key_type_, std::move(identity))); |
61 signaling_thread_->Post(this, MSG_GENERATE_IDENTITY_RESULT, msg); | 61 signaling_thread_->Post(FROM_HERE, this, MSG_GENERATE_IDENTITY_RESULT, msg); |
62 } | 62 } |
63 | 63 |
64 void OnMessage(rtc::Message* msg) override { | 64 void OnMessage(rtc::Message* msg) override { |
65 switch (msg->message_id) { | 65 switch (msg->message_id) { |
66 case MSG_GENERATE_IDENTITY: | 66 case MSG_GENERATE_IDENTITY: |
67 // This message always runs on the worker thread. | 67 // This message always runs on the worker thread. |
68 GenerateIdentity_w(); | 68 GenerateIdentity_w(); |
69 | 69 |
70 // Must delete |this|, owned by msg->pdata, on the signaling thread to | 70 // Must delete |this|, owned by msg->pdata, on the signaling thread to |
71 // avoid races on disconnecting the signal. | 71 // avoid races on disconnecting the signal. |
72 signaling_thread_->Post(this, MSG_DESTROY, msg->pdata); | 72 signaling_thread_->Post(FROM_HERE, this, MSG_DESTROY, msg->pdata); |
73 break; | 73 break; |
74 case MSG_GENERATE_IDENTITY_RESULT: | 74 case MSG_GENERATE_IDENTITY_RESULT: |
75 RTC_DCHECK(signaling_thread_->IsCurrent()); | 75 RTC_DCHECK(signaling_thread_->IsCurrent()); |
76 { | 76 { |
77 std::unique_ptr<IdentityResultMessageData> pdata( | 77 std::unique_ptr<IdentityResultMessageData> pdata( |
78 static_cast<IdentityResultMessageData*>(msg->pdata)); | 78 static_cast<IdentityResultMessageData*>(msg->pdata)); |
79 if (store_) { | 79 if (store_) { |
80 store_->OnIdentityGenerated(pdata->data()->key_type_, | 80 store_->OnIdentityGenerated(pdata->data()->key_type_, |
81 std::move(pdata->data()->identity_)); | 81 std::move(pdata->data()->identity_)); |
82 } | 82 } |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 request_info_[key_type].request_observers_.push(observer); | 156 request_info_[key_type].request_observers_.push(observer); |
157 | 157 |
158 // Already have a free identity generated? | 158 // Already have a free identity generated? |
159 if (request_info_[key_type].free_identity_.get()) { | 159 if (request_info_[key_type].free_identity_.get()) { |
160 // Return identity async - post even though we are on |signaling_thread_|. | 160 // Return identity async - post even though we are on |signaling_thread_|. |
161 LOG(LS_VERBOSE) << "Using a free DTLS identity."; | 161 LOG(LS_VERBOSE) << "Using a free DTLS identity."; |
162 ++request_info_[key_type].gen_in_progress_counts_; | 162 ++request_info_[key_type].gen_in_progress_counts_; |
163 IdentityResultMessageData* msg = | 163 IdentityResultMessageData* msg = |
164 new IdentityResultMessageData(new IdentityResult( | 164 new IdentityResultMessageData(new IdentityResult( |
165 key_type, std::move(request_info_[key_type].free_identity_))); | 165 key_type, std::move(request_info_[key_type].free_identity_))); |
166 signaling_thread_->Post(this, MSG_GENERATE_IDENTITY_RESULT, msg); | 166 signaling_thread_->Post(FROM_HERE, this, MSG_GENERATE_IDENTITY_RESULT, |
| 167 msg); |
167 return; | 168 return; |
168 } | 169 } |
169 | 170 |
170 // Free identity in the process of being generated? | 171 // Free identity in the process of being generated? |
171 if (request_info_[key_type].gen_in_progress_counts_ == | 172 if (request_info_[key_type].gen_in_progress_counts_ == |
172 request_info_[key_type].request_observers_.size()) { | 173 request_info_[key_type].request_observers_.size()) { |
173 // No need to do anything, the free identity will be returned to the | 174 // No need to do anything, the free identity will be returned to the |
174 // observer in a MSG_GENERATE_IDENTITY_RESULT. | 175 // observer in a MSG_GENERATE_IDENTITY_RESULT. |
175 return; | 176 return; |
176 } | 177 } |
177 } | 178 } |
178 | 179 |
179 // Enqueue/Post a worker task to do the generation. | 180 // Enqueue/Post a worker task to do the generation. |
180 ++request_info_[key_type].gen_in_progress_counts_; | 181 ++request_info_[key_type].gen_in_progress_counts_; |
181 WorkerTask* task = new WorkerTask(this, key_type); // Post 1 task/request. | 182 WorkerTask* task = new WorkerTask(this, key_type); // Post 1 task/request. |
182 // The WorkerTask is owned by the message data to make sure it will not be | 183 // The WorkerTask is owned by the message data to make sure it will not be |
183 // leaked even if the task does not get run. | 184 // leaked even if the task does not get run. |
184 WorkerTaskMessageData* msg = new WorkerTaskMessageData(task); | 185 WorkerTaskMessageData* msg = new WorkerTaskMessageData(task); |
185 worker_thread_->Post(task, MSG_GENERATE_IDENTITY, msg); | 186 worker_thread_->Post(FROM_HERE, task, MSG_GENERATE_IDENTITY, msg); |
186 } | 187 } |
187 | 188 |
188 void DtlsIdentityStoreImpl::OnIdentityGenerated( | 189 void DtlsIdentityStoreImpl::OnIdentityGenerated( |
189 rtc::KeyType key_type, | 190 rtc::KeyType key_type, |
190 std::unique_ptr<rtc::SSLIdentity> identity) { | 191 std::unique_ptr<rtc::SSLIdentity> identity) { |
191 RTC_DCHECK(signaling_thread_->IsCurrent()); | 192 RTC_DCHECK(signaling_thread_->IsCurrent()); |
192 | 193 |
193 RTC_DCHECK(request_info_[key_type].gen_in_progress_counts_); | 194 RTC_DCHECK(request_info_[key_type].gen_in_progress_counts_); |
194 --request_info_[key_type].gen_in_progress_counts_; | 195 --request_info_[key_type].gen_in_progress_counts_; |
195 | 196 |
(...skipping 26 matching lines...) Expand all Loading... |
222 key_type == rtc::KT_RSA && // Only necessary for RSA. | 223 key_type == rtc::KT_RSA && // Only necessary for RSA. |
223 !request_info_[key_type].free_identity_.get() && | 224 !request_info_[key_type].free_identity_.get() && |
224 request_info_[key_type].request_observers_.size() == | 225 request_info_[key_type].request_observers_.size() == |
225 request_info_[key_type].gen_in_progress_counts_) { | 226 request_info_[key_type].gen_in_progress_counts_) { |
226 GenerateIdentity(key_type, nullptr); | 227 GenerateIdentity(key_type, nullptr); |
227 } | 228 } |
228 } | 229 } |
229 } | 230 } |
230 | 231 |
231 } // namespace webrtc | 232 } // namespace webrtc |
OLD | NEW |