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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 LOG_J(LS_VERBOSE, this) << "Ice not completed yet for this channel as " | 301 LOG_J(LS_VERBOSE, this) << "Ice not completed yet for this channel as " |
302 << network->ToString() | 302 << network->ToString() |
303 << " has more than 1 connection."; | 303 << " has more than 1 connection."; |
304 return TransportChannelState::STATE_CONNECTING; | 304 return TransportChannelState::STATE_CONNECTING; |
305 } | 305 } |
306 } | 306 } |
307 | 307 |
308 return TransportChannelState::STATE_COMPLETED; | 308 return TransportChannelState::STATE_COMPLETED; |
309 } | 309 } |
310 | 310 |
311 void P2PTransportChannel::SetIceCredentials(const std::string& ice_ufrag, | 311 void P2PTransportChannel::SetIceParameters(const IceParameters& ice_params) { |
312 const std::string& ice_pwd) { | |
313 ASSERT(worker_thread_ == rtc::Thread::Current()); | 312 ASSERT(worker_thread_ == rtc::Thread::Current()); |
314 ice_ufrag_ = ice_ufrag; | 313 ice_parameters_ = ice_params; |
315 ice_pwd_ = ice_pwd; | |
316 // Note: Candidate gathering will restart when MaybeStartGathering is next | 314 // Note: Candidate gathering will restart when MaybeStartGathering is next |
317 // called. | 315 // called. |
318 } | 316 } |
319 | 317 |
320 void P2PTransportChannel::SetRemoteIceCredentials(const std::string& ice_ufrag, | 318 void P2PTransportChannel::SetRemoteIceParameters( |
321 const std::string& ice_pwd) { | 319 const IceParameters& ice_params) { |
322 ASSERT(worker_thread_ == rtc::Thread::Current()); | 320 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 321 LOG(LS_INFO) << "Remote supports ICE renomination ? " |
| 322 << ice_params.renomination; |
323 IceParameters* current_ice = remote_ice(); | 323 IceParameters* current_ice = remote_ice(); |
324 IceParameters new_ice(ice_ufrag, ice_pwd); | 324 if (!current_ice || *current_ice != ice_params) { |
325 if (!current_ice || *current_ice != new_ice) { | |
326 // Keep the ICE credentials so that newer connections | 325 // Keep the ICE credentials so that newer connections |
327 // are prioritized over the older ones. | 326 // are prioritized over the older ones. |
328 remote_ice_parameters_.push_back(new_ice); | 327 remote_ice_parameters_.push_back(ice_params); |
329 } | 328 } |
330 | 329 |
331 // Update the pwd of remote candidate if needed. | 330 // Update the pwd of remote candidate if needed. |
332 for (RemoteCandidate& candidate : remote_candidates_) { | 331 for (RemoteCandidate& candidate : remote_candidates_) { |
333 if (candidate.username() == ice_ufrag && candidate.password().empty()) { | 332 if (candidate.username() == ice_params.ufrag && |
334 candidate.set_password(ice_pwd); | 333 candidate.password().empty()) { |
| 334 candidate.set_password(ice_params.pwd); |
335 } | 335 } |
336 } | 336 } |
337 // We need to update the credentials and generation for any peer reflexive | 337 // We need to update the credentials and generation for any peer reflexive |
338 // candidates. | 338 // candidates. |
339 for (Connection* conn : connections_) { | 339 for (Connection* conn : connections_) { |
340 conn->MaybeSetRemoteIceCredentialsAndGeneration( | 340 conn->MaybeSetRemoteIceParametersAndGeneration( |
341 ice_ufrag, ice_pwd, | 341 ice_params, static_cast<int>(remote_ice_parameters_.size() - 1)); |
342 static_cast<int>(remote_ice_parameters_.size() - 1)); | |
343 } | 342 } |
344 // Updating the remote ICE candidate generation could change the sort order. | 343 // Updating the remote ICE candidate generation could change the sort order. |
345 RequestSortAndStateUpdate(); | 344 RequestSortAndStateUpdate(); |
346 } | 345 } |
347 | 346 |
348 void P2PTransportChannel::SetRemoteIceMode(IceMode mode) { | 347 void P2PTransportChannel::SetRemoteIceMode(IceMode mode) { |
349 remote_ice_mode_ = mode; | 348 remote_ice_mode_ = mode; |
350 } | 349 } |
351 | 350 |
352 void P2PTransportChannel::SetIceConfig(const IceConfig& config) { | 351 void P2PTransportChannel::SetIceConfig(const IceConfig& config) { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 LOG(LS_INFO) << "Set default nomination mode to " | 421 LOG(LS_INFO) << "Set default nomination mode to " |
423 << static_cast<int>(config_.default_nomination_mode); | 422 << static_cast<int>(config_.default_nomination_mode); |
424 } | 423 } |
425 } | 424 } |
426 | 425 |
427 const IceConfig& P2PTransportChannel::config() const { | 426 const IceConfig& P2PTransportChannel::config() const { |
428 return config_; | 427 return config_; |
429 } | 428 } |
430 | 429 |
431 void P2PTransportChannel::MaybeStartGathering() { | 430 void P2PTransportChannel::MaybeStartGathering() { |
432 if (ice_ufrag_.empty() || ice_pwd_.empty()) { | 431 if (ice_parameters_.ufrag.empty() || ice_parameters_.pwd.empty()) { |
433 return; | 432 return; |
434 } | 433 } |
435 // Start gathering if we never started before, or if an ICE restart occurred. | 434 // Start gathering if we never started before, or if an ICE restart occurred. |
436 if (allocator_sessions_.empty() || | 435 if (allocator_sessions_.empty() || |
437 IceCredentialsChanged(allocator_sessions_.back()->ice_ufrag(), | 436 IceCredentialsChanged(allocator_sessions_.back()->ice_ufrag(), |
438 allocator_sessions_.back()->ice_pwd(), ice_ufrag_, | 437 allocator_sessions_.back()->ice_pwd(), |
439 ice_pwd_)) { | 438 ice_parameters_.ufrag, ice_parameters_.pwd)) { |
440 if (gathering_state_ != kIceGatheringGathering) { | 439 if (gathering_state_ != kIceGatheringGathering) { |
441 gathering_state_ = kIceGatheringGathering; | 440 gathering_state_ = kIceGatheringGathering; |
442 SignalGatheringState(this); | 441 SignalGatheringState(this); |
443 } | 442 } |
444 // Time for a new allocator. | 443 // Time for a new allocator. |
445 std::unique_ptr<PortAllocatorSession> pooled_session = | 444 std::unique_ptr<PortAllocatorSession> pooled_session = |
446 allocator_->TakePooledSession(transport_name(), component(), ice_ufrag_, | 445 allocator_->TakePooledSession(transport_name(), component(), |
447 ice_pwd_); | 446 ice_parameters_.ufrag, |
| 447 ice_parameters_.pwd); |
448 if (pooled_session) { | 448 if (pooled_session) { |
449 AddAllocatorSession(std::move(pooled_session)); | 449 AddAllocatorSession(std::move(pooled_session)); |
450 PortAllocatorSession* raw_pooled_session = | 450 PortAllocatorSession* raw_pooled_session = |
451 allocator_sessions_.back().get(); | 451 allocator_sessions_.back().get(); |
452 // Process the pooled session's existing candidates/ports, if they exist. | 452 // Process the pooled session's existing candidates/ports, if they exist. |
453 OnCandidatesReady(raw_pooled_session, | 453 OnCandidatesReady(raw_pooled_session, |
454 raw_pooled_session->ReadyCandidates()); | 454 raw_pooled_session->ReadyCandidates()); |
455 for (PortInterface* port : allocator_sessions_.back()->ReadyPorts()) { | 455 for (PortInterface* port : allocator_sessions_.back()->ReadyPorts()) { |
456 OnPortReady(raw_pooled_session, port); | 456 OnPortReady(raw_pooled_session, port); |
457 } | 457 } |
458 if (allocator_sessions_.back()->CandidatesAllocationDone()) { | 458 if (allocator_sessions_.back()->CandidatesAllocationDone()) { |
459 OnCandidatesAllocationDone(raw_pooled_session); | 459 OnCandidatesAllocationDone(raw_pooled_session); |
460 } | 460 } |
461 } else { | 461 } else { |
462 AddAllocatorSession(allocator_->CreateSession( | 462 AddAllocatorSession(allocator_->CreateSession( |
463 transport_name(), component(), ice_ufrag_, ice_pwd_)); | 463 transport_name(), component(), ice_parameters_.ufrag, |
| 464 ice_parameters_.pwd)); |
464 allocator_sessions_.back()->StartGettingPorts(); | 465 allocator_sessions_.back()->StartGettingPorts(); |
465 } | 466 } |
466 } | 467 } |
467 } | 468 } |
468 | 469 |
469 // A new port is available, attempt to make connections for it | 470 // A new port is available, attempt to make connections for it |
470 void P2PTransportChannel::OnPortReady(PortAllocatorSession *session, | 471 void P2PTransportChannel::OnPortReady(PortAllocatorSession *session, |
471 PortInterface* port) { | 472 PortInterface* port) { |
472 ASSERT(worker_thread_ == rtc::Thread::Current()); | 473 ASSERT(worker_thread_ == rtc::Thread::Current()); |
473 | 474 |
(...skipping 1131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1605 } | 1606 } |
1606 } | 1607 } |
1607 | 1608 |
1608 // Apart from sending ping from |conn| this method also updates | 1609 // Apart from sending ping from |conn| this method also updates |
1609 // |use_candidate_attr| and |nomination| flags. One of the flags is set to | 1610 // |use_candidate_attr| and |nomination| flags. One of the flags is set to |
1610 // nominate |conn| if this channel is in CONTROLLING. | 1611 // nominate |conn| if this channel is in CONTROLLING. |
1611 void P2PTransportChannel::PingConnection(Connection* conn) { | 1612 void P2PTransportChannel::PingConnection(Connection* conn) { |
1612 bool use_candidate_attr = false; | 1613 bool use_candidate_attr = false; |
1613 uint32_t nomination = 0; | 1614 uint32_t nomination = 0; |
1614 if (ice_role_ == ICEROLE_CONTROLLING) { | 1615 if (ice_role_ == ICEROLE_CONTROLLING) { |
1615 if (remote_supports_renomination_) { | 1616 bool renomination_supported = ice_parameters_.renomination && |
| 1617 !remote_ice_parameters_.empty() && |
| 1618 remote_ice_parameters_.back().renomination; |
| 1619 if (renomination_supported) { |
1616 nomination = GetNominationAttr(conn); | 1620 nomination = GetNominationAttr(conn); |
1617 } else { | 1621 } else { |
1618 use_candidate_attr = | 1622 use_candidate_attr = |
1619 GetUseCandidateAttr(conn, config_.default_nomination_mode); | 1623 GetUseCandidateAttr(conn, config_.default_nomination_mode); |
1620 } | 1624 } |
1621 } | 1625 } |
1622 conn->set_nomination(nomination); | 1626 conn->set_nomination(nomination); |
1623 conn->set_use_candidate_attr(use_candidate_attr); | 1627 conn->set_use_candidate_attr(use_candidate_attr); |
1624 last_ping_sent_ms_ = rtc::TimeMillis(); | 1628 last_ping_sent_ms_ = rtc::TimeMillis(); |
1625 conn->Ping(last_ping_sent_ms_); | 1629 conn->Ping(last_ping_sent_ms_); |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1943 | 1947 |
1944 // During the initial state when nothing has been pinged yet, return the first | 1948 // During the initial state when nothing has been pinged yet, return the first |
1945 // one in the ordered |connections_|. | 1949 // one in the ordered |connections_|. |
1946 return *(std::find_if(connections_.begin(), connections_.end(), | 1950 return *(std::find_if(connections_.begin(), connections_.end(), |
1947 [conn1, conn2](Connection* conn) { | 1951 [conn1, conn2](Connection* conn) { |
1948 return conn == conn1 || conn == conn2; | 1952 return conn == conn1 || conn == conn2; |
1949 })); | 1953 })); |
1950 } | 1954 } |
1951 | 1955 |
1952 } // namespace cricket | 1956 } // namespace cricket |
OLD | NEW |