deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #include "webrtc/p2p/base/transportcontroller.h" |
| 12 | |
Taylor Brandstetter | c4d3a5d | 2015-09-30 10:32:59 -0700 | [diff] [blame] | 13 | #include <algorithm> |
jbauch | 555604a | 2016-04-26 03:13:22 -0700 | [diff] [blame] | 14 | #include <memory> |
Taylor Brandstetter | c4d3a5d | 2015-09-30 10:32:59 -0700 | [diff] [blame] | 15 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 16 | #include "webrtc/base/bind.h" |
| 17 | #include "webrtc/base/checks.h" |
| 18 | #include "webrtc/base/thread.h" |
Taylor Brandstetter | c4d3a5d | 2015-09-30 10:32:59 -0700 | [diff] [blame] | 19 | #include "webrtc/p2p/base/port.h" |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 20 | |
deadbeef | 62802a1 | 2016-12-13 16:38:36 -0800 | [diff] [blame] | 21 | namespace { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 22 | |
| 23 | enum { |
| 24 | MSG_ICECONNECTIONSTATE, |
| 25 | MSG_RECEIVING, |
| 26 | MSG_ICEGATHERINGSTATE, |
| 27 | MSG_CANDIDATESGATHERED, |
| 28 | }; |
| 29 | |
| 30 | struct CandidatesData : public rtc::MessageData { |
| 31 | CandidatesData(const std::string& transport_name, |
deadbeef | 62802a1 | 2016-12-13 16:38:36 -0800 | [diff] [blame] | 32 | const cricket::Candidates& candidates) |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 33 | : transport_name(transport_name), candidates(candidates) {} |
| 34 | |
| 35 | std::string transport_name; |
deadbeef | 62802a1 | 2016-12-13 16:38:36 -0800 | [diff] [blame] | 36 | cricket::Candidates candidates; |
| 37 | }; |
| 38 | |
| 39 | } // namespace { |
| 40 | |
| 41 | namespace cricket { |
| 42 | |
| 43 | // This class groups the DTLS and ICE channels, and helps keep track of |
| 44 | // how many external objects (BaseChannels) reference each channel. |
| 45 | class TransportController::ChannelPair { |
| 46 | public: |
| 47 | // TODO(deadbeef): Change the types of |dtls| and |ice| to |
| 48 | // DtlsTransportChannelWrapper and P2PTransportChannelWrapper, |
| 49 | // once TransportChannelImpl is removed. |
| 50 | ChannelPair(TransportChannelImpl* dtls, TransportChannelImpl* ice) |
| 51 | : ice_(ice), dtls_(dtls) {} |
| 52 | |
| 53 | // Currently, all ICE-related calls still go through this DTLS channel. But |
| 54 | // that will change once we get rid of TransportChannelImpl, and the DTLS |
| 55 | // channel interface no longer includes ICE-specific methods. |
| 56 | const TransportChannelImpl* dtls() const { return dtls_.get(); } |
| 57 | TransportChannelImpl* dtls() { return dtls_.get(); } |
| 58 | const TransportChannelImpl* ice() const { return ice_.get(); } |
| 59 | TransportChannelImpl* ice() { return ice_.get(); } |
| 60 | |
| 61 | private: |
| 62 | std::unique_ptr<TransportChannelImpl> ice_; |
| 63 | std::unique_ptr<TransportChannelImpl> dtls_; |
| 64 | |
| 65 | RTC_DISALLOW_COPY_AND_ASSIGN(ChannelPair); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | TransportController::TransportController(rtc::Thread* signaling_thread, |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 69 | rtc::Thread* network_thread, |
Taylor Brandstetter | f0bb360 | 2016-08-26 20:59:24 -0700 | [diff] [blame] | 70 | PortAllocator* port_allocator, |
| 71 | bool redetermine_role_on_ice_restart) |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 72 | : signaling_thread_(signaling_thread), |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 73 | network_thread_(network_thread), |
Taylor Brandstetter | f0bb360 | 2016-08-26 20:59:24 -0700 | [diff] [blame] | 74 | port_allocator_(port_allocator), |
| 75 | redetermine_role_on_ice_restart_(redetermine_role_on_ice_restart) {} |
| 76 | |
| 77 | TransportController::TransportController(rtc::Thread* signaling_thread, |
| 78 | rtc::Thread* network_thread, |
| 79 | PortAllocator* port_allocator) |
| 80 | : TransportController(signaling_thread, |
| 81 | network_thread, |
| 82 | port_allocator, |
| 83 | true) {} |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 84 | |
| 85 | TransportController::~TransportController() { |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 86 | // Channel destructors may try to send packets, so this needs to happen on |
| 87 | // the network thread. |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 88 | network_thread_->Invoke<void>( |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 89 | RTC_FROM_HERE, |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 90 | rtc::Bind(&TransportController::DestroyAllChannels_n, this)); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | bool TransportController::SetSslMaxProtocolVersion( |
| 94 | rtc::SSLProtocolVersion version) { |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 95 | return network_thread_->Invoke<bool>( |
| 96 | RTC_FROM_HERE, rtc::Bind(&TransportController::SetSslMaxProtocolVersion_n, |
| 97 | this, version)); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 98 | } |
| 99 | |
honghaiz | 1f429e3 | 2015-09-28 07:57:34 -0700 | [diff] [blame] | 100 | void TransportController::SetIceConfig(const IceConfig& config) { |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 101 | network_thread_->Invoke<void>( |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 102 | RTC_FROM_HERE, |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 103 | rtc::Bind(&TransportController::SetIceConfig_n, this, config)); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | void TransportController::SetIceRole(IceRole ice_role) { |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 107 | network_thread_->Invoke<void>( |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 108 | RTC_FROM_HERE, |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 109 | rtc::Bind(&TransportController::SetIceRole_n, this, ice_role)); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 110 | } |
| 111 | |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 112 | void TransportController::SetNeedsIceRestartFlag() { |
| 113 | for (auto& kv : transports_) { |
| 114 | kv.second->SetNeedsIceRestartFlag(); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | bool TransportController::NeedsIceRestart( |
| 119 | const std::string& transport_name) const { |
| 120 | const JsepTransport* transport = GetJsepTransport(transport_name); |
| 121 | if (!transport) { |
| 122 | return false; |
| 123 | } |
| 124 | return transport->NeedsIceRestart(); |
| 125 | } |
| 126 | |
Taylor Brandstetter | f475d36 | 2016-01-08 15:35:57 -0800 | [diff] [blame] | 127 | bool TransportController::GetSslRole(const std::string& transport_name, |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 128 | rtc::SSLRole* role) const { |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 129 | return network_thread_->Invoke<bool>( |
| 130 | RTC_FROM_HERE, rtc::Bind(&TransportController::GetSslRole_n, this, |
| 131 | transport_name, role)); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | bool TransportController::SetLocalCertificate( |
| 135 | const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) { |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 136 | return network_thread_->Invoke<bool>( |
| 137 | RTC_FROM_HERE, rtc::Bind(&TransportController::SetLocalCertificate_n, |
| 138 | this, certificate)); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | bool TransportController::GetLocalCertificate( |
| 142 | const std::string& transport_name, |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 143 | rtc::scoped_refptr<rtc::RTCCertificate>* certificate) const { |
hbos | df6075a | 2016-12-19 04:58:02 -0800 | [diff] [blame^] | 144 | if (network_thread_->IsCurrent()) { |
| 145 | return GetLocalCertificate_n(transport_name, certificate); |
| 146 | } |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 147 | return network_thread_->Invoke<bool>( |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 148 | RTC_FROM_HERE, rtc::Bind(&TransportController::GetLocalCertificate_n, |
| 149 | this, transport_name, certificate)); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 150 | } |
| 151 | |
jbauch | 555604a | 2016-04-26 03:13:22 -0700 | [diff] [blame] | 152 | std::unique_ptr<rtc::SSLCertificate> |
kwiberg | b4d01c4 | 2016-04-06 05:15:06 -0700 | [diff] [blame] | 153 | TransportController::GetRemoteSSLCertificate( |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 154 | const std::string& transport_name) const { |
hbos | df6075a | 2016-12-19 04:58:02 -0800 | [diff] [blame^] | 155 | if (network_thread_->IsCurrent()) { |
| 156 | return GetRemoteSSLCertificate_n(transport_name); |
| 157 | } |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 158 | return network_thread_->Invoke<std::unique_ptr<rtc::SSLCertificate>>( |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 159 | RTC_FROM_HERE, rtc::Bind(&TransportController::GetRemoteSSLCertificate_n, |
| 160 | this, transport_name)); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | bool TransportController::SetLocalTransportDescription( |
| 164 | const std::string& transport_name, |
| 165 | const TransportDescription& tdesc, |
| 166 | ContentAction action, |
| 167 | std::string* err) { |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 168 | return network_thread_->Invoke<bool>( |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 169 | RTC_FROM_HERE, |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 170 | rtc::Bind(&TransportController::SetLocalTransportDescription_n, this, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 171 | transport_name, tdesc, action, err)); |
| 172 | } |
| 173 | |
| 174 | bool TransportController::SetRemoteTransportDescription( |
| 175 | const std::string& transport_name, |
| 176 | const TransportDescription& tdesc, |
| 177 | ContentAction action, |
| 178 | std::string* err) { |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 179 | return network_thread_->Invoke<bool>( |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 180 | RTC_FROM_HERE, |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 181 | rtc::Bind(&TransportController::SetRemoteTransportDescription_n, this, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 182 | transport_name, tdesc, action, err)); |
| 183 | } |
| 184 | |
| 185 | void TransportController::MaybeStartGathering() { |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 186 | network_thread_->Invoke<void>( |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 187 | RTC_FROM_HERE, |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 188 | rtc::Bind(&TransportController::MaybeStartGathering_n, this)); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | bool TransportController::AddRemoteCandidates(const std::string& transport_name, |
| 192 | const Candidates& candidates, |
| 193 | std::string* err) { |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 194 | return network_thread_->Invoke<bool>( |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 195 | RTC_FROM_HERE, rtc::Bind(&TransportController::AddRemoteCandidates_n, |
| 196 | this, transport_name, candidates, err)); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 197 | } |
| 198 | |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 199 | bool TransportController::RemoveRemoteCandidates(const Candidates& candidates, |
| 200 | std::string* err) { |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 201 | return network_thread_->Invoke<bool>( |
| 202 | RTC_FROM_HERE, rtc::Bind(&TransportController::RemoveRemoteCandidates_n, |
| 203 | this, candidates, err)); |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 204 | } |
| 205 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 206 | bool TransportController::ReadyForRemoteCandidates( |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 207 | const std::string& transport_name) const { |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 208 | return network_thread_->Invoke<bool>( |
| 209 | RTC_FROM_HERE, rtc::Bind(&TransportController::ReadyForRemoteCandidates_n, |
| 210 | this, transport_name)); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | bool TransportController::GetStats(const std::string& transport_name, |
| 214 | TransportStats* stats) { |
hbos | df6075a | 2016-12-19 04:58:02 -0800 | [diff] [blame^] | 215 | if (network_thread_->IsCurrent()) { |
| 216 | return GetStats_n(transport_name, stats); |
| 217 | } |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 218 | return network_thread_->Invoke<bool>( |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 219 | RTC_FROM_HERE, |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 220 | rtc::Bind(&TransportController::GetStats_n, this, transport_name, stats)); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 221 | } |
| 222 | |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 223 | void TransportController::SetMetricsObserver( |
| 224 | webrtc::MetricsObserverInterface* metrics_observer) { |
| 225 | return network_thread_->Invoke<void>( |
| 226 | RTC_FROM_HERE, rtc::Bind(&TransportController::SetMetricsObserver_n, this, |
| 227 | metrics_observer)); |
| 228 | } |
| 229 | |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 230 | TransportChannel* TransportController::CreateTransportChannel_n( |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 231 | const std::string& transport_name, |
| 232 | int component) { |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 233 | RTC_DCHECK(network_thread_->IsCurrent()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 234 | |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 235 | RefCountedChannel* existing_channel = GetChannel_n(transport_name, component); |
| 236 | if (existing_channel) { |
Taylor Brandstetter | c4d3a5d | 2015-09-30 10:32:59 -0700 | [diff] [blame] | 237 | // Channel already exists; increment reference count and return. |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 238 | existing_channel->AddRef(); |
| 239 | return existing_channel->dtls(); |
Taylor Brandstetter | c4d3a5d | 2015-09-30 10:32:59 -0700 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | // Need to create a new channel. |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 243 | JsepTransport* transport = GetOrCreateJsepTransport(transport_name); |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 244 | |
| 245 | // Create DTLS channel wrapping ICE channel, and configure it. |
| 246 | TransportChannelImpl* ice = |
| 247 | CreateIceTransportChannel_n(transport_name, component); |
| 248 | // TODO(deadbeef): To support QUIC, would need to create a |
| 249 | // QuicTransportChannel here. What is "dtls" in this file would then become |
| 250 | // "dtls or quic". |
| 251 | TransportChannelImpl* dtls = |
| 252 | CreateDtlsTransportChannel_n(transport_name, component, ice); |
| 253 | dtls->SetMetricsObserver(metrics_observer_); |
| 254 | dtls->SetIceRole(ice_role_); |
| 255 | dtls->SetIceTiebreaker(ice_tiebreaker_); |
| 256 | dtls->SetIceConfig(ice_config_); |
| 257 | if (certificate_) { |
| 258 | bool set_cert_success = dtls->SetLocalCertificate(certificate_); |
| 259 | RTC_DCHECK(set_cert_success); |
| 260 | } |
| 261 | |
| 262 | // Connect to signals offered by the channels. Currently, the DTLS channel |
| 263 | // forwards signals from the ICE channel, so we only need to connect to the |
| 264 | // DTLS channel. In the future this won't be the case. |
| 265 | dtls->SignalWritableState.connect( |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 266 | this, &TransportController::OnChannelWritableState_n); |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 267 | dtls->SignalReceivingState.connect( |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 268 | this, &TransportController::OnChannelReceivingState_n); |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 269 | dtls->SignalGatheringState.connect( |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 270 | this, &TransportController::OnChannelGatheringState_n); |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 271 | dtls->SignalCandidateGathered.connect( |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 272 | this, &TransportController::OnChannelCandidateGathered_n); |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 273 | dtls->SignalCandidatesRemoved.connect( |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 274 | this, &TransportController::OnChannelCandidatesRemoved_n); |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 275 | dtls->SignalRoleConflict.connect( |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 276 | this, &TransportController::OnChannelRoleConflict_n); |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 277 | dtls->SignalStateChanged.connect( |
Honghai Zhang | 1590c39 | 2016-05-24 13:15:02 -0700 | [diff] [blame] | 278 | this, &TransportController::OnChannelStateChanged_n); |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 279 | dtls->SignalDtlsHandshakeError.connect( |
zhihuang | d82eee0 | 2016-08-26 11:25:05 -0700 | [diff] [blame] | 280 | this, &TransportController::OnDtlsHandshakeError); |
deadbeef | 62802a1 | 2016-12-13 16:38:36 -0800 | [diff] [blame] | 281 | RefCountedChannel* new_pair = new RefCountedChannel(dtls, ice); |
| 282 | new_pair->AddRef(); |
| 283 | channels_.insert(channels_.end(), new_pair); |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 284 | bool channel_added = transport->AddChannel(dtls, component); |
| 285 | RTC_DCHECK(channel_added); |
Taylor Brandstetter | c4d3a5d | 2015-09-30 10:32:59 -0700 | [diff] [blame] | 286 | // Adding a channel could cause aggregate state to change. |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 287 | UpdateAggregateStates_n(); |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 288 | return dtls; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 289 | } |
| 290 | |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 291 | void TransportController::DestroyTransportChannel_n( |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 292 | const std::string& transport_name, |
| 293 | int component) { |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 294 | RTC_DCHECK(network_thread_->IsCurrent()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 295 | |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 296 | auto it = GetChannelIterator_n(transport_name, component); |
Taylor Brandstetter | c4d3a5d | 2015-09-30 10:32:59 -0700 | [diff] [blame] | 297 | if (it == channels_.end()) { |
| 298 | LOG(LS_WARNING) << "Attempting to delete " << transport_name |
| 299 | << " TransportChannel " << component |
| 300 | << ", which doesn't exist."; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 301 | return; |
| 302 | } |
deadbeef | 62802a1 | 2016-12-13 16:38:36 -0800 | [diff] [blame] | 303 | if ((*it)->Release() > 0) { |
Taylor Brandstetter | c4d3a5d | 2015-09-30 10:32:59 -0700 | [diff] [blame] | 304 | return; |
| 305 | } |
deadbeef | 57fd726 | 2016-12-06 15:28:55 -0800 | [diff] [blame] | 306 | channels_.erase(it); |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 307 | |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 308 | JsepTransport* t = GetJsepTransport(transport_name); |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 309 | bool channel_removed = t->RemoveChannel(component); |
| 310 | RTC_DCHECK(channel_removed); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 311 | // Just as we create a Transport when its first channel is created, |
| 312 | // we delete it when its last channel is deleted. |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 313 | if (!t->HasChannels()) { |
| 314 | transports_.erase(transport_name); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 315 | } |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 316 | |
Taylor Brandstetter | c4d3a5d | 2015-09-30 10:32:59 -0700 | [diff] [blame] | 317 | // Removing a channel could cause aggregate state to change. |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 318 | UpdateAggregateStates_n(); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 319 | } |
| 320 | |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 321 | std::vector<std::string> TransportController::transport_names_for_testing() { |
| 322 | std::vector<std::string> ret; |
| 323 | for (const auto& kv : transports_) { |
| 324 | ret.push_back(kv.first); |
mikescarlett | e774867 | 2016-04-29 20:20:54 -0700 | [diff] [blame] | 325 | } |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 326 | return ret; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 327 | } |
| 328 | |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 329 | std::vector<TransportChannelImpl*> TransportController::channels_for_testing() { |
| 330 | std::vector<TransportChannelImpl*> ret; |
deadbeef | 62802a1 | 2016-12-13 16:38:36 -0800 | [diff] [blame] | 331 | for (RefCountedChannel* channel : channels_) { |
| 332 | ret.push_back(channel->dtls()); |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 333 | } |
| 334 | return ret; |
| 335 | } |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 336 | |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 337 | TransportChannelImpl* TransportController::get_channel_for_testing( |
| 338 | const std::string& transport_name, |
| 339 | int component) { |
| 340 | RefCountedChannel* ch = GetChannel_n(transport_name, component); |
| 341 | return ch ? ch->dtls() : nullptr; |
| 342 | } |
| 343 | |
| 344 | TransportChannelImpl* TransportController::CreateIceTransportChannel_n( |
| 345 | const std::string& transport_name, |
| 346 | int component) { |
| 347 | return new P2PTransportChannel(transport_name, component, port_allocator_); |
| 348 | } |
| 349 | |
| 350 | TransportChannelImpl* TransportController::CreateDtlsTransportChannel_n( |
| 351 | const std::string&, |
| 352 | int, |
| 353 | TransportChannelImpl* ice) { |
| 354 | DtlsTransportChannelWrapper* dtls = new DtlsTransportChannelWrapper(ice); |
| 355 | dtls->SetSslMaxProtocolVersion(ssl_max_version_); |
| 356 | return dtls; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | void TransportController::OnMessage(rtc::Message* pmsg) { |
| 360 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 361 | |
| 362 | switch (pmsg->message_id) { |
| 363 | case MSG_ICECONNECTIONSTATE: { |
| 364 | rtc::TypedMessageData<IceConnectionState>* data = |
| 365 | static_cast<rtc::TypedMessageData<IceConnectionState>*>(pmsg->pdata); |
| 366 | SignalConnectionState(data->data()); |
| 367 | delete data; |
| 368 | break; |
| 369 | } |
| 370 | case MSG_RECEIVING: { |
| 371 | rtc::TypedMessageData<bool>* data = |
| 372 | static_cast<rtc::TypedMessageData<bool>*>(pmsg->pdata); |
| 373 | SignalReceiving(data->data()); |
| 374 | delete data; |
| 375 | break; |
| 376 | } |
| 377 | case MSG_ICEGATHERINGSTATE: { |
| 378 | rtc::TypedMessageData<IceGatheringState>* data = |
| 379 | static_cast<rtc::TypedMessageData<IceGatheringState>*>(pmsg->pdata); |
| 380 | SignalGatheringState(data->data()); |
| 381 | delete data; |
| 382 | break; |
| 383 | } |
| 384 | case MSG_CANDIDATESGATHERED: { |
| 385 | CandidatesData* data = static_cast<CandidatesData*>(pmsg->pdata); |
| 386 | SignalCandidatesGathered(data->transport_name, data->candidates); |
| 387 | delete data; |
| 388 | break; |
| 389 | } |
| 390 | default: |
| 391 | ASSERT(false); |
| 392 | } |
| 393 | } |
| 394 | |
deadbeef | 62802a1 | 2016-12-13 16:38:36 -0800 | [diff] [blame] | 395 | std::vector<TransportController::RefCountedChannel*>::iterator |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 396 | TransportController::GetChannelIterator_n(const std::string& transport_name, |
| 397 | int component) { |
| 398 | RTC_DCHECK(network_thread_->IsCurrent()); |
deadbeef | 62802a1 | 2016-12-13 16:38:36 -0800 | [diff] [blame] | 399 | return std::find_if(channels_.begin(), channels_.end(), |
| 400 | [transport_name, component](RefCountedChannel* channel) { |
| 401 | return channel->dtls()->transport_name() == |
| 402 | transport_name && |
| 403 | channel->dtls()->component() == component; |
| 404 | }); |
Taylor Brandstetter | c4d3a5d | 2015-09-30 10:32:59 -0700 | [diff] [blame] | 405 | } |
| 406 | |
deadbeef | 62802a1 | 2016-12-13 16:38:36 -0800 | [diff] [blame] | 407 | std::vector<TransportController::RefCountedChannel*>::const_iterator |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 408 | TransportController::GetChannelIterator_n(const std::string& transport_name, |
| 409 | int component) const { |
| 410 | RTC_DCHECK(network_thread_->IsCurrent()); |
| 411 | return std::find_if( |
| 412 | channels_.begin(), channels_.end(), |
deadbeef | 62802a1 | 2016-12-13 16:38:36 -0800 | [diff] [blame] | 413 | [transport_name, component](const RefCountedChannel* channel) { |
| 414 | return channel->dtls()->transport_name() == transport_name && |
| 415 | channel->dtls()->component() == component; |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 416 | }); |
| 417 | } |
| 418 | |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 419 | const JsepTransport* TransportController::GetJsepTransport( |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 420 | const std::string& transport_name) const { |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 421 | auto it = transports_.find(transport_name); |
| 422 | return (it == transports_.end()) ? nullptr : it->second.get(); |
| 423 | } |
| 424 | |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 425 | JsepTransport* TransportController::GetJsepTransport( |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 426 | const std::string& transport_name) { |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 427 | auto it = transports_.find(transport_name); |
| 428 | return (it == transports_.end()) ? nullptr : it->second.get(); |
| 429 | } |
| 430 | |
| 431 | const TransportController::RefCountedChannel* TransportController::GetChannel_n( |
| 432 | const std::string& transport_name, |
| 433 | int component) const { |
| 434 | RTC_DCHECK(network_thread_->IsCurrent()); |
| 435 | auto it = GetChannelIterator_n(transport_name, component); |
deadbeef | 62802a1 | 2016-12-13 16:38:36 -0800 | [diff] [blame] | 436 | return (it == channels_.end()) ? nullptr : *it; |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | TransportController::RefCountedChannel* TransportController::GetChannel_n( |
| 440 | const std::string& transport_name, |
| 441 | int component) { |
| 442 | RTC_DCHECK(network_thread_->IsCurrent()); |
| 443 | auto it = GetChannelIterator_n(transport_name, component); |
deadbeef | 62802a1 | 2016-12-13 16:38:36 -0800 | [diff] [blame] | 444 | return (it == channels_.end()) ? nullptr : *it; |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 445 | } |
| 446 | |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 447 | JsepTransport* TransportController::GetOrCreateJsepTransport( |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 448 | const std::string& transport_name) { |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 449 | RTC_DCHECK(network_thread_->IsCurrent()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 450 | |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 451 | JsepTransport* transport = GetJsepTransport(transport_name); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 452 | if (transport) { |
| 453 | return transport; |
| 454 | } |
| 455 | |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 456 | transport = new JsepTransport(transport_name, certificate_); |
| 457 | transports_[transport_name] = std::unique_ptr<JsepTransport>(transport); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 458 | return transport; |
| 459 | } |
| 460 | |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 461 | void TransportController::DestroyAllChannels_n() { |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 462 | RTC_DCHECK(network_thread_->IsCurrent()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 463 | transports_.clear(); |
deadbeef | 62802a1 | 2016-12-13 16:38:36 -0800 | [diff] [blame] | 464 | for (RefCountedChannel* channel : channels_) { |
| 465 | // Even though these objects are normally ref-counted, if |
| 466 | // TransportController is deleted while they still have references, just |
| 467 | // remove all references. |
| 468 | while (channel->Release() > 0) { |
| 469 | } |
| 470 | } |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 471 | channels_.clear(); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 472 | } |
| 473 | |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 474 | bool TransportController::SetSslMaxProtocolVersion_n( |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 475 | rtc::SSLProtocolVersion version) { |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 476 | RTC_DCHECK(network_thread_->IsCurrent()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 477 | |
| 478 | // Max SSL version can only be set before transports are created. |
| 479 | if (!transports_.empty()) { |
| 480 | return false; |
| 481 | } |
| 482 | |
| 483 | ssl_max_version_ = version; |
| 484 | return true; |
| 485 | } |
| 486 | |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 487 | void TransportController::SetIceConfig_n(const IceConfig& config) { |
| 488 | RTC_DCHECK(network_thread_->IsCurrent()); |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 489 | |
honghaiz | 1f429e3 | 2015-09-28 07:57:34 -0700 | [diff] [blame] | 490 | ice_config_ = config; |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 491 | for (auto& channel : channels_) { |
deadbeef | 62802a1 | 2016-12-13 16:38:36 -0800 | [diff] [blame] | 492 | channel->dtls()->SetIceConfig(ice_config_); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 493 | } |
| 494 | } |
| 495 | |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 496 | void TransportController::SetIceRole_n(IceRole ice_role) { |
| 497 | RTC_DCHECK(network_thread_->IsCurrent()); |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 498 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 499 | ice_role_ = ice_role; |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 500 | for (auto& channel : channels_) { |
deadbeef | 62802a1 | 2016-12-13 16:38:36 -0800 | [diff] [blame] | 501 | channel->dtls()->SetIceRole(ice_role_); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 502 | } |
| 503 | } |
| 504 | |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 505 | bool TransportController::GetSslRole_n(const std::string& transport_name, |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 506 | rtc::SSLRole* role) const { |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 507 | RTC_DCHECK(network_thread_->IsCurrent()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 508 | |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 509 | const JsepTransport* t = GetJsepTransport(transport_name); |
Taylor Brandstetter | f475d36 | 2016-01-08 15:35:57 -0800 | [diff] [blame] | 510 | if (!t) { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 511 | return false; |
| 512 | } |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 513 | t->GetSslRole(role); |
| 514 | return true; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 515 | } |
| 516 | |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 517 | bool TransportController::SetLocalCertificate_n( |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 518 | const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) { |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 519 | RTC_DCHECK(network_thread_->IsCurrent()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 520 | |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 521 | // Can't change a certificate, or set a null certificate. |
| 522 | if (certificate_ || !certificate) { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 523 | return false; |
| 524 | } |
| 525 | certificate_ = certificate; |
| 526 | |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 527 | // Set certificate both for Transport, which verifies it matches the |
| 528 | // fingerprint in SDP... |
| 529 | for (auto& kv : transports_) { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 530 | kv.second->SetLocalCertificate(certificate_); |
| 531 | } |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 532 | // ... and for the DTLS channel, which needs it for the DTLS handshake. |
| 533 | for (auto& channel : channels_) { |
deadbeef | 62802a1 | 2016-12-13 16:38:36 -0800 | [diff] [blame] | 534 | bool set_cert_success = channel->dtls()->SetLocalCertificate(certificate); |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 535 | RTC_DCHECK(set_cert_success); |
| 536 | } |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 537 | return true; |
| 538 | } |
| 539 | |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 540 | bool TransportController::GetLocalCertificate_n( |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 541 | const std::string& transport_name, |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 542 | rtc::scoped_refptr<rtc::RTCCertificate>* certificate) const { |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 543 | RTC_DCHECK(network_thread_->IsCurrent()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 544 | |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 545 | const JsepTransport* t = GetJsepTransport(transport_name); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 546 | if (!t) { |
| 547 | return false; |
| 548 | } |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 549 | return t->GetLocalCertificate(certificate); |
| 550 | } |
| 551 | |
jbauch | 555604a | 2016-04-26 03:13:22 -0700 | [diff] [blame] | 552 | std::unique_ptr<rtc::SSLCertificate> |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 553 | TransportController::GetRemoteSSLCertificate_n( |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 554 | const std::string& transport_name) const { |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 555 | RTC_DCHECK(network_thread_->IsCurrent()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 556 | |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 557 | // Get the certificate from the RTP channel's DTLS handshake. Should be |
| 558 | // identical to the RTCP channel's, since they were given the same remote |
| 559 | // fingerprint. |
| 560 | const RefCountedChannel* ch = GetChannel_n(transport_name, 1); |
| 561 | if (!ch) { |
kwiberg | b4d01c4 | 2016-04-06 05:15:06 -0700 | [diff] [blame] | 562 | return nullptr; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 563 | } |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 564 | return ch->dtls()->GetRemoteSSLCertificate(); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 565 | } |
| 566 | |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 567 | bool TransportController::SetLocalTransportDescription_n( |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 568 | const std::string& transport_name, |
| 569 | const TransportDescription& tdesc, |
| 570 | ContentAction action, |
| 571 | std::string* err) { |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 572 | RTC_DCHECK(network_thread_->IsCurrent()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 573 | |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 574 | JsepTransport* transport = GetJsepTransport(transport_name); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 575 | if (!transport) { |
| 576 | // If we didn't find a transport, that's not an error; |
| 577 | // it could have been deleted as a result of bundling. |
| 578 | // TODO(deadbeef): Make callers smarter so they won't attempt to set a |
| 579 | // description on a deleted transport. |
| 580 | return true; |
| 581 | } |
| 582 | |
deadbeef | 91042f8 | 2016-07-15 17:48:13 -0700 | [diff] [blame] | 583 | // Older versions of Chrome expect the ICE role to be re-determined when an |
| 584 | // ICE restart occurs, and also don't perform conflict resolution correctly, |
Taylor Brandstetter | f0bb360 | 2016-08-26 20:59:24 -0700 | [diff] [blame] | 585 | // so for now we can't safely stop doing this, unless the application opts in |
| 586 | // by setting |redetermine_role_on_ice_restart_| to false. |
deadbeef | 91042f8 | 2016-07-15 17:48:13 -0700 | [diff] [blame] | 587 | // See: https://bugs.chromium.org/p/chromium/issues/detail?id=628676 |
| 588 | // TODO(deadbeef): Remove this when these old versions of Chrome reach a low |
| 589 | // enough population. |
Taylor Brandstetter | f0bb360 | 2016-08-26 20:59:24 -0700 | [diff] [blame] | 590 | if (redetermine_role_on_ice_restart_ && transport->local_description() && |
deadbeef | 91042f8 | 2016-07-15 17:48:13 -0700 | [diff] [blame] | 591 | IceCredentialsChanged(transport->local_description()->ice_ufrag, |
| 592 | transport->local_description()->ice_pwd, |
| 593 | tdesc.ice_ufrag, tdesc.ice_pwd)) { |
| 594 | IceRole new_ice_role = |
| 595 | (action == CA_OFFER) ? ICEROLE_CONTROLLING : ICEROLE_CONTROLLED; |
| 596 | SetIceRole(new_ice_role); |
| 597 | } |
| 598 | |
Honghai Zhang | 9ecb085 | 2016-09-15 16:41:04 -0700 | [diff] [blame] | 599 | LOG(LS_INFO) << "Set local transport description on " << transport_name; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 600 | return transport->SetLocalTransportDescription(tdesc, action, err); |
| 601 | } |
| 602 | |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 603 | bool TransportController::SetRemoteTransportDescription_n( |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 604 | const std::string& transport_name, |
| 605 | const TransportDescription& tdesc, |
| 606 | ContentAction action, |
| 607 | std::string* err) { |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 608 | RTC_DCHECK(network_thread_->IsCurrent()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 609 | |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 610 | // If our role is ICEROLE_CONTROLLED and the remote endpoint supports only |
| 611 | // ice_lite, this local endpoint should take the CONTROLLING role. |
| 612 | // TODO(deadbeef): This is a session-level attribute, so it really shouldn't |
| 613 | // be in a TransportDescription in the first place... |
| 614 | if (ice_role_ == ICEROLE_CONTROLLED && tdesc.ice_mode == ICEMODE_LITE) { |
| 615 | SetIceRole_n(ICEROLE_CONTROLLING); |
| 616 | } |
| 617 | |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 618 | JsepTransport* transport = GetJsepTransport(transport_name); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 619 | if (!transport) { |
| 620 | // If we didn't find a transport, that's not an error; |
| 621 | // it could have been deleted as a result of bundling. |
| 622 | // TODO(deadbeef): Make callers smarter so they won't attempt to set a |
| 623 | // description on a deleted transport. |
| 624 | return true; |
| 625 | } |
| 626 | |
Honghai Zhang | 9ecb085 | 2016-09-15 16:41:04 -0700 | [diff] [blame] | 627 | LOG(LS_INFO) << "Set remote transport description on " << transport_name; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 628 | return transport->SetRemoteTransportDescription(tdesc, action, err); |
| 629 | } |
| 630 | |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 631 | void TransportController::MaybeStartGathering_n() { |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 632 | for (auto& channel : channels_) { |
deadbeef | 62802a1 | 2016-12-13 16:38:36 -0800 | [diff] [blame] | 633 | channel->dtls()->MaybeStartGathering(); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 634 | } |
| 635 | } |
| 636 | |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 637 | bool TransportController::AddRemoteCandidates_n( |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 638 | const std::string& transport_name, |
| 639 | const Candidates& candidates, |
| 640 | std::string* err) { |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 641 | RTC_DCHECK(network_thread_->IsCurrent()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 642 | |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 643 | // Verify each candidate before passing down to the transport layer. |
| 644 | if (!VerifyCandidates(candidates, err)) { |
| 645 | return false; |
| 646 | } |
| 647 | |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 648 | JsepTransport* transport = GetJsepTransport(transport_name); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 649 | if (!transport) { |
| 650 | // If we didn't find a transport, that's not an error; |
| 651 | // it could have been deleted as a result of bundling. |
| 652 | return true; |
| 653 | } |
| 654 | |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 655 | for (const Candidate& candidate : candidates) { |
| 656 | RefCountedChannel* channel = |
| 657 | GetChannel_n(transport_name, candidate.component()); |
| 658 | if (!channel) { |
| 659 | *err = "Candidate has an unknown component: " + candidate.ToString() + |
| 660 | " for content: " + transport_name; |
| 661 | return false; |
| 662 | } |
| 663 | channel->dtls()->AddRemoteCandidate(candidate); |
| 664 | } |
| 665 | return true; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 666 | } |
| 667 | |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 668 | bool TransportController::RemoveRemoteCandidates_n(const Candidates& candidates, |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 669 | std::string* err) { |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 670 | RTC_DCHECK(network_thread_->IsCurrent()); |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 671 | |
| 672 | // Verify each candidate before passing down to the transport layer. |
| 673 | if (!VerifyCandidates(candidates, err)) { |
| 674 | return false; |
| 675 | } |
| 676 | |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 677 | std::map<std::string, Candidates> candidates_by_transport_name; |
| 678 | for (const Candidate& cand : candidates) { |
| 679 | RTC_DCHECK(!cand.transport_name().empty()); |
| 680 | candidates_by_transport_name[cand.transport_name()].push_back(cand); |
| 681 | } |
| 682 | |
| 683 | bool result = true; |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 684 | for (const auto& kv : candidates_by_transport_name) { |
| 685 | const std::string& transport_name = kv.first; |
| 686 | const Candidates& candidates = kv.second; |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 687 | JsepTransport* transport = GetJsepTransport(transport_name); |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 688 | if (!transport) { |
| 689 | // If we didn't find a transport, that's not an error; |
| 690 | // it could have been deleted as a result of bundling. |
| 691 | continue; |
| 692 | } |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 693 | for (const Candidate& candidate : candidates) { |
| 694 | RefCountedChannel* channel = |
| 695 | GetChannel_n(transport_name, candidate.component()); |
| 696 | if (channel) { |
| 697 | channel->dtls()->RemoveRemoteCandidate(candidate); |
| 698 | } |
| 699 | } |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 700 | } |
| 701 | return result; |
| 702 | } |
| 703 | |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 704 | bool TransportController::ReadyForRemoteCandidates_n( |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 705 | const std::string& transport_name) const { |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 706 | RTC_DCHECK(network_thread_->IsCurrent()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 707 | |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 708 | const JsepTransport* transport = GetJsepTransport(transport_name); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 709 | if (!transport) { |
| 710 | return false; |
| 711 | } |
| 712 | return transport->ready_for_remote_candidates(); |
| 713 | } |
| 714 | |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 715 | bool TransportController::GetStats_n(const std::string& transport_name, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 716 | TransportStats* stats) { |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 717 | RTC_DCHECK(network_thread_->IsCurrent()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 718 | |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 719 | JsepTransport* transport = GetJsepTransport(transport_name); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 720 | if (!transport) { |
| 721 | return false; |
| 722 | } |
| 723 | return transport->GetStats(stats); |
| 724 | } |
| 725 | |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 726 | void TransportController::SetMetricsObserver_n( |
| 727 | webrtc::MetricsObserverInterface* metrics_observer) { |
| 728 | RTC_DCHECK(network_thread_->IsCurrent()); |
| 729 | metrics_observer_ = metrics_observer; |
| 730 | for (auto& channel : channels_) { |
deadbeef | 62802a1 | 2016-12-13 16:38:36 -0800 | [diff] [blame] | 731 | channel->dtls()->SetMetricsObserver(metrics_observer); |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 732 | } |
| 733 | } |
| 734 | |
johan | d89ab14 | 2016-10-25 10:50:32 -0700 | [diff] [blame] | 735 | void TransportController::OnChannelWritableState_n( |
| 736 | rtc::PacketTransportInterface* transport) { |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 737 | RTC_DCHECK(network_thread_->IsCurrent()); |
johan | d89ab14 | 2016-10-25 10:50:32 -0700 | [diff] [blame] | 738 | LOG(LS_INFO) << " TransportChannel " << transport->debug_name() |
| 739 | << " writability changed to " << transport->writable() << "."; |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 740 | UpdateAggregateStates_n(); |
Taylor Brandstetter | c4d3a5d | 2015-09-30 10:32:59 -0700 | [diff] [blame] | 741 | } |
| 742 | |
johan | 15ca8f6 | 2016-11-01 01:47:41 -0700 | [diff] [blame] | 743 | void TransportController::OnChannelReceivingState_n( |
| 744 | rtc::PacketTransportInterface* transport) { |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 745 | RTC_DCHECK(network_thread_->IsCurrent()); |
| 746 | UpdateAggregateStates_n(); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 747 | } |
| 748 | |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 749 | void TransportController::OnChannelGatheringState_n( |
Taylor Brandstetter | c4d3a5d | 2015-09-30 10:32:59 -0700 | [diff] [blame] | 750 | TransportChannelImpl* channel) { |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 751 | RTC_DCHECK(network_thread_->IsCurrent()); |
| 752 | UpdateAggregateStates_n(); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 753 | } |
| 754 | |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 755 | void TransportController::OnChannelCandidateGathered_n( |
Taylor Brandstetter | c4d3a5d | 2015-09-30 10:32:59 -0700 | [diff] [blame] | 756 | TransportChannelImpl* channel, |
| 757 | const Candidate& candidate) { |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 758 | RTC_DCHECK(network_thread_->IsCurrent()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 759 | |
Taylor Brandstetter | c4d3a5d | 2015-09-30 10:32:59 -0700 | [diff] [blame] | 760 | // We should never signal peer-reflexive candidates. |
| 761 | if (candidate.type() == PRFLX_PORT_TYPE) { |
| 762 | RTC_DCHECK(false); |
| 763 | return; |
| 764 | } |
| 765 | std::vector<Candidate> candidates; |
| 766 | candidates.push_back(candidate); |
| 767 | CandidatesData* data = |
| 768 | new CandidatesData(channel->transport_name(), candidates); |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 769 | signaling_thread_->Post(RTC_FROM_HERE, this, MSG_CANDIDATESGATHERED, data); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 770 | } |
| 771 | |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 772 | void TransportController::OnChannelCandidatesRemoved_n( |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 773 | TransportChannelImpl* channel, |
| 774 | const Candidates& candidates) { |
| 775 | invoker_.AsyncInvoke<void>( |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 776 | RTC_FROM_HERE, signaling_thread_, |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 777 | rtc::Bind(&TransportController::OnChannelCandidatesRemoved, this, |
| 778 | candidates)); |
| 779 | } |
| 780 | |
| 781 | void TransportController::OnChannelCandidatesRemoved( |
| 782 | const Candidates& candidates) { |
| 783 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 784 | SignalCandidatesRemoved(candidates); |
| 785 | } |
| 786 | |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 787 | void TransportController::OnChannelRoleConflict_n( |
Taylor Brandstetter | c4d3a5d | 2015-09-30 10:32:59 -0700 | [diff] [blame] | 788 | TransportChannelImpl* channel) { |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 789 | RTC_DCHECK(network_thread_->IsCurrent()); |
deadbeef | 1c20610 | 2016-05-27 13:34:37 -0700 | [diff] [blame] | 790 | // Note: since the role conflict is handled entirely on the network thread, |
| 791 | // we don't need to worry about role conflicts occurring on two ports at once. |
| 792 | // The first one encountered should immediately reverse the role. |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 793 | IceRole reversed_role = (ice_role_ == ICEROLE_CONTROLLING) |
| 794 | ? ICEROLE_CONTROLLED |
| 795 | : ICEROLE_CONTROLLING; |
deadbeef | 1c20610 | 2016-05-27 13:34:37 -0700 | [diff] [blame] | 796 | LOG(LS_INFO) << "Got role conflict; switching to " |
| 797 | << (reversed_role == ICEROLE_CONTROLLING ? "controlling" |
| 798 | : "controlled") |
| 799 | << " role."; |
| 800 | SetIceRole_n(reversed_role); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 801 | } |
| 802 | |
Honghai Zhang | 1590c39 | 2016-05-24 13:15:02 -0700 | [diff] [blame] | 803 | void TransportController::OnChannelStateChanged_n( |
Taylor Brandstetter | c4d3a5d | 2015-09-30 10:32:59 -0700 | [diff] [blame] | 804 | TransportChannelImpl* channel) { |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 805 | RTC_DCHECK(network_thread_->IsCurrent()); |
Taylor Brandstetter | c4d3a5d | 2015-09-30 10:32:59 -0700 | [diff] [blame] | 806 | LOG(LS_INFO) << channel->transport_name() << " TransportChannel " |
| 807 | << channel->component() |
Honghai Zhang | 1590c39 | 2016-05-24 13:15:02 -0700 | [diff] [blame] | 808 | << " state changed. Check if state is complete."; |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 809 | UpdateAggregateStates_n(); |
Taylor Brandstetter | c4d3a5d | 2015-09-30 10:32:59 -0700 | [diff] [blame] | 810 | } |
| 811 | |
Danil Chapovalov | 7f216b7 | 2016-05-12 09:20:31 +0200 | [diff] [blame] | 812 | void TransportController::UpdateAggregateStates_n() { |
| 813 | RTC_DCHECK(network_thread_->IsCurrent()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 814 | |
| 815 | IceConnectionState new_connection_state = kIceConnectionConnecting; |
| 816 | IceGatheringState new_gathering_state = kIceGatheringNew; |
| 817 | bool any_receiving = false; |
| 818 | bool any_failed = false; |
Taylor Brandstetter | c4d3a5d | 2015-09-30 10:32:59 -0700 | [diff] [blame] | 819 | bool all_connected = !channels_.empty(); |
| 820 | bool all_completed = !channels_.empty(); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 821 | bool any_gathering = false; |
Taylor Brandstetter | c4d3a5d | 2015-09-30 10:32:59 -0700 | [diff] [blame] | 822 | bool all_done_gathering = !channels_.empty(); |
| 823 | for (const auto& channel : channels_) { |
deadbeef | 62802a1 | 2016-12-13 16:38:36 -0800 | [diff] [blame] | 824 | any_receiving = any_receiving || channel->dtls()->receiving(); |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 825 | any_failed = |
| 826 | any_failed || |
deadbeef | 62802a1 | 2016-12-13 16:38:36 -0800 | [diff] [blame] | 827 | channel->dtls()->GetState() == TransportChannelState::STATE_FAILED; |
| 828 | all_connected = all_connected && channel->dtls()->writable(); |
Taylor Brandstetter | c4d3a5d | 2015-09-30 10:32:59 -0700 | [diff] [blame] | 829 | all_completed = |
deadbeef | 62802a1 | 2016-12-13 16:38:36 -0800 | [diff] [blame] | 830 | all_completed && channel->dtls()->writable() && |
| 831 | channel->dtls()->GetState() == TransportChannelState::STATE_COMPLETED && |
| 832 | channel->dtls()->GetIceRole() == ICEROLE_CONTROLLING && |
| 833 | channel->dtls()->gathering_state() == kIceGatheringComplete; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 834 | any_gathering = |
deadbeef | 62802a1 | 2016-12-13 16:38:36 -0800 | [diff] [blame] | 835 | any_gathering || channel->dtls()->gathering_state() != kIceGatheringNew; |
deadbeef | 49f34fd | 2016-12-06 16:22:06 -0800 | [diff] [blame] | 836 | all_done_gathering = |
| 837 | all_done_gathering && |
deadbeef | 62802a1 | 2016-12-13 16:38:36 -0800 | [diff] [blame] | 838 | channel->dtls()->gathering_state() == kIceGatheringComplete; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | if (any_failed) { |
| 842 | new_connection_state = kIceConnectionFailed; |
| 843 | } else if (all_completed) { |
| 844 | new_connection_state = kIceConnectionCompleted; |
| 845 | } else if (all_connected) { |
| 846 | new_connection_state = kIceConnectionConnected; |
| 847 | } |
| 848 | if (connection_state_ != new_connection_state) { |
| 849 | connection_state_ = new_connection_state; |
| 850 | signaling_thread_->Post( |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 851 | RTC_FROM_HERE, this, MSG_ICECONNECTIONSTATE, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 852 | new rtc::TypedMessageData<IceConnectionState>(new_connection_state)); |
| 853 | } |
| 854 | |
| 855 | if (receiving_ != any_receiving) { |
| 856 | receiving_ = any_receiving; |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 857 | signaling_thread_->Post(RTC_FROM_HERE, this, MSG_RECEIVING, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 858 | new rtc::TypedMessageData<bool>(any_receiving)); |
| 859 | } |
| 860 | |
| 861 | if (all_done_gathering) { |
| 862 | new_gathering_state = kIceGatheringComplete; |
| 863 | } else if (any_gathering) { |
| 864 | new_gathering_state = kIceGatheringGathering; |
| 865 | } |
| 866 | if (gathering_state_ != new_gathering_state) { |
| 867 | gathering_state_ = new_gathering_state; |
| 868 | signaling_thread_->Post( |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 869 | RTC_FROM_HERE, this, MSG_ICEGATHERINGSTATE, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 870 | new rtc::TypedMessageData<IceGatheringState>(new_gathering_state)); |
| 871 | } |
| 872 | } |
| 873 | |
zhihuang | d82eee0 | 2016-08-26 11:25:05 -0700 | [diff] [blame] | 874 | void TransportController::OnDtlsHandshakeError(rtc::SSLHandshakeError error) { |
| 875 | SignalDtlsHandshakeError(error); |
| 876 | } |
| 877 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 878 | } // namespace cricket |