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

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: Resync, rebase, and address comments. 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 Transport* transport, 90 Transport* transport,
91 TransportChannelImpl* channel) 91 TransportChannelImpl* channel)
92 : TransportChannelImpl(channel->transport_name(), channel->component()), 92 : TransportChannelImpl(channel->transport_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_->SignalGatheringState.connect( 106 channel_->SignalGatheringState.connect(
109 this, &DtlsTransportChannelWrapper::OnGatheringState); 107 this, &DtlsTransportChannelWrapper::OnGatheringState);
110 channel_->SignalCandidateGathered.connect( 108 channel_->SignalCandidateGathered.connect(
111 this, &DtlsTransportChannelWrapper::OnCandidateGathered); 109 this, &DtlsTransportChannelWrapper::OnCandidateGathered);
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 return -1; 381 return -1;
384 } 382 }
385 383
386 return result; 384 return result;
387 } 385 }
388 386
389 // The state transition logic here is as follows: 387 // The state transition logic here is as follows:
390 // (1) If we're not doing DTLS-SRTP, then the state is just the 388 // (1) If we're not doing DTLS-SRTP, then the state is just the
391 // state of the underlying impl() 389 // state of the underlying impl()
392 // (2) If we're doing DTLS-SRTP: 390 // (2) If we're doing DTLS-SRTP:
393 // - Prior to the DTLS handshake, the state is neither readable or 391 // - Prior to the DTLS handshake, the state is neither receiving nor
394 // writable 392 // writable
395 // - When the impl goes writable for the first time we 393 // - When the impl goes writable for the first time we
396 // start the DTLS handshake 394 // start the DTLS handshake
397 // - Once the DTLS handshake completes, the state is that of the 395 // - Once the DTLS handshake completes, the state is that of the
398 // impl again 396 // impl again
399 void DtlsTransportChannelWrapper::OnReadableState(TransportChannel* channel) {
400 ASSERT(rtc::Thread::Current() == worker_thread_);
401 ASSERT(channel == channel_);
402 LOG_J(LS_VERBOSE, this)
403 << "DTLSTransportChannelWrapper: channel readable state changed to "
404 << channel_->readable();
405
406 if (dtls_state_ == STATE_NONE || dtls_state_ == STATE_OPEN) {
407 set_readable(channel_->readable());
408 // Note: SignalReadableState fired by set_readable.
409 }
410 }
411
412 void DtlsTransportChannelWrapper::OnWritableState(TransportChannel* channel) { 397 void DtlsTransportChannelWrapper::OnWritableState(TransportChannel* channel) {
413 ASSERT(rtc::Thread::Current() == worker_thread_); 398 ASSERT(rtc::Thread::Current() == worker_thread_);
414 ASSERT(channel == channel_); 399 ASSERT(channel == channel_);
415 LOG_J(LS_VERBOSE, this) 400 LOG_J(LS_VERBOSE, this)
416 << "DTLSTransportChannelWrapper: channel writable state changed to " 401 << "DTLSTransportChannelWrapper: channel writable state changed to "
417 << channel_->writable(); 402 << channel_->writable();
418 403
419 switch (dtls_state_) { 404 switch (dtls_state_) {
420 case STATE_NONE: 405 case STATE_NONE:
421 case STATE_OPEN: 406 case STATE_OPEN:
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 int sig, int err) { 521 int sig, int err) {
537 ASSERT(rtc::Thread::Current() == worker_thread_); 522 ASSERT(rtc::Thread::Current() == worker_thread_);
538 ASSERT(dtls == dtls_.get()); 523 ASSERT(dtls == dtls_.get());
539 if (sig & rtc::SE_OPEN) { 524 if (sig & rtc::SE_OPEN) {
540 // This is the first time. 525 // This is the first time.
541 LOG_J(LS_INFO, this) << "DTLS handshake complete."; 526 LOG_J(LS_INFO, this) << "DTLS handshake complete.";
542 if (dtls_->GetState() == rtc::SS_OPEN) { 527 if (dtls_->GetState() == rtc::SS_OPEN) {
543 // The check for OPEN shouldn't be necessary but let's make 528 // The check for OPEN shouldn't be necessary but let's make
544 // sure we don't accidentally frob the state if it's closed. 529 // sure we don't accidentally frob the state if it's closed.
545 dtls_state_ = STATE_OPEN; 530 dtls_state_ = STATE_OPEN;
546
547 set_readable(true);
548 set_writable(true); 531 set_writable(true);
549 } 532 }
550 } 533 }
551 if (sig & rtc::SE_READ) { 534 if (sig & rtc::SE_READ) {
552 char buf[kMaxDtlsPacketLen]; 535 char buf[kMaxDtlsPacketLen];
553 size_t read; 536 size_t read;
554 if (dtls_->Read(buf, sizeof(buf), &read, NULL) == rtc::SR_SUCCESS) { 537 if (dtls_->Read(buf, sizeof(buf), &read, NULL) == rtc::SR_SUCCESS) {
555 SignalReadPacket(this, buf, read, rtc::CreatePacketTime(0), 0); 538 SignalReadPacket(this, buf, read, rtc::CreatePacketTime(0), 0);
556 } 539 }
557 } 540 }
558 if (sig & rtc::SE_CLOSE) { 541 if (sig & rtc::SE_CLOSE) {
559 ASSERT(sig == rtc::SE_CLOSE); // SE_CLOSE should be by itself. 542 ASSERT(sig == rtc::SE_CLOSE); // SE_CLOSE should be by itself.
560 if (!err) { 543 if (!err) {
561 LOG_J(LS_INFO, this) << "DTLS channel closed"; 544 LOG_J(LS_INFO, this) << "DTLS channel closed";
562 } else { 545 } else {
563 LOG_J(LS_INFO, this) << "DTLS channel error, code=" << err; 546 LOG_J(LS_INFO, this) << "DTLS channel error, code=" << err;
564 } 547 }
565
566 set_readable(false);
567 set_writable(false); 548 set_writable(false);
568 dtls_state_ = STATE_CLOSED; 549 dtls_state_ = STATE_CLOSED;
569 } 550 }
570 } 551 }
571 552
572 bool DtlsTransportChannelWrapper::MaybeStartDtls() { 553 bool DtlsTransportChannelWrapper::MaybeStartDtls() {
573 if (channel_->writable()) { 554 if (channel_->writable()) {
574 if (dtls_->StartSSLWithPeer()) { 555 if (dtls_->StartSSLWithPeer()) {
575 LOG_J(LS_ERROR, this) << "Couldn't start DTLS handshake"; 556 LOG_J(LS_ERROR, this) << "Couldn't start DTLS handshake";
576 dtls_state_ = STATE_CLOSED; 557 dtls_state_ = STATE_CLOSED;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 SignalRouteChange(this, candidate); 614 SignalRouteChange(this, candidate);
634 } 615 }
635 616
636 void DtlsTransportChannelWrapper::OnConnectionRemoved( 617 void DtlsTransportChannelWrapper::OnConnectionRemoved(
637 TransportChannelImpl* channel) { 618 TransportChannelImpl* channel) {
638 ASSERT(channel == channel_); 619 ASSERT(channel == channel_);
639 SignalConnectionRemoved(this); 620 SignalConnectionRemoved(this);
640 } 621 }
641 622
642 } // namespace cricket 623 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698