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