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) { |
Taylor Brandstetter
2016/08/08 22:28:15
Should we support renomination going from true to
honghaiz3
2016/08/11 04:57:57
Implementation-wide, I think it allows renominatio
| |
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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
402 config_.receiving_switching_delay = config.receiving_switching_delay; | 401 config_.receiving_switching_delay = config.receiving_switching_delay; |
403 LOG(LS_INFO) << "Set receiving_switching_delay to" | 402 LOG(LS_INFO) << "Set receiving_switching_delay to" |
404 << *config_.receiving_switching_delay; | 403 << *config_.receiving_switching_delay; |
405 } | 404 } |
406 | 405 |
407 if (config_.default_nomination_mode != config.default_nomination_mode) { | 406 if (config_.default_nomination_mode != config.default_nomination_mode) { |
408 config_.default_nomination_mode = config.default_nomination_mode; | 407 config_.default_nomination_mode = config.default_nomination_mode; |
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 } |
411 config_.use_renomination_if_remote_supports = | |
412 config.use_renomination_if_remote_supports; | |
413 LOG(LS_INFO) << "Set use_renomination_if_remote_supports to " | |
414 << config_.use_renomination_if_remote_supports; | |
412 } | 415 } |
413 | 416 |
414 const IceConfig& P2PTransportChannel::config() const { | 417 const IceConfig& P2PTransportChannel::config() const { |
415 return config_; | 418 return config_; |
416 } | 419 } |
417 | 420 |
418 void P2PTransportChannel::MaybeStartGathering() { | 421 void P2PTransportChannel::MaybeStartGathering() { |
419 if (ice_ufrag_.empty() || ice_pwd_.empty()) { | 422 if (ice_parameters_.ufrag.empty() || ice_parameters_.pwd.empty()) { |
420 return; | 423 return; |
421 } | 424 } |
422 // Start gathering if we never started before, or if an ICE restart occurred. | 425 // Start gathering if we never started before, or if an ICE restart occurred. |
423 if (allocator_sessions_.empty() || | 426 if (allocator_sessions_.empty() || |
424 IceCredentialsChanged(allocator_sessions_.back()->ice_ufrag(), | 427 IceCredentialsChanged(allocator_sessions_.back()->ice_ufrag(), |
425 allocator_sessions_.back()->ice_pwd(), ice_ufrag_, | 428 allocator_sessions_.back()->ice_pwd(), |
426 ice_pwd_)) { | 429 ice_parameters_.ufrag, ice_parameters_.pwd)) { |
427 if (gathering_state_ != kIceGatheringGathering) { | 430 if (gathering_state_ != kIceGatheringGathering) { |
428 gathering_state_ = kIceGatheringGathering; | 431 gathering_state_ = kIceGatheringGathering; |
429 SignalGatheringState(this); | 432 SignalGatheringState(this); |
430 } | 433 } |
431 // Time for a new allocator. | 434 // Time for a new allocator. |
432 std::unique_ptr<PortAllocatorSession> pooled_session = | 435 std::unique_ptr<PortAllocatorSession> pooled_session = |
433 allocator_->TakePooledSession(transport_name(), component(), ice_ufrag_, | 436 allocator_->TakePooledSession(transport_name(), component(), |
434 ice_pwd_); | 437 ice_parameters_.ufrag, |
438 ice_parameters_.pwd); | |
435 if (pooled_session) { | 439 if (pooled_session) { |
436 AddAllocatorSession(std::move(pooled_session)); | 440 AddAllocatorSession(std::move(pooled_session)); |
437 PortAllocatorSession* raw_pooled_session = | 441 PortAllocatorSession* raw_pooled_session = |
438 allocator_sessions_.back().get(); | 442 allocator_sessions_.back().get(); |
439 // Process the pooled session's existing candidates/ports, if they exist. | 443 // Process the pooled session's existing candidates/ports, if they exist. |
440 OnCandidatesReady(raw_pooled_session, | 444 OnCandidatesReady(raw_pooled_session, |
441 raw_pooled_session->ReadyCandidates()); | 445 raw_pooled_session->ReadyCandidates()); |
442 for (PortInterface* port : allocator_sessions_.back()->ReadyPorts()) { | 446 for (PortInterface* port : allocator_sessions_.back()->ReadyPorts()) { |
443 OnPortReady(raw_pooled_session, port); | 447 OnPortReady(raw_pooled_session, port); |
444 } | 448 } |
445 if (allocator_sessions_.back()->CandidatesAllocationDone()) { | 449 if (allocator_sessions_.back()->CandidatesAllocationDone()) { |
446 OnCandidatesAllocationDone(raw_pooled_session); | 450 OnCandidatesAllocationDone(raw_pooled_session); |
447 } | 451 } |
448 } else { | 452 } else { |
449 AddAllocatorSession(allocator_->CreateSession( | 453 AddAllocatorSession(allocator_->CreateSession( |
450 SessionId(), transport_name(), component(), ice_ufrag_, ice_pwd_)); | 454 SessionId(), transport_name(), component(), ice_parameters_.ufrag, |
455 ice_parameters_.pwd)); | |
451 allocator_sessions_.back()->StartGettingPorts(); | 456 allocator_sessions_.back()->StartGettingPorts(); |
452 } | 457 } |
453 } | 458 } |
454 } | 459 } |
455 | 460 |
456 // A new port is available, attempt to make connections for it | 461 // A new port is available, attempt to make connections for it |
457 void P2PTransportChannel::OnPortReady(PortAllocatorSession *session, | 462 void P2PTransportChannel::OnPortReady(PortAllocatorSession *session, |
458 PortInterface* port) { | 463 PortInterface* port) { |
459 ASSERT(worker_thread_ == rtc::Thread::Current()); | 464 ASSERT(worker_thread_ == rtc::Thread::Current()); |
460 | 465 |
(...skipping 1130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1591 } | 1596 } |
1592 } | 1597 } |
1593 | 1598 |
1594 // Apart from sending ping from |conn| this method also updates | 1599 // Apart from sending ping from |conn| this method also updates |
1595 // |use_candidate_attr| and |nomination| flags. One of the flags is set to | 1600 // |use_candidate_attr| and |nomination| flags. One of the flags is set to |
1596 // nominate |conn| if this channel is in CONTROLLING. | 1601 // nominate |conn| if this channel is in CONTROLLING. |
1597 void P2PTransportChannel::PingConnection(Connection* conn) { | 1602 void P2PTransportChannel::PingConnection(Connection* conn) { |
1598 bool use_candidate_attr = false; | 1603 bool use_candidate_attr = false; |
1599 uint32_t nomination = 0; | 1604 uint32_t nomination = 0; |
1600 if (ice_role_ == ICEROLE_CONTROLLING) { | 1605 if (ice_role_ == ICEROLE_CONTROLLING) { |
1601 if (remote_supports_renomination_) { | 1606 bool remote_supports_renomination = |
1607 !remote_ice_parameters_.empty() && | |
1608 remote_ice_parameters_.back().renomination; | |
1609 if (remote_supports_renomination && | |
1610 config_.use_renomination_if_remote_supports) { | |
1602 nomination = GetNominationAttr(conn); | 1611 nomination = GetNominationAttr(conn); |
1603 } else { | 1612 } else { |
1604 use_candidate_attr = | 1613 use_candidate_attr = |
1605 GetUseCandidateAttr(conn, config_.default_nomination_mode); | 1614 GetUseCandidateAttr(conn, config_.default_nomination_mode); |
1606 } | 1615 } |
1607 } | 1616 } |
1608 conn->set_nomination(nomination); | 1617 conn->set_nomination(nomination); |
1609 conn->set_use_candidate_attr(use_candidate_attr); | 1618 conn->set_use_candidate_attr(use_candidate_attr); |
1610 last_ping_sent_ms_ = rtc::TimeMillis(); | 1619 last_ping_sent_ms_ = rtc::TimeMillis(); |
1611 conn->Ping(last_ping_sent_ms_); | 1620 conn->Ping(last_ping_sent_ms_); |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1929 | 1938 |
1930 // During the initial state when nothing has been pinged yet, return the first | 1939 // During the initial state when nothing has been pinged yet, return the first |
1931 // one in the ordered |connections_|. | 1940 // one in the ordered |connections_|. |
1932 return *(std::find_if(connections_.begin(), connections_.end(), | 1941 return *(std::find_if(connections_.begin(), connections_.end(), |
1933 [conn1, conn2](Connection* conn) { | 1942 [conn1, conn2](Connection* conn) { |
1934 return conn == conn1 || conn == conn2; | 1943 return conn == conn1 || conn == conn2; |
1935 })); | 1944 })); |
1936 } | 1945 } |
1937 | 1946 |
1938 } // namespace cricket | 1947 } // namespace cricket |
OLD | NEW |