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

Side by Side Diff: webrtc/p2p/base/dtlstransportchannel.cc

Issue 1414363002: Exposing DTLS transport state from TransportChannel. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Renaming, fixing comment. Created 5 years, 2 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
« no previous file with comments | « no previous file | webrtc/p2p/base/transport.h » ('j') | webrtc/p2p/base/transportchannel.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2011 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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 dtls_state_ = STATE_NONE; 223 dtls_state_ = STATE_NONE;
224 return true; 224 return true;
225 } 225 }
226 226
227 // At this point we know we are doing DTLS 227 // At this point we know we are doing DTLS
228 remote_fingerprint_value_ = remote_fingerprint_value.Pass(); 228 remote_fingerprint_value_ = remote_fingerprint_value.Pass();
229 remote_fingerprint_algorithm_ = digest_alg; 229 remote_fingerprint_algorithm_ = digest_alg;
230 230
231 if (!SetupDtls()) { 231 if (!SetupDtls()) {
232 dtls_state_ = STATE_CLOSED; 232 dtls_state_ = STATE_CLOSED;
233 set_dtls_transport_state(DTLS_TRANSPORT_FAILED);
233 return false; 234 return false;
234 } 235 }
235 236
236 dtls_state_ = STATE_ACCEPTED; 237 dtls_state_ = STATE_ACCEPTED;
237 return true; 238 return true;
238 } 239 }
239 240
240 bool DtlsTransportChannelWrapper::GetRemoteSSLCertificate( 241 bool DtlsTransportChannelWrapper::GetRemoteSSLCertificate(
241 rtc::SSLCertificate** cert) const { 242 rtc::SSLCertificate** cert) const {
242 if (!dtls_) 243 if (!dtls_) {
243 return false; 244 return false;
245 }
244 246
245 return dtls_->GetPeerCertificate(cert); 247 return dtls_->GetPeerCertificate(cert);
246 } 248 }
247 249
248 bool DtlsTransportChannelWrapper::SetupDtls() { 250 bool DtlsTransportChannelWrapper::SetupDtls() {
249 StreamInterfaceChannel* downward = new StreamInterfaceChannel(channel_); 251 StreamInterfaceChannel* downward = new StreamInterfaceChannel(channel_);
250 252
251 dtls_.reset(rtc::SSLStreamAdapter::Create(downward)); 253 dtls_.reset(rtc::SSLStreamAdapter::Create(downward));
252 if (!dtls_) { 254 if (!dtls_) {
253 LOG_J(LS_ERROR, this) << "Failed to create DTLS adapter."; 255 LOG_J(LS_ERROR, this) << "Failed to create DTLS adapter.";
(...skipping 25 matching lines...) Expand all
279 } else { 281 } else {
280 LOG_J(LS_INFO, this) << "Not using DTLS."; 282 LOG_J(LS_INFO, this) << "Not using DTLS.";
281 } 283 }
282 284
283 LOG_J(LS_INFO, this) << "DTLS setup complete."; 285 LOG_J(LS_INFO, this) << "DTLS setup complete.";
284 return true; 286 return true;
285 } 287 }
286 288
287 bool DtlsTransportChannelWrapper::SetSrtpCiphers( 289 bool DtlsTransportChannelWrapper::SetSrtpCiphers(
288 const std::vector<std::string>& ciphers) { 290 const std::vector<std::string>& ciphers) {
289 if (srtp_ciphers_ == ciphers) 291 if (srtp_ciphers_ == ciphers) {
290 return true; 292 return true;
293 }
291 294
292 if (dtls_state_ == STATE_STARTED) { 295 if (dtls_state_ == STATE_STARTED) {
293 LOG(LS_WARNING) << "Ignoring new SRTP ciphers while DTLS is negotiating"; 296 LOG(LS_WARNING) << "Ignoring new SRTP ciphers while DTLS is negotiating";
294 return true; 297 return true;
295 } 298 }
296 299
297 if (dtls_state_ == STATE_OPEN) { 300 if (dtls_state_ == STATE_OPEN) {
298 // We don't support DTLS renegotiation currently. If new set of srtp ciphers 301 // We don't support DTLS renegotiation currently. If new set of srtp ciphers
299 // are different than what's being used currently, we will not use it. 302 // are different than what's being used currently, we will not use it.
300 // So for now, let's be happy (or sad) with a warning message. 303 // So for now, let's be happy (or sad) with a warning message.
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 ASSERT(rtc::Thread::Current() == worker_thread_); 534 ASSERT(rtc::Thread::Current() == worker_thread_);
532 ASSERT(dtls == dtls_.get()); 535 ASSERT(dtls == dtls_.get());
533 if (sig & rtc::SE_OPEN) { 536 if (sig & rtc::SE_OPEN) {
534 // This is the first time. 537 // This is the first time.
535 LOG_J(LS_INFO, this) << "DTLS handshake complete."; 538 LOG_J(LS_INFO, this) << "DTLS handshake complete.";
536 if (dtls_->GetState() == rtc::SS_OPEN) { 539 if (dtls_->GetState() == rtc::SS_OPEN) {
537 // The check for OPEN shouldn't be necessary but let's make 540 // The check for OPEN shouldn't be necessary but let's make
538 // sure we don't accidentally frob the state if it's closed. 541 // sure we don't accidentally frob the state if it's closed.
539 dtls_state_ = STATE_OPEN; 542 dtls_state_ = STATE_OPEN;
540 set_writable(true); 543 set_writable(true);
544 set_dtls_transport_state(DTLS_TRANSPORT_CONNECTED);
541 } 545 }
542 } 546 }
543 if (sig & rtc::SE_READ) { 547 if (sig & rtc::SE_READ) {
544 char buf[kMaxDtlsPacketLen]; 548 char buf[kMaxDtlsPacketLen];
545 size_t read; 549 size_t read;
546 if (dtls_->Read(buf, sizeof(buf), &read, NULL) == rtc::SR_SUCCESS) { 550 if (dtls_->Read(buf, sizeof(buf), &read, NULL) == rtc::SR_SUCCESS) {
547 SignalReadPacket(this, buf, read, rtc::CreatePacketTime(0), 0); 551 SignalReadPacket(this, buf, read, rtc::CreatePacketTime(0), 0);
548 } 552 }
549 } 553 }
550 if (sig & rtc::SE_CLOSE) { 554 if (sig & rtc::SE_CLOSE) {
551 ASSERT(sig == rtc::SE_CLOSE); // SE_CLOSE should be by itself. 555 ASSERT(sig == rtc::SE_CLOSE); // SE_CLOSE should be by itself.
552 if (!err) { 556 if (!err) {
553 LOG_J(LS_INFO, this) << "DTLS channel closed"; 557 LOG_J(LS_INFO, this) << "DTLS channel closed";
554 } else { 558 } else {
555 LOG_J(LS_INFO, this) << "DTLS channel error, code=" << err; 559 LOG_J(LS_INFO, this) << "DTLS channel error, code=" << err;
556 } 560 }
557 set_writable(false); 561 set_writable(false);
558 dtls_state_ = STATE_CLOSED; 562 dtls_state_ = STATE_CLOSED;
563 set_dtls_transport_state(err ? DTLS_TRANSPORT_FAILED
564 : DTLS_TRANSPORT_CLOSED);
559 } 565 }
560 } 566 }
561 567
562 bool DtlsTransportChannelWrapper::MaybeStartDtls() { 568 bool DtlsTransportChannelWrapper::MaybeStartDtls() {
563 if (channel_->writable()) { 569 if (channel_->writable()) {
564 if (dtls_->StartSSLWithPeer()) { 570 if (dtls_->StartSSLWithPeer()) {
565 LOG_J(LS_ERROR, this) << "Couldn't start DTLS handshake"; 571 LOG_J(LS_ERROR, this) << "Couldn't start DTLS handshake";
566 dtls_state_ = STATE_CLOSED; 572 dtls_state_ = STATE_CLOSED;
573 set_dtls_transport_state(DTLS_TRANSPORT_FAILED);
567 return false; 574 return false;
568 } 575 }
569 LOG_J(LS_INFO, this) 576 LOG_J(LS_INFO, this)
570 << "DtlsTransportChannelWrapper: Started DTLS handshake"; 577 << "DtlsTransportChannelWrapper: Started DTLS handshake";
571 578
572 dtls_state_ = STATE_STARTED; 579 dtls_state_ = STATE_STARTED;
580 set_dtls_transport_state(DTLS_TRANSPORT_CONNECTING);
pthatcher1 2015/10/20 20:28:06 Please see if we can reduce down to one dtls_state
Taylor Brandstetter 2015/10/21 16:28:16 Done.
573 } 581 }
574 return true; 582 return true;
575 } 583 }
576 584
577 // Called from OnReadPacket when a DTLS packet is received. 585 // Called from OnReadPacket when a DTLS packet is received.
578 bool DtlsTransportChannelWrapper::HandleDtlsPacket(const char* data, 586 bool DtlsTransportChannelWrapper::HandleDtlsPacket(const char* data,
579 size_t size) { 587 size_t size) {
580 // Sanity check we're not passing junk that 588 // Sanity check we're not passing junk that
581 // just looks like DTLS. 589 // just looks like DTLS.
582 const uint8_t* tmp_data = reinterpret_cast<const uint8_t*>(data); 590 const uint8_t* tmp_data = reinterpret_cast<const uint8_t*>(data);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 SignalRouteChange(this, candidate); 631 SignalRouteChange(this, candidate);
624 } 632 }
625 633
626 void DtlsTransportChannelWrapper::OnConnectionRemoved( 634 void DtlsTransportChannelWrapper::OnConnectionRemoved(
627 TransportChannelImpl* channel) { 635 TransportChannelImpl* channel) {
628 ASSERT(channel == channel_); 636 ASSERT(channel == channel_);
629 SignalConnectionRemoved(this); 637 SignalConnectionRemoved(this);
630 } 638 }
631 639
632 } // namespace cricket 640 } // namespace cricket
OLDNEW
« no previous file with comments | « no previous file | webrtc/p2p/base/transport.h » ('j') | webrtc/p2p/base/transportchannel.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698