Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2004 Google Inc. | 3 * Copyright 2004 Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 } | 242 } |
| 243 | 243 |
| 244 bool BaseChannel::SetTransport_w(const std::string& transport_name) { | 244 bool BaseChannel::SetTransport_w(const std::string& transport_name) { |
| 245 ASSERT(worker_thread_ == rtc::Thread::Current()); | 245 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 246 | 246 |
| 247 if (transport_name == transport_name_) { | 247 if (transport_name == transport_name_) { |
| 248 // Nothing to do if transport name isn't changing | 248 // Nothing to do if transport name isn't changing |
| 249 return true; | 249 return true; |
| 250 } | 250 } |
| 251 | 251 |
| 252 // For DTLS/SRTP case, the SrtpFilter should be set up by the certificate | |
|
pthatcher1
2015/12/01 23:29:35
Would be more clear as:
"When using DTLS-SRTP, we
| |
| 253 // associated with the TransportChannel, reset the |srtp_filter_|. | |
| 254 if (ShouldSetupDtlsSrtp()) { | |
| 255 srtp_filter_.ResetParams(); | |
| 256 } | |
| 257 | |
| 252 set_transport_channel(transport_controller_->CreateTransportChannel_w( | 258 set_transport_channel(transport_controller_->CreateTransportChannel_w( |
| 253 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 259 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 254 if (!transport_channel()) { | 260 if (!transport_channel()) { |
| 255 return false; | 261 return false; |
| 256 } | 262 } |
| 257 if (rtcp_transport_enabled()) { | 263 if (rtcp_transport_enabled()) { |
| 258 LOG(LS_INFO) << "Create RTCP TransportChannel for " << content_name() | 264 LOG(LS_INFO) << "Create RTCP TransportChannel for " << content_name() |
| 259 << " on " << transport_name << " transport "; | 265 << " on " << transport_name << " transport "; |
| 260 set_rtcp_transport_channel(transport_controller_->CreateTransportChannel_w( | 266 set_rtcp_transport_channel(transport_controller_->CreateTransportChannel_w( |
| 261 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP)); | 267 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP)); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 311 | 317 |
| 312 if (old_tc) { | 318 if (old_tc) { |
| 313 DisconnectFromTransportChannel(old_tc); | 319 DisconnectFromTransportChannel(old_tc); |
| 314 transport_controller_->DestroyTransportChannel_w( | 320 transport_controller_->DestroyTransportChannel_w( |
| 315 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP); | 321 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP); |
| 316 } | 322 } |
| 317 | 323 |
| 318 rtcp_transport_channel_ = new_tc; | 324 rtcp_transport_channel_ = new_tc; |
| 319 | 325 |
| 320 if (new_tc) { | 326 if (new_tc) { |
| 327 RTC_CHECK(!(ShouldSetupDtlsSrtp() && srtp_filter_.IsActive())) | |
| 328 << "setting RTCP for DTLS/SRTP after SrtpFilter is active " | |
|
pthatcher1
2015/12/01 23:29:35
setting => Setting
| |
| 329 << "should never happen."; | |
| 321 ConnectToTransportChannel(new_tc); | 330 ConnectToTransportChannel(new_tc); |
| 322 for (const auto& pair : rtcp_socket_options_) { | 331 for (const auto& pair : rtcp_socket_options_) { |
| 323 new_tc->SetOption(pair.first, pair.second); | 332 new_tc->SetOption(pair.first, pair.second); |
| 324 } | 333 } |
| 325 } | 334 } |
| 326 | 335 |
| 327 // Update aggregate writable/ready-to-send state between RTP and RTCP upon | 336 // Update aggregate writable/ready-to-send state between RTP and RTCP upon |
| 328 // setting new channel | 337 // setting new channel |
| 329 UpdateWritableState_w(); | 338 UpdateWritableState_w(); |
| 330 SetReadyToSend(true, new_tc && new_tc->writable()); | 339 SetReadyToSend(true, new_tc && new_tc->writable()); |
| 331 } | 340 } |
| 332 | 341 |
| 333 void BaseChannel::ConnectToTransportChannel(TransportChannel* tc) { | 342 void BaseChannel::ConnectToTransportChannel(TransportChannel* tc) { |
| 334 ASSERT(worker_thread_ == rtc::Thread::Current()); | 343 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 335 | 344 |
| 336 tc->SignalWritableState.connect(this, &BaseChannel::OnWritableState); | 345 tc->SignalWritableState.connect(this, &BaseChannel::OnWritableState); |
| 337 tc->SignalReadPacket.connect(this, &BaseChannel::OnChannelRead); | 346 tc->SignalReadPacket.connect(this, &BaseChannel::OnChannelRead); |
| 338 tc->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend); | 347 tc->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend); |
| 348 tc->SignalDtlsState.connect(this, &BaseChannel::OnDtlsState); | |
| 339 } | 349 } |
| 340 | 350 |
| 341 void BaseChannel::DisconnectFromTransportChannel(TransportChannel* tc) { | 351 void BaseChannel::DisconnectFromTransportChannel(TransportChannel* tc) { |
| 342 ASSERT(worker_thread_ == rtc::Thread::Current()); | 352 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 343 | 353 |
| 344 tc->SignalWritableState.disconnect(this); | 354 tc->SignalWritableState.disconnect(this); |
| 345 tc->SignalReadPacket.disconnect(this); | 355 tc->SignalReadPacket.disconnect(this); |
| 346 tc->SignalReadyToSend.disconnect(this); | 356 tc->SignalReadyToSend.disconnect(this); |
| 357 tc->SignalDtlsState.disconnect(this); | |
| 347 } | 358 } |
| 348 | 359 |
| 349 bool BaseChannel::Enable(bool enable) { | 360 bool BaseChannel::Enable(bool enable) { |
| 350 worker_thread_->Invoke<void>(Bind( | 361 worker_thread_->Invoke<void>(Bind( |
| 351 enable ? &BaseChannel::EnableMedia_w : &BaseChannel::DisableMedia_w, | 362 enable ? &BaseChannel::EnableMedia_w : &BaseChannel::DisableMedia_w, |
| 352 this)); | 363 this)); |
| 353 return true; | 364 return true; |
| 354 } | 365 } |
| 355 | 366 |
| 356 bool BaseChannel::AddRecvStream(const StreamParams& sp) { | 367 bool BaseChannel::AddRecvStream(const StreamParams& sp) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 409 } | 420 } |
| 410 | 421 |
| 411 bool BaseChannel::IsReadyToReceive() const { | 422 bool BaseChannel::IsReadyToReceive() const { |
| 412 // Receive data if we are enabled and have local content, | 423 // Receive data if we are enabled and have local content, |
| 413 return enabled() && IsReceiveContentDirection(local_content_direction_); | 424 return enabled() && IsReceiveContentDirection(local_content_direction_); |
| 414 } | 425 } |
| 415 | 426 |
| 416 bool BaseChannel::IsReadyToSend() const { | 427 bool BaseChannel::IsReadyToSend() const { |
| 417 // Send outgoing data if we are enabled, have local and remote content, | 428 // Send outgoing data if we are enabled, have local and remote content, |
| 418 // and we have had some form of connectivity. | 429 // and we have had some form of connectivity. |
| 419 return enabled() && | 430 return enabled() && IsReceiveContentDirection(remote_content_direction_) && |
| 420 IsReceiveContentDirection(remote_content_direction_) && | |
| 421 IsSendContentDirection(local_content_direction_) && | 431 IsSendContentDirection(local_content_direction_) && |
| 422 was_ever_writable(); | 432 was_ever_writable() && |
| 433 (srtp_filter_.IsActive() || !ShouldSetupDtlsSrtp()); | |
| 423 } | 434 } |
| 424 | 435 |
| 425 bool BaseChannel::SendPacket(rtc::Buffer* packet, | 436 bool BaseChannel::SendPacket(rtc::Buffer* packet, |
| 426 const rtc::PacketOptions& options) { | 437 const rtc::PacketOptions& options) { |
| 427 return SendPacket(false, packet, options); | 438 return SendPacket(false, packet, options); |
| 428 } | 439 } |
| 429 | 440 |
| 430 bool BaseChannel::SendRtcp(rtc::Buffer* packet, | 441 bool BaseChannel::SendRtcp(rtc::Buffer* packet, |
| 431 const rtc::PacketOptions& options) { | 442 const rtc::PacketOptions& options) { |
| 432 return SendPacket(true, packet, options); | 443 return SendPacket(true, packet, options); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 467 bool rtcp = PacketIsRtcp(channel, data, len); | 478 bool rtcp = PacketIsRtcp(channel, data, len); |
| 468 rtc::Buffer packet(data, len); | 479 rtc::Buffer packet(data, len); |
| 469 HandlePacket(rtcp, &packet, packet_time); | 480 HandlePacket(rtcp, &packet, packet_time); |
| 470 } | 481 } |
| 471 | 482 |
| 472 void BaseChannel::OnReadyToSend(TransportChannel* channel) { | 483 void BaseChannel::OnReadyToSend(TransportChannel* channel) { |
| 473 ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_); | 484 ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_); |
| 474 SetReadyToSend(channel == rtcp_transport_channel_, true); | 485 SetReadyToSend(channel == rtcp_transport_channel_, true); |
| 475 } | 486 } |
| 476 | 487 |
| 488 void BaseChannel::OnDtlsState(TransportChannel* channel, | |
| 489 DtlsTransportState state) { | |
| 490 if (!ShouldSetupDtlsSrtp()) { | |
| 491 return; | |
| 492 } | |
| 493 | |
| 494 // Reset the srtp filter if it's not the CONNECTED state. For CONNECTED | |
|
pthatcher1
2015/12/01 23:29:35
For CONNECTED state => For the CONNECTED state
| |
| 495 // state, setting up DTLS-SRTP context is deferred to ChannelWritable_w to | |
| 496 // cover other scenarios like the whole channel is writable (not just this | |
| 497 // TransportChannel) or when TransportChannel is attached after DTLS is | |
| 498 // negotiated. | |
| 499 if (state != DTLS_TRANSPORT_CONNECTED) { | |
| 500 srtp_filter_.ResetParams(); | |
| 501 } | |
| 502 } | |
| 503 | |
| 477 void BaseChannel::SetReadyToSend(bool rtcp, bool ready) { | 504 void BaseChannel::SetReadyToSend(bool rtcp, bool ready) { |
| 478 if (rtcp) { | 505 if (rtcp) { |
| 479 rtcp_ready_to_send_ = ready; | 506 rtcp_ready_to_send_ = ready; |
| 480 } else { | 507 } else { |
| 481 rtp_ready_to_send_ = ready; | 508 rtp_ready_to_send_ = ready; |
| 482 } | 509 } |
| 483 | 510 |
| 484 if (rtp_ready_to_send_ && | 511 if (rtp_ready_to_send_ && |
| 485 // In the case of rtcp mux |rtcp_transport_channel_| will be null. | 512 // In the case of rtcp mux |rtcp_transport_channel_| will be null. |
| 486 (rtcp_ready_to_send_ || !rtcp_transport_channel_)) { | 513 (rtcp_ready_to_send_ || !rtcp_transport_channel_)) { |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 754 if (transport_channel_ && transport_channel_->writable() && | 781 if (transport_channel_ && transport_channel_->writable() && |
| 755 (!rtcp_transport_channel_ || rtcp_transport_channel_->writable())) { | 782 (!rtcp_transport_channel_ || rtcp_transport_channel_->writable())) { |
| 756 ChannelWritable_w(); | 783 ChannelWritable_w(); |
| 757 } else { | 784 } else { |
| 758 ChannelNotWritable_w(); | 785 ChannelNotWritable_w(); |
| 759 } | 786 } |
| 760 } | 787 } |
| 761 | 788 |
| 762 void BaseChannel::ChannelWritable_w() { | 789 void BaseChannel::ChannelWritable_w() { |
| 763 ASSERT(worker_thread_ == rtc::Thread::Current()); | 790 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 764 if (writable_) | 791 if (writable_) { |
| 765 return; | 792 return; |
| 793 } | |
| 766 | 794 |
| 767 LOG(LS_INFO) << "Channel writable (" << content_name_ << ")" | 795 LOG(LS_INFO) << "Channel writable (" << content_name_ << ")" |
| 768 << (was_ever_writable_ ? "" : " for the first time"); | 796 << (was_ever_writable_ ? "" : " for the first time"); |
| 769 | 797 |
| 770 std::vector<ConnectionInfo> infos; | 798 std::vector<ConnectionInfo> infos; |
| 771 transport_channel_->GetStats(&infos); | 799 transport_channel_->GetStats(&infos); |
| 772 for (std::vector<ConnectionInfo>::const_iterator it = infos.begin(); | 800 for (std::vector<ConnectionInfo>::const_iterator it = infos.begin(); |
| 773 it != infos.end(); ++it) { | 801 it != infos.end(); ++it) { |
| 774 if (it->best_connection) { | 802 if (it->best_connection) { |
| 775 LOG(LS_INFO) << "Using " << it->local_candidate.ToSensitiveString() | 803 LOG(LS_INFO) << "Using " << it->local_candidate.ToSensitiveString() |
| 776 << "->" << it->remote_candidate.ToSensitiveString(); | 804 << "->" << it->remote_candidate.ToSensitiveString(); |
| 777 break; | 805 break; |
| 778 } | 806 } |
| 779 } | 807 } |
| 780 | 808 |
| 781 // If we're doing DTLS-SRTP, now is the time. | |
| 782 if (!was_ever_writable_ && ShouldSetupDtlsSrtp()) { | |
| 783 if (!SetupDtlsSrtp(false)) { | |
| 784 SignalDtlsSetupFailure_w(false); | |
| 785 return; | |
| 786 } | |
| 787 | |
| 788 if (rtcp_transport_channel_) { | |
| 789 if (!SetupDtlsSrtp(true)) { | |
| 790 SignalDtlsSetupFailure_w(true); | |
| 791 return; | |
| 792 } | |
| 793 } | |
| 794 } | |
| 795 | |
| 796 was_ever_writable_ = true; | 809 was_ever_writable_ = true; |
| 810 MaybeSetupDtlsSrtp_w(); | |
| 797 writable_ = true; | 811 writable_ = true; |
| 798 ChangeState(); | 812 ChangeState(); |
| 799 } | 813 } |
| 800 | 814 |
| 801 void BaseChannel::SignalDtlsSetupFailure_w(bool rtcp) { | 815 void BaseChannel::SignalDtlsSetupFailure_w(bool rtcp) { |
| 802 ASSERT(worker_thread() == rtc::Thread::Current()); | 816 ASSERT(worker_thread() == rtc::Thread::Current()); |
| 803 signaling_thread()->Invoke<void>(Bind( | 817 signaling_thread()->Invoke<void>(Bind( |
| 804 &BaseChannel::SignalDtlsSetupFailure_s, this, rtcp)); | 818 &BaseChannel::SignalDtlsSetupFailure_s, this, rtcp)); |
| 805 } | 819 } |
| 806 | 820 |
| 807 void BaseChannel::SignalDtlsSetupFailure_s(bool rtcp) { | 821 void BaseChannel::SignalDtlsSetupFailure_s(bool rtcp) { |
| 808 ASSERT(signaling_thread() == rtc::Thread::Current()); | 822 ASSERT(signaling_thread() == rtc::Thread::Current()); |
| 809 SignalDtlsSetupFailure(this, rtcp); | 823 SignalDtlsSetupFailure(this, rtcp); |
| 810 } | 824 } |
| 811 | 825 |
| 812 bool BaseChannel::SetDtlsSrtpCryptoSuites(TransportChannel* tc, bool rtcp) { | 826 bool BaseChannel::SetDtlsSrtpCryptoSuites(TransportChannel* tc, bool rtcp) { |
| 813 std::vector<int> crypto_suites; | 827 std::vector<int> crypto_suites; |
| 814 // We always use the default SRTP crypto suites for RTCP, but we may use | 828 // We always use the default SRTP crypto suites for RTCP, but we may use |
| 815 // different crypto suites for RTP depending on the media type. | 829 // different crypto suites for RTP depending on the media type. |
| 816 if (!rtcp) { | 830 if (!rtcp) { |
| 817 GetSrtpCryptoSuites(&crypto_suites); | 831 GetSrtpCryptoSuites(&crypto_suites); |
| 818 } else { | 832 } else { |
| 819 GetDefaultSrtpCryptoSuites(&crypto_suites); | 833 GetDefaultSrtpCryptoSuites(&crypto_suites); |
| 820 } | 834 } |
| 821 return tc->SetSrtpCryptoSuites(crypto_suites); | 835 return tc->SetSrtpCryptoSuites(crypto_suites); |
| 822 } | 836 } |
| 823 | 837 |
| 824 bool BaseChannel::ShouldSetupDtlsSrtp() const { | 838 bool BaseChannel::ShouldSetupDtlsSrtp() const { |
| 825 return true; | 839 // Since DTLS is applied to all channels, checking RTP should be enough. |
| 840 return transport_channel_ && transport_channel_->IsDtlsActive(); | |
| 826 } | 841 } |
| 827 | 842 |
| 828 // This function returns true if either DTLS-SRTP is not in use | 843 // This function returns true if either DTLS-SRTP is not in use |
| 829 // *or* DTLS-SRTP is successfully set up. | 844 // *or* DTLS-SRTP is successfully set up. |
| 830 bool BaseChannel::SetupDtlsSrtp(bool rtcp_channel) { | 845 bool BaseChannel::SetupDtlsSrtp(bool rtcp_channel) { |
| 831 bool ret = false; | 846 bool ret = false; |
| 832 | 847 |
| 833 TransportChannel* channel = | 848 TransportChannel* channel = |
| 834 rtcp_channel ? rtcp_transport_channel_ : transport_channel_; | 849 rtcp_channel ? rtcp_transport_channel_ : transport_channel_; |
| 835 | 850 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 908 } | 923 } |
| 909 | 924 |
| 910 if (!ret) | 925 if (!ret) |
| 911 LOG(LS_WARNING) << "DTLS-SRTP key installation failed"; | 926 LOG(LS_WARNING) << "DTLS-SRTP key installation failed"; |
| 912 else | 927 else |
| 913 dtls_keyed_ = true; | 928 dtls_keyed_ = true; |
| 914 | 929 |
| 915 return ret; | 930 return ret; |
| 916 } | 931 } |
| 917 | 932 |
| 933 void BaseChannel::MaybeSetupDtlsSrtp_w() { | |
| 934 if (srtp_filter_.IsActive()) { | |
| 935 return; | |
| 936 } | |
| 937 | |
| 938 if (!ShouldSetupDtlsSrtp()) { | |
| 939 return; | |
| 940 } | |
| 941 | |
| 942 if (!SetupDtlsSrtp(false)) { | |
| 943 SignalDtlsSetupFailure_w(false); | |
| 944 return; | |
| 945 } | |
| 946 | |
| 947 if (rtcp_transport_channel_) { | |
| 948 if (!SetupDtlsSrtp(true)) { | |
| 949 SignalDtlsSetupFailure_w(true); | |
| 950 return; | |
| 951 } | |
| 952 } | |
| 953 } | |
| 954 | |
| 918 void BaseChannel::ChannelNotWritable_w() { | 955 void BaseChannel::ChannelNotWritable_w() { |
| 919 ASSERT(worker_thread_ == rtc::Thread::Current()); | 956 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 920 if (!writable_) | 957 if (!writable_) |
| 921 return; | 958 return; |
| 922 | 959 |
| 923 LOG(LS_INFO) << "Channel not writable (" << content_name_ << ")"; | 960 LOG(LS_INFO) << "Channel not writable (" << content_name_ << ")"; |
| 924 writable_ = false; | 961 writable_ = false; |
| 925 ChangeState(); | 962 ChangeState(); |
| 926 } | 963 } |
| 927 | 964 |
| (...skipping 1340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2268 // that the transport channel is ready. | 2305 // that the transport channel is ready. |
| 2269 signaling_thread()->Post(this, MSG_READYTOSENDDATA, | 2306 signaling_thread()->Post(this, MSG_READYTOSENDDATA, |
| 2270 new DataChannelReadyToSendMessageData(writable)); | 2307 new DataChannelReadyToSendMessageData(writable)); |
| 2271 } | 2308 } |
| 2272 | 2309 |
| 2273 void DataChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const { | 2310 void DataChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const { |
| 2274 GetSupportedDataCryptoSuites(crypto_suites); | 2311 GetSupportedDataCryptoSuites(crypto_suites); |
| 2275 } | 2312 } |
| 2276 | 2313 |
| 2277 bool DataChannel::ShouldSetupDtlsSrtp() const { | 2314 bool DataChannel::ShouldSetupDtlsSrtp() const { |
| 2278 return (data_channel_type_ == DCT_RTP); | 2315 return (data_channel_type_ == DCT_RTP) && BaseChannel::ShouldSetupDtlsSrtp(); |
| 2279 } | 2316 } |
| 2280 | 2317 |
| 2281 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { | 2318 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { |
| 2282 rtc::TypedMessageData<uint32_t>* message = | 2319 rtc::TypedMessageData<uint32_t>* message = |
| 2283 new rtc::TypedMessageData<uint32_t>(sid); | 2320 new rtc::TypedMessageData<uint32_t>(sid); |
| 2284 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message); | 2321 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message); |
| 2285 } | 2322 } |
| 2286 | 2323 |
| 2287 } // namespace cricket | 2324 } // namespace cricket |
| OLD | NEW |