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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
170 transport_controller_(transport_controller), | 170 transport_controller_(transport_controller), |
171 media_channel_(media_channel), | 171 media_channel_(media_channel), |
172 content_name_(content_name), | 172 content_name_(content_name), |
173 rtcp_transport_enabled_(rtcp), | 173 rtcp_transport_enabled_(rtcp), |
174 transport_channel_(nullptr), | 174 transport_channel_(nullptr), |
175 rtcp_transport_channel_(nullptr), | 175 rtcp_transport_channel_(nullptr), |
176 enabled_(false), | 176 enabled_(false), |
177 writable_(false), | 177 writable_(false), |
178 rtp_ready_to_send_(false), | 178 rtp_ready_to_send_(false), |
179 rtcp_ready_to_send_(false), | 179 rtcp_ready_to_send_(false), |
180 was_ever_writable_(false), | 180 dtls_srtp_setup_pending_(false), |
181 local_content_direction_(MD_INACTIVE), | 181 local_content_direction_(MD_INACTIVE), |
182 remote_content_direction_(MD_INACTIVE), | 182 remote_content_direction_(MD_INACTIVE), |
183 has_received_packet_(false), | 183 has_received_packet_(false), |
184 dtls_keyed_(false), | 184 dtls_keyed_(false), |
185 secure_required_(false), | 185 secure_required_(false), |
186 rtp_abs_sendtime_extn_id_(-1) { | 186 rtp_abs_sendtime_extn_id_(-1) { |
187 ASSERT(worker_thread_ == rtc::Thread::Current()); | 187 ASSERT(worker_thread_ == rtc::Thread::Current()); |
188 LOG(LS_INFO) << "Created channel for " << content_name; | 188 LOG(LS_INFO) << "Created channel for " << content_name; |
189 } | 189 } |
190 | 190 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
271 void BaseChannel::set_transport_channel(TransportChannel* new_tc) { | 271 void BaseChannel::set_transport_channel(TransportChannel* new_tc) { |
272 ASSERT(worker_thread_ == rtc::Thread::Current()); | 272 ASSERT(worker_thread_ == rtc::Thread::Current()); |
273 | 273 |
274 TransportChannel* old_tc = transport_channel_; | 274 TransportChannel* old_tc = transport_channel_; |
275 if (!old_tc && !new_tc) { | 275 if (!old_tc && !new_tc) { |
276 // Nothing to do | 276 // Nothing to do |
277 return; | 277 return; |
278 } | 278 } |
279 ASSERT(old_tc != new_tc); | 279 ASSERT(old_tc != new_tc); |
280 | 280 |
281 // When a TransportChannel is attached, we always assume there is something to | |
282 // do for DTLS/SRTP to prevent sending anything without encrypted. | |
283 dtls_srtp_setup_pending_ = true; | |
pthatcher1
2015/11/30 20:23:11
This is kind of hard to read and understand. In t
guoweis_webrtc
2015/12/01 22:05:12
Done.
| |
284 | |
281 if (old_tc) { | 285 if (old_tc) { |
282 DisconnectFromTransportChannel(old_tc); | 286 DisconnectFromTransportChannel(old_tc); |
283 transport_controller_->DestroyTransportChannel_w( | 287 transport_controller_->DestroyTransportChannel_w( |
284 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTP); | 288 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
285 } | 289 } |
286 | 290 |
287 transport_channel_ = new_tc; | 291 transport_channel_ = new_tc; |
288 | 292 |
289 if (new_tc) { | 293 if (new_tc) { |
290 ConnectToTransportChannel(new_tc); | 294 ConnectToTransportChannel(new_tc); |
(...skipping 20 matching lines...) Expand all Loading... | |
311 | 315 |
312 if (old_tc) { | 316 if (old_tc) { |
313 DisconnectFromTransportChannel(old_tc); | 317 DisconnectFromTransportChannel(old_tc); |
314 transport_controller_->DestroyTransportChannel_w( | 318 transport_controller_->DestroyTransportChannel_w( |
315 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP); | 319 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP); |
316 } | 320 } |
317 | 321 |
318 rtcp_transport_channel_ = new_tc; | 322 rtcp_transport_channel_ = new_tc; |
319 | 323 |
320 if (new_tc) { | 324 if (new_tc) { |
325 // When a TransportChannel is attached, we always assume there is something | |
326 // to do for DTLS/SRTP to prevent sending anything without encrypted. | |
327 dtls_srtp_setup_pending_ = true; | |
pthatcher1
2015/11/30 20:23:11
Same here as with set_transport_channel()
guoweis_webrtc
2015/12/01 22:05:12
Done.
| |
328 | |
321 ConnectToTransportChannel(new_tc); | 329 ConnectToTransportChannel(new_tc); |
322 for (const auto& pair : rtcp_socket_options_) { | 330 for (const auto& pair : rtcp_socket_options_) { |
323 new_tc->SetOption(pair.first, pair.second); | 331 new_tc->SetOption(pair.first, pair.second); |
324 } | 332 } |
325 } | 333 } |
326 | 334 |
327 // Update aggregate writable/ready-to-send state between RTP and RTCP upon | 335 // Update aggregate writable/ready-to-send state between RTP and RTCP upon |
328 // setting new channel | 336 // setting new channel |
329 UpdateWritableState_w(); | 337 UpdateWritableState_w(); |
330 SetReadyToSend(true, new_tc && new_tc->writable()); | 338 SetReadyToSend(true, new_tc && new_tc->writable()); |
331 } | 339 } |
332 | 340 |
333 void BaseChannel::ConnectToTransportChannel(TransportChannel* tc) { | 341 void BaseChannel::ConnectToTransportChannel(TransportChannel* tc) { |
334 ASSERT(worker_thread_ == rtc::Thread::Current()); | 342 ASSERT(worker_thread_ == rtc::Thread::Current()); |
335 | 343 |
336 tc->SignalWritableState.connect(this, &BaseChannel::OnWritableState); | 344 tc->SignalWritableState.connect(this, &BaseChannel::OnWritableState); |
337 tc->SignalReadPacket.connect(this, &BaseChannel::OnChannelRead); | 345 tc->SignalReadPacket.connect(this, &BaseChannel::OnChannelRead); |
338 tc->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend); | 346 tc->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend); |
347 tc->SignalDtlsState.connect(this, &BaseChannel::OnDtlsState); | |
339 } | 348 } |
340 | 349 |
341 void BaseChannel::DisconnectFromTransportChannel(TransportChannel* tc) { | 350 void BaseChannel::DisconnectFromTransportChannel(TransportChannel* tc) { |
342 ASSERT(worker_thread_ == rtc::Thread::Current()); | 351 ASSERT(worker_thread_ == rtc::Thread::Current()); |
343 | 352 |
344 tc->SignalWritableState.disconnect(this); | 353 tc->SignalWritableState.disconnect(this); |
345 tc->SignalReadPacket.disconnect(this); | 354 tc->SignalReadPacket.disconnect(this); |
346 tc->SignalReadyToSend.disconnect(this); | 355 tc->SignalReadyToSend.disconnect(this); |
356 tc->SignalDtlsState.disconnect(this); | |
347 } | 357 } |
348 | 358 |
349 bool BaseChannel::Enable(bool enable) { | 359 bool BaseChannel::Enable(bool enable) { |
350 worker_thread_->Invoke<void>(Bind( | 360 worker_thread_->Invoke<void>(Bind( |
351 enable ? &BaseChannel::EnableMedia_w : &BaseChannel::DisableMedia_w, | 361 enable ? &BaseChannel::EnableMedia_w : &BaseChannel::DisableMedia_w, |
352 this)); | 362 this)); |
353 return true; | 363 return true; |
354 } | 364 } |
355 | 365 |
356 bool BaseChannel::AddRecvStream(const StreamParams& sp) { | 366 bool BaseChannel::AddRecvStream(const StreamParams& sp) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
409 } | 419 } |
410 | 420 |
411 bool BaseChannel::IsReadyToReceive() const { | 421 bool BaseChannel::IsReadyToReceive() const { |
412 // Receive data if we are enabled and have local content, | 422 // Receive data if we are enabled and have local content, |
413 return enabled() && IsReceiveContentDirection(local_content_direction_); | 423 return enabled() && IsReceiveContentDirection(local_content_direction_); |
414 } | 424 } |
415 | 425 |
416 bool BaseChannel::IsReadyToSend() const { | 426 bool BaseChannel::IsReadyToSend() const { |
417 // Send outgoing data if we are enabled, have local and remote content, | 427 // Send outgoing data if we are enabled, have local and remote content, |
418 // and we have had some form of connectivity. | 428 // and we have had some form of connectivity. |
419 return enabled() && | 429 return enabled() && IsReceiveContentDirection(remote_content_direction_) && |
420 IsReceiveContentDirection(remote_content_direction_) && | |
421 IsSendContentDirection(local_content_direction_) && | 430 IsSendContentDirection(local_content_direction_) && |
422 was_ever_writable(); | 431 !dtls_srtp_setup_pending(); |
pthatcher1
2015/11/30 20:23:11
I think we need this to be something like:
was_ev
guoweis_webrtc
2015/12/01 22:05:12
Done.
| |
423 } | 432 } |
424 | 433 |
425 bool BaseChannel::SendPacket(rtc::Buffer* packet, | 434 bool BaseChannel::SendPacket(rtc::Buffer* packet, |
426 const rtc::PacketOptions& options) { | 435 const rtc::PacketOptions& options) { |
427 return SendPacket(false, packet, options); | 436 return SendPacket(false, packet, options); |
428 } | 437 } |
429 | 438 |
430 bool BaseChannel::SendRtcp(rtc::Buffer* packet, | 439 bool BaseChannel::SendRtcp(rtc::Buffer* packet, |
431 const rtc::PacketOptions& options) { | 440 const rtc::PacketOptions& options) { |
432 return SendPacket(true, packet, options); | 441 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); | 476 bool rtcp = PacketIsRtcp(channel, data, len); |
468 rtc::Buffer packet(data, len); | 477 rtc::Buffer packet(data, len); |
469 HandlePacket(rtcp, &packet, packet_time); | 478 HandlePacket(rtcp, &packet, packet_time); |
470 } | 479 } |
471 | 480 |
472 void BaseChannel::OnReadyToSend(TransportChannel* channel) { | 481 void BaseChannel::OnReadyToSend(TransportChannel* channel) { |
473 ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_); | 482 ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_); |
474 SetReadyToSend(channel == rtcp_transport_channel_, true); | 483 SetReadyToSend(channel == rtcp_transport_channel_, true); |
475 } | 484 } |
476 | 485 |
486 void BaseChannel::OnDtlsState(TransportChannel* channel, | |
487 DtlsTransportState state) { | |
488 if (!ShouldSetupDtlsSrtp()) { | |
pthatcher1
2015/11/30 20:23:11
I think it would make it more readable to rename S
guoweis_webrtc
2015/12/01 22:05:12
NeedSrtp doesn't capture the Dtls concept.
| |
489 dtls_srtp_setup_pending_ = false; | |
pthatcher1
2015/11/30 20:23:11
I think a combination of (srtp_ready() || !NeedSrt
| |
490 return; | |
491 } | |
492 | |
493 // Resetting the srtp filter as long as it's not the CONNECTED signal. For | |
pthatcher1
2015/11/30 20:23:11
Resetting => Reset
as long as => if
pthatcher1
2015/11/30 20:23:11
CONNECTED signal => CONNECTED state
guoweis_webrtc
2015/12/01 22:05:12
Done.
| |
494 // CONNECTED signal, setting up DTLS-SRTP context is deferred to | |
pthatcher1
2015/11/30 20:23:11
For CONNECTED signal => For the connected state.
guoweis_webrtc
2015/12/01 22:05:12
Done.
| |
495 // ChannelWritable_w to cover other scenarios like the whole channel is | |
496 // writable (not just this TransportChannel) or when TransportChannel is | |
497 // attached after DTLS is negotiated. | |
498 if (state != DTLS_TRANSPORT_CONNECTED) { | |
499 srtp_filter_.ResetParams(); | |
500 dtls_srtp_setup_pending_ = true; | |
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 << (dtls_srtp_setup_pending_ ? "" : " for the first time"); |
pthatcher1
2015/11/30 20:23:11
Now this isn't accurate any more. Perhaps it woul
| |
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. | 809 TrySetupDtlsSrtp_w(); |
pthatcher1
2015/11/30 20:23:11
Why is this TrySetupDtlsSrtp_w() instead of SetupD
guoweis_webrtc
2015/12/01 22:05:12
Done.
| |
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; | |
797 writable_ = true; | 810 writable_ = true; |
798 ChangeState(); | 811 ChangeState(); |
799 } | 812 } |
800 | 813 |
801 void BaseChannel::SignalDtlsSetupFailure_w(bool rtcp) { | 814 void BaseChannel::SignalDtlsSetupFailure_w(bool rtcp) { |
802 ASSERT(worker_thread() == rtc::Thread::Current()); | 815 ASSERT(worker_thread() == rtc::Thread::Current()); |
803 signaling_thread()->Invoke<void>(Bind( | 816 signaling_thread()->Invoke<void>(Bind( |
804 &BaseChannel::SignalDtlsSetupFailure_s, this, rtcp)); | 817 &BaseChannel::SignalDtlsSetupFailure_s, this, rtcp)); |
805 } | 818 } |
806 | 819 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
908 } | 921 } |
909 | 922 |
910 if (!ret) | 923 if (!ret) |
911 LOG(LS_WARNING) << "DTLS-SRTP key installation failed"; | 924 LOG(LS_WARNING) << "DTLS-SRTP key installation failed"; |
912 else | 925 else |
913 dtls_keyed_ = true; | 926 dtls_keyed_ = true; |
914 | 927 |
915 return ret; | 928 return ret; |
916 } | 929 } |
917 | 930 |
931 void BaseChannel::TrySetupDtlsSrtp_w() { | |
932 if (!dtls_srtp_setup_pending_) { | |
933 return; | |
934 } | |
935 | |
936 if (!ShouldSetupDtlsSrtp()) { | |
937 dtls_srtp_setup_pending_ = false; | |
938 return; | |
939 } | |
940 | |
941 if (!SetupDtlsSrtp(false)) { | |
942 SignalDtlsSetupFailure_w(false); | |
943 return; | |
944 } | |
945 | |
946 if (rtcp_transport_channel_) { | |
947 if (!SetupDtlsSrtp(true)) { | |
948 SignalDtlsSetupFailure_w(true); | |
949 return; | |
950 } | |
951 } | |
952 dtls_srtp_setup_pending_ = false; | |
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 1350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2278 return (data_channel_type_ == DCT_RTP); | 2315 return (data_channel_type_ == DCT_RTP); |
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 |