| 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_connection.h" | 5 #include "net/quic/quic_connection.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <ostream> | 9 #include <ostream> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 // have the same value and then removes them. | 134 // have the same value and then removes them. |
| 135 class TaggingDecrypter : public QuicDecrypter { | 135 class TaggingDecrypter : public QuicDecrypter { |
| 136 public: | 136 public: |
| 137 ~TaggingDecrypter() override {} | 137 ~TaggingDecrypter() override {} |
| 138 | 138 |
| 139 // QuicDecrypter interface | 139 // QuicDecrypter interface |
| 140 bool SetKey(StringPiece key) override { return true; } | 140 bool SetKey(StringPiece key) override { return true; } |
| 141 | 141 |
| 142 bool SetNoncePrefix(StringPiece nonce_prefix) override { return true; } | 142 bool SetNoncePrefix(StringPiece nonce_prefix) override { return true; } |
| 143 | 143 |
| 144 bool SetPreliminaryKey(StringPiece key) override { |
| 145 QUIC_BUG << "should not be called"; |
| 146 return false; |
| 147 } |
| 148 |
| 149 bool SetDiversificationNonce(DiversificationNonce key) override { |
| 150 return true; |
| 151 } |
| 152 |
| 144 bool DecryptPacket(QuicPathId path_id, | 153 bool DecryptPacket(QuicPathId path_id, |
| 145 QuicPacketNumber packet_number, | 154 QuicPacketNumber packet_number, |
| 146 StringPiece associated_data, | 155 StringPiece associated_data, |
| 147 StringPiece ciphertext, | 156 StringPiece ciphertext, |
| 148 char* output, | 157 char* output, |
| 149 size_t* output_length, | 158 size_t* output_length, |
| 150 size_t max_output_length) override { | 159 size_t max_output_length) override { |
| 151 if (ciphertext.size() < kTagSize) { | 160 if (ciphertext.size() < kTagSize) { |
| 152 return false; | 161 return false; |
| 153 } | 162 } |
| (...skipping 3269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3423 kTestEntropyHash, HAS_RETRANSMITTABLE_DATA, false, | 3432 kTestEntropyHash, HAS_RETRANSMITTABLE_DATA, false, |
| 3424 false); | 3433 false); |
| 3425 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 3434 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 3426 } | 3435 } |
| 3427 | 3436 |
| 3428 TEST_P(QuicConnectionTest, TestQueueLimitsOnSendStreamData) { | 3437 TEST_P(QuicConnectionTest, TestQueueLimitsOnSendStreamData) { |
| 3429 // All packets carry version info till version is negotiated. | 3438 // All packets carry version info till version is negotiated. |
| 3430 size_t payload_length; | 3439 size_t payload_length; |
| 3431 size_t length = GetPacketLengthForOneStream( | 3440 size_t length = GetPacketLengthForOneStream( |
| 3432 connection_.version(), kIncludeVersion, !kIncludePathId, | 3441 connection_.version(), kIncludeVersion, !kIncludePathId, |
| 3433 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_PACKET_NUMBER, &payload_length); | 3442 !kIncludeDiversificationNonce, PACKET_8BYTE_CONNECTION_ID, |
| 3443 PACKET_1BYTE_PACKET_NUMBER, &payload_length); |
| 3434 connection_.SetMaxPacketLength(length); | 3444 connection_.SetMaxPacketLength(length); |
| 3435 | 3445 |
| 3436 // Queue the first packet. | 3446 // Queue the first packet. |
| 3437 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _)) | 3447 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _)) |
| 3438 .WillOnce(testing::Return(QuicTime::Delta::FromMicroseconds(10))); | 3448 .WillOnce(testing::Return(QuicTime::Delta::FromMicroseconds(10))); |
| 3439 const string payload(payload_length, 'a'); | 3449 const string payload(payload_length, 'a'); |
| 3440 EXPECT_EQ(0u, | 3450 EXPECT_EQ(0u, |
| 3441 connection_.SendStreamDataWithString(3, payload, 0, !kFin, nullptr) | 3451 connection_.SendStreamDataWithString(3, payload, 0, !kFin, nullptr) |
| 3442 .bytes_consumed); | 3452 .bytes_consumed); |
| 3443 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 3453 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 3444 } | 3454 } |
| 3445 | 3455 |
| 3446 TEST_P(QuicConnectionTest, LoopThroughSendingPackets) { | 3456 TEST_P(QuicConnectionTest, LoopThroughSendingPackets) { |
| 3447 // All packets carry version info till version is negotiated. | 3457 // All packets carry version info till version is negotiated. |
| 3448 size_t payload_length; | 3458 size_t payload_length; |
| 3449 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining | 3459 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining |
| 3450 // packet length. The size of the offset field in a stream frame is 0 for | 3460 // packet length. The size of the offset field in a stream frame is 0 for |
| 3451 // offset 0, and 2 for non-zero offsets up through 16K. Increase | 3461 // offset 0, and 2 for non-zero offsets up through 16K. Increase |
| 3452 // max_packet_length by 2 so that subsequent packets containing subsequent | 3462 // max_packet_length by 2 so that subsequent packets containing subsequent |
| 3453 // stream frames with non-zero offets will fit within the packet length. | 3463 // stream frames with non-zero offets will fit within the packet length. |
| 3454 size_t length = 2 + GetPacketLengthForOneStream( | 3464 size_t length = |
| 3455 connection_.version(), kIncludeVersion, | 3465 2 + GetPacketLengthForOneStream( |
| 3456 !kIncludePathId, PACKET_8BYTE_CONNECTION_ID, | 3466 connection_.version(), kIncludeVersion, !kIncludePathId, |
| 3457 PACKET_1BYTE_PACKET_NUMBER, &payload_length); | 3467 !kIncludeDiversificationNonce, PACKET_8BYTE_CONNECTION_ID, |
| 3468 PACKET_1BYTE_PACKET_NUMBER, &payload_length); |
| 3458 connection_.SetMaxPacketLength(length); | 3469 connection_.SetMaxPacketLength(length); |
| 3459 | 3470 |
| 3460 // Queue the first packet. | 3471 // Queue the first packet. |
| 3461 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(7); | 3472 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(7); |
| 3462 // The first stream frame will have 2 fewer overhead bytes than the other six. | 3473 // The first stream frame will have 2 fewer overhead bytes than the other six. |
| 3463 const string payload(payload_length * 7 + 2, 'a'); | 3474 const string payload(payload_length * 7 + 2, 'a'); |
| 3464 EXPECT_EQ(payload.size(), | 3475 EXPECT_EQ(payload.size(), |
| 3465 connection_.SendStreamDataWithString(1, payload, 0, !kFin, nullptr) | 3476 connection_.SendStreamDataWithString(1, payload, 0, !kFin, nullptr) |
| 3466 .bytes_consumed); | 3477 .bytes_consumed); |
| 3467 } | 3478 } |
| 3468 | 3479 |
| 3469 TEST_P(QuicConnectionTest, LoopThroughSendingPacketsWithTruncation) { | 3480 TEST_P(QuicConnectionTest, LoopThroughSendingPacketsWithTruncation) { |
| 3470 // Set up a larger payload than will fit in one packet. | 3481 // Set up a larger payload than will fit in one packet. |
| 3471 const string payload(connection_.max_packet_length(), 'a'); | 3482 const string payload(connection_.max_packet_length(), 'a'); |
| 3472 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)).Times(AnyNumber()); | 3483 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)).Times(AnyNumber()); |
| 3473 | 3484 |
| 3474 // Now send some packets with no truncation. | 3485 // Now send some packets with no truncation. |
| 3475 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); | 3486 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); |
| 3476 EXPECT_EQ(payload.size(), | 3487 EXPECT_EQ(payload.size(), |
| 3477 connection_.SendStreamDataWithString(3, payload, 0, !kFin, nullptr) | 3488 connection_.SendStreamDataWithString(3, payload, 0, !kFin, nullptr) |
| 3478 .bytes_consumed); | 3489 .bytes_consumed); |
| 3479 // Track the size of the second packet here. The overhead will be the largest | 3490 // Track the size of the second packet here. The overhead will be the largest |
| 3480 // we see in this test, due to the non-truncated connection id. | 3491 // we see in this test, due to the non-truncated connection id. |
| 3481 size_t non_truncated_packet_size = writer_->last_packet_size(); | 3492 size_t non_truncated_packet_size = writer_->last_packet_size(); |
| 3482 | 3493 |
| 3483 // Change to a 4 byte connection id. | 3494 // Change to a 0 byte connection id. |
| 3484 QuicConfig config; | 3495 QuicConfig config; |
| 3485 QuicConfigPeer::SetReceivedBytesForConnectionId(&config, 4); | |
| 3486 connection_.SetFromConfig(config); | |
| 3487 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); | |
| 3488 EXPECT_EQ(payload.size(), | |
| 3489 connection_.SendStreamDataWithString(3, payload, 0, !kFin, nullptr) | |
| 3490 .bytes_consumed); | |
| 3491 // Verify that we have 8 fewer bytes than in the non-truncated case. The | |
| 3492 // first packet got 4 bytes of extra payload due to the truncation, and the | |
| 3493 // headers here are also 4 byte smaller. | |
| 3494 EXPECT_EQ(non_truncated_packet_size, writer_->last_packet_size() + 8); | |
| 3495 | |
| 3496 // Change to a 1 byte connection id. | |
| 3497 QuicConfigPeer::SetReceivedBytesForConnectionId(&config, 1); | |
| 3498 connection_.SetFromConfig(config); | |
| 3499 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); | |
| 3500 EXPECT_EQ(payload.size(), | |
| 3501 connection_.SendStreamDataWithString(3, payload, 0, !kFin, nullptr) | |
| 3502 .bytes_consumed); | |
| 3503 // Just like above, we save 7 bytes on payload, and 7 on truncation. | |
| 3504 EXPECT_EQ(non_truncated_packet_size, writer_->last_packet_size() + 7 * 2); | |
| 3505 | |
| 3506 // Change to a 0 byte connection id. | |
| 3507 QuicConfigPeer::SetReceivedBytesForConnectionId(&config, 0); | 3496 QuicConfigPeer::SetReceivedBytesForConnectionId(&config, 0); |
| 3508 connection_.SetFromConfig(config); | 3497 connection_.SetFromConfig(config); |
| 3509 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); | 3498 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); |
| 3510 EXPECT_EQ(payload.size(), | 3499 EXPECT_EQ(payload.size(), |
| 3511 connection_.SendStreamDataWithString(3, payload, 0, !kFin, nullptr) | 3500 connection_.SendStreamDataWithString(3, payload, 0, !kFin, nullptr) |
| 3512 .bytes_consumed); | 3501 .bytes_consumed); |
| 3513 // Just like above, we save 8 bytes on payload, and 8 on truncation. | 3502 // Just like above, we save 8 bytes on payload, and 8 on truncation. |
| 3514 EXPECT_EQ(non_truncated_packet_size, writer_->last_packet_size() + 8 * 2); | 3503 EXPECT_EQ(non_truncated_packet_size, writer_->last_packet_size() + 8 * 2); |
| 3515 } | 3504 } |
| 3516 | 3505 |
| (...skipping 1199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4716 EXPECT_CALL(visitor_, OnConnectionClosed(_, _, _)).Times(1); | 4705 EXPECT_CALL(visitor_, OnConnectionClosed(_, _, _)).Times(1); |
| 4717 connection_.CloseConnection(QUIC_NO_ERROR, "no reason", | 4706 connection_.CloseConnection(QUIC_NO_ERROR, "no reason", |
| 4718 ConnectionCloseBehavior::SILENT_CLOSE); | 4707 ConnectionCloseBehavior::SILENT_CLOSE); |
| 4719 connection_.CloseConnection(QUIC_NO_ERROR, "no reason", | 4708 connection_.CloseConnection(QUIC_NO_ERROR, "no reason", |
| 4720 ConnectionCloseBehavior::SILENT_CLOSE); | 4709 ConnectionCloseBehavior::SILENT_CLOSE); |
| 4721 } | 4710 } |
| 4722 | 4711 |
| 4723 } // namespace | 4712 } // namespace |
| 4724 } // namespace test | 4713 } // namespace test |
| 4725 } // namespace net | 4714 } // namespace net |
| OLD | NEW |