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

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

Issue 1351673003: Replace readable with receiving where receiving means receiving anything (stun ping, response or da… (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 5 years, 3 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
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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 local_identity_(NULL), 98 local_identity_(NULL),
99 ssl_role_(rtc::SSL_CLIENT), 99 ssl_role_(rtc::SSL_CLIENT),
100 ssl_max_version_(rtc::SSL_PROTOCOL_DTLS_10) { 100 ssl_max_version_(rtc::SSL_PROTOCOL_DTLS_10) {
101 channel_->SignalReadableState.connect(this,
102 &DtlsTransportChannelWrapper::OnReadableState);
103 channel_->SignalWritableState.connect(this, 101 channel_->SignalWritableState.connect(this,
104 &DtlsTransportChannelWrapper::OnWritableState); 102 &DtlsTransportChannelWrapper::OnWritableState);
105 channel_->SignalReadPacket.connect(this, 103 channel_->SignalReadPacket.connect(this,
106 &DtlsTransportChannelWrapper::OnReadPacket); 104 &DtlsTransportChannelWrapper::OnReadPacket);
107 channel_->SignalReadyToSend.connect(this, 105 channel_->SignalReadyToSend.connect(this,
108 &DtlsTransportChannelWrapper::OnReadyToSend); 106 &DtlsTransportChannelWrapper::OnReadyToSend);
109 channel_->SignalRequestSignaling.connect(this, 107 channel_->SignalRequestSignaling.connect(this,
110 &DtlsTransportChannelWrapper::OnRequestSignaling); 108 &DtlsTransportChannelWrapper::OnRequestSignaling);
111 channel_->SignalCandidateReady.connect(this, 109 channel_->SignalCandidateReady.connect(this,
112 &DtlsTransportChannelWrapper::OnCandidateReady); 110 &DtlsTransportChannelWrapper::OnCandidateReady);
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 return -1; 388 return -1;
391 } 389 }
392 390
393 return result; 391 return result;
394 } 392 }
395 393
396 // The state transition logic here is as follows: 394 // The state transition logic here is as follows:
397 // (1) If we're not doing DTLS-SRTP, then the state is just the 395 // (1) If we're not doing DTLS-SRTP, then the state is just the
398 // state of the underlying impl() 396 // state of the underlying impl()
399 // (2) If we're doing DTLS-SRTP: 397 // (2) If we're doing DTLS-SRTP:
400 // - Prior to the DTLS handshake, the state is neither readable or 398 // - Prior to the DTLS handshake, the state is neither receiving nor
401 // writable 399 // writable
402 // - When the impl goes writable for the first time we 400 // - When the impl goes writable for the first time we
403 // start the DTLS handshake 401 // start the DTLS handshake
404 // - Once the DTLS handshake completes, the state is that of the 402 // - Once the DTLS handshake completes, the state is that of the
405 // impl again 403 // impl again
406 void DtlsTransportChannelWrapper::OnReadableState(TransportChannel* channel) {
407 ASSERT(rtc::Thread::Current() == worker_thread_);
408 ASSERT(channel == channel_);
409 LOG_J(LS_VERBOSE, this)
410 << "DTLSTransportChannelWrapper: channel readable state changed to "
411 << channel_->readable();
412
413 if (dtls_state_ == STATE_NONE || dtls_state_ == STATE_OPEN) {
414 set_readable(channel_->readable());
415 // Note: SignalReadableState fired by set_readable.
416 }
417 }
418
419 void DtlsTransportChannelWrapper::OnWritableState(TransportChannel* channel) { 404 void DtlsTransportChannelWrapper::OnWritableState(TransportChannel* channel) {
420 ASSERT(rtc::Thread::Current() == worker_thread_); 405 ASSERT(rtc::Thread::Current() == worker_thread_);
421 ASSERT(channel == channel_); 406 ASSERT(channel == channel_);
422 LOG_J(LS_VERBOSE, this) 407 LOG_J(LS_VERBOSE, this)
423 << "DTLSTransportChannelWrapper: channel writable state changed to " 408 << "DTLSTransportChannelWrapper: channel writable state changed to "
424 << channel_->writable(); 409 << channel_->writable();
425 410
426 switch (dtls_state_) { 411 switch (dtls_state_) {
427 case STATE_NONE: 412 case STATE_NONE:
428 case STATE_OPEN: 413 case STATE_OPEN:
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 int sig, int err) { 528 int sig, int err) {
544 ASSERT(rtc::Thread::Current() == worker_thread_); 529 ASSERT(rtc::Thread::Current() == worker_thread_);
545 ASSERT(dtls == dtls_.get()); 530 ASSERT(dtls == dtls_.get());
546 if (sig & rtc::SE_OPEN) { 531 if (sig & rtc::SE_OPEN) {
547 // This is the first time. 532 // This is the first time.
548 LOG_J(LS_INFO, this) << "DTLS handshake complete."; 533 LOG_J(LS_INFO, this) << "DTLS handshake complete.";
549 if (dtls_->GetState() == rtc::SS_OPEN) { 534 if (dtls_->GetState() == rtc::SS_OPEN) {
550 // The check for OPEN shouldn't be necessary but let's make 535 // The check for OPEN shouldn't be necessary but let's make
551 // sure we don't accidentally frob the state if it's closed. 536 // sure we don't accidentally frob the state if it's closed.
552 dtls_state_ = STATE_OPEN; 537 dtls_state_ = STATE_OPEN;
553
554 set_readable(true);
555 set_writable(true); 538 set_writable(true);
556 } 539 }
557 } 540 }
558 if (sig & rtc::SE_READ) { 541 if (sig & rtc::SE_READ) {
559 char buf[kMaxDtlsPacketLen]; 542 char buf[kMaxDtlsPacketLen];
560 size_t read; 543 size_t read;
561 if (dtls_->Read(buf, sizeof(buf), &read, NULL) == rtc::SR_SUCCESS) { 544 if (dtls_->Read(buf, sizeof(buf), &read, NULL) == rtc::SR_SUCCESS) {
562 SignalReadPacket(this, buf, read, rtc::CreatePacketTime(0), 0); 545 SignalReadPacket(this, buf, read, rtc::CreatePacketTime(0), 0);
563 } 546 }
564 } 547 }
565 if (sig & rtc::SE_CLOSE) { 548 if (sig & rtc::SE_CLOSE) {
566 ASSERT(sig == rtc::SE_CLOSE); // SE_CLOSE should be by itself. 549 ASSERT(sig == rtc::SE_CLOSE); // SE_CLOSE should be by itself.
567 if (!err) { 550 if (!err) {
568 LOG_J(LS_INFO, this) << "DTLS channel closed"; 551 LOG_J(LS_INFO, this) << "DTLS channel closed";
569 } else { 552 } else {
570 LOG_J(LS_INFO, this) << "DTLS channel error, code=" << err; 553 LOG_J(LS_INFO, this) << "DTLS channel error, code=" << err;
571 } 554 }
572
573 set_readable(false);
574 set_writable(false); 555 set_writable(false);
575 dtls_state_ = STATE_CLOSED; 556 dtls_state_ = STATE_CLOSED;
576 } 557 }
577 } 558 }
578 559
579 bool DtlsTransportChannelWrapper::MaybeStartDtls() { 560 bool DtlsTransportChannelWrapper::MaybeStartDtls() {
580 if (channel_->writable()) { 561 if (channel_->writable()) {
581 if (dtls_->StartSSLWithPeer()) { 562 if (dtls_->StartSSLWithPeer()) {
582 LOG_J(LS_ERROR, this) << "Couldn't start DTLS handshake"; 563 LOG_J(LS_ERROR, this) << "Couldn't start DTLS handshake";
583 dtls_state_ = STATE_CLOSED; 564 dtls_state_ = STATE_CLOSED;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 SignalRouteChange(this, candidate); 626 SignalRouteChange(this, candidate);
646 } 627 }
647 628
648 void DtlsTransportChannelWrapper::OnConnectionRemoved( 629 void DtlsTransportChannelWrapper::OnConnectionRemoved(
649 TransportChannelImpl* channel) { 630 TransportChannelImpl* channel) {
650 ASSERT(channel == channel_); 631 ASSERT(channel == channel_);
651 SignalConnectionRemoved(this); 632 SignalConnectionRemoved(this);
652 } 633 }
653 634
654 } // namespace cricket 635 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698