| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/quic/core/quic_session.h" | 5 #include "net/quic/core/quic_session.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "net/quic/core/crypto/crypto_protocol.h" | 15 #include "net/quic/core/crypto/crypto_protocol.h" |
| 16 #include "net/quic/core/crypto/null_encrypter.h" | 16 #include "net/quic/core/crypto/null_encrypter.h" |
| 17 #include "net/quic/core/quic_crypto_stream.h" | 17 #include "net/quic/core/quic_crypto_stream.h" |
| 18 #include "net/quic/core/quic_flags.h" | 18 #include "net/quic/core/quic_flags.h" |
| 19 #include "net/quic/core/quic_protocol.h" | 19 #include "net/quic/core/quic_protocol.h" |
| 20 #include "net/quic/core/quic_stream.h" |
| 20 #include "net/quic/core/quic_utils.h" | 21 #include "net/quic/core/quic_utils.h" |
| 21 #include "net/quic/core/reliable_quic_stream.h" | |
| 22 #include "net/quic/test_tools/quic_config_peer.h" | 22 #include "net/quic/test_tools/quic_config_peer.h" |
| 23 #include "net/quic/test_tools/quic_connection_peer.h" | 23 #include "net/quic/test_tools/quic_connection_peer.h" |
| 24 #include "net/quic/test_tools/quic_flow_controller_peer.h" | 24 #include "net/quic/test_tools/quic_flow_controller_peer.h" |
| 25 #include "net/quic/test_tools/quic_headers_stream_peer.h" | 25 #include "net/quic/test_tools/quic_headers_stream_peer.h" |
| 26 #include "net/quic/test_tools/quic_session_peer.h" | 26 #include "net/quic/test_tools/quic_session_peer.h" |
| 27 #include "net/quic/test_tools/quic_spdy_session_peer.h" | 27 #include "net/quic/test_tools/quic_spdy_session_peer.h" |
| 28 #include "net/quic/test_tools/quic_spdy_stream_peer.h" | 28 #include "net/quic/test_tools/quic_spdy_stream_peer.h" |
| 29 #include "net/quic/test_tools/quic_stream_peer.h" |
| 29 #include "net/quic/test_tools/quic_test_utils.h" | 30 #include "net/quic/test_tools/quic_test_utils.h" |
| 30 #include "net/quic/test_tools/reliable_quic_stream_peer.h" | |
| 31 #include "net/spdy/spdy_framer.h" | 31 #include "net/spdy/spdy_framer.h" |
| 32 #include "net/test/gtest_util.h" | 32 #include "net/test/gtest_util.h" |
| 33 #include "testing/gmock/include/gmock/gmock.h" | 33 #include "testing/gmock/include/gmock/gmock.h" |
| 34 #include "testing/gmock_mutant.h" | 34 #include "testing/gmock_mutant.h" |
| 35 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
| 36 | 36 |
| 37 using net::SpdyHeaderBlock; | 37 using net::SpdyHeaderBlock; |
| 38 using net::SpdyPriority; | 38 using net::SpdyPriority; |
| 39 using std::string; | 39 using std::string; |
| 40 using testing::CreateFunctor; | 40 using testing::CreateFunctor; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 : QuicHeadersStream(session) {} | 81 : QuicHeadersStream(session) {} |
| 82 | 82 |
| 83 MOCK_METHOD0(OnCanWrite, void()); | 83 MOCK_METHOD0(OnCanWrite, void()); |
| 84 }; | 84 }; |
| 85 | 85 |
| 86 class TestStream : public QuicSpdyStream { | 86 class TestStream : public QuicSpdyStream { |
| 87 public: | 87 public: |
| 88 TestStream(QuicStreamId id, QuicSpdySession* session) | 88 TestStream(QuicStreamId id, QuicSpdySession* session) |
| 89 : QuicSpdyStream(id, session) {} | 89 : QuicSpdyStream(id, session) {} |
| 90 | 90 |
| 91 using ReliableQuicStream::CloseWriteSide; | 91 using QuicStream::CloseWriteSide; |
| 92 | 92 |
| 93 void OnDataAvailable() override {} | 93 void OnDataAvailable() override {} |
| 94 | 94 |
| 95 MOCK_METHOD0(OnCanWrite, void()); | 95 MOCK_METHOD0(OnCanWrite, void()); |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 // Poor man's functor for use as callback in a mock. | 98 // Poor man's functor for use as callback in a mock. |
| 99 class StreamBlocker { | 99 class StreamBlocker { |
| 100 public: | 100 public: |
| 101 StreamBlocker(QuicSession* session, QuicStreamId stream_id) | 101 StreamBlocker(QuicSession* session, QuicStreamId stream_id) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 bool ShouldCreateIncomingDynamicStream(QuicStreamId /*id*/) override { | 149 bool ShouldCreateIncomingDynamicStream(QuicStreamId /*id*/) override { |
| 150 return true; | 150 return true; |
| 151 } | 151 } |
| 152 | 152 |
| 153 bool ShouldCreateOutgoingDynamicStream() override { return true; } | 153 bool ShouldCreateOutgoingDynamicStream() override { return true; } |
| 154 | 154 |
| 155 bool IsClosedStream(QuicStreamId id) { | 155 bool IsClosedStream(QuicStreamId id) { |
| 156 return QuicSession::IsClosedStream(id); | 156 return QuicSession::IsClosedStream(id); |
| 157 } | 157 } |
| 158 | 158 |
| 159 ReliableQuicStream* GetOrCreateDynamicStream(QuicStreamId stream_id) { | 159 QuicStream* GetOrCreateDynamicStream(QuicStreamId stream_id) { |
| 160 return QuicSpdySession::GetOrCreateDynamicStream(stream_id); | 160 return QuicSpdySession::GetOrCreateDynamicStream(stream_id); |
| 161 } | 161 } |
| 162 | 162 |
| 163 QuicConsumedData WritevData( | 163 QuicConsumedData WritevData( |
| 164 ReliableQuicStream* stream, | 164 QuicStream* stream, |
| 165 QuicStreamId id, | 165 QuicStreamId id, |
| 166 QuicIOVector data, | 166 QuicIOVector data, |
| 167 QuicStreamOffset offset, | 167 QuicStreamOffset offset, |
| 168 bool fin, | 168 bool fin, |
| 169 QuicAckListenerInterface* ack_notifier_delegate) override { | 169 QuicAckListenerInterface* ack_notifier_delegate) override { |
| 170 QuicConsumedData consumed(data.total_length, fin); | 170 QuicConsumedData consumed(data.total_length, fin); |
| 171 if (!writev_consumes_all_data_) { | 171 if (!writev_consumes_all_data_) { |
| 172 consumed = QuicSession::WritevData(stream, id, data, offset, fin, | 172 consumed = QuicSession::WritevData(stream, id, data, offset, fin, |
| 173 ack_notifier_delegate); | 173 ack_notifier_delegate); |
| 174 } | 174 } |
| 175 stream->set_stream_bytes_written(stream->stream_bytes_written() + | 175 stream->set_stream_bytes_written(stream->stream_bytes_written() + |
| 176 consumed.bytes_consumed); | 176 consumed.bytes_consumed); |
| 177 if (fin && consumed.fin_consumed) { | 177 if (fin && consumed.fin_consumed) { |
| 178 stream->set_fin_sent(true); | 178 stream->set_fin_sent(true); |
| 179 } | 179 } |
| 180 QuicSessionPeer::GetWriteBlockedStreams(this)->UpdateBytesForStream( | 180 QuicSessionPeer::GetWriteBlockedStreams(this)->UpdateBytesForStream( |
| 181 id, consumed.bytes_consumed); | 181 id, consumed.bytes_consumed); |
| 182 return consumed; | 182 return consumed; |
| 183 } | 183 } |
| 184 | 184 |
| 185 void set_writev_consumes_all_data(bool val) { | 185 void set_writev_consumes_all_data(bool val) { |
| 186 writev_consumes_all_data_ = val; | 186 writev_consumes_all_data_ = val; |
| 187 } | 187 } |
| 188 | 188 |
| 189 QuicConsumedData SendStreamData(ReliableQuicStream* stream) { | 189 QuicConsumedData SendStreamData(QuicStream* stream) { |
| 190 struct iovec iov; | 190 struct iovec iov; |
| 191 if (stream->id() != kCryptoStreamId) { | 191 if (stream->id() != kCryptoStreamId) { |
| 192 this->connection()->SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); | 192 this->connection()->SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); |
| 193 } | 193 } |
| 194 QuicConsumedData consumed = | 194 QuicConsumedData consumed = |
| 195 WritevData(stream, stream->id(), MakeIOVector("not empty", &iov), 0, | 195 WritevData(stream, stream->id(), MakeIOVector("not empty", &iov), 0, |
| 196 true, nullptr); | 196 true, nullptr); |
| 197 return consumed; | 197 return consumed; |
| 198 } | 198 } |
| 199 | 199 |
| 200 QuicConsumedData SendLargeFakeData(ReliableQuicStream* stream, int bytes) { | 200 QuicConsumedData SendLargeFakeData(QuicStream* stream, int bytes) { |
| 201 DCHECK(writev_consumes_all_data_); | 201 DCHECK(writev_consumes_all_data_); |
| 202 struct iovec iov; | 202 struct iovec iov; |
| 203 iov.iov_base = nullptr; // should not be read. | 203 iov.iov_base = nullptr; // should not be read. |
| 204 iov.iov_len = static_cast<size_t>(bytes); | 204 iov.iov_len = static_cast<size_t>(bytes); |
| 205 return WritevData(stream, stream->id(), QuicIOVector(&iov, 1, bytes), 0, | 205 return WritevData(stream, stream->id(), QuicIOVector(&iov, 1, bytes), 0, |
| 206 true, nullptr); | 206 true, nullptr); |
| 207 } | 207 } |
| 208 | 208 |
| 209 using QuicSession::PostProcessAfterData; | 209 using QuicSession::PostProcessAfterData; |
| 210 | 210 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 QuicStreamId stream_id1 = kClientDataStreamId1; | 337 QuicStreamId stream_id1 = kClientDataStreamId1; |
| 338 QuicStreamId stream_id2 = kClientDataStreamId2; | 338 QuicStreamId stream_id2 = kClientDataStreamId2; |
| 339 session_.GetOrCreateDynamicStream(stream_id1); | 339 session_.GetOrCreateDynamicStream(stream_id1); |
| 340 session_.GetOrCreateDynamicStream(stream_id2); | 340 session_.GetOrCreateDynamicStream(stream_id2); |
| 341 | 341 |
| 342 CheckClosedStreams(); | 342 CheckClosedStreams(); |
| 343 CloseStream(stream_id1); | 343 CloseStream(stream_id1); |
| 344 CheckClosedStreams(); | 344 CheckClosedStreams(); |
| 345 CloseStream(stream_id2); | 345 CloseStream(stream_id2); |
| 346 // Create a stream, and make another available. | 346 // Create a stream, and make another available. |
| 347 ReliableQuicStream* stream3 = | 347 QuicStream* stream3 = session_.GetOrCreateDynamicStream(stream_id2 + 4); |
| 348 session_.GetOrCreateDynamicStream(stream_id2 + 4); | |
| 349 CheckClosedStreams(); | 348 CheckClosedStreams(); |
| 350 // Close one, but make sure the other is still not closed | 349 // Close one, but make sure the other is still not closed |
| 351 CloseStream(stream3->id()); | 350 CloseStream(stream3->id()); |
| 352 CheckClosedStreams(); | 351 CheckClosedStreams(); |
| 353 } | 352 } |
| 354 | 353 |
| 355 TEST_P(QuicSessionTestServer, MaximumAvailableOpenedStreams) { | 354 TEST_P(QuicSessionTestServer, MaximumAvailableOpenedStreams) { |
| 356 QuicStreamId stream_id = kClientDataStreamId1; | 355 QuicStreamId stream_id = kClientDataStreamId1; |
| 357 session_.GetOrCreateDynamicStream(stream_id); | 356 session_.GetOrCreateDynamicStream(stream_id); |
| 358 EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(0); | 357 EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(0); |
| (...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1043 EXPECT_LT(kInitialConnectionBytesConsumed, | 1042 EXPECT_LT(kInitialConnectionBytesConsumed, |
| 1044 kInitialConnectionHighestReceivedOffset); | 1043 kInitialConnectionHighestReceivedOffset); |
| 1045 session_.flow_controller()->UpdateHighestReceivedOffset( | 1044 session_.flow_controller()->UpdateHighestReceivedOffset( |
| 1046 kInitialConnectionHighestReceivedOffset); | 1045 kInitialConnectionHighestReceivedOffset); |
| 1047 session_.flow_controller()->AddBytesConsumed(kInitialConnectionBytesConsumed); | 1046 session_.flow_controller()->AddBytesConsumed(kInitialConnectionBytesConsumed); |
| 1048 | 1047 |
| 1049 // Reset our stream: this results in the stream being closed locally. | 1048 // Reset our stream: this results in the stream being closed locally. |
| 1050 TestStream* stream = session_.CreateOutgoingDynamicStream(kDefaultPriority); | 1049 TestStream* stream = session_.CreateOutgoingDynamicStream(kDefaultPriority); |
| 1051 EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _)); | 1050 EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _)); |
| 1052 stream->Reset(QUIC_STREAM_CANCELLED); | 1051 stream->Reset(QUIC_STREAM_CANCELLED); |
| 1053 EXPECT_TRUE(ReliableQuicStreamPeer::read_side_closed(stream)); | 1052 EXPECT_TRUE(QuicStreamPeer::read_side_closed(stream)); |
| 1054 | 1053 |
| 1055 // Now receive a RST from the peer. We should handle this by adjusting the | 1054 // Now receive a RST from the peer. We should handle this by adjusting the |
| 1056 // connection level flow control receive window to take into account the total | 1055 // connection level flow control receive window to take into account the total |
| 1057 // number of bytes sent by the peer. | 1056 // number of bytes sent by the peer. |
| 1058 const QuicStreamOffset kByteOffset = 5678; | 1057 const QuicStreamOffset kByteOffset = 5678; |
| 1059 QuicRstStreamFrame rst_frame(stream->id(), QUIC_STREAM_CANCELLED, | 1058 QuicRstStreamFrame rst_frame(stream->id(), QUIC_STREAM_CANCELLED, |
| 1060 kByteOffset); | 1059 kByteOffset); |
| 1061 session_.OnRstStream(rst_frame); | 1060 session_.OnRstStream(rst_frame); |
| 1062 | 1061 |
| 1063 EXPECT_EQ(kInitialConnectionBytesConsumed + kByteOffset, | 1062 EXPECT_EQ(kInitialConnectionBytesConsumed + kByteOffset, |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1235 } | 1234 } |
| 1236 | 1235 |
| 1237 TEST_P(QuicSessionTestClient, RecordFinAfterReadSideClosed) { | 1236 TEST_P(QuicSessionTestClient, RecordFinAfterReadSideClosed) { |
| 1238 // Verify that an incoming FIN is recorded in a stream object even if the read | 1237 // Verify that an incoming FIN is recorded in a stream object even if the read |
| 1239 // side has been closed. This prevents an entry from being made in | 1238 // side has been closed. This prevents an entry from being made in |
| 1240 // locally_closed_streams_highest_offset_ (which will never be deleted). | 1239 // locally_closed_streams_highest_offset_ (which will never be deleted). |
| 1241 TestStream* stream = session_.CreateOutgoingDynamicStream(kDefaultPriority); | 1240 TestStream* stream = session_.CreateOutgoingDynamicStream(kDefaultPriority); |
| 1242 QuicStreamId stream_id = stream->id(); | 1241 QuicStreamId stream_id = stream->id(); |
| 1243 | 1242 |
| 1244 // Close the read side manually. | 1243 // Close the read side manually. |
| 1245 ReliableQuicStreamPeer::CloseReadSide(stream); | 1244 QuicStreamPeer::CloseReadSide(stream); |
| 1246 | 1245 |
| 1247 // Receive a stream data frame with FIN. | 1246 // Receive a stream data frame with FIN. |
| 1248 QuicStreamFrame frame(stream_id, true, 0, StringPiece()); | 1247 QuicStreamFrame frame(stream_id, true, 0, StringPiece()); |
| 1249 session_.OnStreamFrame(frame); | 1248 session_.OnStreamFrame(frame); |
| 1250 EXPECT_TRUE(stream->fin_received()); | 1249 EXPECT_TRUE(stream->fin_received()); |
| 1251 | 1250 |
| 1252 // Reset stream locally. | 1251 // Reset stream locally. |
| 1253 EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _)); | 1252 EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _)); |
| 1254 stream->Reset(QUIC_STREAM_CANCELLED); | 1253 stream->Reset(QUIC_STREAM_CANCELLED); |
| 1255 EXPECT_TRUE(ReliableQuicStreamPeer::read_side_closed(stream)); | 1254 EXPECT_TRUE(QuicStreamPeer::read_side_closed(stream)); |
| 1256 | 1255 |
| 1257 // Allow the session to delete the stream object. | 1256 // Allow the session to delete the stream object. |
| 1258 session_.PostProcessAfterData(); | 1257 session_.PostProcessAfterData(); |
| 1259 EXPECT_TRUE(connection_->connected()); | 1258 EXPECT_TRUE(connection_->connected()); |
| 1260 EXPECT_TRUE(QuicSessionPeer::IsStreamClosed(&session_, stream_id)); | 1259 EXPECT_TRUE(QuicSessionPeer::IsStreamClosed(&session_, stream_id)); |
| 1261 EXPECT_FALSE(QuicSessionPeer::IsStreamCreated(&session_, stream_id)); | 1260 EXPECT_FALSE(QuicSessionPeer::IsStreamCreated(&session_, stream_id)); |
| 1262 | 1261 |
| 1263 // The stream is not waiting for the arrival of the peer's final offset as it | 1262 // The stream is not waiting for the arrival of the peer's final offset as it |
| 1264 // was received with the FIN earlier. | 1263 // was received with the FIN earlier. |
| 1265 EXPECT_EQ( | 1264 EXPECT_EQ( |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1295 if (version() <= QUIC_VERSION_35) { | 1294 if (version() <= QUIC_VERSION_35) { |
| 1296 EXPECT_FALSE(session_.force_hol_blocking()); | 1295 EXPECT_FALSE(session_.force_hol_blocking()); |
| 1297 } else { | 1296 } else { |
| 1298 EXPECT_TRUE(session_.force_hol_blocking()); | 1297 EXPECT_TRUE(session_.force_hol_blocking()); |
| 1299 } | 1298 } |
| 1300 } | 1299 } |
| 1301 | 1300 |
| 1302 } // namespace | 1301 } // namespace |
| 1303 } // namespace test | 1302 } // namespace test |
| 1304 } // namespace net | 1303 } // namespace net |
| OLD | NEW |