| 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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 ASSERT(worker_thread_ == rtc::Thread::Current()); | 279 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 280 if (!ports_.empty()) { | 280 if (!ports_.empty()) { |
| 281 LOG(LS_ERROR) | 281 LOG(LS_ERROR) |
| 282 << "Attempt to change tiebreaker after Port has been allocated."; | 282 << "Attempt to change tiebreaker after Port has been allocated."; |
| 283 return; | 283 return; |
| 284 } | 284 } |
| 285 | 285 |
| 286 tiebreaker_ = tiebreaker; | 286 tiebreaker_ = tiebreaker; |
| 287 } | 287 } |
| 288 | 288 |
| 289 // Currently a channel is considered ICE completed once there is no | 289 // A channel is considered ICE completed once there is at most one active |
| 290 // more than one connection per Network. This works for a single NIC | 290 // connection per network and at least one active connection. |
| 291 // with both IPv4 and IPv6 enabled. However, this condition won't | |
| 292 // happen when there are multiple NICs and all of them have | |
| 293 // connectivity. | |
| 294 // TODO(guoweis): Change Completion to be driven by a channel level | |
| 295 // timer. | |
| 296 TransportChannelState P2PTransportChannel::GetState() const { | 291 TransportChannelState P2PTransportChannel::GetState() const { |
| 297 std::set<rtc::Network*> networks; | 292 if (!had_connection_) { |
| 298 | 293 return TransportChannelState::STATE_INIT; |
| 299 if (connections_.empty()) { | |
| 300 return had_connection_ ? TransportChannelState::STATE_FAILED | |
| 301 : TransportChannelState::STATE_INIT; | |
| 302 } | 294 } |
| 303 | 295 |
| 304 for (uint32 i = 0; i < connections_.size(); ++i) { | 296 std::vector<Connection*> active_connections; |
| 305 rtc::Network* network = connections_[i]->port()->Network(); | 297 for (Connection* connection : connections_) { |
| 298 if (connection->Active()) { |
| 299 active_connections.push_back(connection); |
| 300 } |
| 301 } |
| 302 if (active_connections.empty()) { |
| 303 return TransportChannelState::STATE_FAILED; |
| 304 } |
| 305 |
| 306 std::set<rtc::Network*> networks; |
| 307 for (Connection* connection : active_connections) { |
| 308 rtc::Network* network = connection->port()->Network(); |
| 306 if (networks.find(network) == networks.end()) { | 309 if (networks.find(network) == networks.end()) { |
| 307 networks.insert(network); | 310 networks.insert(network); |
| 308 } else { | 311 } else { |
| 309 LOG_J(LS_VERBOSE, this) << "Ice not completed yet for this channel as " | 312 LOG_J(LS_VERBOSE, this) << "Ice not completed yet for this channel as " |
| 310 << network->ToString() | 313 << network->ToString() |
| 311 << " has more than 1 connection."; | 314 << " has more than 1 connection."; |
| 312 return TransportChannelState::STATE_CONNECTING; | 315 return TransportChannelState::STATE_CONNECTING; |
| 313 } | 316 } |
| 314 } | 317 } |
| 318 |
| 315 LOG_J(LS_VERBOSE, this) << "Ice is completed for this channel."; | 319 LOG_J(LS_VERBOSE, this) << "Ice is completed for this channel."; |
| 316 | |
| 317 return TransportChannelState::STATE_COMPLETED; | 320 return TransportChannelState::STATE_COMPLETED; |
| 318 } | 321 } |
| 319 | 322 |
| 320 void P2PTransportChannel::SetIceCredentials(const std::string& ice_ufrag, | 323 void P2PTransportChannel::SetIceCredentials(const std::string& ice_ufrag, |
| 321 const std::string& ice_pwd) { | 324 const std::string& ice_pwd) { |
| 322 ASSERT(worker_thread_ == rtc::Thread::Current()); | 325 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 323 ice_ufrag_ = ice_ufrag; | 326 ice_ufrag_ = ice_ufrag; |
| 324 ice_pwd_ = ice_pwd; | 327 ice_pwd_ = ice_pwd; |
| 325 // Note: Candidate gathering will restart when MaybeStartGathering is next | 328 // Note: Candidate gathering will restart when MaybeStartGathering is next |
| 326 // called. | 329 // called. |
| (...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 } | 868 } |
| 866 return sent; | 869 return sent; |
| 867 } | 870 } |
| 868 | 871 |
| 869 bool P2PTransportChannel::GetStats(ConnectionInfos *infos) { | 872 bool P2PTransportChannel::GetStats(ConnectionInfos *infos) { |
| 870 ASSERT(worker_thread_ == rtc::Thread::Current()); | 873 ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 871 // Gather connection infos. | 874 // Gather connection infos. |
| 872 infos->clear(); | 875 infos->clear(); |
| 873 | 876 |
| 874 std::vector<Connection *>::const_iterator it; | 877 std::vector<Connection *>::const_iterator it; |
| 875 for (it = connections_.begin(); it != connections_.end(); ++it) { | 878 for (Connection* connection : connections_) { |
| 876 Connection* connection = *it; | |
| 877 ConnectionInfo info; | 879 ConnectionInfo info; |
| 878 info.best_connection = (best_connection_ == connection); | 880 info.best_connection = (best_connection_ == connection); |
| 879 info.receiving = connection->receiving(); | 881 info.receiving = connection->receiving(); |
| 880 info.writable = | 882 info.writable = |
| 881 (connection->write_state() == Connection::STATE_WRITABLE); | 883 (connection->write_state() == Connection::STATE_WRITABLE); |
| 882 info.timeout = | 884 info.timeout = |
| 883 (connection->write_state() == Connection::STATE_WRITE_TIMEOUT); | 885 (connection->write_state() == Connection::STATE_WRITE_TIMEOUT); |
| 884 info.new_connection = !connection->reported(); | 886 info.new_connection = !connection->reported(); |
| 885 connection->set_reported(true); | 887 connection->set_reported(true); |
| 886 info.rtt = connection->rtt(); | 888 info.rtt = connection->rtt(); |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1354 } | 1356 } |
| 1355 } | 1357 } |
| 1356 | 1358 |
| 1357 void P2PTransportChannel::OnReadyToSend(Connection* connection) { | 1359 void P2PTransportChannel::OnReadyToSend(Connection* connection) { |
| 1358 if (connection == best_connection_ && writable()) { | 1360 if (connection == best_connection_ && writable()) { |
| 1359 SignalReadyToSend(this); | 1361 SignalReadyToSend(this); |
| 1360 } | 1362 } |
| 1361 } | 1363 } |
| 1362 | 1364 |
| 1363 } // namespace cricket | 1365 } // namespace cricket |
| OLD | NEW |