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