| 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/quic_session.h" | 5 #include "net/quic/quic_session.h" | 
| 6 | 6 | 
| 7 #include <set> | 7 #include <set> | 
| 8 | 8 | 
| 9 #include "base/basictypes.h" |  | 
| 10 #include "base/containers/hash_tables.h" | 9 #include "base/containers/hash_tables.h" | 
| 11 #include "base/rand_util.h" | 10 #include "base/rand_util.h" | 
| 12 #include "base/stl_util.h" | 11 #include "base/stl_util.h" | 
| 13 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" | 
| 14 #include "build/build_config.h" | 13 #include "build/build_config.h" | 
| 15 #include "net/quic/crypto/crypto_protocol.h" | 14 #include "net/quic/crypto/crypto_protocol.h" | 
| 16 #include "net/quic/quic_crypto_stream.h" | 15 #include "net/quic/quic_crypto_stream.h" | 
| 17 #include "net/quic/quic_flags.h" | 16 #include "net/quic/quic_flags.h" | 
| 18 #include "net/quic/quic_protocol.h" | 17 #include "net/quic/quic_protocol.h" | 
| 19 #include "net/quic/quic_utils.h" | 18 #include "net/quic/quic_utils.h" | 
| (...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 933   EXPECT_EQ(kByteOffset, session_.flow_controller()->bytes_consumed()); | 932   EXPECT_EQ(kByteOffset, session_.flow_controller()->bytes_consumed()); | 
| 934 } | 933 } | 
| 935 | 934 | 
| 936 TEST_P(QuicSessionTestServer, ConnectionFlowControlAccountingFinAfterRst) { | 935 TEST_P(QuicSessionTestServer, ConnectionFlowControlAccountingFinAfterRst) { | 
| 937   // Test that when we RST the stream (and tear down stream state), and then | 936   // Test that when we RST the stream (and tear down stream state), and then | 
| 938   // receive a FIN from the peer, we correctly adjust our connection level flow | 937   // receive a FIN from the peer, we correctly adjust our connection level flow | 
| 939   // control receive window. | 938   // control receive window. | 
| 940 | 939 | 
| 941   // Connection starts with some non-zero highest received byte offset, | 940   // Connection starts with some non-zero highest received byte offset, | 
| 942   // due to other active streams. | 941   // due to other active streams. | 
| 943   const uint64 kInitialConnectionBytesConsumed = 567; | 942   const uint64_t kInitialConnectionBytesConsumed = 567; | 
| 944   const uint64 kInitialConnectionHighestReceivedOffset = 1234; | 943   const uint64_t kInitialConnectionHighestReceivedOffset = 1234; | 
| 945   EXPECT_LT(kInitialConnectionBytesConsumed, | 944   EXPECT_LT(kInitialConnectionBytesConsumed, | 
| 946             kInitialConnectionHighestReceivedOffset); | 945             kInitialConnectionHighestReceivedOffset); | 
| 947   session_.flow_controller()->UpdateHighestReceivedOffset( | 946   session_.flow_controller()->UpdateHighestReceivedOffset( | 
| 948       kInitialConnectionHighestReceivedOffset); | 947       kInitialConnectionHighestReceivedOffset); | 
| 949   session_.flow_controller()->AddBytesConsumed(kInitialConnectionBytesConsumed); | 948   session_.flow_controller()->AddBytesConsumed(kInitialConnectionBytesConsumed); | 
| 950 | 949 | 
| 951   // Reset our stream: this results in the stream being closed locally. | 950   // Reset our stream: this results in the stream being closed locally. | 
| 952   TestStream* stream = session_.CreateOutgoingDynamicStream(kDefaultPriority); | 951   TestStream* stream = session_.CreateOutgoingDynamicStream(kDefaultPriority); | 
| 953   EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _)); | 952   EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _)); | 
| 954   stream->Reset(QUIC_STREAM_CANCELLED); | 953   stream->Reset(QUIC_STREAM_CANCELLED); | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
| 970       session_.flow_controller()->highest_received_byte_offset()); | 969       session_.flow_controller()->highest_received_byte_offset()); | 
| 971 } | 970 } | 
| 972 | 971 | 
| 973 TEST_P(QuicSessionTestServer, ConnectionFlowControlAccountingRstAfterRst) { | 972 TEST_P(QuicSessionTestServer, ConnectionFlowControlAccountingRstAfterRst) { | 
| 974   // Test that when we RST the stream (and tear down stream state), and then | 973   // Test that when we RST the stream (and tear down stream state), and then | 
| 975   // receive a RST from the peer, we correctly adjust our connection level flow | 974   // receive a RST from the peer, we correctly adjust our connection level flow | 
| 976   // control receive window. | 975   // control receive window. | 
| 977 | 976 | 
| 978   // Connection starts with some non-zero highest received byte offset, | 977   // Connection starts with some non-zero highest received byte offset, | 
| 979   // due to other active streams. | 978   // due to other active streams. | 
| 980   const uint64 kInitialConnectionBytesConsumed = 567; | 979   const uint64_t kInitialConnectionBytesConsumed = 567; | 
| 981   const uint64 kInitialConnectionHighestReceivedOffset = 1234; | 980   const uint64_t kInitialConnectionHighestReceivedOffset = 1234; | 
| 982   EXPECT_LT(kInitialConnectionBytesConsumed, | 981   EXPECT_LT(kInitialConnectionBytesConsumed, | 
| 983             kInitialConnectionHighestReceivedOffset); | 982             kInitialConnectionHighestReceivedOffset); | 
| 984   session_.flow_controller()->UpdateHighestReceivedOffset( | 983   session_.flow_controller()->UpdateHighestReceivedOffset( | 
| 985       kInitialConnectionHighestReceivedOffset); | 984       kInitialConnectionHighestReceivedOffset); | 
| 986   session_.flow_controller()->AddBytesConsumed(kInitialConnectionBytesConsumed); | 985   session_.flow_controller()->AddBytesConsumed(kInitialConnectionBytesConsumed); | 
| 987 | 986 | 
| 988   // Reset our stream: this results in the stream being closed locally. | 987   // Reset our stream: this results in the stream being closed locally. | 
| 989   TestStream* stream = session_.CreateOutgoingDynamicStream(kDefaultPriority); | 988   TestStream* stream = session_.CreateOutgoingDynamicStream(kDefaultPriority); | 
| 990   EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _)); | 989   EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _)); | 
| 991   stream->Reset(QUIC_STREAM_CANCELLED); | 990   stream->Reset(QUIC_STREAM_CANCELLED); | 
| 992   EXPECT_TRUE(ReliableQuicStreamPeer::read_side_closed(stream)); | 991   EXPECT_TRUE(ReliableQuicStreamPeer::read_side_closed(stream)); | 
| 993 | 992 | 
| 994   // Now receive a RST from the peer. We should handle this by adjusting the | 993   // Now receive a RST from the peer. We should handle this by adjusting the | 
| 995   // connection level flow control receive window to take into account the total | 994   // connection level flow control receive window to take into account the total | 
| 996   // number of bytes sent by the peer. | 995   // number of bytes sent by the peer. | 
| 997   const QuicStreamOffset kByteOffset = 5678; | 996   const QuicStreamOffset kByteOffset = 5678; | 
| 998   QuicRstStreamFrame rst_frame(stream->id(), QUIC_STREAM_CANCELLED, | 997   QuicRstStreamFrame rst_frame(stream->id(), QUIC_STREAM_CANCELLED, | 
| 999                                kByteOffset); | 998                                kByteOffset); | 
| 1000   session_.OnRstStream(rst_frame); | 999   session_.OnRstStream(rst_frame); | 
| 1001 | 1000 | 
| 1002   EXPECT_EQ(kInitialConnectionBytesConsumed + kByteOffset, | 1001   EXPECT_EQ(kInitialConnectionBytesConsumed + kByteOffset, | 
| 1003             session_.flow_controller()->bytes_consumed()); | 1002             session_.flow_controller()->bytes_consumed()); | 
| 1004   EXPECT_EQ(kInitialConnectionHighestReceivedOffset + kByteOffset, | 1003   EXPECT_EQ(kInitialConnectionHighestReceivedOffset + kByteOffset, | 
| 1005             session_.flow_controller()->highest_received_byte_offset()); | 1004             session_.flow_controller()->highest_received_byte_offset()); | 
| 1006 } | 1005 } | 
| 1007 | 1006 | 
| 1008 TEST_P(QuicSessionTestServer, InvalidStreamFlowControlWindowInHandshake) { | 1007 TEST_P(QuicSessionTestServer, InvalidStreamFlowControlWindowInHandshake) { | 
| 1009   // Test that receipt of an invalid (< default) stream flow control window from | 1008   // Test that receipt of an invalid (< default) stream flow control window from | 
| 1010   // the peer results in the connection being torn down. | 1009   // the peer results in the connection being torn down. | 
| 1011   const uint32 kInvalidWindow = kMinimumFlowControlSendWindow - 1; | 1010   const uint32_t kInvalidWindow = kMinimumFlowControlSendWindow - 1; | 
| 1012   QuicConfigPeer::SetReceivedInitialStreamFlowControlWindow(session_.config(), | 1011   QuicConfigPeer::SetReceivedInitialStreamFlowControlWindow(session_.config(), | 
| 1013                                                             kInvalidWindow); | 1012                                                             kInvalidWindow); | 
| 1014 | 1013 | 
| 1015   EXPECT_CALL(*connection_, | 1014   EXPECT_CALL(*connection_, | 
| 1016               SendConnectionClose(QUIC_FLOW_CONTROL_INVALID_WINDOW)); | 1015               SendConnectionClose(QUIC_FLOW_CONTROL_INVALID_WINDOW)); | 
| 1017   session_.OnConfigNegotiated(); | 1016   session_.OnConfigNegotiated(); | 
| 1018 } | 1017 } | 
| 1019 | 1018 | 
| 1020 TEST_P(QuicSessionTestServer, InvalidSessionFlowControlWindowInHandshake) { | 1019 TEST_P(QuicSessionTestServer, InvalidSessionFlowControlWindowInHandshake) { | 
| 1021   // Test that receipt of an invalid (< default) session flow control window | 1020   // Test that receipt of an invalid (< default) session flow control window | 
| 1022   // from the peer results in the connection being torn down. | 1021   // from the peer results in the connection being torn down. | 
| 1023   const uint32 kInvalidWindow = kMinimumFlowControlSendWindow - 1; | 1022   const uint32_t kInvalidWindow = kMinimumFlowControlSendWindow - 1; | 
| 1024   QuicConfigPeer::SetReceivedInitialSessionFlowControlWindow(session_.config(), | 1023   QuicConfigPeer::SetReceivedInitialSessionFlowControlWindow(session_.config(), | 
| 1025                                                              kInvalidWindow); | 1024                                                              kInvalidWindow); | 
| 1026 | 1025 | 
| 1027   EXPECT_CALL(*connection_, | 1026   EXPECT_CALL(*connection_, | 
| 1028               SendConnectionClose(QUIC_FLOW_CONTROL_INVALID_WINDOW)); | 1027               SendConnectionClose(QUIC_FLOW_CONTROL_INVALID_WINDOW)); | 
| 1029   session_.OnConfigNegotiated(); | 1028   session_.OnConfigNegotiated(); | 
| 1030 } | 1029 } | 
| 1031 | 1030 | 
| 1032 TEST_P(QuicSessionTestServer, FlowControlWithInvalidFinalOffset) { | 1031 TEST_P(QuicSessionTestServer, FlowControlWithInvalidFinalOffset) { | 
| 1033   // Test that if we receive a stream RST with a highest byte offset that | 1032   // Test that if we receive a stream RST with a highest byte offset that | 
| 1034   // violates flow control, that we close the connection. | 1033   // violates flow control, that we close the connection. | 
| 1035   const uint64 kLargeOffset = kInitialSessionFlowControlWindowForTest + 1; | 1034   const uint64_t kLargeOffset = kInitialSessionFlowControlWindowForTest + 1; | 
| 1036   EXPECT_CALL(*connection_, | 1035   EXPECT_CALL(*connection_, | 
| 1037               SendConnectionClose(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA)) | 1036               SendConnectionClose(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA)) | 
| 1038       .Times(2); | 1037       .Times(2); | 
| 1039 | 1038 | 
| 1040   // Check that stream frame + FIN results in connection close. | 1039   // Check that stream frame + FIN results in connection close. | 
| 1041   TestStream* stream = session_.CreateOutgoingDynamicStream(kDefaultPriority); | 1040   TestStream* stream = session_.CreateOutgoingDynamicStream(kDefaultPriority); | 
| 1042   EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _)); | 1041   EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _)); | 
| 1043   stream->Reset(QUIC_STREAM_CANCELLED); | 1042   stream->Reset(QUIC_STREAM_CANCELLED); | 
| 1044   QuicStreamFrame frame(stream->id(), true, kLargeOffset, StringPiece()); | 1043   QuicStreamFrame frame(stream->id(), true, kLargeOffset, StringPiece()); | 
| 1045   session_.OnStreamFrame(frame); | 1044   session_.OnStreamFrame(frame); | 
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1187 | 1186 | 
| 1188   // The stream is not waiting for the arrival of the peer's final offset as it | 1187   // The stream is not waiting for the arrival of the peer's final offset as it | 
| 1189   // was received with the FIN earlier. | 1188   // was received with the FIN earlier. | 
| 1190   EXPECT_EQ(0u, QuicSessionPeer::GetLocallyClosedStreamsHighestOffset(&session_) | 1189   EXPECT_EQ(0u, QuicSessionPeer::GetLocallyClosedStreamsHighestOffset(&session_) | 
| 1191                     .size()); | 1190                     .size()); | 
| 1192 } | 1191 } | 
| 1193 | 1192 | 
| 1194 }  // namespace | 1193 }  // namespace | 
| 1195 }  // namespace test | 1194 }  // namespace test | 
| 1196 }  // namespace net | 1195 }  // namespace net | 
| OLD | NEW | 
|---|