Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: webrtc/p2p/base/p2ptransportchannel.cc

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

Powered by Google App Engine
This is Rietveld 408576698