OLD | NEW |
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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 Transport* transport, | 90 Transport* transport, |
91 TransportChannelImpl* channel) | 91 TransportChannelImpl* channel) |
92 : TransportChannelImpl(channel->content_name(), channel->component()), | 92 : TransportChannelImpl(channel->content_name(), channel->component()), |
93 transport_(transport), | 93 transport_(transport), |
94 worker_thread_(rtc::Thread::Current()), | 94 worker_thread_(rtc::Thread::Current()), |
95 channel_(channel), | 95 channel_(channel), |
96 downward_(NULL), | 96 downward_(NULL), |
97 dtls_state_(STATE_NONE), | 97 dtls_state_(STATE_NONE), |
98 ssl_role_(rtc::SSL_CLIENT), | 98 ssl_role_(rtc::SSL_CLIENT), |
99 ssl_max_version_(rtc::SSL_PROTOCOL_DTLS_10) { | 99 ssl_max_version_(rtc::SSL_PROTOCOL_DTLS_10) { |
100 channel_->SignalReadableState.connect(this, | |
101 &DtlsTransportChannelWrapper::OnReadableState); | |
102 channel_->SignalWritableState.connect(this, | 100 channel_->SignalWritableState.connect(this, |
103 &DtlsTransportChannelWrapper::OnWritableState); | 101 &DtlsTransportChannelWrapper::OnWritableState); |
104 channel_->SignalReadPacket.connect(this, | 102 channel_->SignalReadPacket.connect(this, |
105 &DtlsTransportChannelWrapper::OnReadPacket); | 103 &DtlsTransportChannelWrapper::OnReadPacket); |
106 channel_->SignalReadyToSend.connect(this, | 104 channel_->SignalReadyToSend.connect(this, |
107 &DtlsTransportChannelWrapper::OnReadyToSend); | 105 &DtlsTransportChannelWrapper::OnReadyToSend); |
108 channel_->SignalRequestSignaling.connect(this, | 106 channel_->SignalRequestSignaling.connect(this, |
109 &DtlsTransportChannelWrapper::OnRequestSignaling); | 107 &DtlsTransportChannelWrapper::OnRequestSignaling); |
110 channel_->SignalCandidateReady.connect(this, | 108 channel_->SignalCandidateReady.connect(this, |
111 &DtlsTransportChannelWrapper::OnCandidateReady); | 109 &DtlsTransportChannelWrapper::OnCandidateReady); |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 return -1; | 383 return -1; |
386 } | 384 } |
387 | 385 |
388 return result; | 386 return result; |
389 } | 387 } |
390 | 388 |
391 // The state transition logic here is as follows: | 389 // The state transition logic here is as follows: |
392 // (1) If we're not doing DTLS-SRTP, then the state is just the | 390 // (1) If we're not doing DTLS-SRTP, then the state is just the |
393 // state of the underlying impl() | 391 // state of the underlying impl() |
394 // (2) If we're doing DTLS-SRTP: | 392 // (2) If we're doing DTLS-SRTP: |
395 // - Prior to the DTLS handshake, the state is neither readable or | 393 // - Prior to the DTLS handshake, the state is neither receiving nor |
396 // writable | 394 // writable |
397 // - When the impl goes writable for the first time we | 395 // - When the impl goes writable for the first time we |
398 // start the DTLS handshake | 396 // start the DTLS handshake |
399 // - Once the DTLS handshake completes, the state is that of the | 397 // - Once the DTLS handshake completes, the state is that of the |
400 // impl again | 398 // impl again |
401 void DtlsTransportChannelWrapper::OnReadableState(TransportChannel* channel) { | |
402 ASSERT(rtc::Thread::Current() == worker_thread_); | |
403 ASSERT(channel == channel_); | |
404 LOG_J(LS_VERBOSE, this) | |
405 << "DTLSTransportChannelWrapper: channel readable state changed to " | |
406 << channel_->readable(); | |
407 | |
408 if (dtls_state_ == STATE_NONE || dtls_state_ == STATE_OPEN) { | |
409 set_readable(channel_->readable()); | |
410 // Note: SignalReadableState fired by set_readable. | |
411 } | |
412 } | |
413 | |
414 void DtlsTransportChannelWrapper::OnWritableState(TransportChannel* channel) { | 399 void DtlsTransportChannelWrapper::OnWritableState(TransportChannel* channel) { |
415 ASSERT(rtc::Thread::Current() == worker_thread_); | 400 ASSERT(rtc::Thread::Current() == worker_thread_); |
416 ASSERT(channel == channel_); | 401 ASSERT(channel == channel_); |
417 LOG_J(LS_VERBOSE, this) | 402 LOG_J(LS_VERBOSE, this) |
418 << "DTLSTransportChannelWrapper: channel writable state changed to " | 403 << "DTLSTransportChannelWrapper: channel writable state changed to " |
419 << channel_->writable(); | 404 << channel_->writable(); |
420 | 405 |
421 switch (dtls_state_) { | 406 switch (dtls_state_) { |
422 case STATE_NONE: | 407 case STATE_NONE: |
423 case STATE_OPEN: | 408 case STATE_OPEN: |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 int sig, int err) { | 523 int sig, int err) { |
539 ASSERT(rtc::Thread::Current() == worker_thread_); | 524 ASSERT(rtc::Thread::Current() == worker_thread_); |
540 ASSERT(dtls == dtls_.get()); | 525 ASSERT(dtls == dtls_.get()); |
541 if (sig & rtc::SE_OPEN) { | 526 if (sig & rtc::SE_OPEN) { |
542 // This is the first time. | 527 // This is the first time. |
543 LOG_J(LS_INFO, this) << "DTLS handshake complete."; | 528 LOG_J(LS_INFO, this) << "DTLS handshake complete."; |
544 if (dtls_->GetState() == rtc::SS_OPEN) { | 529 if (dtls_->GetState() == rtc::SS_OPEN) { |
545 // The check for OPEN shouldn't be necessary but let's make | 530 // The check for OPEN shouldn't be necessary but let's make |
546 // sure we don't accidentally frob the state if it's closed. | 531 // sure we don't accidentally frob the state if it's closed. |
547 dtls_state_ = STATE_OPEN; | 532 dtls_state_ = STATE_OPEN; |
548 | |
549 set_readable(true); | |
550 set_writable(true); | 533 set_writable(true); |
551 } | 534 } |
552 } | 535 } |
553 if (sig & rtc::SE_READ) { | 536 if (sig & rtc::SE_READ) { |
554 char buf[kMaxDtlsPacketLen]; | 537 char buf[kMaxDtlsPacketLen]; |
555 size_t read; | 538 size_t read; |
556 if (dtls_->Read(buf, sizeof(buf), &read, NULL) == rtc::SR_SUCCESS) { | 539 if (dtls_->Read(buf, sizeof(buf), &read, NULL) == rtc::SR_SUCCESS) { |
557 SignalReadPacket(this, buf, read, rtc::CreatePacketTime(0), 0); | 540 SignalReadPacket(this, buf, read, rtc::CreatePacketTime(0), 0); |
558 } | 541 } |
559 } | 542 } |
560 if (sig & rtc::SE_CLOSE) { | 543 if (sig & rtc::SE_CLOSE) { |
561 ASSERT(sig == rtc::SE_CLOSE); // SE_CLOSE should be by itself. | 544 ASSERT(sig == rtc::SE_CLOSE); // SE_CLOSE should be by itself. |
562 if (!err) { | 545 if (!err) { |
563 LOG_J(LS_INFO, this) << "DTLS channel closed"; | 546 LOG_J(LS_INFO, this) << "DTLS channel closed"; |
564 } else { | 547 } else { |
565 LOG_J(LS_INFO, this) << "DTLS channel error, code=" << err; | 548 LOG_J(LS_INFO, this) << "DTLS channel error, code=" << err; |
566 } | 549 } |
567 | |
568 set_readable(false); | |
569 set_writable(false); | 550 set_writable(false); |
570 dtls_state_ = STATE_CLOSED; | 551 dtls_state_ = STATE_CLOSED; |
571 } | 552 } |
572 } | 553 } |
573 | 554 |
574 bool DtlsTransportChannelWrapper::MaybeStartDtls() { | 555 bool DtlsTransportChannelWrapper::MaybeStartDtls() { |
575 if (channel_->writable()) { | 556 if (channel_->writable()) { |
576 if (dtls_->StartSSLWithPeer()) { | 557 if (dtls_->StartSSLWithPeer()) { |
577 LOG_J(LS_ERROR, this) << "Couldn't start DTLS handshake"; | 558 LOG_J(LS_ERROR, this) << "Couldn't start DTLS handshake"; |
578 dtls_state_ = STATE_CLOSED; | 559 dtls_state_ = STATE_CLOSED; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 SignalRouteChange(this, candidate); | 621 SignalRouteChange(this, candidate); |
641 } | 622 } |
642 | 623 |
643 void DtlsTransportChannelWrapper::OnConnectionRemoved( | 624 void DtlsTransportChannelWrapper::OnConnectionRemoved( |
644 TransportChannelImpl* channel) { | 625 TransportChannelImpl* channel) { |
645 ASSERT(channel == channel_); | 626 ASSERT(channel == channel_); |
646 SignalConnectionRemoved(this); | 627 SignalConnectionRemoved(this); |
647 } | 628 } |
648 | 629 |
649 } // namespace cricket | 630 } // namespace cricket |
OLD | NEW |