| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 LOG_J(LS_VERBOSE, this) << "Ice not completed yet for this channel as " | 288 LOG_J(LS_VERBOSE, this) << "Ice not completed yet for this channel as " |
| 289 << network->ToString() | 289 << network->ToString() |
| 290 << " has more than 1 connection."; | 290 << " has more than 1 connection."; |
| 291 return TransportChannelState::STATE_CONNECTING; | 291 return TransportChannelState::STATE_CONNECTING; |
| 292 } | 292 } |
| 293 } | 293 } |
| 294 | 294 |
| 295 return TransportChannelState::STATE_COMPLETED; | 295 return TransportChannelState::STATE_COMPLETED; |
| 296 } | 296 } |
| 297 | 297 |
| 298 void P2PTransportChannel::SetIceCredentials(const std::string& ice_ufrag, | 298 void P2PTransportChannel::SetIceParameters(const IceParameters& ice_params) { |
| 299 const std::string& ice_pwd) { | |
| 300 ASSERT(worker_thread_ == rtc::Thread::Current()); | 299 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 301 ice_ufrag_ = ice_ufrag; | 300 ice_parameters_ = ice_params; |
| 302 ice_pwd_ = ice_pwd; | |
| 303 // Note: Candidate gathering will restart when MaybeStartGathering is next | 301 // Note: Candidate gathering will restart when MaybeStartGathering is next |
| 304 // called. | 302 // called. |
| 305 } | 303 } |
| 306 | 304 |
| 307 void P2PTransportChannel::SetRemoteIceCredentials(const std::string& ice_ufrag, | 305 void P2PTransportChannel::SetRemoteIceParameters( |
| 308 const std::string& ice_pwd) { | 306 const IceParameters& ice_params) { |
| 309 ASSERT(worker_thread_ == rtc::Thread::Current()); | 307 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 308 LOG(LS_INFO) << "Remote supports ICE renomination ? " |
| 309 << ice_params.renomination; |
| 310 IceParameters* current_ice = remote_ice(); | 310 IceParameters* current_ice = remote_ice(); |
| 311 IceParameters new_ice(ice_ufrag, ice_pwd); | 311 if (!current_ice || *current_ice != ice_params) { |
| 312 if (!current_ice || *current_ice != new_ice) { | |
| 313 // Keep the ICE credentials so that newer connections | 312 // Keep the ICE credentials so that newer connections |
| 314 // are prioritized over the older ones. | 313 // are prioritized over the older ones. |
| 315 remote_ice_parameters_.push_back(new_ice); | 314 remote_ice_parameters_.push_back(ice_params); |
| 316 } | 315 } |
| 317 | 316 |
| 318 // Update the pwd of remote candidate if needed. | 317 // Update the pwd of remote candidate if needed. |
| 319 for (RemoteCandidate& candidate : remote_candidates_) { | 318 for (RemoteCandidate& candidate : remote_candidates_) { |
| 320 if (candidate.username() == ice_ufrag && candidate.password().empty()) { | 319 if (candidate.username() == ice_params.ufrag && |
| 321 candidate.set_password(ice_pwd); | 320 candidate.password().empty()) { |
| 321 candidate.set_password(ice_params.pwd); |
| 322 } | 322 } |
| 323 } | 323 } |
| 324 // We need to update the credentials and generation for any peer reflexive | 324 // We need to update the credentials and generation for any peer reflexive |
| 325 // candidates. | 325 // candidates. |
| 326 for (Connection* conn : connections_) { | 326 for (Connection* conn : connections_) { |
| 327 conn->MaybeSetRemoteIceCredentialsAndGeneration( | 327 conn->MaybeSetRemoteIceParametersAndGeneration( |
| 328 ice_ufrag, ice_pwd, | 328 ice_params, static_cast<int>(remote_ice_parameters_.size() - 1)); |
| 329 static_cast<int>(remote_ice_parameters_.size() - 1)); | |
| 330 } | 329 } |
| 331 // Updating the remote ICE candidate generation could change the sort order. | 330 // Updating the remote ICE candidate generation could change the sort order. |
| 332 RequestSortAndStateUpdate(); | 331 RequestSortAndStateUpdate(); |
| 333 } | 332 } |
| 334 | 333 |
| 335 void P2PTransportChannel::SetRemoteIceMode(IceMode mode) { | 334 void P2PTransportChannel::SetRemoteIceMode(IceMode mode) { |
| 336 remote_ice_mode_ = mode; | 335 remote_ice_mode_ = mode; |
| 337 } | 336 } |
| 338 | 337 |
| 339 void P2PTransportChannel::SetIceConfig(const IceConfig& config) { | 338 void P2PTransportChannel::SetIceConfig(const IceConfig& config) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 LOG(LS_INFO) << "Set default nomination mode to " | 408 LOG(LS_INFO) << "Set default nomination mode to " |
| 410 << static_cast<int>(config_.default_nomination_mode); | 409 << static_cast<int>(config_.default_nomination_mode); |
| 411 } | 410 } |
| 412 } | 411 } |
| 413 | 412 |
| 414 const IceConfig& P2PTransportChannel::config() const { | 413 const IceConfig& P2PTransportChannel::config() const { |
| 415 return config_; | 414 return config_; |
| 416 } | 415 } |
| 417 | 416 |
| 418 void P2PTransportChannel::MaybeStartGathering() { | 417 void P2PTransportChannel::MaybeStartGathering() { |
| 419 if (ice_ufrag_.empty() || ice_pwd_.empty()) { | 418 if (ice_parameters_.ufrag.empty() || ice_parameters_.pwd.empty()) { |
| 420 return; | 419 return; |
| 421 } | 420 } |
| 422 // Start gathering if we never started before, or if an ICE restart occurred. | 421 // Start gathering if we never started before, or if an ICE restart occurred. |
| 423 if (allocator_sessions_.empty() || | 422 if (allocator_sessions_.empty() || |
| 424 IceCredentialsChanged(allocator_sessions_.back()->ice_ufrag(), | 423 IceCredentialsChanged(allocator_sessions_.back()->ice_ufrag(), |
| 425 allocator_sessions_.back()->ice_pwd(), ice_ufrag_, | 424 allocator_sessions_.back()->ice_pwd(), |
| 426 ice_pwd_)) { | 425 ice_parameters_.ufrag, ice_parameters_.pwd)) { |
| 427 if (gathering_state_ != kIceGatheringGathering) { | 426 if (gathering_state_ != kIceGatheringGathering) { |
| 428 gathering_state_ = kIceGatheringGathering; | 427 gathering_state_ = kIceGatheringGathering; |
| 429 SignalGatheringState(this); | 428 SignalGatheringState(this); |
| 430 } | 429 } |
| 431 // Time for a new allocator. | 430 // Time for a new allocator. |
| 432 std::unique_ptr<PortAllocatorSession> pooled_session = | 431 std::unique_ptr<PortAllocatorSession> pooled_session = |
| 433 allocator_->TakePooledSession(transport_name(), component(), ice_ufrag_, | 432 allocator_->TakePooledSession(transport_name(), component(), |
| 434 ice_pwd_); | 433 ice_parameters_.ufrag, |
| 434 ice_parameters_.pwd); |
| 435 if (pooled_session) { | 435 if (pooled_session) { |
| 436 AddAllocatorSession(std::move(pooled_session)); | 436 AddAllocatorSession(std::move(pooled_session)); |
| 437 PortAllocatorSession* raw_pooled_session = | 437 PortAllocatorSession* raw_pooled_session = |
| 438 allocator_sessions_.back().get(); | 438 allocator_sessions_.back().get(); |
| 439 // Process the pooled session's existing candidates/ports, if they exist. | 439 // Process the pooled session's existing candidates/ports, if they exist. |
| 440 OnCandidatesReady(raw_pooled_session, | 440 OnCandidatesReady(raw_pooled_session, |
| 441 raw_pooled_session->ReadyCandidates()); | 441 raw_pooled_session->ReadyCandidates()); |
| 442 for (PortInterface* port : allocator_sessions_.back()->ReadyPorts()) { | 442 for (PortInterface* port : allocator_sessions_.back()->ReadyPorts()) { |
| 443 OnPortReady(raw_pooled_session, port); | 443 OnPortReady(raw_pooled_session, port); |
| 444 } | 444 } |
| 445 if (allocator_sessions_.back()->CandidatesAllocationDone()) { | 445 if (allocator_sessions_.back()->CandidatesAllocationDone()) { |
| 446 OnCandidatesAllocationDone(raw_pooled_session); | 446 OnCandidatesAllocationDone(raw_pooled_session); |
| 447 } | 447 } |
| 448 } else { | 448 } else { |
| 449 AddAllocatorSession(allocator_->CreateSession( | 449 AddAllocatorSession(allocator_->CreateSession( |
| 450 transport_name(), component(), ice_ufrag_, ice_pwd_)); | 450 transport_name(), component(), ice_parameters_.ufrag, |
| 451 ice_parameters_.pwd)); |
| 451 allocator_sessions_.back()->StartGettingPorts(); | 452 allocator_sessions_.back()->StartGettingPorts(); |
| 452 } | 453 } |
| 453 } | 454 } |
| 454 } | 455 } |
| 455 | 456 |
| 456 // A new port is available, attempt to make connections for it | 457 // A new port is available, attempt to make connections for it |
| 457 void P2PTransportChannel::OnPortReady(PortAllocatorSession *session, | 458 void P2PTransportChannel::OnPortReady(PortAllocatorSession *session, |
| 458 PortInterface* port) { | 459 PortInterface* port) { |
| 459 ASSERT(worker_thread_ == rtc::Thread::Current()); | 460 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 460 | 461 |
| (...skipping 1130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1591 } | 1592 } |
| 1592 } | 1593 } |
| 1593 | 1594 |
| 1594 // Apart from sending ping from |conn| this method also updates | 1595 // Apart from sending ping from |conn| this method also updates |
| 1595 // |use_candidate_attr| and |nomination| flags. One of the flags is set to | 1596 // |use_candidate_attr| and |nomination| flags. One of the flags is set to |
| 1596 // nominate |conn| if this channel is in CONTROLLING. | 1597 // nominate |conn| if this channel is in CONTROLLING. |
| 1597 void P2PTransportChannel::PingConnection(Connection* conn) { | 1598 void P2PTransportChannel::PingConnection(Connection* conn) { |
| 1598 bool use_candidate_attr = false; | 1599 bool use_candidate_attr = false; |
| 1599 uint32_t nomination = 0; | 1600 uint32_t nomination = 0; |
| 1600 if (ice_role_ == ICEROLE_CONTROLLING) { | 1601 if (ice_role_ == ICEROLE_CONTROLLING) { |
| 1601 if (remote_supports_renomination_) { | 1602 bool renomination_supported = ice_parameters_.renomination && |
| 1603 !remote_ice_parameters_.empty() && |
| 1604 remote_ice_parameters_.back().renomination; |
| 1605 if (renomination_supported) { |
| 1602 nomination = GetNominationAttr(conn); | 1606 nomination = GetNominationAttr(conn); |
| 1603 } else { | 1607 } else { |
| 1604 use_candidate_attr = | 1608 use_candidate_attr = |
| 1605 GetUseCandidateAttr(conn, config_.default_nomination_mode); | 1609 GetUseCandidateAttr(conn, config_.default_nomination_mode); |
| 1606 } | 1610 } |
| 1607 } | 1611 } |
| 1608 conn->set_nomination(nomination); | 1612 conn->set_nomination(nomination); |
| 1609 conn->set_use_candidate_attr(use_candidate_attr); | 1613 conn->set_use_candidate_attr(use_candidate_attr); |
| 1610 last_ping_sent_ms_ = rtc::TimeMillis(); | 1614 last_ping_sent_ms_ = rtc::TimeMillis(); |
| 1611 conn->Ping(last_ping_sent_ms_); | 1615 conn->Ping(last_ping_sent_ms_); |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1929 | 1933 |
| 1930 // During the initial state when nothing has been pinged yet, return the first | 1934 // During the initial state when nothing has been pinged yet, return the first |
| 1931 // one in the ordered |connections_|. | 1935 // one in the ordered |connections_|. |
| 1932 return *(std::find_if(connections_.begin(), connections_.end(), | 1936 return *(std::find_if(connections_.begin(), connections_.end(), |
| 1933 [conn1, conn2](Connection* conn) { | 1937 [conn1, conn2](Connection* conn) { |
| 1934 return conn == conn1 || conn == conn2; | 1938 return conn == conn1 || conn == conn2; |
| 1935 })); | 1939 })); |
| 1936 } | 1940 } |
| 1937 | 1941 |
| 1938 } // namespace cricket | 1942 } // namespace cricket |
| OLD | NEW |