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 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
462 | 462 |
463 if (!dtls_active_) { | 463 if (!dtls_active_) { |
464 // Not doing DTLS. | 464 // Not doing DTLS. |
465 SignalReadPacket(this, data, size, packet_time, 0); | 465 SignalReadPacket(this, data, size, packet_time, 0); |
466 return; | 466 return; |
467 } | 467 } |
468 | 468 |
469 switch (dtls_state()) { | 469 switch (dtls_state()) { |
470 case DTLS_TRANSPORT_NEW: | 470 case DTLS_TRANSPORT_NEW: |
471 if (dtls_) { | 471 if (dtls_) { |
472 // Drop packets received before DTLS has actually started. | 472 LOG_J(LS_INFO, this) << "Packet received before DTLS started."; |
473 LOG_J(LS_INFO, this) << "Dropping packet received before DTLS started."; | |
474 } else { | 473 } else { |
475 // Currently drop the packet, but we might in future | 474 LOG_J(LS_WARNING, this) << "Packet received before we know if we are " |
476 // decide to take this as evidence that the other | 475 << "doing DTLS or not."; |
477 // side is ready to do DTLS and start the handshake | 476 } |
478 // on our end. | 477 // Cache the last DTLS packet (should be a client hello) received before |
479 LOG_J(LS_WARNING, this) << "Received packet before we know if we are " | 478 // DTLS has actually started. |
480 << "doing DTLS or not; dropping."; | 479 if (IsDtlsPacket(data, size)) { |
juberti2
2016/04/25 20:40:18
We should probably also verify this is a CLIENT HE
Taylor Brandstetter
2016/04/26 22:55:58
Done.
| |
480 LOG_J(LS_INFO, this) << "Caching DTLS packet until DTLS is started."; | |
481 cached_dtls_packet_.SetData(data, size); | |
482 } else { | |
483 LOG_J(LS_INFO, this) << "Not a DTLS packet; dropping."; | |
481 } | 484 } |
482 break; | 485 break; |
483 | 486 |
484 case DTLS_TRANSPORT_CONNECTING: | 487 case DTLS_TRANSPORT_CONNECTING: |
485 case DTLS_TRANSPORT_CONNECTED: | 488 case DTLS_TRANSPORT_CONNECTED: |
486 // We should only get DTLS or SRTP packets; STUN's already been demuxed. | 489 // We should only get DTLS or SRTP packets; STUN's already been demuxed. |
487 // Is this potentially a DTLS packet? | 490 // Is this potentially a DTLS packet? |
488 if (IsDtlsPacket(data, size)) { | 491 if (IsDtlsPacket(data, size)) { |
489 if (!HandleDtlsPacket(data, size)) { | 492 if (!HandleDtlsPacket(data, size)) { |
490 LOG_J(LS_ERROR, this) << "Failed to handle DTLS packet."; | 493 LOG_J(LS_ERROR, this) << "Failed to handle DTLS packet."; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
569 bool DtlsTransportChannelWrapper::MaybeStartDtls() { | 572 bool DtlsTransportChannelWrapper::MaybeStartDtls() { |
570 if (dtls_ && channel_->writable()) { | 573 if (dtls_ && channel_->writable()) { |
571 if (dtls_->StartSSLWithPeer()) { | 574 if (dtls_->StartSSLWithPeer()) { |
572 LOG_J(LS_ERROR, this) << "Couldn't start DTLS handshake"; | 575 LOG_J(LS_ERROR, this) << "Couldn't start DTLS handshake"; |
573 set_dtls_state(DTLS_TRANSPORT_FAILED); | 576 set_dtls_state(DTLS_TRANSPORT_FAILED); |
574 return false; | 577 return false; |
575 } | 578 } |
576 LOG_J(LS_INFO, this) | 579 LOG_J(LS_INFO, this) |
577 << "DtlsTransportChannelWrapper: Started DTLS handshake"; | 580 << "DtlsTransportChannelWrapper: Started DTLS handshake"; |
578 set_dtls_state(DTLS_TRANSPORT_CONNECTING); | 581 set_dtls_state(DTLS_TRANSPORT_CONNECTING); |
582 // Now that the handshake has started, we can process a cached packet | |
583 // (if one exists). | |
584 if (cached_dtls_packet_.size()) { | |
585 if (ssl_role_ == rtc::SSL_SERVER) { | |
586 LOG_J(LS_INFO, this) << "Handling cached DTLS packet."; | |
587 if (!HandleDtlsPacket(cached_dtls_packet_.data<char>(), | |
588 cached_dtls_packet_.size())) { | |
589 LOG_J(LS_ERROR, this) << "Failed to handle DTLS packet."; | |
590 } | |
591 } else { | |
592 LOG_J(LS_WARNING, this) << "Discarding cached DTLS packet because " | |
juberti2
2016/04/25 20:40:18
Log text could be clearer to indicate this is a re
Taylor Brandstetter
2016/04/26 22:55:58
Now that the message is changed to "discarding cac
| |
593 << "we don't have the server role."; | |
594 } | |
595 cached_dtls_packet_.Clear(); | |
596 } | |
579 } | 597 } |
580 return true; | 598 return true; |
581 } | 599 } |
582 | 600 |
583 // Called from OnReadPacket when a DTLS packet is received. | 601 // Called from OnReadPacket when a DTLS packet is received. |
584 bool DtlsTransportChannelWrapper::HandleDtlsPacket(const char* data, | 602 bool DtlsTransportChannelWrapper::HandleDtlsPacket(const char* data, |
585 size_t size) { | 603 size_t size) { |
586 // Sanity check we're not passing junk that | 604 // Sanity check we're not passing junk that |
587 // just looks like DTLS. | 605 // just looks like DTLS. |
588 const uint8_t* tmp_data = reinterpret_cast<const uint8_t*>(data); | 606 const uint8_t* tmp_data = reinterpret_cast<const uint8_t*>(data); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
653 | 671 |
654 void DtlsTransportChannelWrapper::Reconnect() { | 672 void DtlsTransportChannelWrapper::Reconnect() { |
655 set_dtls_state(DTLS_TRANSPORT_NEW); | 673 set_dtls_state(DTLS_TRANSPORT_NEW); |
656 set_writable(false); | 674 set_writable(false); |
657 if (channel_->writable()) { | 675 if (channel_->writable()) { |
658 OnWritableState(channel_); | 676 OnWritableState(channel_); |
659 } | 677 } |
660 } | 678 } |
661 | 679 |
662 } // namespace cricket | 680 } // namespace cricket |
OLD | NEW |