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 170 matching lines...) Loading... |
181 // ii) For controlled side, | 181 // ii) For controlled side, |
182 // a) nomination state, | 182 // a) nomination state, |
183 // b) last data received time. | 183 // b) last data received time. |
184 // iii) Lower cost / higher priority. | 184 // iii) Lower cost / higher priority. |
185 // iv) rtt. | 185 // iv) rtt. |
186 // TODO(honghaiz): Stop the aggressive nomination on the controlling side and | 186 // TODO(honghaiz): Stop the aggressive nomination on the controlling side and |
187 // implement the ice-renomination option. | 187 // implement the ice-renomination option. |
188 bool P2PTransportChannel::ShouldSwitchSelectedConnection( | 188 bool P2PTransportChannel::ShouldSwitchSelectedConnection( |
189 Connection* new_connection, | 189 Connection* new_connection, |
190 bool* missed_receiving_unchanged_threshold) const { | 190 bool* missed_receiving_unchanged_threshold) const { |
191 if (!new_connection || selected_connection_ == new_connection) { | 191 if (!ReadyToSend(new_connection) || selected_connection_ == new_connection) { |
192 return false; | 192 return false; |
193 } | 193 } |
194 | 194 |
195 if (selected_connection_ == nullptr) { | 195 if (selected_connection_ == nullptr) { |
196 return true; | 196 return true; |
197 } | 197 } |
198 | 198 |
199 rtc::Optional<int64_t> receiving_unchanged_threshold( | 199 rtc::Optional<int64_t> receiving_unchanged_threshold( |
200 rtc::TimeMillis() - config_.receiving_switching_delay.value_or(0)); | 200 rtc::TimeMillis() - config_.receiving_switching_delay.value_or(0)); |
201 int cmp = CompareConnections(selected_connection_, new_connection, | 201 int cmp = CompareConnections(selected_connection_, new_connection, |
(...skipping 728 matching lines...) Loading... |
930 int P2PTransportChannel::SendPacket(const char *data, size_t len, | 930 int P2PTransportChannel::SendPacket(const char *data, size_t len, |
931 const rtc::PacketOptions& options, | 931 const rtc::PacketOptions& options, |
932 int flags) { | 932 int flags) { |
933 ASSERT(worker_thread_ == rtc::Thread::Current()); | 933 ASSERT(worker_thread_ == rtc::Thread::Current()); |
934 if (flags != 0) { | 934 if (flags != 0) { |
935 error_ = EINVAL; | 935 error_ = EINVAL; |
936 return -1; | 936 return -1; |
937 } | 937 } |
938 // If we don't think the connection is working yet, return ENOTCONN | 938 // If we don't think the connection is working yet, return ENOTCONN |
939 // instead of sending a packet that will probably be dropped. | 939 // instead of sending a packet that will probably be dropped. |
940 if (!ReadyToSend()) { | 940 if (!ReadyToSend(selected_connection_)) { |
941 error_ = ENOTCONN; | 941 error_ = ENOTCONN; |
942 return -1; | 942 return -1; |
943 } | 943 } |
944 | 944 |
945 last_sent_packet_id_ = options.packet_id; | 945 last_sent_packet_id_ = options.packet_id; |
946 int sent = selected_connection_->Send(data, len, options); | 946 int sent = selected_connection_->Send(data, len, options); |
947 if (sent <= 0) { | 947 if (sent <= 0) { |
948 ASSERT(sent < 0); | 948 ASSERT(sent < 0); |
949 error_ = selected_connection_->GetError(); | 949 error_ = selected_connection_->GetError(); |
950 } | 950 } |
(...skipping 354 matching lines...) Loading... |
1305 // send; then it will only signal ready-to-send if the media channel | 1305 // send; then it will only signal ready-to-send if the media channel |
1306 // has been disallowed to send. | 1306 // has been disallowed to send. |
1307 if (selected_connection_->writable() || | 1307 if (selected_connection_->writable() || |
1308 PresumedWritable(selected_connection_)) { | 1308 PresumedWritable(selected_connection_)) { |
1309 SignalReadyToSend(this); | 1309 SignalReadyToSend(this); |
1310 } | 1310 } |
1311 } else { | 1311 } else { |
1312 LOG_J(LS_INFO, this) << "No selected connection"; | 1312 LOG_J(LS_INFO, this) << "No selected connection"; |
1313 } | 1313 } |
1314 SignalSelectedCandidatePairChanged(this, selected_connection_, | 1314 SignalSelectedCandidatePairChanged(this, selected_connection_, |
1315 last_sent_packet_id_, ReadyToSend()); | 1315 last_sent_packet_id_, |
| 1316 ReadyToSend(selected_connection_)); |
1316 } | 1317 } |
1317 | 1318 |
1318 // Warning: UpdateState should eventually be called whenever a connection | 1319 // Warning: UpdateState should eventually be called whenever a connection |
1319 // is added, deleted, or the write state of any connection changes so that the | 1320 // is added, deleted, or the write state of any connection changes so that the |
1320 // transport controller will get the up-to-date channel state. However it | 1321 // transport controller will get the up-to-date channel state. However it |
1321 // should not be called too often; in the case that multiple connection states | 1322 // should not be called too often; in the case that multiple connection states |
1322 // change, it should be called after all the connection states have changed. For | 1323 // change, it should be called after all the connection states have changed. For |
1323 // example, we call this at the end of SortConnectionsAndUpdateState. | 1324 // example, we call this at the end of SortConnectionsAndUpdateState. |
1324 void P2PTransportChannel::UpdateState() { | 1325 void P2PTransportChannel::UpdateState() { |
1325 TransportChannelState state = ComputeState(); | 1326 TransportChannelState state = ComputeState(); |
(...skipping 73 matching lines...) Loading... |
1399 void P2PTransportChannel::HandleAllTimedOut() { | 1400 void P2PTransportChannel::HandleAllTimedOut() { |
1400 for (Connection* connection : connections_) { | 1401 for (Connection* connection : connections_) { |
1401 connection->Destroy(); | 1402 connection->Destroy(); |
1402 } | 1403 } |
1403 } | 1404 } |
1404 | 1405 |
1405 bool P2PTransportChannel::weak() const { | 1406 bool P2PTransportChannel::weak() const { |
1406 return !selected_connection_ || selected_connection_->weak(); | 1407 return !selected_connection_ || selected_connection_->weak(); |
1407 } | 1408 } |
1408 | 1409 |
1409 bool P2PTransportChannel::ReadyToSend() const { | 1410 bool P2PTransportChannel::ReadyToSend(Connection* connection) const { |
1410 // Note that we allow sending on an unreliable connection, because it's | 1411 // Note that we allow sending on an unreliable connection, because it's |
1411 // possible that it became unreliable simply due to bad chance. | 1412 // possible that it became unreliable simply due to bad chance. |
1412 // So this shouldn't prevent attempting to send media. | 1413 // So this shouldn't prevent attempting to send media. |
1413 return selected_connection_ != nullptr && | 1414 return connection != nullptr && |
1414 (selected_connection_->writable() || | 1415 (connection->writable() || |
1415 PresumedWritable(selected_connection_) || | 1416 connection->write_state() == Connection::STATE_WRITE_UNRELIABLE || |
1416 selected_connection_->write_state() == | 1417 PresumedWritable(connection)); |
1417 Connection::STATE_WRITE_UNRELIABLE); | |
1418 } | 1418 } |
1419 | 1419 |
1420 // If we have a selected connection, return it, otherwise return top one in the | 1420 // If we have a selected connection, return it, otherwise return top one in the |
1421 // list (later we will mark it best). | 1421 // list (later we will mark it best). |
1422 Connection* P2PTransportChannel::GetBestConnectionOnNetwork( | 1422 Connection* P2PTransportChannel::GetBestConnectionOnNetwork( |
1423 rtc::Network* network) const { | 1423 rtc::Network* network) const { |
1424 // If the selected connection is on this network, then it wins. | 1424 // If the selected connection is on this network, then it wins. |
1425 if (selected_connection_ && | 1425 if (selected_connection_ && |
1426 (selected_connection_->port()->Network() == network)) { | 1426 (selected_connection_->port()->Network() == network)) { |
1427 return selected_connection_; | 1427 return selected_connection_; |
(...skipping 501 matching lines...) Loading... |
1929 | 1929 |
1930 // During the initial state when nothing has been pinged yet, return the first | 1930 // During the initial state when nothing has been pinged yet, return the first |
1931 // one in the ordered |connections_|. | 1931 // one in the ordered |connections_|. |
1932 return *(std::find_if(connections_.begin(), connections_.end(), | 1932 return *(std::find_if(connections_.begin(), connections_.end(), |
1933 [conn1, conn2](Connection* conn) { | 1933 [conn1, conn2](Connection* conn) { |
1934 return conn == conn1 || conn == conn2; | 1934 return conn == conn1 || conn == conn2; |
1935 })); | 1935 })); |
1936 } | 1936 } |
1937 | 1937 |
1938 } // namespace cricket | 1938 } // namespace cricket |
OLD | NEW |