| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/protocol/ice_transport_channel.h" | 5 #include "remoting/protocol/ice_transport_channel.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 ice_username_fragment_( | 53 ice_username_fragment_( |
| 54 rtc::CreateRandomString(cricket::ICE_UFRAG_LENGTH)), | 54 rtc::CreateRandomString(cricket::ICE_UFRAG_LENGTH)), |
| 55 connect_attempts_left_(kMaxReconnectAttempts), | 55 connect_attempts_left_(kMaxReconnectAttempts), |
| 56 weak_factory_(this) { | 56 weak_factory_(this) { |
| 57 DCHECK(!ice_username_fragment_.empty()); | 57 DCHECK(!ice_username_fragment_.empty()); |
| 58 } | 58 } |
| 59 | 59 |
| 60 IceTransportChannel::~IceTransportChannel() { | 60 IceTransportChannel::~IceTransportChannel() { |
| 61 DCHECK(delegate_); | 61 DCHECK(delegate_); |
| 62 | 62 |
| 63 delegate_->OnTransportDeleted(this); | 63 delegate_->OnChannelDeleted(this); |
| 64 | 64 |
| 65 auto task_runner = base::ThreadTaskRunnerHandle::Get(); | 65 auto task_runner = base::ThreadTaskRunnerHandle::Get(); |
| 66 if (channel_) | 66 if (channel_) |
| 67 task_runner->DeleteSoon(FROM_HERE, channel_.release()); | 67 task_runner->DeleteSoon(FROM_HERE, channel_.release()); |
| 68 if (port_allocator_) | 68 if (port_allocator_) |
| 69 task_runner->DeleteSoon(FROM_HERE, port_allocator_.release()); | 69 task_runner->DeleteSoon(FROM_HERE, port_allocator_.release()); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void IceTransportChannel::Connect(const std::string& name, | 72 void IceTransportChannel::Connect(const std::string& name, |
| 73 Delegate* delegate, | 73 Delegate* delegate, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 95 | 95 |
| 96 // Create P2PTransportChannel, attach signal handlers and connect it. | 96 // Create P2PTransportChannel, attach signal handlers and connect it. |
| 97 // TODO(sergeyu): Specify correct component ID for the channel. | 97 // TODO(sergeyu): Specify correct component ID for the channel. |
| 98 channel_.reset(new cricket::P2PTransportChannel( | 98 channel_.reset(new cricket::P2PTransportChannel( |
| 99 std::string(), 0, nullptr, port_allocator_.get())); | 99 std::string(), 0, nullptr, port_allocator_.get())); |
| 100 std::string ice_password = rtc::CreateRandomString(cricket::ICE_PWD_LENGTH); | 100 std::string ice_password = rtc::CreateRandomString(cricket::ICE_PWD_LENGTH); |
| 101 channel_->SetIceProtocolType(cricket::ICEPROTO_RFC5245); | 101 channel_->SetIceProtocolType(cricket::ICEPROTO_RFC5245); |
| 102 channel_->SetIceRole((transport_context_->role() == TransportRole::CLIENT) | 102 channel_->SetIceRole((transport_context_->role() == TransportRole::CLIENT) |
| 103 ? cricket::ICEROLE_CONTROLLING | 103 ? cricket::ICEROLE_CONTROLLING |
| 104 : cricket::ICEROLE_CONTROLLED); | 104 : cricket::ICEROLE_CONTROLLED); |
| 105 delegate_->OnTransportIceCredentials(this, ice_username_fragment_, | 105 delegate_->OnChannelIceCredentials(this, ice_username_fragment_, |
| 106 ice_password); | 106 ice_password); |
| 107 channel_->SetIceCredentials(ice_username_fragment_, ice_password); | 107 channel_->SetIceCredentials(ice_username_fragment_, ice_password); |
| 108 channel_->SignalCandidateGathered.connect( | 108 channel_->SignalCandidateGathered.connect( |
| 109 this, &IceTransportChannel::OnCandidateGathered); | 109 this, &IceTransportChannel::OnCandidateGathered); |
| 110 channel_->SignalRouteChange.connect( | 110 channel_->SignalRouteChange.connect( |
| 111 this, &IceTransportChannel::OnRouteChange); | 111 this, &IceTransportChannel::OnRouteChange); |
| 112 channel_->SignalReceivingState.connect( | 112 channel_->SignalReceivingState.connect( |
| 113 this, &IceTransportChannel::OnReceivingState); | 113 this, &IceTransportChannel::OnReceivingState); |
| 114 channel_->SignalWritableState.connect( | 114 channel_->SignalWritableState.connect( |
| 115 this, &IceTransportChannel::OnWritableState); | 115 this, &IceTransportChannel::OnWritableState); |
| 116 channel_->set_incoming_only(!(transport_context_->network_settings().flags & | 116 channel_->set_incoming_only(!(transport_context_->network_settings().flags & |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 | 183 |
| 184 bool IceTransportChannel::is_connected() const { | 184 bool IceTransportChannel::is_connected() const { |
| 185 DCHECK(thread_checker_.CalledOnValidThread()); | 185 DCHECK(thread_checker_.CalledOnValidThread()); |
| 186 return callback_.is_null(); | 186 return callback_.is_null(); |
| 187 } | 187 } |
| 188 | 188 |
| 189 void IceTransportChannel::OnCandidateGathered( | 189 void IceTransportChannel::OnCandidateGathered( |
| 190 cricket::TransportChannelImpl* channel, | 190 cricket::TransportChannelImpl* channel, |
| 191 const cricket::Candidate& candidate) { | 191 const cricket::Candidate& candidate) { |
| 192 DCHECK(thread_checker_.CalledOnValidThread()); | 192 DCHECK(thread_checker_.CalledOnValidThread()); |
| 193 delegate_->OnTransportCandidate(this, candidate); | 193 delegate_->OnChannelCandidate(this, candidate); |
| 194 } | 194 } |
| 195 | 195 |
| 196 void IceTransportChannel::OnRouteChange( | 196 void IceTransportChannel::OnRouteChange( |
| 197 cricket::TransportChannel* channel, | 197 cricket::TransportChannel* channel, |
| 198 const cricket::Candidate& candidate) { | 198 const cricket::Candidate& candidate) { |
| 199 // Ignore notifications if the channel is not writable. | 199 // Ignore notifications if the channel is not writable. |
| 200 if (channel_->writable()) | 200 if (channel_->writable()) |
| 201 NotifyRouteChanged(); | 201 NotifyRouteChanged(); |
| 202 } | 202 } |
| 203 | 203 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 LOG(FATAL) << "Failed to convert peer IP address."; | 253 LOG(FATAL) << "Failed to convert peer IP address."; |
| 254 } | 254 } |
| 255 | 255 |
| 256 const cricket::Candidate& local_candidate = | 256 const cricket::Candidate& local_candidate = |
| 257 channel_->best_connection()->local_candidate(); | 257 channel_->best_connection()->local_candidate(); |
| 258 if (!jingle_glue::SocketAddressToIPEndPoint( | 258 if (!jingle_glue::SocketAddressToIPEndPoint( |
| 259 local_candidate.address(), &route.local_address)) { | 259 local_candidate.address(), &route.local_address)) { |
| 260 LOG(FATAL) << "Failed to convert local IP address."; | 260 LOG(FATAL) << "Failed to convert local IP address."; |
| 261 } | 261 } |
| 262 | 262 |
| 263 delegate_->OnTransportRouteChange(this, route); | 263 delegate_->OnChannelRouteChange(this, route); |
| 264 } | 264 } |
| 265 | 265 |
| 266 void IceTransportChannel::TryReconnect() { | 266 void IceTransportChannel::TryReconnect() { |
| 267 DCHECK(!channel_->writable()); | 267 DCHECK(!channel_->writable()); |
| 268 | 268 |
| 269 if (connect_attempts_left_ <= 0) { | 269 if (connect_attempts_left_ <= 0) { |
| 270 reconnect_timer_.Stop(); | 270 reconnect_timer_.Stop(); |
| 271 | 271 |
| 272 // Notify the caller that ICE connection has failed - normally that will | 272 // Notify the caller that ICE connection has failed - normally that will |
| 273 // terminate Jingle connection (i.e. the transport will be destroyed). | 273 // terminate Jingle connection (i.e. the transport will be destroyed). |
| 274 delegate_->OnTransportFailed(this); | 274 delegate_->OnChannelFailed(this); |
| 275 return; | 275 return; |
| 276 } | 276 } |
| 277 --connect_attempts_left_; | 277 --connect_attempts_left_; |
| 278 | 278 |
| 279 // Restart ICE by resetting ICE password. | 279 // Restart ICE by resetting ICE password. |
| 280 std::string ice_password = rtc::CreateRandomString(cricket::ICE_PWD_LENGTH); | 280 std::string ice_password = rtc::CreateRandomString(cricket::ICE_PWD_LENGTH); |
| 281 delegate_->OnTransportIceCredentials(this, ice_username_fragment_, | 281 delegate_->OnChannelIceCredentials(this, ice_username_fragment_, |
| 282 ice_password); | 282 ice_password); |
| 283 channel_->SetIceCredentials(ice_username_fragment_, ice_password); | 283 channel_->SetIceCredentials(ice_username_fragment_, ice_password); |
| 284 } | 284 } |
| 285 | 285 |
| 286 } // namespace protocol | 286 } // namespace protocol |
| 287 } // namespace remoting | 287 } // namespace remoting |
| OLD | NEW |