| 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_framer.h" | 5 #include "net/quic/quic_framer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 } | 97 } |
| 98 | 98 |
| 99 // Index into the message tag of the public reset packet. | 99 // Index into the message tag of the public reset packet. |
| 100 // Public resets always have full connection_ids. | 100 // Public resets always have full connection_ids. |
| 101 const size_t kPublicResetPacketMessageTagOffset = | 101 const size_t kPublicResetPacketMessageTagOffset = |
| 102 kConnectionIdOffset + PACKET_8BYTE_CONNECTION_ID; | 102 kConnectionIdOffset + PACKET_8BYTE_CONNECTION_ID; |
| 103 | 103 |
| 104 class TestEncrypter : public QuicEncrypter { | 104 class TestEncrypter : public QuicEncrypter { |
| 105 public: | 105 public: |
| 106 virtual ~TestEncrypter() {} | 106 virtual ~TestEncrypter() {} |
| 107 virtual bool SetKey(StringPiece key) OVERRIDE { | 107 virtual bool SetKey(StringPiece key) override { |
| 108 return true; | 108 return true; |
| 109 } | 109 } |
| 110 virtual bool SetNoncePrefix(StringPiece nonce_prefix) OVERRIDE { | 110 virtual bool SetNoncePrefix(StringPiece nonce_prefix) override { |
| 111 return true; | 111 return true; |
| 112 } | 112 } |
| 113 virtual bool Encrypt(StringPiece nonce, | 113 virtual bool Encrypt(StringPiece nonce, |
| 114 StringPiece associated_data, | 114 StringPiece associated_data, |
| 115 StringPiece plaintext, | 115 StringPiece plaintext, |
| 116 unsigned char* output) OVERRIDE { | 116 unsigned char* output) override { |
| 117 CHECK(false) << "Not implemented"; | 117 CHECK(false) << "Not implemented"; |
| 118 return false; | 118 return false; |
| 119 } | 119 } |
| 120 virtual QuicData* EncryptPacket(QuicPacketSequenceNumber sequence_number, | 120 virtual QuicData* EncryptPacket(QuicPacketSequenceNumber sequence_number, |
| 121 StringPiece associated_data, | 121 StringPiece associated_data, |
| 122 StringPiece plaintext) OVERRIDE { | 122 StringPiece plaintext) override { |
| 123 sequence_number_ = sequence_number; | 123 sequence_number_ = sequence_number; |
| 124 associated_data_ = associated_data.as_string(); | 124 associated_data_ = associated_data.as_string(); |
| 125 plaintext_ = plaintext.as_string(); | 125 plaintext_ = plaintext.as_string(); |
| 126 return new QuicData(plaintext.data(), plaintext.length()); | 126 return new QuicData(plaintext.data(), plaintext.length()); |
| 127 } | 127 } |
| 128 virtual size_t GetKeySize() const OVERRIDE { | 128 virtual size_t GetKeySize() const override { |
| 129 return 0; | 129 return 0; |
| 130 } | 130 } |
| 131 virtual size_t GetNoncePrefixSize() const OVERRIDE { | 131 virtual size_t GetNoncePrefixSize() const override { |
| 132 return 0; | 132 return 0; |
| 133 } | 133 } |
| 134 virtual size_t GetMaxPlaintextSize(size_t ciphertext_size) const OVERRIDE { | 134 virtual size_t GetMaxPlaintextSize(size_t ciphertext_size) const override { |
| 135 return ciphertext_size; | 135 return ciphertext_size; |
| 136 } | 136 } |
| 137 virtual size_t GetCiphertextSize(size_t plaintext_size) const OVERRIDE { | 137 virtual size_t GetCiphertextSize(size_t plaintext_size) const override { |
| 138 return plaintext_size; | 138 return plaintext_size; |
| 139 } | 139 } |
| 140 virtual StringPiece GetKey() const OVERRIDE { | 140 virtual StringPiece GetKey() const override { |
| 141 return StringPiece(); | 141 return StringPiece(); |
| 142 } | 142 } |
| 143 virtual StringPiece GetNoncePrefix() const OVERRIDE { | 143 virtual StringPiece GetNoncePrefix() const override { |
| 144 return StringPiece(); | 144 return StringPiece(); |
| 145 } | 145 } |
| 146 QuicPacketSequenceNumber sequence_number_; | 146 QuicPacketSequenceNumber sequence_number_; |
| 147 string associated_data_; | 147 string associated_data_; |
| 148 string plaintext_; | 148 string plaintext_; |
| 149 }; | 149 }; |
| 150 | 150 |
| 151 class TestDecrypter : public QuicDecrypter { | 151 class TestDecrypter : public QuicDecrypter { |
| 152 public: | 152 public: |
| 153 virtual ~TestDecrypter() {} | 153 virtual ~TestDecrypter() {} |
| 154 virtual bool SetKey(StringPiece key) OVERRIDE { | 154 virtual bool SetKey(StringPiece key) override { |
| 155 return true; | 155 return true; |
| 156 } | 156 } |
| 157 virtual bool SetNoncePrefix(StringPiece nonce_prefix) OVERRIDE { | 157 virtual bool SetNoncePrefix(StringPiece nonce_prefix) override { |
| 158 return true; | 158 return true; |
| 159 } | 159 } |
| 160 virtual bool Decrypt(StringPiece nonce, | 160 virtual bool Decrypt(StringPiece nonce, |
| 161 StringPiece associated_data, | 161 StringPiece associated_data, |
| 162 StringPiece ciphertext, | 162 StringPiece ciphertext, |
| 163 unsigned char* output, | 163 unsigned char* output, |
| 164 size_t* output_length) OVERRIDE { | 164 size_t* output_length) override { |
| 165 CHECK(false) << "Not implemented"; | 165 CHECK(false) << "Not implemented"; |
| 166 return false; | 166 return false; |
| 167 } | 167 } |
| 168 virtual QuicData* DecryptPacket(QuicPacketSequenceNumber sequence_number, | 168 virtual QuicData* DecryptPacket(QuicPacketSequenceNumber sequence_number, |
| 169 StringPiece associated_data, | 169 StringPiece associated_data, |
| 170 StringPiece ciphertext) OVERRIDE { | 170 StringPiece ciphertext) override { |
| 171 sequence_number_ = sequence_number; | 171 sequence_number_ = sequence_number; |
| 172 associated_data_ = associated_data.as_string(); | 172 associated_data_ = associated_data.as_string(); |
| 173 ciphertext_ = ciphertext.as_string(); | 173 ciphertext_ = ciphertext.as_string(); |
| 174 return new QuicData(ciphertext.data(), ciphertext.length()); | 174 return new QuicData(ciphertext.data(), ciphertext.length()); |
| 175 } | 175 } |
| 176 virtual StringPiece GetKey() const OVERRIDE { | 176 virtual StringPiece GetKey() const override { |
| 177 return StringPiece(); | 177 return StringPiece(); |
| 178 } | 178 } |
| 179 virtual StringPiece GetNoncePrefix() const OVERRIDE { | 179 virtual StringPiece GetNoncePrefix() const override { |
| 180 return StringPiece(); | 180 return StringPiece(); |
| 181 } | 181 } |
| 182 QuicPacketSequenceNumber sequence_number_; | 182 QuicPacketSequenceNumber sequence_number_; |
| 183 string associated_data_; | 183 string associated_data_; |
| 184 string ciphertext_; | 184 string ciphertext_; |
| 185 }; | 185 }; |
| 186 | 186 |
| 187 class TestQuicVisitor : public ::net::QuicFramerVisitorInterface { | 187 class TestQuicVisitor : public ::net::QuicFramerVisitorInterface { |
| 188 public: | 188 public: |
| 189 TestQuicVisitor() | 189 TestQuicVisitor() |
| (...skipping 10 matching lines...) Expand all Loading... |
| 200 | 200 |
| 201 virtual ~TestQuicVisitor() { | 201 virtual ~TestQuicVisitor() { |
| 202 STLDeleteElements(&stream_frames_); | 202 STLDeleteElements(&stream_frames_); |
| 203 STLDeleteElements(&ack_frames_); | 203 STLDeleteElements(&ack_frames_); |
| 204 STLDeleteElements(&congestion_feedback_frames_); | 204 STLDeleteElements(&congestion_feedback_frames_); |
| 205 STLDeleteElements(&stop_waiting_frames_); | 205 STLDeleteElements(&stop_waiting_frames_); |
| 206 STLDeleteElements(&ping_frames_); | 206 STLDeleteElements(&ping_frames_); |
| 207 STLDeleteElements(&fec_data_); | 207 STLDeleteElements(&fec_data_); |
| 208 } | 208 } |
| 209 | 209 |
| 210 virtual void OnError(QuicFramer* f) OVERRIDE { | 210 virtual void OnError(QuicFramer* f) override { |
| 211 DVLOG(1) << "QuicFramer Error: " << QuicUtils::ErrorToString(f->error()) | 211 DVLOG(1) << "QuicFramer Error: " << QuicUtils::ErrorToString(f->error()) |
| 212 << " (" << f->error() << ")"; | 212 << " (" << f->error() << ")"; |
| 213 ++error_count_; | 213 ++error_count_; |
| 214 } | 214 } |
| 215 | 215 |
| 216 virtual void OnPacket() OVERRIDE {} | 216 virtual void OnPacket() override {} |
| 217 | 217 |
| 218 virtual void OnPublicResetPacket( | 218 virtual void OnPublicResetPacket( |
| 219 const QuicPublicResetPacket& packet) OVERRIDE { | 219 const QuicPublicResetPacket& packet) override { |
| 220 public_reset_packet_.reset(new QuicPublicResetPacket(packet)); | 220 public_reset_packet_.reset(new QuicPublicResetPacket(packet)); |
| 221 } | 221 } |
| 222 | 222 |
| 223 virtual void OnVersionNegotiationPacket( | 223 virtual void OnVersionNegotiationPacket( |
| 224 const QuicVersionNegotiationPacket& packet) OVERRIDE { | 224 const QuicVersionNegotiationPacket& packet) override { |
| 225 version_negotiation_packet_.reset(new QuicVersionNegotiationPacket(packet)); | 225 version_negotiation_packet_.reset(new QuicVersionNegotiationPacket(packet)); |
| 226 } | 226 } |
| 227 | 227 |
| 228 virtual void OnRevivedPacket() OVERRIDE { | 228 virtual void OnRevivedPacket() override { |
| 229 ++revived_packets_; | 229 ++revived_packets_; |
| 230 } | 230 } |
| 231 | 231 |
| 232 virtual bool OnProtocolVersionMismatch(QuicVersion version) OVERRIDE { | 232 virtual bool OnProtocolVersionMismatch(QuicVersion version) override { |
| 233 DVLOG(1) << "QuicFramer Version Mismatch, version: " << version; | 233 DVLOG(1) << "QuicFramer Version Mismatch, version: " << version; |
| 234 ++version_mismatch_; | 234 ++version_mismatch_; |
| 235 return true; | 235 return true; |
| 236 } | 236 } |
| 237 | 237 |
| 238 virtual bool OnUnauthenticatedPublicHeader( | 238 virtual bool OnUnauthenticatedPublicHeader( |
| 239 const QuicPacketPublicHeader& header) OVERRIDE { | 239 const QuicPacketPublicHeader& header) override { |
| 240 public_header_.reset(new QuicPacketPublicHeader(header)); | 240 public_header_.reset(new QuicPacketPublicHeader(header)); |
| 241 return accept_public_header_; | 241 return accept_public_header_; |
| 242 } | 242 } |
| 243 | 243 |
| 244 virtual bool OnUnauthenticatedHeader( | 244 virtual bool OnUnauthenticatedHeader( |
| 245 const QuicPacketHeader& header) OVERRIDE { | 245 const QuicPacketHeader& header) override { |
| 246 return true; | 246 return true; |
| 247 } | 247 } |
| 248 | 248 |
| 249 virtual void OnDecryptedPacket(EncryptionLevel level) OVERRIDE {} | 249 virtual void OnDecryptedPacket(EncryptionLevel level) override {} |
| 250 | 250 |
| 251 virtual bool OnPacketHeader(const QuicPacketHeader& header) OVERRIDE { | 251 virtual bool OnPacketHeader(const QuicPacketHeader& header) override { |
| 252 ++packet_count_; | 252 ++packet_count_; |
| 253 header_.reset(new QuicPacketHeader(header)); | 253 header_.reset(new QuicPacketHeader(header)); |
| 254 return accept_packet_; | 254 return accept_packet_; |
| 255 } | 255 } |
| 256 | 256 |
| 257 virtual bool OnStreamFrame(const QuicStreamFrame& frame) OVERRIDE { | 257 virtual bool OnStreamFrame(const QuicStreamFrame& frame) override { |
| 258 ++frame_count_; | 258 ++frame_count_; |
| 259 stream_frames_.push_back(new QuicStreamFrame(frame)); | 259 stream_frames_.push_back(new QuicStreamFrame(frame)); |
| 260 return true; | 260 return true; |
| 261 } | 261 } |
| 262 | 262 |
| 263 virtual void OnFecProtectedPayload(StringPiece payload) OVERRIDE { | 263 virtual void OnFecProtectedPayload(StringPiece payload) override { |
| 264 fec_protected_payload_ = payload.as_string(); | 264 fec_protected_payload_ = payload.as_string(); |
| 265 } | 265 } |
| 266 | 266 |
| 267 virtual bool OnAckFrame(const QuicAckFrame& frame) OVERRIDE { | 267 virtual bool OnAckFrame(const QuicAckFrame& frame) override { |
| 268 ++frame_count_; | 268 ++frame_count_; |
| 269 ack_frames_.push_back(new QuicAckFrame(frame)); | 269 ack_frames_.push_back(new QuicAckFrame(frame)); |
| 270 return true; | 270 return true; |
| 271 } | 271 } |
| 272 | 272 |
| 273 virtual bool OnCongestionFeedbackFrame( | 273 virtual bool OnCongestionFeedbackFrame( |
| 274 const QuicCongestionFeedbackFrame& frame) OVERRIDE { | 274 const QuicCongestionFeedbackFrame& frame) override { |
| 275 ++frame_count_; | 275 ++frame_count_; |
| 276 congestion_feedback_frames_.push_back( | 276 congestion_feedback_frames_.push_back( |
| 277 new QuicCongestionFeedbackFrame(frame)); | 277 new QuicCongestionFeedbackFrame(frame)); |
| 278 return true; | 278 return true; |
| 279 } | 279 } |
| 280 | 280 |
| 281 virtual bool OnStopWaitingFrame(const QuicStopWaitingFrame& frame) OVERRIDE { | 281 virtual bool OnStopWaitingFrame(const QuicStopWaitingFrame& frame) override { |
| 282 ++frame_count_; | 282 ++frame_count_; |
| 283 stop_waiting_frames_.push_back(new QuicStopWaitingFrame(frame)); | 283 stop_waiting_frames_.push_back(new QuicStopWaitingFrame(frame)); |
| 284 return true; | 284 return true; |
| 285 } | 285 } |
| 286 | 286 |
| 287 virtual bool OnPingFrame(const QuicPingFrame& frame) OVERRIDE { | 287 virtual bool OnPingFrame(const QuicPingFrame& frame) override { |
| 288 ++frame_count_; | 288 ++frame_count_; |
| 289 ping_frames_.push_back(new QuicPingFrame(frame)); | 289 ping_frames_.push_back(new QuicPingFrame(frame)); |
| 290 return true; | 290 return true; |
| 291 } | 291 } |
| 292 | 292 |
| 293 virtual void OnFecData(const QuicFecData& fec) OVERRIDE { | 293 virtual void OnFecData(const QuicFecData& fec) override { |
| 294 ++fec_count_; | 294 ++fec_count_; |
| 295 fec_data_.push_back(new QuicFecData(fec)); | 295 fec_data_.push_back(new QuicFecData(fec)); |
| 296 } | 296 } |
| 297 | 297 |
| 298 virtual void OnPacketComplete() OVERRIDE { | 298 virtual void OnPacketComplete() override { |
| 299 ++complete_packets_; | 299 ++complete_packets_; |
| 300 } | 300 } |
| 301 | 301 |
| 302 virtual bool OnRstStreamFrame(const QuicRstStreamFrame& frame) OVERRIDE { | 302 virtual bool OnRstStreamFrame(const QuicRstStreamFrame& frame) override { |
| 303 rst_stream_frame_ = frame; | 303 rst_stream_frame_ = frame; |
| 304 return true; | 304 return true; |
| 305 } | 305 } |
| 306 | 306 |
| 307 virtual bool OnConnectionCloseFrame( | 307 virtual bool OnConnectionCloseFrame( |
| 308 const QuicConnectionCloseFrame& frame) OVERRIDE { | 308 const QuicConnectionCloseFrame& frame) override { |
| 309 connection_close_frame_ = frame; | 309 connection_close_frame_ = frame; |
| 310 return true; | 310 return true; |
| 311 } | 311 } |
| 312 | 312 |
| 313 virtual bool OnGoAwayFrame(const QuicGoAwayFrame& frame) OVERRIDE { | 313 virtual bool OnGoAwayFrame(const QuicGoAwayFrame& frame) override { |
| 314 goaway_frame_ = frame; | 314 goaway_frame_ = frame; |
| 315 return true; | 315 return true; |
| 316 } | 316 } |
| 317 | 317 |
| 318 virtual bool OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) | 318 virtual bool OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) |
| 319 OVERRIDE { | 319 override { |
| 320 window_update_frame_ = frame; | 320 window_update_frame_ = frame; |
| 321 return true; | 321 return true; |
| 322 } | 322 } |
| 323 | 323 |
| 324 virtual bool OnBlockedFrame(const QuicBlockedFrame& frame) OVERRIDE { | 324 virtual bool OnBlockedFrame(const QuicBlockedFrame& frame) override { |
| 325 blocked_frame_ = frame; | 325 blocked_frame_ = frame; |
| 326 return true; | 326 return true; |
| 327 } | 327 } |
| 328 | 328 |
| 329 // Counters from the visitor_ callbacks. | 329 // Counters from the visitor_ callbacks. |
| 330 int error_count_; | 330 int error_count_; |
| 331 int version_mismatch_; | 331 int version_mismatch_; |
| 332 int packet_count_; | 332 int packet_count_; |
| 333 int frame_count_; | 333 int frame_count_; |
| 334 int fec_count_; | 334 int fec_count_; |
| (...skipping 4730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5065 EXPECT_CALL(visitor, OnPacketComplete()); | 5065 EXPECT_CALL(visitor, OnPacketComplete()); |
| 5066 EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)).WillOnce(Return(true)); | 5066 EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)).WillOnce(Return(true)); |
| 5067 | 5067 |
| 5068 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 5068 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
| 5069 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 5069 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 5070 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 5070 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 5071 } | 5071 } |
| 5072 | 5072 |
| 5073 } // namespace test | 5073 } // namespace test |
| 5074 } // namespace net | 5074 } // namespace net |
| OLD | NEW |