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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 static const int DEFAULT_REGATHER_ON_FAILED_NETWORKS_INTERVAL = 5 * 60 * 1000; | 94 static const int DEFAULT_REGATHER_ON_FAILED_NETWORKS_INTERVAL = 5 * 60 * 1000; |
95 | 95 |
96 static constexpr int DEFAULT_BACKUP_CONNECTION_PING_INTERVAL = 25 * 1000; | 96 static constexpr int DEFAULT_BACKUP_CONNECTION_PING_INTERVAL = 25 * 1000; |
97 | 97 |
98 static constexpr int a_is_better = 1; | 98 static constexpr int a_is_better = 1; |
99 static constexpr int b_is_better = -1; | 99 static constexpr int b_is_better = -1; |
100 | 100 |
101 P2PTransportChannel::P2PTransportChannel(const std::string& transport_name, | 101 P2PTransportChannel::P2PTransportChannel(const std::string& transport_name, |
102 int component, | 102 int component, |
103 PortAllocator* allocator) | 103 PortAllocator* allocator) |
104 : TransportChannelImpl(transport_name, component), | 104 : transport_name_(transport_name), |
| 105 component_(component), |
105 allocator_(allocator), | 106 allocator_(allocator), |
106 network_thread_(rtc::Thread::Current()), | 107 network_thread_(rtc::Thread::Current()), |
107 incoming_only_(false), | 108 incoming_only_(false), |
108 error_(0), | 109 error_(0), |
109 sort_dirty_(false), | 110 sort_dirty_(false), |
110 remote_ice_mode_(ICEMODE_FULL), | 111 remote_ice_mode_(ICEMODE_FULL), |
111 ice_role_(ICEROLE_UNKNOWN), | 112 ice_role_(ICEROLE_UNKNOWN), |
112 tiebreaker_(0), | 113 tiebreaker_(0), |
113 gathering_state_(kIceGatheringNew), | 114 gathering_state_(kIceGatheringNew), |
114 check_receiving_interval_(MIN_CHECK_RECEIVING_INTERVAL * 5), | 115 check_receiving_interval_(MIN_CHECK_RECEIVING_INTERVAL * 5), |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 RTC_DCHECK(network_thread_ == rtc::Thread::Current()); | 266 RTC_DCHECK(network_thread_ == rtc::Thread::Current()); |
266 if (!ports_.empty() || !pruned_ports_.empty()) { | 267 if (!ports_.empty() || !pruned_ports_.empty()) { |
267 LOG(LS_ERROR) | 268 LOG(LS_ERROR) |
268 << "Attempt to change tiebreaker after Port has been allocated."; | 269 << "Attempt to change tiebreaker after Port has been allocated."; |
269 return; | 270 return; |
270 } | 271 } |
271 | 272 |
272 tiebreaker_ = tiebreaker; | 273 tiebreaker_ = tiebreaker; |
273 } | 274 } |
274 | 275 |
275 TransportChannelState P2PTransportChannel::GetState() const { | 276 IceTransportState P2PTransportChannel::GetState() const { |
276 return state_; | 277 return state_; |
277 } | 278 } |
278 | 279 |
279 // A channel is considered ICE completed once there is at most one active | 280 // A channel is considered ICE completed once there is at most one active |
280 // connection per network and at least one active connection. | 281 // connection per network and at least one active connection. |
281 TransportChannelState P2PTransportChannel::ComputeState() const { | 282 IceTransportState P2PTransportChannel::ComputeState() const { |
282 if (!had_connection_) { | 283 if (!had_connection_) { |
283 return TransportChannelState::STATE_INIT; | 284 return IceTransportState::STATE_INIT; |
284 } | 285 } |
285 | 286 |
286 std::vector<Connection*> active_connections; | 287 std::vector<Connection*> active_connections; |
287 for (Connection* connection : connections_) { | 288 for (Connection* connection : connections_) { |
288 if (connection->active()) { | 289 if (connection->active()) { |
289 active_connections.push_back(connection); | 290 active_connections.push_back(connection); |
290 } | 291 } |
291 } | 292 } |
292 if (active_connections.empty()) { | 293 if (active_connections.empty()) { |
293 return TransportChannelState::STATE_FAILED; | 294 return IceTransportState::STATE_FAILED; |
294 } | 295 } |
295 | 296 |
296 std::set<rtc::Network*> networks; | 297 std::set<rtc::Network*> networks; |
297 for (Connection* connection : active_connections) { | 298 for (Connection* connection : active_connections) { |
298 rtc::Network* network = connection->port()->Network(); | 299 rtc::Network* network = connection->port()->Network(); |
299 if (networks.find(network) == networks.end()) { | 300 if (networks.find(network) == networks.end()) { |
300 networks.insert(network); | 301 networks.insert(network); |
301 } else { | 302 } else { |
302 LOG_J(LS_VERBOSE, this) << "Ice not completed yet for this channel as " | 303 LOG_J(LS_VERBOSE, this) << "Ice not completed yet for this channel as " |
303 << network->ToString() | 304 << network->ToString() |
304 << " has more than 1 connection."; | 305 << " has more than 1 connection."; |
305 return TransportChannelState::STATE_CONNECTING; | 306 return IceTransportState::STATE_CONNECTING; |
306 } | 307 } |
307 } | 308 } |
308 | 309 |
309 return TransportChannelState::STATE_COMPLETED; | 310 return IceTransportState::STATE_COMPLETED; |
310 } | 311 } |
311 | 312 |
312 void P2PTransportChannel::SetIceParameters(const IceParameters& ice_params) { | 313 void P2PTransportChannel::SetIceParameters(const IceParameters& ice_params) { |
313 RTC_DCHECK(network_thread_ == rtc::Thread::Current()); | 314 RTC_DCHECK(network_thread_ == rtc::Thread::Current()); |
314 LOG(LS_INFO) << "Set ICE ufrag: " << ice_params.ufrag | 315 LOG(LS_INFO) << "Set ICE ufrag: " << ice_params.ufrag |
315 << " pwd: " << ice_params.pwd << " on transport " | 316 << " pwd: " << ice_params.pwd << " on transport " |
316 << transport_name(); | 317 << transport_name(); |
317 ice_parameters_ = ice_params; | 318 ice_parameters_ = ice_params; |
318 // Note: Candidate gathering will restart when MaybeStartGathering is next | 319 // Note: Candidate gathering will restart when MaybeStartGathering is next |
319 // called. | 320 // called. |
(...skipping 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1384 ReadyToSend(selected_connection_)); | 1385 ReadyToSend(selected_connection_)); |
1385 } | 1386 } |
1386 | 1387 |
1387 // Warning: UpdateState should eventually be called whenever a connection | 1388 // Warning: UpdateState should eventually be called whenever a connection |
1388 // is added, deleted, or the write state of any connection changes so that the | 1389 // is added, deleted, or the write state of any connection changes so that the |
1389 // transport controller will get the up-to-date channel state. However it | 1390 // transport controller will get the up-to-date channel state. However it |
1390 // should not be called too often; in the case that multiple connection states | 1391 // should not be called too often; in the case that multiple connection states |
1391 // change, it should be called after all the connection states have changed. For | 1392 // change, it should be called after all the connection states have changed. For |
1392 // example, we call this at the end of SortConnectionsAndUpdateState. | 1393 // example, we call this at the end of SortConnectionsAndUpdateState. |
1393 void P2PTransportChannel::UpdateState() { | 1394 void P2PTransportChannel::UpdateState() { |
1394 TransportChannelState state = ComputeState(); | 1395 IceTransportState state = ComputeState(); |
1395 if (state_ != state) { | 1396 if (state_ != state) { |
1396 LOG_J(LS_INFO, this) << "Transport channel state changed from " << state_ | 1397 LOG_J(LS_INFO, this) << "Transport channel state changed from " |
1397 << " to " << state; | 1398 << static_cast<int>(state_) << " to " |
| 1399 << static_cast<int>(state); |
1398 // Check that the requested transition is allowed. Note that | 1400 // Check that the requested transition is allowed. Note that |
1399 // P2PTransportChannel does not (yet) implement a direct mapping of the ICE | 1401 // P2PTransportChannel does not (yet) implement a direct mapping of the ICE |
1400 // states from the standard; the difference is covered by | 1402 // states from the standard; the difference is covered by |
1401 // TransportController and PeerConnection. | 1403 // TransportController and PeerConnection. |
1402 switch (state_) { | 1404 switch (state_) { |
1403 case STATE_INIT: | 1405 case IceTransportState::STATE_INIT: |
1404 // TODO(deadbeef): Once we implement end-of-candidates signaling, | 1406 // TODO(deadbeef): Once we implement end-of-candidates signaling, |
1405 // we shouldn't go from INIT to COMPLETED. | 1407 // we shouldn't go from INIT to COMPLETED. |
1406 RTC_DCHECK(state == STATE_CONNECTING || state == STATE_COMPLETED); | 1408 RTC_DCHECK(state == IceTransportState::STATE_CONNECTING || |
| 1409 state == IceTransportState::STATE_COMPLETED); |
1407 break; | 1410 break; |
1408 case STATE_CONNECTING: | 1411 case IceTransportState::STATE_CONNECTING: |
1409 RTC_DCHECK(state == STATE_COMPLETED || state == STATE_FAILED); | 1412 RTC_DCHECK(state == IceTransportState::STATE_COMPLETED || |
| 1413 state == IceTransportState::STATE_FAILED); |
1410 break; | 1414 break; |
1411 case STATE_COMPLETED: | 1415 case IceTransportState::STATE_COMPLETED: |
1412 // TODO(deadbeef): Once we implement end-of-candidates signaling, | 1416 // TODO(deadbeef): Once we implement end-of-candidates signaling, |
1413 // we shouldn't go from COMPLETED to CONNECTING. | 1417 // we shouldn't go from COMPLETED to CONNECTING. |
1414 // Though we *can* go from COMPlETED to FAILED, if consent expires. | 1418 // Though we *can* go from COMPlETED to FAILED, if consent expires. |
1415 RTC_DCHECK(state == STATE_CONNECTING || state == STATE_FAILED); | 1419 RTC_DCHECK(state == IceTransportState::STATE_CONNECTING || |
| 1420 state == IceTransportState::STATE_FAILED); |
1416 break; | 1421 break; |
1417 case STATE_FAILED: | 1422 case IceTransportState::STATE_FAILED: |
1418 // TODO(deadbeef): Once we implement end-of-candidates signaling, | 1423 // TODO(deadbeef): Once we implement end-of-candidates signaling, |
1419 // we shouldn't go from FAILED to CONNECTING or COMPLETED. | 1424 // we shouldn't go from FAILED to CONNECTING or COMPLETED. |
1420 RTC_DCHECK(state == STATE_CONNECTING || state == STATE_COMPLETED); | 1425 RTC_DCHECK(state == IceTransportState::STATE_CONNECTING || |
| 1426 state == IceTransportState::STATE_COMPLETED); |
1421 break; | 1427 break; |
1422 default: | 1428 default: |
1423 RTC_NOTREACHED(); | 1429 RTC_NOTREACHED(); |
1424 break; | 1430 break; |
1425 } | 1431 } |
1426 state_ = state; | 1432 state_ = state; |
1427 SignalStateChanged(this); | 1433 SignalStateChanged(this); |
1428 } | 1434 } |
1429 | 1435 |
1430 // If our selected connection is "presumed writable" (TURN-TURN with no | 1436 // If our selected connection is "presumed writable" (TURN-TURN with no |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1526 MarkConnectionPinged(conn); | 1532 MarkConnectionPinged(conn); |
1527 } | 1533 } |
1528 } | 1534 } |
1529 int delay = std::min(ping_interval, check_receiving_interval_); | 1535 int delay = std::min(ping_interval, check_receiving_interval_); |
1530 thread()->PostDelayed(RTC_FROM_HERE, delay, this, MSG_CHECK_AND_PING); | 1536 thread()->PostDelayed(RTC_FROM_HERE, delay, this, MSG_CHECK_AND_PING); |
1531 } | 1537 } |
1532 | 1538 |
1533 // A connection is considered a backup connection if the channel state | 1539 // A connection is considered a backup connection if the channel state |
1534 // is completed, the connection is not the selected connection and it is active. | 1540 // is completed, the connection is not the selected connection and it is active. |
1535 bool P2PTransportChannel::IsBackupConnection(const Connection* conn) const { | 1541 bool P2PTransportChannel::IsBackupConnection(const Connection* conn) const { |
1536 return state_ == STATE_COMPLETED && conn != selected_connection_ && | 1542 return state_ == IceTransportState::STATE_COMPLETED && |
1537 conn->active(); | 1543 conn != selected_connection_ && conn->active(); |
1538 } | 1544 } |
1539 | 1545 |
1540 // Is the connection in a state for us to even consider pinging the other side? | 1546 // Is the connection in a state for us to even consider pinging the other side? |
1541 // We consider a connection pingable even if it's not connected because that's | 1547 // We consider a connection pingable even if it's not connected because that's |
1542 // how a TCP connection is kicked into reconnecting on the active side. | 1548 // how a TCP connection is kicked into reconnecting on the active side. |
1543 bool P2PTransportChannel::IsPingable(const Connection* conn, | 1549 bool P2PTransportChannel::IsPingable(const Connection* conn, |
1544 int64_t now) const { | 1550 int64_t now) const { |
1545 const Candidate& remote = conn->remote_candidate(); | 1551 const Candidate& remote = conn->remote_candidate(); |
1546 // We should never get this far with an empty remote ufrag. | 1552 // We should never get this far with an empty remote ufrag. |
1547 RTC_DCHECK(!remote.username().empty()); | 1553 RTC_DCHECK(!remote.username().empty()); |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2007 } | 2013 } |
2008 | 2014 |
2009 // During the initial state when nothing has been pinged yet, return the first | 2015 // During the initial state when nothing has been pinged yet, return the first |
2010 // one in the ordered |connections_|. | 2016 // one in the ordered |connections_|. |
2011 return *(std::find_if(connections_.begin(), connections_.end(), | 2017 return *(std::find_if(connections_.begin(), connections_.end(), |
2012 [conn1, conn2](Connection* conn) { | 2018 [conn1, conn2](Connection* conn) { |
2013 return conn == conn1 || conn == conn2; | 2019 return conn == conn1 || conn == conn2; |
2014 })); | 2020 })); |
2015 } | 2021 } |
2016 | 2022 |
| 2023 void P2PTransportChannel::set_writable(bool writable) { |
| 2024 if (writable_ == writable) { |
| 2025 return; |
| 2026 } |
| 2027 LOG_J(LS_VERBOSE, this) << "set_writable from:" << writable_ << " to " |
| 2028 << writable; |
| 2029 writable_ = writable; |
| 2030 if (writable_) { |
| 2031 SignalReadyToSend(this); |
| 2032 } |
| 2033 SignalWritableState(this); |
| 2034 } |
| 2035 |
| 2036 void P2PTransportChannel::set_receiving(bool receiving) { |
| 2037 if (receiving_ == receiving) { |
| 2038 return; |
| 2039 } |
| 2040 receiving_ = receiving; |
| 2041 SignalReceivingState(this); |
| 2042 } |
| 2043 |
2017 } // namespace cricket | 2044 } // namespace cricket |
OLD | NEW |