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