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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 | 60 |
61 const int kDefaultRetransmissionTimeMs = 500; | 61 const int kDefaultRetransmissionTimeMs = 500; |
62 | 62 |
63 class TestReceiveAlgorithm : public ReceiveAlgorithmInterface { | 63 class TestReceiveAlgorithm : public ReceiveAlgorithmInterface { |
64 public: | 64 public: |
65 explicit TestReceiveAlgorithm(QuicCongestionFeedbackFrame* feedback) | 65 explicit TestReceiveAlgorithm(QuicCongestionFeedbackFrame* feedback) |
66 : feedback_(feedback) { | 66 : feedback_(feedback) { |
67 } | 67 } |
68 | 68 |
69 bool GenerateCongestionFeedback( | 69 bool GenerateCongestionFeedback( |
70 QuicCongestionFeedbackFrame* congestion_feedback) { | 70 QuicCongestionFeedbackFrame* congestion_feedback) override { |
71 if (feedback_ == nullptr) { | 71 if (feedback_ == nullptr) { |
72 return false; | 72 return false; |
73 } | 73 } |
74 *congestion_feedback = *feedback_; | 74 *congestion_feedback = *feedback_; |
75 return true; | 75 return true; |
76 } | 76 } |
77 | 77 |
78 MOCK_METHOD3(RecordIncomingPacket, | 78 MOCK_METHOD3(RecordIncomingPacket, |
79 void(QuicByteCount, QuicPacketSequenceNumber, QuicTime)); | 79 void(QuicByteCount, QuicPacketSequenceNumber, QuicTime)); |
80 | 80 |
81 private: | 81 private: |
82 QuicCongestionFeedbackFrame* feedback_; | 82 QuicCongestionFeedbackFrame* feedback_; |
83 | 83 |
84 DISALLOW_COPY_AND_ASSIGN(TestReceiveAlgorithm); | 84 DISALLOW_COPY_AND_ASSIGN(TestReceiveAlgorithm); |
85 }; | 85 }; |
86 | 86 |
87 // TaggingEncrypter appends kTagSize bytes of |tag| to the end of each message. | 87 // TaggingEncrypter appends kTagSize bytes of |tag| to the end of each message. |
88 class TaggingEncrypter : public QuicEncrypter { | 88 class TaggingEncrypter : public QuicEncrypter { |
89 public: | 89 public: |
90 explicit TaggingEncrypter(uint8 tag) | 90 explicit TaggingEncrypter(uint8 tag) |
91 : tag_(tag) { | 91 : tag_(tag) { |
92 } | 92 } |
93 | 93 |
94 ~TaggingEncrypter() override {} | 94 ~TaggingEncrypter() override {} |
95 | 95 |
96 // QuicEncrypter interface. | 96 // QuicEncrypter interface. |
97 bool SetKey(StringPiece key) override { return true; } | 97 bool SetKey(StringPiece key) override { return true; } |
| 98 |
98 bool SetNoncePrefix(StringPiece nonce_prefix) override { return true; } | 99 bool SetNoncePrefix(StringPiece nonce_prefix) override { return true; } |
99 | 100 |
100 bool Encrypt(StringPiece nonce, | 101 bool Encrypt(StringPiece nonce, |
101 StringPiece associated_data, | 102 StringPiece associated_data, |
102 StringPiece plaintext, | 103 StringPiece plaintext, |
103 unsigned char* output) override { | 104 unsigned char* output) override { |
104 memcpy(output, plaintext.data(), plaintext.size()); | 105 memcpy(output, plaintext.data(), plaintext.size()); |
105 output += plaintext.size(); | 106 output += plaintext.size(); |
106 memset(output, tag_, kTagSize); | 107 memset(output, tag_, kTagSize); |
107 return true; | 108 return true; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 }; | 143 }; |
143 | 144 |
144 // TaggingDecrypter ensures that the final kTagSize bytes of the message all | 145 // TaggingDecrypter ensures that the final kTagSize bytes of the message all |
145 // have the same value and then removes them. | 146 // have the same value and then removes them. |
146 class TaggingDecrypter : public QuicDecrypter { | 147 class TaggingDecrypter : public QuicDecrypter { |
147 public: | 148 public: |
148 ~TaggingDecrypter() override {} | 149 ~TaggingDecrypter() override {} |
149 | 150 |
150 // QuicDecrypter interface | 151 // QuicDecrypter interface |
151 bool SetKey(StringPiece key) override { return true; } | 152 bool SetKey(StringPiece key) override { return true; } |
| 153 |
152 bool SetNoncePrefix(StringPiece nonce_prefix) override { return true; } | 154 bool SetNoncePrefix(StringPiece nonce_prefix) override { return true; } |
153 | 155 |
154 bool Decrypt(StringPiece nonce, | 156 bool Decrypt(StringPiece nonce, |
155 StringPiece associated_data, | 157 StringPiece associated_data, |
156 StringPiece ciphertext, | 158 StringPiece ciphertext, |
157 unsigned char* output, | 159 unsigned char* output, |
158 size_t* output_length) override { | 160 size_t* output_length) override { |
159 if (ciphertext.size() < kTagSize) { | 161 if (ciphertext.size() < kTagSize) { |
160 return false; | 162 return false; |
161 } | 163 } |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 | 592 |
591 private: | 593 private: |
592 QuicPacketHeader revived_header_; | 594 QuicPacketHeader revived_header_; |
593 }; | 595 }; |
594 | 596 |
595 class MockPacketWriterFactory : public QuicConnection::PacketWriterFactory { | 597 class MockPacketWriterFactory : public QuicConnection::PacketWriterFactory { |
596 public: | 598 public: |
597 MockPacketWriterFactory(QuicPacketWriter* writer) { | 599 MockPacketWriterFactory(QuicPacketWriter* writer) { |
598 ON_CALL(*this, Create(_)).WillByDefault(Return(writer)); | 600 ON_CALL(*this, Create(_)).WillByDefault(Return(writer)); |
599 } | 601 } |
600 virtual ~MockPacketWriterFactory() {} | 602 ~MockPacketWriterFactory() override {} |
601 | 603 |
602 MOCK_CONST_METHOD1(Create, QuicPacketWriter*(QuicConnection* connection)); | 604 MOCK_CONST_METHOD1(Create, QuicPacketWriter*(QuicConnection* connection)); |
603 }; | 605 }; |
604 | 606 |
605 class QuicConnectionTest : public ::testing::TestWithParam<QuicVersion> { | 607 class QuicConnectionTest : public ::testing::TestWithParam<QuicVersion> { |
606 protected: | 608 protected: |
607 QuicConnectionTest() | 609 QuicConnectionTest() |
608 : connection_id_(42), | 610 : connection_id_(42), |
609 framer_(SupportedVersions(version()), QuicTime::Zero(), false), | 611 framer_(SupportedVersions(version()), QuicTime::Zero(), false), |
610 peer_creator_(connection_id_, &framer_, &random_generator_), | 612 peer_creator_(connection_id_, &framer_, &random_generator_), |
(...skipping 3485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4096 QuicBlockedFrame blocked; | 4098 QuicBlockedFrame blocked; |
4097 blocked.stream_id = 3; | 4099 blocked.stream_id = 3; |
4098 EXPECT_CALL(visitor_, OnBlockedFrames(_)); | 4100 EXPECT_CALL(visitor_, OnBlockedFrames(_)); |
4099 ProcessFramePacket(QuicFrame(&blocked)); | 4101 ProcessFramePacket(QuicFrame(&blocked)); |
4100 EXPECT_TRUE(ack_alarm->IsSet()); | 4102 EXPECT_TRUE(ack_alarm->IsSet()); |
4101 } | 4103 } |
4102 | 4104 |
4103 } // namespace | 4105 } // namespace |
4104 } // namespace test | 4106 } // namespace test |
4105 } // namespace net | 4107 } // namespace net |
OLD | NEW |