| 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_connection.h" | 5 #include "net/quic/core/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 20 matching lines...) Expand all Loading... |
| 31 #include "net/quic/test_tools/quic_framer_peer.h" | 31 #include "net/quic/test_tools/quic_framer_peer.h" |
| 32 #include "net/quic/test_tools/quic_packet_creator_peer.h" | 32 #include "net/quic/test_tools/quic_packet_creator_peer.h" |
| 33 #include "net/quic/test_tools/quic_packet_generator_peer.h" | 33 #include "net/quic/test_tools/quic_packet_generator_peer.h" |
| 34 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" | 34 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" |
| 35 #include "net/quic/test_tools/quic_test_utils.h" | 35 #include "net/quic/test_tools/quic_test_utils.h" |
| 36 #include "net/quic/test_tools/simple_quic_framer.h" | 36 #include "net/quic/test_tools/simple_quic_framer.h" |
| 37 #include "net/test/gtest_util.h" | 37 #include "net/test/gtest_util.h" |
| 38 #include "testing/gmock/include/gmock/gmock.h" | 38 #include "testing/gmock/include/gmock/gmock.h" |
| 39 #include "testing/gtest/include/gtest/gtest.h" | 39 #include "testing/gtest/include/gtest/gtest.h" |
| 40 | 40 |
| 41 using base::StringPiece; | |
| 42 using std::string; | 41 using std::string; |
| 43 using testing::AnyNumber; | 42 using testing::AnyNumber; |
| 44 using testing::AtLeast; | 43 using testing::AtLeast; |
| 45 using testing::DoAll; | 44 using testing::DoAll; |
| 46 using testing::InSequence; | 45 using testing::InSequence; |
| 47 using testing::InvokeWithoutArgs; | 46 using testing::InvokeWithoutArgs; |
| 48 using testing::NiceMock; | 47 using testing::NiceMock; |
| 49 using testing::Ref; | 48 using testing::Ref; |
| 50 using testing::Return; | 49 using testing::Return; |
| 51 using testing::SaveArg; | 50 using testing::SaveArg; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 78 } | 77 } |
| 79 | 78 |
| 80 // TaggingEncrypter appends kTagSize bytes of |tag| to the end of each message. | 79 // TaggingEncrypter appends kTagSize bytes of |tag| to the end of each message. |
| 81 class TaggingEncrypter : public QuicEncrypter { | 80 class TaggingEncrypter : public QuicEncrypter { |
| 82 public: | 81 public: |
| 83 explicit TaggingEncrypter(uint8_t tag) : tag_(tag) {} | 82 explicit TaggingEncrypter(uint8_t tag) : tag_(tag) {} |
| 84 | 83 |
| 85 ~TaggingEncrypter() override {} | 84 ~TaggingEncrypter() override {} |
| 86 | 85 |
| 87 // QuicEncrypter interface. | 86 // QuicEncrypter interface. |
| 88 bool SetKey(StringPiece key) override { return true; } | 87 bool SetKey(QuicStringPiece key) override { return true; } |
| 89 | 88 |
| 90 bool SetNoncePrefix(StringPiece nonce_prefix) override { return true; } | 89 bool SetNoncePrefix(QuicStringPiece nonce_prefix) override { return true; } |
| 91 | 90 |
| 92 bool EncryptPacket(QuicVersion /*version*/, | 91 bool EncryptPacket(QuicVersion /*version*/, |
| 93 QuicPacketNumber packet_number, | 92 QuicPacketNumber packet_number, |
| 94 StringPiece associated_data, | 93 QuicStringPiece associated_data, |
| 95 StringPiece plaintext, | 94 QuicStringPiece plaintext, |
| 96 char* output, | 95 char* output, |
| 97 size_t* output_length, | 96 size_t* output_length, |
| 98 size_t max_output_length) override { | 97 size_t max_output_length) override { |
| 99 const size_t len = plaintext.size() + kTagSize; | 98 const size_t len = plaintext.size() + kTagSize; |
| 100 if (max_output_length < len) { | 99 if (max_output_length < len) { |
| 101 return false; | 100 return false; |
| 102 } | 101 } |
| 103 // Memmove is safe for inplace encryption. | 102 // Memmove is safe for inplace encryption. |
| 104 memmove(output, plaintext.data(), plaintext.size()); | 103 memmove(output, plaintext.data(), plaintext.size()); |
| 105 output += plaintext.size(); | 104 output += plaintext.size(); |
| 106 memset(output, tag_, kTagSize); | 105 memset(output, tag_, kTagSize); |
| 107 *output_length = len; | 106 *output_length = len; |
| 108 return true; | 107 return true; |
| 109 } | 108 } |
| 110 | 109 |
| 111 size_t GetKeySize() const override { return 0; } | 110 size_t GetKeySize() const override { return 0; } |
| 112 size_t GetNoncePrefixSize() const override { return 0; } | 111 size_t GetNoncePrefixSize() const override { return 0; } |
| 113 | 112 |
| 114 size_t GetMaxPlaintextSize(size_t ciphertext_size) const override { | 113 size_t GetMaxPlaintextSize(size_t ciphertext_size) const override { |
| 115 return ciphertext_size - kTagSize; | 114 return ciphertext_size - kTagSize; |
| 116 } | 115 } |
| 117 | 116 |
| 118 size_t GetCiphertextSize(size_t plaintext_size) const override { | 117 size_t GetCiphertextSize(size_t plaintext_size) const override { |
| 119 return plaintext_size + kTagSize; | 118 return plaintext_size + kTagSize; |
| 120 } | 119 } |
| 121 | 120 |
| 122 StringPiece GetKey() const override { return StringPiece(); } | 121 QuicStringPiece GetKey() const override { return QuicStringPiece(); } |
| 123 | 122 |
| 124 StringPiece GetNoncePrefix() const override { return StringPiece(); } | 123 QuicStringPiece GetNoncePrefix() const override { return QuicStringPiece(); } |
| 125 | 124 |
| 126 private: | 125 private: |
| 127 enum { | 126 enum { |
| 128 kTagSize = 12, | 127 kTagSize = 12, |
| 129 }; | 128 }; |
| 130 | 129 |
| 131 const uint8_t tag_; | 130 const uint8_t tag_; |
| 132 | 131 |
| 133 DISALLOW_COPY_AND_ASSIGN(TaggingEncrypter); | 132 DISALLOW_COPY_AND_ASSIGN(TaggingEncrypter); |
| 134 }; | 133 }; |
| 135 | 134 |
| 136 // TaggingDecrypter ensures that the final kTagSize bytes of the message all | 135 // TaggingDecrypter ensures that the final kTagSize bytes of the message all |
| 137 // have the same value and then removes them. | 136 // have the same value and then removes them. |
| 138 class TaggingDecrypter : public QuicDecrypter { | 137 class TaggingDecrypter : public QuicDecrypter { |
| 139 public: | 138 public: |
| 140 ~TaggingDecrypter() override {} | 139 ~TaggingDecrypter() override {} |
| 141 | 140 |
| 142 // QuicDecrypter interface | 141 // QuicDecrypter interface |
| 143 bool SetKey(StringPiece key) override { return true; } | 142 bool SetKey(QuicStringPiece key) override { return true; } |
| 144 | 143 |
| 145 bool SetNoncePrefix(StringPiece nonce_prefix) override { return true; } | 144 bool SetNoncePrefix(QuicStringPiece nonce_prefix) override { return true; } |
| 146 | 145 |
| 147 bool SetPreliminaryKey(StringPiece key) override { | 146 bool SetPreliminaryKey(QuicStringPiece key) override { |
| 148 QUIC_BUG << "should not be called"; | 147 QUIC_BUG << "should not be called"; |
| 149 return false; | 148 return false; |
| 150 } | 149 } |
| 151 | 150 |
| 152 bool SetDiversificationNonce(const DiversificationNonce& key) override { | 151 bool SetDiversificationNonce(const DiversificationNonce& key) override { |
| 153 return true; | 152 return true; |
| 154 } | 153 } |
| 155 | 154 |
| 156 bool DecryptPacket(QuicVersion /*version*/, | 155 bool DecryptPacket(QuicVersion /*version*/, |
| 157 QuicPacketNumber packet_number, | 156 QuicPacketNumber packet_number, |
| 158 StringPiece associated_data, | 157 QuicStringPiece associated_data, |
| 159 StringPiece ciphertext, | 158 QuicStringPiece ciphertext, |
| 160 char* output, | 159 char* output, |
| 161 size_t* output_length, | 160 size_t* output_length, |
| 162 size_t max_output_length) override { | 161 size_t max_output_length) override { |
| 163 if (ciphertext.size() < kTagSize) { | 162 if (ciphertext.size() < kTagSize) { |
| 164 return false; | 163 return false; |
| 165 } | 164 } |
| 166 if (!CheckTag(ciphertext, GetTag(ciphertext))) { | 165 if (!CheckTag(ciphertext, GetTag(ciphertext))) { |
| 167 return false; | 166 return false; |
| 168 } | 167 } |
| 169 *output_length = ciphertext.size() - kTagSize; | 168 *output_length = ciphertext.size() - kTagSize; |
| 170 memcpy(output, ciphertext.data(), *output_length); | 169 memcpy(output, ciphertext.data(), *output_length); |
| 171 return true; | 170 return true; |
| 172 } | 171 } |
| 173 | 172 |
| 174 StringPiece GetKey() const override { return StringPiece(); } | 173 QuicStringPiece GetKey() const override { return QuicStringPiece(); } |
| 175 StringPiece GetNoncePrefix() const override { return StringPiece(); } | 174 QuicStringPiece GetNoncePrefix() const override { return QuicStringPiece(); } |
| 176 const char* cipher_name() const override { return "Tagging"; } | 175 const char* cipher_name() const override { return "Tagging"; } |
| 177 // Use a distinct value starting with 0xFFFFFF, which is never used by TLS. | 176 // Use a distinct value starting with 0xFFFFFF, which is never used by TLS. |
| 178 uint32_t cipher_id() const override { return 0xFFFFFFF0; } | 177 uint32_t cipher_id() const override { return 0xFFFFFFF0; } |
| 179 | 178 |
| 180 protected: | 179 protected: |
| 181 virtual uint8_t GetTag(StringPiece ciphertext) { | 180 virtual uint8_t GetTag(QuicStringPiece ciphertext) { |
| 182 return ciphertext.data()[ciphertext.size() - 1]; | 181 return ciphertext.data()[ciphertext.size() - 1]; |
| 183 } | 182 } |
| 184 | 183 |
| 185 private: | 184 private: |
| 186 enum { | 185 enum { |
| 187 kTagSize = 12, | 186 kTagSize = 12, |
| 188 }; | 187 }; |
| 189 | 188 |
| 190 bool CheckTag(StringPiece ciphertext, uint8_t tag) { | 189 bool CheckTag(QuicStringPiece ciphertext, uint8_t tag) { |
| 191 for (size_t i = ciphertext.size() - kTagSize; i < ciphertext.size(); i++) { | 190 for (size_t i = ciphertext.size() - kTagSize; i < ciphertext.size(); i++) { |
| 192 if (ciphertext.data()[i] != tag) { | 191 if (ciphertext.data()[i] != tag) { |
| 193 return false; | 192 return false; |
| 194 } | 193 } |
| 195 } | 194 } |
| 196 | 195 |
| 197 return true; | 196 return true; |
| 198 } | 197 } |
| 199 }; | 198 }; |
| 200 | 199 |
| 201 // StringTaggingDecrypter ensures that the final kTagSize bytes of the message | 200 // StringTaggingDecrypter ensures that the final kTagSize bytes of the message |
| 202 // match the expected value. | 201 // match the expected value. |
| 203 class StrictTaggingDecrypter : public TaggingDecrypter { | 202 class StrictTaggingDecrypter : public TaggingDecrypter { |
| 204 public: | 203 public: |
| 205 explicit StrictTaggingDecrypter(uint8_t tag) : tag_(tag) {} | 204 explicit StrictTaggingDecrypter(uint8_t tag) : tag_(tag) {} |
| 206 ~StrictTaggingDecrypter() override {} | 205 ~StrictTaggingDecrypter() override {} |
| 207 | 206 |
| 208 // TaggingQuicDecrypter | 207 // TaggingQuicDecrypter |
| 209 uint8_t GetTag(StringPiece ciphertext) override { return tag_; } | 208 uint8_t GetTag(QuicStringPiece ciphertext) override { return tag_; } |
| 210 | 209 |
| 211 const char* cipher_name() const override { return "StrictTagging"; } | 210 const char* cipher_name() const override { return "StrictTagging"; } |
| 212 // Use a distinct value starting with 0xFFFFFF, which is never used by TLS. | 211 // Use a distinct value starting with 0xFFFFFF, which is never used by TLS. |
| 213 uint32_t cipher_id() const override { return 0xFFFFFFF1; } | 212 uint32_t cipher_id() const override { return 0xFFFFFFF1; } |
| 214 | 213 |
| 215 private: | 214 private: |
| 216 const uint8_t tag_; | 215 const uint8_t tag_; |
| 217 }; | 216 }; |
| 218 | 217 |
| 219 class TestConnectionHelper : public QuicConnectionHelperInterface { | 218 class TestConnectionHelper : public QuicConnectionHelperInterface { |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 has_ack, has_pending_frames); | 502 has_ack, has_pending_frames); |
| 504 if (retransmittable == HAS_RETRANSMITTABLE_DATA) { | 503 if (retransmittable == HAS_RETRANSMITTABLE_DATA) { |
| 505 serialized_packet.retransmittable_frames.push_back( | 504 serialized_packet.retransmittable_frames.push_back( |
| 506 QuicFrame(new QuicStreamFrame())); | 505 QuicFrame(new QuicStreamFrame())); |
| 507 } | 506 } |
| 508 OnSerializedPacket(&serialized_packet); | 507 OnSerializedPacket(&serialized_packet); |
| 509 } | 508 } |
| 510 | 509 |
| 511 QuicConsumedData SendStreamDataWithString( | 510 QuicConsumedData SendStreamDataWithString( |
| 512 QuicStreamId id, | 511 QuicStreamId id, |
| 513 StringPiece data, | 512 QuicStringPiece data, |
| 514 QuicStreamOffset offset, | 513 QuicStreamOffset offset, |
| 515 bool fin, | 514 bool fin, |
| 516 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener) { | 515 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener) { |
| 517 if (id != kCryptoStreamId && this->encryption_level() == ENCRYPTION_NONE) { | 516 if (id != kCryptoStreamId && this->encryption_level() == ENCRYPTION_NONE) { |
| 518 this->SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); | 517 this->SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); |
| 519 } | 518 } |
| 520 struct iovec iov; | 519 struct iovec iov; |
| 521 QuicIOVector data_iov(MakeIOVector(data, &iov)); | 520 QuicIOVector data_iov(MakeIOVector(data, &iov)); |
| 522 return QuicConnection::SendStreamData(id, data_iov, offset, fin, | 521 return QuicConnection::SendStreamData(id, data_iov, offset, fin, |
| 523 std::move(ack_listener)); | 522 std::move(ack_listener)); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 connection_(connection_id_, | 698 connection_(connection_id_, |
| 700 kPeerAddress, | 699 kPeerAddress, |
| 701 helper_.get(), | 700 helper_.get(), |
| 702 alarm_factory_.get(), | 701 alarm_factory_.get(), |
| 703 writer_.get(), | 702 writer_.get(), |
| 704 Perspective::IS_CLIENT, | 703 Perspective::IS_CLIENT, |
| 705 version()), | 704 version()), |
| 706 creator_(QuicConnectionPeer::GetPacketCreator(&connection_)), | 705 creator_(QuicConnectionPeer::GetPacketCreator(&connection_)), |
| 707 generator_(QuicConnectionPeer::GetPacketGenerator(&connection_)), | 706 generator_(QuicConnectionPeer::GetPacketGenerator(&connection_)), |
| 708 manager_(QuicConnectionPeer::GetSentPacketManager(&connection_)), | 707 manager_(QuicConnectionPeer::GetSentPacketManager(&connection_)), |
| 709 frame1_(1, false, 0, StringPiece(data1)), | 708 frame1_(1, false, 0, QuicStringPiece(data1)), |
| 710 frame2_(1, false, 3, StringPiece(data2)), | 709 frame2_(1, false, 3, QuicStringPiece(data2)), |
| 711 packet_number_length_(PACKET_6BYTE_PACKET_NUMBER), | 710 packet_number_length_(PACKET_6BYTE_PACKET_NUMBER), |
| 712 connection_id_length_(PACKET_8BYTE_CONNECTION_ID) { | 711 connection_id_length_(PACKET_8BYTE_CONNECTION_ID) { |
| 713 connection_.set_defer_send_in_response_to_packets(GetParam().ack_response == | 712 connection_.set_defer_send_in_response_to_packets(GetParam().ack_response == |
| 714 AckResponse::kDefer); | 713 AckResponse::kDefer); |
| 715 QuicConnectionPeer::SetNoStopWaitingFrames(&connection_, | 714 QuicConnectionPeer::SetNoStopWaitingFrames(&connection_, |
| 716 GetParam().no_stop_waiting); | 715 GetParam().no_stop_waiting); |
| 717 connection_.set_visitor(&visitor_); | 716 connection_.set_visitor(&visitor_); |
| 718 connection_.SetSendAlgorithm(send_algorithm_); | 717 connection_.SetSendAlgorithm(send_algorithm_); |
| 719 connection_.SetLossAlgorithm(loss_algorithm_.get()); | 718 connection_.SetLossAlgorithm(loss_algorithm_.get()); |
| 720 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _)) | 719 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _)) |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 876 std::unique_ptr<QuicPacket> packet(ConstructClosePacket(number)); | 875 std::unique_ptr<QuicPacket> packet(ConstructClosePacket(number)); |
| 877 char buffer[kMaxPacketSize]; | 876 char buffer[kMaxPacketSize]; |
| 878 size_t encrypted_length = peer_framer_.EncryptPayload( | 877 size_t encrypted_length = peer_framer_.EncryptPayload( |
| 879 ENCRYPTION_NONE, number, *packet, buffer, kMaxPacketSize); | 878 ENCRYPTION_NONE, number, *packet, buffer, kMaxPacketSize); |
| 880 connection_.ProcessUdpPacket( | 879 connection_.ProcessUdpPacket( |
| 881 kSelfAddress, kPeerAddress, | 880 kSelfAddress, kPeerAddress, |
| 882 QuicReceivedPacket(buffer, encrypted_length, QuicTime::Zero(), false)); | 881 QuicReceivedPacket(buffer, encrypted_length, QuicTime::Zero(), false)); |
| 883 } | 882 } |
| 884 | 883 |
| 885 QuicByteCount SendStreamDataToPeer(QuicStreamId id, | 884 QuicByteCount SendStreamDataToPeer(QuicStreamId id, |
| 886 StringPiece data, | 885 QuicStringPiece data, |
| 887 QuicStreamOffset offset, | 886 QuicStreamOffset offset, |
| 888 bool fin, | 887 bool fin, |
| 889 QuicPacketNumber* last_packet) { | 888 QuicPacketNumber* last_packet) { |
| 890 QuicByteCount packet_size; | 889 QuicByteCount packet_size; |
| 891 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) | 890 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
| 892 .WillOnce(DoAll(SaveArg<3>(&packet_size), Return(true))); | 891 .WillOnce(DoAll(SaveArg<3>(&packet_size), Return(true))); |
| 893 connection_.SendStreamDataWithString(id, data, offset, fin, nullptr); | 892 connection_.SendStreamDataWithString(id, data, offset, fin, nullptr); |
| 894 if (last_packet != nullptr) { | 893 if (last_packet != nullptr) { |
| 895 *last_packet = creator_->packet_number(); | 894 *last_packet = creator_->packet_number(); |
| 896 } | 895 } |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1085 INSTANTIATE_TEST_CASE_P(SupportedVersion, | 1084 INSTANTIATE_TEST_CASE_P(SupportedVersion, |
| 1086 QuicConnectionTest, | 1085 QuicConnectionTest, |
| 1087 ::testing::ValuesIn(GetTestParams())); | 1086 ::testing::ValuesIn(GetTestParams())); |
| 1088 | 1087 |
| 1089 TEST_P(QuicConnectionTest, SelfAddressChangeAtClient) { | 1088 TEST_P(QuicConnectionTest, SelfAddressChangeAtClient) { |
| 1090 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1089 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1091 | 1090 |
| 1092 EXPECT_EQ(Perspective::IS_CLIENT, connection_.perspective()); | 1091 EXPECT_EQ(Perspective::IS_CLIENT, connection_.perspective()); |
| 1093 EXPECT_TRUE(connection_.connected()); | 1092 EXPECT_TRUE(connection_.connected()); |
| 1094 | 1093 |
| 1095 QuicStreamFrame stream_frame(1u, false, 0u, StringPiece()); | 1094 QuicStreamFrame stream_frame(1u, false, 0u, QuicStringPiece()); |
| 1096 EXPECT_CALL(visitor_, OnStreamFrame(_)); | 1095 EXPECT_CALL(visitor_, OnStreamFrame(_)); |
| 1097 ProcessFramePacketWithAddresses(QuicFrame(&stream_frame), kSelfAddress, | 1096 ProcessFramePacketWithAddresses(QuicFrame(&stream_frame), kSelfAddress, |
| 1098 kPeerAddress); | 1097 kPeerAddress); |
| 1099 // Cause change in self_address. | 1098 // Cause change in self_address. |
| 1100 QuicIpAddress host; | 1099 QuicIpAddress host; |
| 1101 host.FromString("1.1.1.1"); | 1100 host.FromString("1.1.1.1"); |
| 1102 QuicSocketAddress self_address(host, 123); | 1101 QuicSocketAddress self_address(host, 123); |
| 1103 EXPECT_CALL(visitor_, OnStreamFrame(_)); | 1102 EXPECT_CALL(visitor_, OnStreamFrame(_)); |
| 1104 ProcessFramePacketWithAddresses(QuicFrame(&stream_frame), self_address, | 1103 ProcessFramePacketWithAddresses(QuicFrame(&stream_frame), self_address, |
| 1105 kPeerAddress); | 1104 kPeerAddress); |
| 1106 EXPECT_TRUE(connection_.connected()); | 1105 EXPECT_TRUE(connection_.connected()); |
| 1107 } | 1106 } |
| 1108 | 1107 |
| 1109 TEST_P(QuicConnectionTest, SelfAddressChangeAtServer) { | 1108 TEST_P(QuicConnectionTest, SelfAddressChangeAtServer) { |
| 1110 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1109 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1111 | 1110 |
| 1112 set_perspective(Perspective::IS_SERVER); | 1111 set_perspective(Perspective::IS_SERVER); |
| 1113 QuicPacketCreatorPeer::SetSendVersionInPacket(creator_, false); | 1112 QuicPacketCreatorPeer::SetSendVersionInPacket(creator_, false); |
| 1114 | 1113 |
| 1115 EXPECT_EQ(Perspective::IS_SERVER, connection_.perspective()); | 1114 EXPECT_EQ(Perspective::IS_SERVER, connection_.perspective()); |
| 1116 EXPECT_TRUE(connection_.connected()); | 1115 EXPECT_TRUE(connection_.connected()); |
| 1117 | 1116 |
| 1118 QuicStreamFrame stream_frame(1u, false, 0u, StringPiece()); | 1117 QuicStreamFrame stream_frame(1u, false, 0u, QuicStringPiece()); |
| 1119 EXPECT_CALL(visitor_, OnStreamFrame(_)); | 1118 EXPECT_CALL(visitor_, OnStreamFrame(_)); |
| 1120 ProcessFramePacketWithAddresses(QuicFrame(&stream_frame), kSelfAddress, | 1119 ProcessFramePacketWithAddresses(QuicFrame(&stream_frame), kSelfAddress, |
| 1121 kPeerAddress); | 1120 kPeerAddress); |
| 1122 // Cause change in self_address. | 1121 // Cause change in self_address. |
| 1123 QuicIpAddress host; | 1122 QuicIpAddress host; |
| 1124 host.FromString("1.1.1.1"); | 1123 host.FromString("1.1.1.1"); |
| 1125 QuicSocketAddress self_address(host, 123); | 1124 QuicSocketAddress self_address(host, 123); |
| 1126 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_ERROR_MIGRATING_ADDRESS, _, _)); | 1125 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_ERROR_MIGRATING_ADDRESS, _, _)); |
| 1127 ProcessFramePacketWithAddresses(QuicFrame(&stream_frame), self_address, | 1126 ProcessFramePacketWithAddresses(QuicFrame(&stream_frame), self_address, |
| 1128 kPeerAddress); | 1127 kPeerAddress); |
| 1129 EXPECT_FALSE(connection_.connected()); | 1128 EXPECT_FALSE(connection_.connected()); |
| 1130 } | 1129 } |
| 1131 | 1130 |
| 1132 TEST_P(QuicConnectionTest, AllowSelfAddressChangeToMappedIpv4AddressAtServer) { | 1131 TEST_P(QuicConnectionTest, AllowSelfAddressChangeToMappedIpv4AddressAtServer) { |
| 1133 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1132 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1134 | 1133 |
| 1135 set_perspective(Perspective::IS_SERVER); | 1134 set_perspective(Perspective::IS_SERVER); |
| 1136 QuicPacketCreatorPeer::SetSendVersionInPacket(creator_, false); | 1135 QuicPacketCreatorPeer::SetSendVersionInPacket(creator_, false); |
| 1137 | 1136 |
| 1138 EXPECT_EQ(Perspective::IS_SERVER, connection_.perspective()); | 1137 EXPECT_EQ(Perspective::IS_SERVER, connection_.perspective()); |
| 1139 EXPECT_TRUE(connection_.connected()); | 1138 EXPECT_TRUE(connection_.connected()); |
| 1140 | 1139 |
| 1141 QuicStreamFrame stream_frame(1u, false, 0u, StringPiece()); | 1140 QuicStreamFrame stream_frame(1u, false, 0u, QuicStringPiece()); |
| 1142 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(3); | 1141 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(3); |
| 1143 QuicIpAddress host; | 1142 QuicIpAddress host; |
| 1144 host.FromString("1.1.1.1"); | 1143 host.FromString("1.1.1.1"); |
| 1145 QuicSocketAddress self_address1(host, 443); | 1144 QuicSocketAddress self_address1(host, 443); |
| 1146 ProcessFramePacketWithAddresses(QuicFrame(&stream_frame), self_address1, | 1145 ProcessFramePacketWithAddresses(QuicFrame(&stream_frame), self_address1, |
| 1147 kPeerAddress); | 1146 kPeerAddress); |
| 1148 // Cause self_address change to mapped Ipv4 address. | 1147 // Cause self_address change to mapped Ipv4 address. |
| 1149 QuicIpAddress host2; | 1148 QuicIpAddress host2; |
| 1150 host2.FromString( | 1149 host2.FromString( |
| 1151 QuicStrCat("::ffff:", connection_.self_address().host().ToString())); | 1150 QuicStrCat("::ffff:", connection_.self_address().host().ToString())); |
| 1152 QuicSocketAddress self_address2(host2, connection_.self_address().port()); | 1151 QuicSocketAddress self_address2(host2, connection_.self_address().port()); |
| 1153 ProcessFramePacketWithAddresses(QuicFrame(&stream_frame), self_address2, | 1152 ProcessFramePacketWithAddresses(QuicFrame(&stream_frame), self_address2, |
| 1154 kPeerAddress); | 1153 kPeerAddress); |
| 1155 EXPECT_TRUE(connection_.connected()); | 1154 EXPECT_TRUE(connection_.connected()); |
| 1156 // self_address change back to Ipv4 address. | 1155 // self_address change back to Ipv4 address. |
| 1157 ProcessFramePacketWithAddresses(QuicFrame(&stream_frame), self_address1, | 1156 ProcessFramePacketWithAddresses(QuicFrame(&stream_frame), self_address1, |
| 1158 kPeerAddress); | 1157 kPeerAddress); |
| 1159 EXPECT_TRUE(connection_.connected()); | 1158 EXPECT_TRUE(connection_.connected()); |
| 1160 } | 1159 } |
| 1161 | 1160 |
| 1162 TEST_P(QuicConnectionTest, ClientAddressChangeAndPacketReordered) { | 1161 TEST_P(QuicConnectionTest, ClientAddressChangeAndPacketReordered) { |
| 1163 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1162 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1164 set_perspective(Perspective::IS_SERVER); | 1163 set_perspective(Perspective::IS_SERVER); |
| 1165 QuicPacketCreatorPeer::SetSendVersionInPacket(creator_, false); | 1164 QuicPacketCreatorPeer::SetSendVersionInPacket(creator_, false); |
| 1166 // Clear peer address. | 1165 // Clear peer address. |
| 1167 QuicConnectionPeer::SetPeerAddress(&connection_, QuicSocketAddress()); | 1166 QuicConnectionPeer::SetPeerAddress(&connection_, QuicSocketAddress()); |
| 1168 | 1167 |
| 1169 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, 5); | 1168 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, 5); |
| 1170 QuicStreamFrame stream_frame(1u, false, 0u, StringPiece()); | 1169 QuicStreamFrame stream_frame(1u, false, 0u, QuicStringPiece()); |
| 1171 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(AnyNumber()); | 1170 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(AnyNumber()); |
| 1172 const QuicSocketAddress kNewPeerAddress = | 1171 const QuicSocketAddress kNewPeerAddress = |
| 1173 QuicSocketAddress(QuicIpAddress::Loopback6(), | 1172 QuicSocketAddress(QuicIpAddress::Loopback6(), |
| 1174 /*port=*/23456); | 1173 /*port=*/23456); |
| 1175 ProcessFramePacketWithAddresses(QuicFrame(&stream_frame), kSelfAddress, | 1174 ProcessFramePacketWithAddresses(QuicFrame(&stream_frame), kSelfAddress, |
| 1176 kNewPeerAddress); | 1175 kNewPeerAddress); |
| 1177 | 1176 |
| 1178 // Decrease packet number to simulate out-of-order packets. | 1177 // Decrease packet number to simulate out-of-order packets. |
| 1179 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, 4); | 1178 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, 4); |
| 1180 // This is an old packet, do not migrate. | 1179 // This is an old packet, do not migrate. |
| (...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1847 | 1846 |
| 1848 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1847 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 1849 EXPECT_FALSE(connection_.HasQueuedData()); | 1848 EXPECT_FALSE(connection_.HasQueuedData()); |
| 1850 | 1849 |
| 1851 // Parse the last packet and ensure multiple iovector blocks have | 1850 // Parse the last packet and ensure multiple iovector blocks have |
| 1852 // been packed into a single stream frame from one stream. | 1851 // been packed into a single stream frame from one stream. |
| 1853 EXPECT_EQ(1u, writer_->frame_count()); | 1852 EXPECT_EQ(1u, writer_->frame_count()); |
| 1854 EXPECT_EQ(1u, writer_->stream_frames().size()); | 1853 EXPECT_EQ(1u, writer_->stream_frames().size()); |
| 1855 QuicStreamFrame* frame = writer_->stream_frames()[0].get(); | 1854 QuicStreamFrame* frame = writer_->stream_frames()[0].get(); |
| 1856 EXPECT_EQ(1u, frame->stream_id); | 1855 EXPECT_EQ(1u, frame->stream_id); |
| 1857 EXPECT_EQ("ABCD", StringPiece(frame->data_buffer, frame->data_length)); | 1856 EXPECT_EQ("ABCD", QuicStringPiece(frame->data_buffer, frame->data_length)); |
| 1858 } | 1857 } |
| 1859 | 1858 |
| 1860 TEST_P(QuicConnectionTest, FramePackingSendvQueued) { | 1859 TEST_P(QuicConnectionTest, FramePackingSendvQueued) { |
| 1861 // Try to send two stream frames in 1 packet by using writev. | 1860 // Try to send two stream frames in 1 packet by using writev. |
| 1862 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 1861 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
| 1863 | 1862 |
| 1864 BlockOnNextWrite(); | 1863 BlockOnNextWrite(); |
| 1865 char data[] = "ABCD"; | 1864 char data[] = "ABCD"; |
| 1866 struct iovec iov[2]; | 1865 struct iovec iov[2]; |
| 1867 iov[0].iov_base = data; | 1866 iov[0].iov_base = data; |
| (...skipping 3295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5163 error_details, ConnectionCloseSource::FROM_PEER)); | 5162 error_details, ConnectionCloseSource::FROM_PEER)); |
| 5164 connection_.set_perspective(Perspective::IS_CLIENT); | 5163 connection_.set_perspective(Perspective::IS_CLIENT); |
| 5165 connection_.CloseConnection(QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT, | 5164 connection_.CloseConnection(QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT, |
| 5166 error_details, | 5165 error_details, |
| 5167 ConnectionCloseBehavior::SILENT_CLOSE); | 5166 ConnectionCloseBehavior::SILENT_CLOSE); |
| 5168 } | 5167 } |
| 5169 | 5168 |
| 5170 } // namespace | 5169 } // namespace |
| 5171 } // namespace test | 5170 } // namespace test |
| 5172 } // namespace net | 5171 } // namespace net |
| OLD | NEW |