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