| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 struct CandidatesData : public rtc::MessageData { | 32 struct CandidatesData : public rtc::MessageData { |
| 33 CandidatesData(const std::string& transport_name, | 33 CandidatesData(const std::string& transport_name, |
| 34 const Candidates& candidates) | 34 const Candidates& candidates) |
| 35 : transport_name(transport_name), candidates(candidates) {} | 35 : transport_name(transport_name), candidates(candidates) {} |
| 36 | 36 |
| 37 std::string transport_name; | 37 std::string transport_name; |
| 38 Candidates candidates; | 38 Candidates candidates; |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 TransportController::TransportController(rtc::Thread* signaling_thread, | 41 TransportController::TransportController(rtc::Thread* signaling_thread, |
| 42 rtc::Thread* worker_thread, | 42 rtc::Thread* network_thread, |
| 43 PortAllocator* port_allocator) | 43 PortAllocator* port_allocator) |
| 44 : signaling_thread_(signaling_thread), | 44 : signaling_thread_(signaling_thread), |
| 45 worker_thread_(worker_thread), | 45 network_thread_(network_thread), |
| 46 port_allocator_(port_allocator) {} | 46 port_allocator_(port_allocator) {} |
| 47 | 47 |
| 48 TransportController::~TransportController() { | 48 TransportController::~TransportController() { |
| 49 worker_thread_->Invoke<void>( | 49 network_thread_->Invoke<void>( |
| 50 rtc::Bind(&TransportController::DestroyAllTransports_w, this)); | 50 rtc::Bind(&TransportController::DestroyAllTransports_n, this)); |
| 51 signaling_thread_->Clear(this); | 51 signaling_thread_->Clear(this); |
| 52 } | 52 } |
| 53 | 53 |
| 54 bool TransportController::SetSslMaxProtocolVersion( | 54 bool TransportController::SetSslMaxProtocolVersion( |
| 55 rtc::SSLProtocolVersion version) { | 55 rtc::SSLProtocolVersion version) { |
| 56 return worker_thread_->Invoke<bool>(rtc::Bind( | 56 return network_thread_->Invoke<bool>(rtc::Bind( |
| 57 &TransportController::SetSslMaxProtocolVersion_w, this, version)); | 57 &TransportController::SetSslMaxProtocolVersion_n, this, version)); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void TransportController::SetIceConfig(const IceConfig& config) { | 60 void TransportController::SetIceConfig(const IceConfig& config) { |
| 61 worker_thread_->Invoke<void>( | 61 network_thread_->Invoke<void>( |
| 62 rtc::Bind(&TransportController::SetIceConfig_w, this, config)); | 62 rtc::Bind(&TransportController::SetIceConfig_n, this, config)); |
| 63 } | 63 } |
| 64 | 64 |
| 65 void TransportController::SetIceRole(IceRole ice_role) { | 65 void TransportController::SetIceRole(IceRole ice_role) { |
| 66 worker_thread_->Invoke<void>( | 66 network_thread_->Invoke<void>( |
| 67 rtc::Bind(&TransportController::SetIceRole_w, this, ice_role)); | 67 rtc::Bind(&TransportController::SetIceRole_n, this, ice_role)); |
| 68 } | 68 } |
| 69 | 69 |
| 70 bool TransportController::GetSslRole(const std::string& transport_name, | 70 bool TransportController::GetSslRole(const std::string& transport_name, |
| 71 rtc::SSLRole* role) { | 71 rtc::SSLRole* role) { |
| 72 return worker_thread_->Invoke<bool>(rtc::Bind( | 72 return network_thread_->Invoke<bool>(rtc::Bind( |
| 73 &TransportController::GetSslRole_w, this, transport_name, role)); | 73 &TransportController::GetSslRole_n, this, transport_name, role)); |
| 74 } | 74 } |
| 75 | 75 |
| 76 bool TransportController::SetLocalCertificate( | 76 bool TransportController::SetLocalCertificate( |
| 77 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) { | 77 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) { |
| 78 return worker_thread_->Invoke<bool>(rtc::Bind( | 78 return network_thread_->Invoke<bool>(rtc::Bind( |
| 79 &TransportController::SetLocalCertificate_w, this, certificate)); | 79 &TransportController::SetLocalCertificate_n, this, certificate)); |
| 80 } | 80 } |
| 81 | 81 |
| 82 bool TransportController::GetLocalCertificate( | 82 bool TransportController::GetLocalCertificate( |
| 83 const std::string& transport_name, | 83 const std::string& transport_name, |
| 84 rtc::scoped_refptr<rtc::RTCCertificate>* certificate) { | 84 rtc::scoped_refptr<rtc::RTCCertificate>* certificate) { |
| 85 return worker_thread_->Invoke<bool>( | 85 return network_thread_->Invoke<bool>( |
| 86 rtc::Bind(&TransportController::GetLocalCertificate_w, this, | 86 rtc::Bind(&TransportController::GetLocalCertificate_n, this, |
| 87 transport_name, certificate)); | 87 transport_name, certificate)); |
| 88 } | 88 } |
| 89 | 89 |
| 90 std::unique_ptr<rtc::SSLCertificate> | 90 std::unique_ptr<rtc::SSLCertificate> |
| 91 TransportController::GetRemoteSSLCertificate( | 91 TransportController::GetRemoteSSLCertificate( |
| 92 const std::string& transport_name) { | 92 const std::string& transport_name) { |
| 93 return worker_thread_->Invoke<std::unique_ptr<rtc::SSLCertificate>>(rtc::Bind( | 93 return network_thread_->Invoke<std::unique_ptr<rtc::SSLCertificate>>( |
| 94 &TransportController::GetRemoteSSLCertificate_w, this, transport_name)); | 94 rtc::Bind(&TransportController::GetRemoteSSLCertificate_n, this, |
| 95 transport_name)); |
| 95 } | 96 } |
| 96 | 97 |
| 97 bool TransportController::SetLocalTransportDescription( | 98 bool TransportController::SetLocalTransportDescription( |
| 98 const std::string& transport_name, | 99 const std::string& transport_name, |
| 99 const TransportDescription& tdesc, | 100 const TransportDescription& tdesc, |
| 100 ContentAction action, | 101 ContentAction action, |
| 101 std::string* err) { | 102 std::string* err) { |
| 102 return worker_thread_->Invoke<bool>( | 103 return network_thread_->Invoke<bool>( |
| 103 rtc::Bind(&TransportController::SetLocalTransportDescription_w, this, | 104 rtc::Bind(&TransportController::SetLocalTransportDescription_n, this, |
| 104 transport_name, tdesc, action, err)); | 105 transport_name, tdesc, action, err)); |
| 105 } | 106 } |
| 106 | 107 |
| 107 bool TransportController::SetRemoteTransportDescription( | 108 bool TransportController::SetRemoteTransportDescription( |
| 108 const std::string& transport_name, | 109 const std::string& transport_name, |
| 109 const TransportDescription& tdesc, | 110 const TransportDescription& tdesc, |
| 110 ContentAction action, | 111 ContentAction action, |
| 111 std::string* err) { | 112 std::string* err) { |
| 112 return worker_thread_->Invoke<bool>( | 113 return network_thread_->Invoke<bool>( |
| 113 rtc::Bind(&TransportController::SetRemoteTransportDescription_w, this, | 114 rtc::Bind(&TransportController::SetRemoteTransportDescription_n, this, |
| 114 transport_name, tdesc, action, err)); | 115 transport_name, tdesc, action, err)); |
| 115 } | 116 } |
| 116 | 117 |
| 117 void TransportController::MaybeStartGathering() { | 118 void TransportController::MaybeStartGathering() { |
| 118 worker_thread_->Invoke<void>( | 119 network_thread_->Invoke<void>( |
| 119 rtc::Bind(&TransportController::MaybeStartGathering_w, this)); | 120 rtc::Bind(&TransportController::MaybeStartGathering_n, this)); |
| 120 } | 121 } |
| 121 | 122 |
| 122 bool TransportController::AddRemoteCandidates(const std::string& transport_name, | 123 bool TransportController::AddRemoteCandidates(const std::string& transport_name, |
| 123 const Candidates& candidates, | 124 const Candidates& candidates, |
| 124 std::string* err) { | 125 std::string* err) { |
| 125 return worker_thread_->Invoke<bool>( | 126 return network_thread_->Invoke<bool>( |
| 126 rtc::Bind(&TransportController::AddRemoteCandidates_w, this, | 127 rtc::Bind(&TransportController::AddRemoteCandidates_n, this, |
| 127 transport_name, candidates, err)); | 128 transport_name, candidates, err)); |
| 128 } | 129 } |
| 129 | 130 |
| 130 bool TransportController::RemoveRemoteCandidates(const Candidates& candidates, | 131 bool TransportController::RemoveRemoteCandidates(const Candidates& candidates, |
| 131 std::string* err) { | 132 std::string* err) { |
| 132 return worker_thread_->Invoke<bool>(rtc::Bind( | 133 return network_thread_->Invoke<bool>(rtc::Bind( |
| 133 &TransportController::RemoveRemoteCandidates_w, this, candidates, err)); | 134 &TransportController::RemoveRemoteCandidates_n, this, candidates, err)); |
| 134 } | 135 } |
| 135 | 136 |
| 136 bool TransportController::ReadyForRemoteCandidates( | 137 bool TransportController::ReadyForRemoteCandidates( |
| 137 const std::string& transport_name) { | 138 const std::string& transport_name) { |
| 138 return worker_thread_->Invoke<bool>(rtc::Bind( | 139 return network_thread_->Invoke<bool>(rtc::Bind( |
| 139 &TransportController::ReadyForRemoteCandidates_w, this, transport_name)); | 140 &TransportController::ReadyForRemoteCandidates_n, this, transport_name)); |
| 140 } | 141 } |
| 141 | 142 |
| 142 bool TransportController::GetStats(const std::string& transport_name, | 143 bool TransportController::GetStats(const std::string& transport_name, |
| 143 TransportStats* stats) { | 144 TransportStats* stats) { |
| 144 return worker_thread_->Invoke<bool>( | 145 return network_thread_->Invoke<bool>( |
| 145 rtc::Bind(&TransportController::GetStats_w, this, transport_name, stats)); | 146 rtc::Bind(&TransportController::GetStats_n, this, transport_name, stats)); |
| 146 } | 147 } |
| 147 | 148 |
| 148 TransportChannel* TransportController::CreateTransportChannel_w( | 149 TransportChannel* TransportController::CreateTransportChannel_n( |
| 149 const std::string& transport_name, | 150 const std::string& transport_name, |
| 150 int component) { | 151 int component) { |
| 151 RTC_DCHECK(worker_thread_->IsCurrent()); | 152 RTC_DCHECK(network_thread_->IsCurrent()); |
| 152 | 153 |
| 153 auto it = FindChannel_w(transport_name, component); | 154 auto it = FindChannel_n(transport_name, component); |
| 154 if (it != channels_.end()) { | 155 if (it != channels_.end()) { |
| 155 // Channel already exists; increment reference count and return. | 156 // Channel already exists; increment reference count and return. |
| 156 it->AddRef(); | 157 it->AddRef(); |
| 157 return it->get(); | 158 return it->get(); |
| 158 } | 159 } |
| 159 | 160 |
| 160 // Need to create a new channel. | 161 // Need to create a new channel. |
| 161 Transport* transport = GetOrCreateTransport_w(transport_name); | 162 Transport* transport = GetOrCreateTransport_n(transport_name); |
| 162 TransportChannelImpl* channel = transport->CreateChannel(component); | 163 TransportChannelImpl* channel = transport->CreateChannel(component); |
| 163 channel->SignalWritableState.connect( | 164 channel->SignalWritableState.connect( |
| 164 this, &TransportController::OnChannelWritableState_w); | 165 this, &TransportController::OnChannelWritableState_n); |
| 165 channel->SignalReceivingState.connect( | 166 channel->SignalReceivingState.connect( |
| 166 this, &TransportController::OnChannelReceivingState_w); | 167 this, &TransportController::OnChannelReceivingState_n); |
| 167 channel->SignalGatheringState.connect( | 168 channel->SignalGatheringState.connect( |
| 168 this, &TransportController::OnChannelGatheringState_w); | 169 this, &TransportController::OnChannelGatheringState_n); |
| 169 channel->SignalCandidateGathered.connect( | 170 channel->SignalCandidateGathered.connect( |
| 170 this, &TransportController::OnChannelCandidateGathered_w); | 171 this, &TransportController::OnChannelCandidateGathered_n); |
| 171 channel->SignalCandidatesRemoved.connect( | 172 channel->SignalCandidatesRemoved.connect( |
| 172 this, &TransportController::OnChannelCandidatesRemoved_w); | 173 this, &TransportController::OnChannelCandidatesRemoved_n); |
| 173 channel->SignalRoleConflict.connect( | 174 channel->SignalRoleConflict.connect( |
| 174 this, &TransportController::OnChannelRoleConflict_w); | 175 this, &TransportController::OnChannelRoleConflict_n); |
| 175 channel->SignalConnectionRemoved.connect( | 176 channel->SignalConnectionRemoved.connect( |
| 176 this, &TransportController::OnChannelConnectionRemoved_w); | 177 this, &TransportController::OnChannelConnectionRemoved_n); |
| 177 channels_.insert(channels_.end(), RefCountedChannel(channel))->AddRef(); | 178 channels_.insert(channels_.end(), RefCountedChannel(channel))->AddRef(); |
| 178 // Adding a channel could cause aggregate state to change. | 179 // Adding a channel could cause aggregate state to change. |
| 179 UpdateAggregateStates_w(); | 180 UpdateAggregateStates_n(); |
| 180 return channel; | 181 return channel; |
| 181 } | 182 } |
| 182 | 183 |
| 183 void TransportController::DestroyTransportChannel_w( | 184 void TransportController::DestroyTransportChannel_n( |
| 184 const std::string& transport_name, | 185 const std::string& transport_name, |
| 185 int component) { | 186 int component) { |
| 186 RTC_DCHECK(worker_thread_->IsCurrent()); | 187 RTC_DCHECK(network_thread_->IsCurrent()); |
| 187 | 188 |
| 188 auto it = FindChannel_w(transport_name, component); | 189 auto it = FindChannel_n(transport_name, component); |
| 189 if (it == channels_.end()) { | 190 if (it == channels_.end()) { |
| 190 LOG(LS_WARNING) << "Attempting to delete " << transport_name | 191 LOG(LS_WARNING) << "Attempting to delete " << transport_name |
| 191 << " TransportChannel " << component | 192 << " TransportChannel " << component |
| 192 << ", which doesn't exist."; | 193 << ", which doesn't exist."; |
| 193 return; | 194 return; |
| 194 } | 195 } |
| 195 | 196 |
| 196 it->DecRef(); | 197 it->DecRef(); |
| 197 if (it->ref() > 0) { | 198 if (it->ref() > 0) { |
| 198 return; | 199 return; |
| 199 } | 200 } |
| 200 | 201 |
| 201 channels_.erase(it); | 202 channels_.erase(it); |
| 202 Transport* transport = GetTransport_w(transport_name); | 203 Transport* transport = GetTransport_n(transport_name); |
| 203 transport->DestroyChannel(component); | 204 transport->DestroyChannel(component); |
| 204 // Just as we create a Transport when its first channel is created, | 205 // Just as we create a Transport when its first channel is created, |
| 205 // we delete it when its last channel is deleted. | 206 // we delete it when its last channel is deleted. |
| 206 if (!transport->HasChannels()) { | 207 if (!transport->HasChannels()) { |
| 207 DestroyTransport_w(transport_name); | 208 DestroyTransport_n(transport_name); |
| 208 } | 209 } |
| 209 // Removing a channel could cause aggregate state to change. | 210 // Removing a channel could cause aggregate state to change. |
| 210 UpdateAggregateStates_w(); | 211 UpdateAggregateStates_n(); |
| 211 } | 212 } |
| 212 | 213 |
| 213 const rtc::scoped_refptr<rtc::RTCCertificate>& | 214 const rtc::scoped_refptr<rtc::RTCCertificate>& |
| 214 TransportController::certificate_for_testing() { | 215 TransportController::certificate_for_testing() { |
| 215 return certificate_; | 216 return certificate_; |
| 216 } | 217 } |
| 217 | 218 |
| 218 Transport* TransportController::CreateTransport_w( | 219 Transport* TransportController::CreateTransport_n( |
| 219 const std::string& transport_name) { | 220 const std::string& transport_name) { |
| 220 RTC_DCHECK(worker_thread_->IsCurrent()); | 221 RTC_DCHECK(network_thread_->IsCurrent()); |
| 221 | 222 |
| 222 Transport* transport = new DtlsTransport<P2PTransport>( | 223 Transport* transport = new DtlsTransport<P2PTransport>( |
| 223 transport_name, port_allocator(), certificate_); | 224 transport_name, port_allocator(), certificate_); |
| 224 return transport; | 225 return transport; |
| 225 } | 226 } |
| 226 | 227 |
| 227 Transport* TransportController::GetTransport_w( | 228 Transport* TransportController::GetTransport_n( |
| 228 const std::string& transport_name) { | 229 const std::string& transport_name) { |
| 229 RTC_DCHECK(worker_thread_->IsCurrent()); | 230 RTC_DCHECK(network_thread_->IsCurrent()); |
| 230 | 231 |
| 231 auto iter = transports_.find(transport_name); | 232 auto iter = transports_.find(transport_name); |
| 232 return (iter != transports_.end()) ? iter->second : nullptr; | 233 return (iter != transports_.end()) ? iter->second : nullptr; |
| 233 } | 234 } |
| 234 | 235 |
| 235 void TransportController::OnMessage(rtc::Message* pmsg) { | 236 void TransportController::OnMessage(rtc::Message* pmsg) { |
| 236 RTC_DCHECK(signaling_thread_->IsCurrent()); | 237 RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 237 | 238 |
| 238 switch (pmsg->message_id) { | 239 switch (pmsg->message_id) { |
| 239 case MSG_ICECONNECTIONSTATE: { | 240 case MSG_ICECONNECTIONSTATE: { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 262 SignalCandidatesGathered(data->transport_name, data->candidates); | 263 SignalCandidatesGathered(data->transport_name, data->candidates); |
| 263 delete data; | 264 delete data; |
| 264 break; | 265 break; |
| 265 } | 266 } |
| 266 default: | 267 default: |
| 267 ASSERT(false); | 268 ASSERT(false); |
| 268 } | 269 } |
| 269 } | 270 } |
| 270 | 271 |
| 271 std::vector<TransportController::RefCountedChannel>::iterator | 272 std::vector<TransportController::RefCountedChannel>::iterator |
| 272 TransportController::FindChannel_w(const std::string& transport_name, | 273 TransportController::FindChannel_n(const std::string& transport_name, |
| 273 int component) { | 274 int component) { |
| 274 return std::find_if( | 275 return std::find_if( |
| 275 channels_.begin(), channels_.end(), | 276 channels_.begin(), channels_.end(), |
| 276 [transport_name, component](const RefCountedChannel& channel) { | 277 [transport_name, component](const RefCountedChannel& channel) { |
| 277 return channel->transport_name() == transport_name && | 278 return channel->transport_name() == transport_name && |
| 278 channel->component() == component; | 279 channel->component() == component; |
| 279 }); | 280 }); |
| 280 } | 281 } |
| 281 | 282 |
| 282 Transport* TransportController::GetOrCreateTransport_w( | 283 Transport* TransportController::GetOrCreateTransport_n( |
| 283 const std::string& transport_name) { | 284 const std::string& transport_name) { |
| 284 RTC_DCHECK(worker_thread_->IsCurrent()); | 285 RTC_DCHECK(network_thread_->IsCurrent()); |
| 285 | 286 |
| 286 Transport* transport = GetTransport_w(transport_name); | 287 Transport* transport = GetTransport_n(transport_name); |
| 287 if (transport) { | 288 if (transport) { |
| 288 return transport; | 289 return transport; |
| 289 } | 290 } |
| 290 | 291 |
| 291 transport = CreateTransport_w(transport_name); | 292 transport = CreateTransport_n(transport_name); |
| 292 // The stuff below happens outside of CreateTransport_w so that unit tests | 293 // The stuff below happens outside of CreateTransport_w so that unit tests |
| 293 // can override CreateTransport_w to return a different type of transport. | 294 // can override CreateTransport_w to return a different type of transport. |
| 294 transport->SetSslMaxProtocolVersion(ssl_max_version_); | 295 transport->SetSslMaxProtocolVersion(ssl_max_version_); |
| 295 transport->SetIceConfig(ice_config_); | 296 transport->SetIceConfig(ice_config_); |
| 296 transport->SetIceRole(ice_role_); | 297 transport->SetIceRole(ice_role_); |
| 297 transport->SetIceTiebreaker(ice_tiebreaker_); | 298 transport->SetIceTiebreaker(ice_tiebreaker_); |
| 298 if (certificate_) { | 299 if (certificate_) { |
| 299 transport->SetLocalCertificate(certificate_); | 300 transport->SetLocalCertificate(certificate_); |
| 300 } | 301 } |
| 301 transports_[transport_name] = transport; | 302 transports_[transport_name] = transport; |
| 302 | 303 |
| 303 return transport; | 304 return transport; |
| 304 } | 305 } |
| 305 | 306 |
| 306 void TransportController::DestroyTransport_w( | 307 void TransportController::DestroyTransport_n( |
| 307 const std::string& transport_name) { | 308 const std::string& transport_name) { |
| 308 RTC_DCHECK(worker_thread_->IsCurrent()); | 309 RTC_DCHECK(network_thread_->IsCurrent()); |
| 309 | 310 |
| 310 auto iter = transports_.find(transport_name); | 311 auto iter = transports_.find(transport_name); |
| 311 if (iter != transports_.end()) { | 312 if (iter != transports_.end()) { |
| 312 delete iter->second; | 313 delete iter->second; |
| 313 transports_.erase(transport_name); | 314 transports_.erase(transport_name); |
| 314 } | 315 } |
| 315 } | 316 } |
| 316 | 317 |
| 317 void TransportController::DestroyAllTransports_w() { | 318 void TransportController::DestroyAllTransports_n() { |
| 318 RTC_DCHECK(worker_thread_->IsCurrent()); | 319 RTC_DCHECK(network_thread_->IsCurrent()); |
| 319 | 320 |
| 320 for (const auto& kv : transports_) { | 321 for (const auto& kv : transports_) { |
| 321 delete kv.second; | 322 delete kv.second; |
| 322 } | 323 } |
| 323 transports_.clear(); | 324 transports_.clear(); |
| 324 } | 325 } |
| 325 | 326 |
| 326 bool TransportController::SetSslMaxProtocolVersion_w( | 327 bool TransportController::SetSslMaxProtocolVersion_n( |
| 327 rtc::SSLProtocolVersion version) { | 328 rtc::SSLProtocolVersion version) { |
| 328 RTC_DCHECK(worker_thread_->IsCurrent()); | 329 RTC_DCHECK(network_thread_->IsCurrent()); |
| 329 | 330 |
| 330 // Max SSL version can only be set before transports are created. | 331 // Max SSL version can only be set before transports are created. |
| 331 if (!transports_.empty()) { | 332 if (!transports_.empty()) { |
| 332 return false; | 333 return false; |
| 333 } | 334 } |
| 334 | 335 |
| 335 ssl_max_version_ = version; | 336 ssl_max_version_ = version; |
| 336 return true; | 337 return true; |
| 337 } | 338 } |
| 338 | 339 |
| 339 void TransportController::SetIceConfig_w(const IceConfig& config) { | 340 void TransportController::SetIceConfig_n(const IceConfig& config) { |
| 340 RTC_DCHECK(worker_thread_->IsCurrent()); | 341 RTC_DCHECK(network_thread_->IsCurrent()); |
| 341 ice_config_ = config; | 342 ice_config_ = config; |
| 342 for (const auto& kv : transports_) { | 343 for (const auto& kv : transports_) { |
| 343 kv.second->SetIceConfig(ice_config_); | 344 kv.second->SetIceConfig(ice_config_); |
| 344 } | 345 } |
| 345 } | 346 } |
| 346 | 347 |
| 347 void TransportController::SetIceRole_w(IceRole ice_role) { | 348 void TransportController::SetIceRole_n(IceRole ice_role) { |
| 348 RTC_DCHECK(worker_thread_->IsCurrent()); | 349 RTC_DCHECK(network_thread_->IsCurrent()); |
| 349 ice_role_ = ice_role; | 350 ice_role_ = ice_role; |
| 350 for (const auto& kv : transports_) { | 351 for (const auto& kv : transports_) { |
| 351 kv.second->SetIceRole(ice_role_); | 352 kv.second->SetIceRole(ice_role_); |
| 352 } | 353 } |
| 353 } | 354 } |
| 354 | 355 |
| 355 bool TransportController::GetSslRole_w(const std::string& transport_name, | 356 bool TransportController::GetSslRole_n(const std::string& transport_name, |
| 356 rtc::SSLRole* role) { | 357 rtc::SSLRole* role) { |
| 357 RTC_DCHECK(worker_thread()->IsCurrent()); | 358 RTC_DCHECK(network_thread_->IsCurrent()); |
| 358 | 359 |
| 359 Transport* t = GetTransport_w(transport_name); | 360 Transport* t = GetTransport_n(transport_name); |
| 360 if (!t) { | 361 if (!t) { |
| 361 return false; | 362 return false; |
| 362 } | 363 } |
| 363 | 364 |
| 364 return t->GetSslRole(role); | 365 return t->GetSslRole(role); |
| 365 } | 366 } |
| 366 | 367 |
| 367 bool TransportController::SetLocalCertificate_w( | 368 bool TransportController::SetLocalCertificate_n( |
| 368 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) { | 369 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) { |
| 369 RTC_DCHECK(worker_thread_->IsCurrent()); | 370 RTC_DCHECK(network_thread_->IsCurrent()); |
| 370 | 371 |
| 371 if (certificate_) { | 372 if (certificate_) { |
| 372 return false; | 373 return false; |
| 373 } | 374 } |
| 374 if (!certificate) { | 375 if (!certificate) { |
| 375 return false; | 376 return false; |
| 376 } | 377 } |
| 377 certificate_ = certificate; | 378 certificate_ = certificate; |
| 378 | 379 |
| 379 for (const auto& kv : transports_) { | 380 for (const auto& kv : transports_) { |
| 380 kv.second->SetLocalCertificate(certificate_); | 381 kv.second->SetLocalCertificate(certificate_); |
| 381 } | 382 } |
| 382 return true; | 383 return true; |
| 383 } | 384 } |
| 384 | 385 |
| 385 bool TransportController::GetLocalCertificate_w( | 386 bool TransportController::GetLocalCertificate_n( |
| 386 const std::string& transport_name, | 387 const std::string& transport_name, |
| 387 rtc::scoped_refptr<rtc::RTCCertificate>* certificate) { | 388 rtc::scoped_refptr<rtc::RTCCertificate>* certificate) { |
| 388 RTC_DCHECK(worker_thread_->IsCurrent()); | 389 RTC_DCHECK(network_thread_->IsCurrent()); |
| 389 | 390 |
| 390 Transport* t = GetTransport_w(transport_name); | 391 Transport* t = GetTransport_n(transport_name); |
| 391 if (!t) { | 392 if (!t) { |
| 392 return false; | 393 return false; |
| 393 } | 394 } |
| 394 | 395 |
| 395 return t->GetLocalCertificate(certificate); | 396 return t->GetLocalCertificate(certificate); |
| 396 } | 397 } |
| 397 | 398 |
| 398 std::unique_ptr<rtc::SSLCertificate> | 399 std::unique_ptr<rtc::SSLCertificate> |
| 399 TransportController::GetRemoteSSLCertificate_w( | 400 TransportController::GetRemoteSSLCertificate_n( |
| 400 const std::string& transport_name) { | 401 const std::string& transport_name) { |
| 401 RTC_DCHECK(worker_thread_->IsCurrent()); | 402 RTC_DCHECK(network_thread_->IsCurrent()); |
| 402 | 403 |
| 403 Transport* t = GetTransport_w(transport_name); | 404 Transport* t = GetTransport_n(transport_name); |
| 404 if (!t) { | 405 if (!t) { |
| 405 return nullptr; | 406 return nullptr; |
| 406 } | 407 } |
| 407 | 408 |
| 408 return t->GetRemoteSSLCertificate(); | 409 return t->GetRemoteSSLCertificate(); |
| 409 } | 410 } |
| 410 | 411 |
| 411 bool TransportController::SetLocalTransportDescription_w( | 412 bool TransportController::SetLocalTransportDescription_n( |
| 412 const std::string& transport_name, | 413 const std::string& transport_name, |
| 413 const TransportDescription& tdesc, | 414 const TransportDescription& tdesc, |
| 414 ContentAction action, | 415 ContentAction action, |
| 415 std::string* err) { | 416 std::string* err) { |
| 416 RTC_DCHECK(worker_thread()->IsCurrent()); | 417 RTC_DCHECK(network_thread_->IsCurrent()); |
| 417 | 418 |
| 418 Transport* transport = GetTransport_w(transport_name); | 419 Transport* transport = GetTransport_n(transport_name); |
| 419 if (!transport) { | 420 if (!transport) { |
| 420 // If we didn't find a transport, that's not an error; | 421 // If we didn't find a transport, that's not an error; |
| 421 // it could have been deleted as a result of bundling. | 422 // it could have been deleted as a result of bundling. |
| 422 // TODO(deadbeef): Make callers smarter so they won't attempt to set a | 423 // TODO(deadbeef): Make callers smarter so they won't attempt to set a |
| 423 // description on a deleted transport. | 424 // description on a deleted transport. |
| 424 return true; | 425 return true; |
| 425 } | 426 } |
| 426 | 427 |
| 427 return transport->SetLocalTransportDescription(tdesc, action, err); | 428 return transport->SetLocalTransportDescription(tdesc, action, err); |
| 428 } | 429 } |
| 429 | 430 |
| 430 bool TransportController::SetRemoteTransportDescription_w( | 431 bool TransportController::SetRemoteTransportDescription_n( |
| 431 const std::string& transport_name, | 432 const std::string& transport_name, |
| 432 const TransportDescription& tdesc, | 433 const TransportDescription& tdesc, |
| 433 ContentAction action, | 434 ContentAction action, |
| 434 std::string* err) { | 435 std::string* err) { |
| 435 RTC_DCHECK(worker_thread()->IsCurrent()); | 436 RTC_DCHECK(network_thread_->IsCurrent()); |
| 436 | 437 |
| 437 Transport* transport = GetTransport_w(transport_name); | 438 Transport* transport = GetTransport_n(transport_name); |
| 438 if (!transport) { | 439 if (!transport) { |
| 439 // If we didn't find a transport, that's not an error; | 440 // If we didn't find a transport, that's not an error; |
| 440 // it could have been deleted as a result of bundling. | 441 // it could have been deleted as a result of bundling. |
| 441 // TODO(deadbeef): Make callers smarter so they won't attempt to set a | 442 // TODO(deadbeef): Make callers smarter so they won't attempt to set a |
| 442 // description on a deleted transport. | 443 // description on a deleted transport. |
| 443 return true; | 444 return true; |
| 444 } | 445 } |
| 445 | 446 |
| 446 return transport->SetRemoteTransportDescription(tdesc, action, err); | 447 return transport->SetRemoteTransportDescription(tdesc, action, err); |
| 447 } | 448 } |
| 448 | 449 |
| 449 void TransportController::MaybeStartGathering_w() { | 450 void TransportController::MaybeStartGathering_n() { |
| 450 for (const auto& kv : transports_) { | 451 for (const auto& kv : transports_) { |
| 451 kv.second->MaybeStartGathering(); | 452 kv.second->MaybeStartGathering(); |
| 452 } | 453 } |
| 453 } | 454 } |
| 454 | 455 |
| 455 bool TransportController::AddRemoteCandidates_w( | 456 bool TransportController::AddRemoteCandidates_n( |
| 456 const std::string& transport_name, | 457 const std::string& transport_name, |
| 457 const Candidates& candidates, | 458 const Candidates& candidates, |
| 458 std::string* err) { | 459 std::string* err) { |
| 459 RTC_DCHECK(worker_thread()->IsCurrent()); | 460 RTC_DCHECK(network_thread_->IsCurrent()); |
| 460 | 461 |
| 461 Transport* transport = GetTransport_w(transport_name); | 462 Transport* transport = GetTransport_n(transport_name); |
| 462 if (!transport) { | 463 if (!transport) { |
| 463 // If we didn't find a transport, that's not an error; | 464 // If we didn't find a transport, that's not an error; |
| 464 // it could have been deleted as a result of bundling. | 465 // it could have been deleted as a result of bundling. |
| 465 return true; | 466 return true; |
| 466 } | 467 } |
| 467 | 468 |
| 468 return transport->AddRemoteCandidates(candidates, err); | 469 return transport->AddRemoteCandidates(candidates, err); |
| 469 } | 470 } |
| 470 | 471 |
| 471 bool TransportController::RemoveRemoteCandidates_w(const Candidates& candidates, | 472 bool TransportController::RemoveRemoteCandidates_n(const Candidates& candidates, |
| 472 std::string* err) { | 473 std::string* err) { |
| 473 RTC_DCHECK(worker_thread()->IsCurrent()); | 474 RTC_DCHECK(network_thread_->IsCurrent()); |
| 474 std::map<std::string, Candidates> candidates_by_transport_name; | 475 std::map<std::string, Candidates> candidates_by_transport_name; |
| 475 for (const Candidate& cand : candidates) { | 476 for (const Candidate& cand : candidates) { |
| 476 RTC_DCHECK(!cand.transport_name().empty()); | 477 RTC_DCHECK(!cand.transport_name().empty()); |
| 477 candidates_by_transport_name[cand.transport_name()].push_back(cand); | 478 candidates_by_transport_name[cand.transport_name()].push_back(cand); |
| 478 } | 479 } |
| 479 | 480 |
| 480 bool result = true; | 481 bool result = true; |
| 481 for (auto kv : candidates_by_transport_name) { | 482 for (auto kv : candidates_by_transport_name) { |
| 482 Transport* transport = GetTransport_w(kv.first); | 483 Transport* transport = GetTransport_n(kv.first); |
| 483 if (!transport) { | 484 if (!transport) { |
| 484 // If we didn't find a transport, that's not an error; | 485 // If we didn't find a transport, that's not an error; |
| 485 // it could have been deleted as a result of bundling. | 486 // it could have been deleted as a result of bundling. |
| 486 continue; | 487 continue; |
| 487 } | 488 } |
| 488 result &= transport->RemoveRemoteCandidates(kv.second, err); | 489 result &= transport->RemoveRemoteCandidates(kv.second, err); |
| 489 } | 490 } |
| 490 return result; | 491 return result; |
| 491 } | 492 } |
| 492 | 493 |
| 493 bool TransportController::ReadyForRemoteCandidates_w( | 494 bool TransportController::ReadyForRemoteCandidates_n( |
| 494 const std::string& transport_name) { | 495 const std::string& transport_name) { |
| 495 RTC_DCHECK(worker_thread()->IsCurrent()); | 496 RTC_DCHECK(network_thread_->IsCurrent()); |
| 496 | 497 |
| 497 Transport* transport = GetTransport_w(transport_name); | 498 Transport* transport = GetTransport_n(transport_name); |
| 498 if (!transport) { | 499 if (!transport) { |
| 499 return false; | 500 return false; |
| 500 } | 501 } |
| 501 return transport->ready_for_remote_candidates(); | 502 return transport->ready_for_remote_candidates(); |
| 502 } | 503 } |
| 503 | 504 |
| 504 bool TransportController::GetStats_w(const std::string& transport_name, | 505 bool TransportController::GetStats_n(const std::string& transport_name, |
| 505 TransportStats* stats) { | 506 TransportStats* stats) { |
| 506 RTC_DCHECK(worker_thread()->IsCurrent()); | 507 RTC_DCHECK(network_thread_->IsCurrent()); |
| 507 | 508 |
| 508 Transport* transport = GetTransport_w(transport_name); | 509 Transport* transport = GetTransport_n(transport_name); |
| 509 if (!transport) { | 510 if (!transport) { |
| 510 return false; | 511 return false; |
| 511 } | 512 } |
| 512 return transport->GetStats(stats); | 513 return transport->GetStats(stats); |
| 513 } | 514 } |
| 514 | 515 |
| 515 void TransportController::OnChannelWritableState_w(TransportChannel* channel) { | 516 void TransportController::OnChannelWritableState_n(TransportChannel* channel) { |
| 516 RTC_DCHECK(worker_thread_->IsCurrent()); | 517 RTC_DCHECK(network_thread_->IsCurrent()); |
| 517 LOG(LS_INFO) << channel->transport_name() << " TransportChannel " | 518 LOG(LS_INFO) << channel->transport_name() << " TransportChannel " |
| 518 << channel->component() << " writability changed to " | 519 << channel->component() << " writability changed to " |
| 519 << channel->writable() << "."; | 520 << channel->writable() << "."; |
| 520 UpdateAggregateStates_w(); | 521 UpdateAggregateStates_n(); |
| 521 } | 522 } |
| 522 | 523 |
| 523 void TransportController::OnChannelReceivingState_w(TransportChannel* channel) { | 524 void TransportController::OnChannelReceivingState_n(TransportChannel* channel) { |
| 524 RTC_DCHECK(worker_thread_->IsCurrent()); | 525 RTC_DCHECK(network_thread_->IsCurrent()); |
| 525 UpdateAggregateStates_w(); | 526 UpdateAggregateStates_n(); |
| 526 } | 527 } |
| 527 | 528 |
| 528 void TransportController::OnChannelGatheringState_w( | 529 void TransportController::OnChannelGatheringState_n( |
| 529 TransportChannelImpl* channel) { | 530 TransportChannelImpl* channel) { |
| 530 RTC_DCHECK(worker_thread_->IsCurrent()); | 531 RTC_DCHECK(network_thread_->IsCurrent()); |
| 531 UpdateAggregateStates_w(); | 532 UpdateAggregateStates_n(); |
| 532 } | 533 } |
| 533 | 534 |
| 534 void TransportController::OnChannelCandidateGathered_w( | 535 void TransportController::OnChannelCandidateGathered_n( |
| 535 TransportChannelImpl* channel, | 536 TransportChannelImpl* channel, |
| 536 const Candidate& candidate) { | 537 const Candidate& candidate) { |
| 537 RTC_DCHECK(worker_thread_->IsCurrent()); | 538 RTC_DCHECK(network_thread_->IsCurrent()); |
| 538 | 539 |
| 539 // We should never signal peer-reflexive candidates. | 540 // We should never signal peer-reflexive candidates. |
| 540 if (candidate.type() == PRFLX_PORT_TYPE) { | 541 if (candidate.type() == PRFLX_PORT_TYPE) { |
| 541 RTC_DCHECK(false); | 542 RTC_DCHECK(false); |
| 542 return; | 543 return; |
| 543 } | 544 } |
| 544 std::vector<Candidate> candidates; | 545 std::vector<Candidate> candidates; |
| 545 candidates.push_back(candidate); | 546 candidates.push_back(candidate); |
| 546 CandidatesData* data = | 547 CandidatesData* data = |
| 547 new CandidatesData(channel->transport_name(), candidates); | 548 new CandidatesData(channel->transport_name(), candidates); |
| 548 signaling_thread_->Post(this, MSG_CANDIDATESGATHERED, data); | 549 signaling_thread_->Post(this, MSG_CANDIDATESGATHERED, data); |
| 549 } | 550 } |
| 550 | 551 |
| 551 void TransportController::OnChannelCandidatesRemoved_w( | 552 void TransportController::OnChannelCandidatesRemoved_n( |
| 552 TransportChannelImpl* channel, | 553 TransportChannelImpl* channel, |
| 553 const Candidates& candidates) { | 554 const Candidates& candidates) { |
| 554 invoker_.AsyncInvoke<void>( | 555 invoker_.AsyncInvoke<void>( |
| 555 signaling_thread_, | 556 signaling_thread_, |
| 556 rtc::Bind(&TransportController::OnChannelCandidatesRemoved, this, | 557 rtc::Bind(&TransportController::OnChannelCandidatesRemoved, this, |
| 557 candidates)); | 558 candidates)); |
| 558 } | 559 } |
| 559 | 560 |
| 560 void TransportController::OnChannelCandidatesRemoved( | 561 void TransportController::OnChannelCandidatesRemoved( |
| 561 const Candidates& candidates) { | 562 const Candidates& candidates) { |
| 562 RTC_DCHECK(signaling_thread_->IsCurrent()); | 563 RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 563 SignalCandidatesRemoved(candidates); | 564 SignalCandidatesRemoved(candidates); |
| 564 } | 565 } |
| 565 | 566 |
| 566 void TransportController::OnChannelRoleConflict_w( | 567 void TransportController::OnChannelRoleConflict_n( |
| 567 TransportChannelImpl* channel) { | 568 TransportChannelImpl* channel) { |
| 568 RTC_DCHECK(worker_thread_->IsCurrent()); | 569 RTC_DCHECK(network_thread_->IsCurrent()); |
| 569 | 570 |
| 570 if (ice_role_switch_) { | 571 if (ice_role_switch_) { |
| 571 LOG(LS_WARNING) | 572 LOG(LS_WARNING) |
| 572 << "Repeat of role conflict signal from TransportChannelImpl."; | 573 << "Repeat of role conflict signal from TransportChannelImpl."; |
| 573 return; | 574 return; |
| 574 } | 575 } |
| 575 | 576 |
| 576 ice_role_switch_ = true; | 577 ice_role_switch_ = true; |
| 577 IceRole reversed_role = (ice_role_ == ICEROLE_CONTROLLING) | 578 IceRole reversed_role = (ice_role_ == ICEROLE_CONTROLLING) |
| 578 ? ICEROLE_CONTROLLED | 579 ? ICEROLE_CONTROLLED |
| 579 : ICEROLE_CONTROLLING; | 580 : ICEROLE_CONTROLLING; |
| 580 for (const auto& kv : transports_) { | 581 for (const auto& kv : transports_) { |
| 581 kv.second->SetIceRole(reversed_role); | 582 kv.second->SetIceRole(reversed_role); |
| 582 } | 583 } |
| 583 } | 584 } |
| 584 | 585 |
| 585 void TransportController::OnChannelConnectionRemoved_w( | 586 void TransportController::OnChannelConnectionRemoved_n( |
| 586 TransportChannelImpl* channel) { | 587 TransportChannelImpl* channel) { |
| 587 RTC_DCHECK(worker_thread_->IsCurrent()); | 588 RTC_DCHECK(network_thread_->IsCurrent()); |
| 588 LOG(LS_INFO) << channel->transport_name() << " TransportChannel " | 589 LOG(LS_INFO) << channel->transport_name() << " TransportChannel " |
| 589 << channel->component() | 590 << channel->component() |
| 590 << " connection removed. Check if state is complete."; | 591 << " connection removed. Check if state is complete."; |
| 591 UpdateAggregateStates_w(); | 592 UpdateAggregateStates_n(); |
| 592 } | 593 } |
| 593 | 594 |
| 594 void TransportController::UpdateAggregateStates_w() { | 595 void TransportController::UpdateAggregateStates_n() { |
| 595 RTC_DCHECK(worker_thread_->IsCurrent()); | 596 RTC_DCHECK(network_thread_->IsCurrent()); |
| 596 | 597 |
| 597 IceConnectionState new_connection_state = kIceConnectionConnecting; | 598 IceConnectionState new_connection_state = kIceConnectionConnecting; |
| 598 IceGatheringState new_gathering_state = kIceGatheringNew; | 599 IceGatheringState new_gathering_state = kIceGatheringNew; |
| 599 bool any_receiving = false; | 600 bool any_receiving = false; |
| 600 bool any_failed = false; | 601 bool any_failed = false; |
| 601 bool all_connected = !channels_.empty(); | 602 bool all_connected = !channels_.empty(); |
| 602 bool all_completed = !channels_.empty(); | 603 bool all_completed = !channels_.empty(); |
| 603 bool any_gathering = false; | 604 bool any_gathering = false; |
| 604 bool all_done_gathering = !channels_.empty(); | 605 bool all_done_gathering = !channels_.empty(); |
| 605 for (const auto& channel : channels_) { | 606 for (const auto& channel : channels_) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 } | 646 } |
| 646 if (gathering_state_ != new_gathering_state) { | 647 if (gathering_state_ != new_gathering_state) { |
| 647 gathering_state_ = new_gathering_state; | 648 gathering_state_ = new_gathering_state; |
| 648 signaling_thread_->Post( | 649 signaling_thread_->Post( |
| 649 this, MSG_ICEGATHERINGSTATE, | 650 this, MSG_ICEGATHERINGSTATE, |
| 650 new rtc::TypedMessageData<IceGatheringState>(new_gathering_state)); | 651 new rtc::TypedMessageData<IceGatheringState>(new_gathering_state)); |
| 651 } | 652 } |
| 652 } | 653 } |
| 653 | 654 |
| 654 } // namespace cricket | 655 } // namespace cricket |
| OLD | NEW |