diff options
author | rch@chromium.org <rch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-23 01:39:30 +0000 |
---|---|---|
committer | rch@chromium.org <rch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-23 01:39:30 +0000 |
commit | ca33c884398cbc1c4d9b658ab07454fbb25e9f1f (patch) | |
tree | f8c53a31da5a527a51ed81ad29d97be6511857fc | |
parent | c64827a67cb5409b4a000951c06e2d01cbc3783e (diff) | |
download | chromium_src-ca33c884398cbc1c4d9b658ab07454fbb25e9f1f.zip chromium_src-ca33c884398cbc1c4d9b658ab07454fbb25e9f1f.tar.gz chromium_src-ca33c884398cbc1c4d9b658ab07454fbb25e9f1f.tar.bz2 |
Land SpdyFramer (et. al.) changes to support setting the credential slot id in SYN_STREAM.
Add credential_slot to BufferedSpdyFramer::CreateSynStream
Review URL: http://codereview.chromium.org/9839013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@128382 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | net/spdy/buffered_spdy_framer.cc | 6 | ||||
-rw-r--r-- | net/spdy/buffered_spdy_framer.h | 1 | ||||
-rw-r--r-- | net/spdy/buffered_spdy_framer_spdy2_unittest.cc | 1 | ||||
-rw-r--r-- | net/spdy/buffered_spdy_framer_spdy3_unittest.cc | 1 | ||||
-rw-r--r-- | net/spdy/spdy_frame_builder.h | 3 | ||||
-rw-r--r-- | net/spdy/spdy_framer.cc | 8 | ||||
-rw-r--r-- | net/spdy/spdy_framer.h | 2 | ||||
-rw-r--r-- | net/spdy/spdy_framer_test.cc | 130 | ||||
-rw-r--r-- | net/spdy/spdy_protocol.h | 15 | ||||
-rw-r--r-- | net/spdy/spdy_protocol_test.cc | 7 | ||||
-rw-r--r-- | net/spdy/spdy_session.cc | 2 | ||||
-rw-r--r-- | net/spdy/spdy_test_util_spdy2.cc | 2 | ||||
-rw-r--r-- | net/spdy/spdy_test_util_spdy3.cc | 2 | ||||
-rw-r--r-- | net/tools/flip_server/spdy_interface.cc | 2 |
14 files changed, 145 insertions, 37 deletions
diff --git a/net/spdy/buffered_spdy_framer.cc b/net/spdy/buffered_spdy_framer.cc index 279d1d7..3160101 100644 --- a/net/spdy/buffered_spdy_framer.cc +++ b/net/spdy/buffered_spdy_framer.cc @@ -172,11 +172,13 @@ SpdySynStreamControlFrame* BufferedSpdyFramer::CreateSynStream( SpdyStreamId stream_id, SpdyStreamId associated_stream_id, int priority, + uint8 credential_slot, SpdyControlFlags flags, bool compressed, const SpdyHeaderBlock* headers) { - return spdy_framer_.CreateSynStream( - stream_id, associated_stream_id, priority, flags, compressed, headers); + return spdy_framer_.CreateSynStream(stream_id, associated_stream_id, priority, + credential_slot, flags, compressed, + headers); } SpdySynReplyControlFrame* BufferedSpdyFramer::CreateSynReply( diff --git a/net/spdy/buffered_spdy_framer.h b/net/spdy/buffered_spdy_framer.h index 726fb0b..4c0a9ce 100644 --- a/net/spdy/buffered_spdy_framer.h +++ b/net/spdy/buffered_spdy_framer.h @@ -111,6 +111,7 @@ class NET_EXPORT_PRIVATE BufferedSpdyFramer SpdySynStreamControlFrame* CreateSynStream(SpdyStreamId stream_id, SpdyStreamId associated_stream_id, int priority, + uint8 credential_slot, SpdyControlFlags flags, bool compressed, const SpdyHeaderBlock* headers); diff --git a/net/spdy/buffered_spdy_framer_spdy2_unittest.cc b/net/spdy/buffered_spdy_framer_spdy2_unittest.cc index 800f28f..fbe97ab 100644 --- a/net/spdy/buffered_spdy_framer_spdy2_unittest.cc +++ b/net/spdy/buffered_spdy_framer_spdy2_unittest.cc @@ -199,6 +199,7 @@ TEST_F(BufferedSpdyFramerSpdy2Test, ReadSynStreamHeaderBlock) { framer.CreateSynStream(1, // stream_id 0, // associated_stream_id 1, // priority + 0, // credential_slot CONTROL_FLAG_NONE, true, // compress &headers)); diff --git a/net/spdy/buffered_spdy_framer_spdy3_unittest.cc b/net/spdy/buffered_spdy_framer_spdy3_unittest.cc index acd0079..933965b 100644 --- a/net/spdy/buffered_spdy_framer_spdy3_unittest.cc +++ b/net/spdy/buffered_spdy_framer_spdy3_unittest.cc @@ -199,6 +199,7 @@ TEST_F(BufferedSpdyFramerSpdy3Test, ReadSynStreamHeaderBlock) { framer.CreateSynStream(1, // stream_id 0, // associated_stream_id 1, // priority + 0, // credential_slot CONTROL_FLAG_NONE, true, // compress &headers)); diff --git a/net/spdy/spdy_frame_builder.h b/net/spdy/spdy_frame_builder.h index c38d11b..a0c1ba7 100644 --- a/net/spdy/spdy_frame_builder.h +++ b/net/spdy/spdy_frame_builder.h @@ -48,6 +48,9 @@ class NET_EXPORT_PRIVATE SpdyFrameBuilder { // Methods for adding to the payload. These values are appended to the end // of the SpdyFrameBuilder payload. Note - binary integers are converted from // host to network form. + bool WriteUInt8(uint8 value) { + return WriteBytes(&value, sizeof(value)); + } bool WriteUInt16(uint16 value) { value = htons(value); return WriteBytes(&value, sizeof(value)); diff --git a/net/spdy/spdy_framer.cc b/net/spdy/spdy_framer.cc index c8b07b8..faa2893 100644 --- a/net/spdy/spdy_framer.cc +++ b/net/spdy/spdy_framer.cc @@ -352,6 +352,7 @@ size_t SpdyFramer::ProcessInput(const char* data, size_t len) { size_t bytes_read = ProcessCredentialFramePayload(data, len); len -= bytes_read; data += bytes_read; + continue; } case SPDY_CONTROL_FRAME_PAYLOAD: { @@ -856,6 +857,8 @@ size_t SpdyFramer::ProcessControlFramePayload(const char* data, size_t len) { } size_t SpdyFramer::ProcessCredentialFramePayload(const char* data, size_t len) { + // Process only up to the end of this CREDENTIAL frame. + len = std::min(len, remaining_control_payload_); bool processed_succesfully = visitor_->OnCredentialFrameData(data, len); remaining_control_payload_ -= len; remaining_data_ -= len; @@ -863,6 +866,7 @@ size_t SpdyFramer::ProcessCredentialFramePayload(const char* data, size_t len) { set_error(SPDY_CREDENTIAL_FRAME_CORRUPT); } else if (remaining_control_payload_ == 0) { visitor_->OnCredentialFrameData(NULL, 0); + CHANGE_STATE(SPDY_AUTO_RESET); } return len; } @@ -1054,6 +1058,7 @@ SpdySynStreamControlFrame* SpdyFramer::CreateSynStream( SpdyStreamId stream_id, SpdyStreamId associated_stream_id, SpdyPriority priority, + uint8 credential_slot, SpdyControlFlags flags, bool compressed, const SpdyHeaderBlock* headers) { @@ -1081,7 +1086,8 @@ SpdySynStreamControlFrame* SpdyFramer::CreateSynStream( priority = GetLowestPriority(); } // Priority is 2 bits for <spdy3, 3 bits otherwise. - frame.WriteUInt16(ntohs(priority) << (spdy_version_ < 3 ? 6 : 5)); + frame.WriteUInt8(priority << ((spdy_version_ < 3) ? 6 : 5)); + frame.WriteUInt8((spdy_version_ < 3) ? 0 : credential_slot); WriteHeaderBlock(&frame, headers); scoped_ptr<SpdySynStreamControlFrame> syn_frame( diff --git a/net/spdy/spdy_framer.h b/net/spdy/spdy_framer.h index bfe4b85..5ebc2f2 100644 --- a/net/spdy/spdy_framer.h +++ b/net/spdy/spdy_framer.h @@ -271,6 +271,7 @@ class NET_EXPORT_PRIVATE SpdyFramer { // |associated_stream_id| is the associated stream id for this stream. // |priority| is the priority (GetHighestPriority()-GetLowestPriority) for // this stream. + // |credential_slot| is the CREDENTIAL slot to be used for this request. // |flags| is the flags to use with the data. // To mark this frame as the last frame, enable CONTROL_FLAG_FIN. // |compressed| specifies whether the frame should be compressed. @@ -278,6 +279,7 @@ class NET_EXPORT_PRIVATE SpdyFramer { SpdySynStreamControlFrame* CreateSynStream(SpdyStreamId stream_id, SpdyStreamId associated_stream_id, SpdyPriority priority, + uint8 credential_slot, SpdyControlFlags flags, bool compressed, const SpdyHeaderBlock* headers); diff --git a/net/spdy/spdy_framer_test.cc b/net/spdy/spdy_framer_test.cc index af47005..1cfa101 100644 --- a/net/spdy/spdy_framer_test.cc +++ b/net/spdy/spdy_framer_test.cc @@ -533,7 +533,13 @@ TEST_P(SpdyFramerTest, HeaderBlockInBuffer) { // Encode the header block into a SynStream frame. scoped_ptr<SpdySynStreamControlFrame> frame( - framer.CreateSynStream(1, 0, 1, CONTROL_FLAG_NONE, false, &headers)); + framer.CreateSynStream(1, // stream id + 0, // associated stream id + 1, // priority + 0, // credential slot + CONTROL_FLAG_NONE, + false, // compress + &headers)); EXPECT_TRUE(frame.get() != NULL); std::string serialized_headers(frame->header_block(), frame->header_block_len()); @@ -556,7 +562,13 @@ TEST_P(SpdyFramerTest, UndersizedHeaderBlockInBuffer) { // Encode the header block into a SynStream frame. scoped_ptr<SpdySynStreamControlFrame> frame( - framer.CreateSynStream(1, 0, 1, CONTROL_FLAG_NONE, false, &headers)); + framer.CreateSynStream(1, // stream id + 0, // associated stream id + 1, // priority + 0, // credential slot + CONTROL_FLAG_NONE, + false, // compress + &headers)); EXPECT_TRUE(frame.get() != NULL); std::string serialized_headers(frame->header_block(), @@ -766,12 +778,22 @@ TEST_P(SpdyFramerTest, BasicCompression) { SpdyFramer framer(spdy_version_); framer.set_enable_compression(true); - scoped_ptr<SpdySynStreamControlFrame> - frame1(framer.CreateSynStream(1, 0, 1, CONTROL_FLAG_NONE, true, - &headers)); - scoped_ptr<SpdySynStreamControlFrame> - frame2(framer.CreateSynStream(1, 0, 1, CONTROL_FLAG_NONE, true, - &headers)); + scoped_ptr<SpdySynStreamControlFrame> frame1( + framer.CreateSynStream(1, // stream id + 0, // associated stream id + 1, // priority + 0, // credential slot + CONTROL_FLAG_NONE, + true, // compress + &headers)); + scoped_ptr<SpdySynStreamControlFrame> frame2( + framer.CreateSynStream(1, // stream id + 0, // associated stream id + 1, // priority + 0, // credential slot + CONTROL_FLAG_NONE, + true, // compress + &headers)); // Expect the second frame to be more compact than the first. EXPECT_LE(frame2->length(), frame1->length()); @@ -792,9 +814,14 @@ TEST_P(SpdyFramerTest, BasicCompression) { // Expect frames 3 to be the same as a uncompressed frame created // from scratch. - scoped_ptr<SpdySynStreamControlFrame> - uncompressed_frame(framer.CreateSynStream(1, 0, 1, CONTROL_FLAG_NONE, - false, &headers)); + scoped_ptr<SpdySynStreamControlFrame> uncompressed_frame( + framer.CreateSynStream(1, // stream id + 0, // associated stream id + 1, // priority + 0, // credential slot + CONTROL_FLAG_NONE, + false, // compress + &headers)); EXPECT_EQ(frame3->length(), uncompressed_frame->length()); EXPECT_EQ(0, memcmp(frame3->data(), uncompressed_frame->data(), @@ -1088,13 +1115,25 @@ TEST_P(SpdyFramerTest, HeaderCompression) { block[kHeader2] = kValue2; SpdyControlFlags flags(CONTROL_FLAG_NONE); scoped_ptr<SpdySynStreamControlFrame> syn_frame_1( - send_framer.CreateSynStream(1, 0, 0, flags, true, &block)); + send_framer.CreateSynStream(1, // stream id + 0, // associated stream id + 0, // priority + 0, // credential slot + flags, + true, // compress + &block)); EXPECT_TRUE(syn_frame_1.get() != NULL); // SYN_STREAM #2 block[kHeader3] = kValue3; scoped_ptr<SpdySynStreamControlFrame> syn_frame_2( - send_framer.CreateSynStream(3, 0, 0, flags, true, &block)); + send_framer.CreateSynStream(3, // stream id + 0, // associated stream id + 0, // priority + 0, // credential slot + flags, + true, // compress + &block)); EXPECT_TRUE(syn_frame_2.get() != NULL); // Now start decompressing @@ -1162,7 +1201,13 @@ TEST_P(SpdyFramerTest, UnclosedStreamDataCompressors) { block[kHeader2] = kValue2; SpdyControlFlags flags(CONTROL_FLAG_NONE); scoped_ptr<SpdyFrame> syn_frame( - send_framer.CreateSynStream(1, 0, 0, flags, true, &block)); + send_framer.CreateSynStream(1, // stream id + 0, // associated stream id + 0, // priority + 0, // credential slot + flags, + true, // compress + &block)); EXPECT_TRUE(syn_frame.get() != NULL); const char bytes[] = "this is a test test test test test!"; @@ -1215,7 +1260,13 @@ TEST_P(SpdyFramerTest, UnclosedStreamDataCompressorsOneByteAtATime) { block[kHeader2] = kValue2; SpdyControlFlags flags(CONTROL_FLAG_NONE); scoped_ptr<SpdyFrame> syn_frame( - send_framer.CreateSynStream(1, 0, 0, flags, true, &block)); + send_framer.CreateSynStream(1, // stream id + 0, // associated stream id + 0, // priority + 0, // credential slot + flags, + true, // compress + &block)); EXPECT_TRUE(syn_frame.get() != NULL); const char bytes[] = "this is a test test test test test!"; @@ -1369,13 +1420,14 @@ TEST_P(SpdyFramerTest, CreateSynStreamUncompressed) { framer.set_enable_compression(false); { - const char kDescription[] = "SYN_STREAM frame, lowest pri, no FIN"; + const char kDescription[] = "SYN_STREAM frame, lowest pri, slot 2, no FIN"; SpdyHeaderBlock headers; headers["bar"] = "foo"; headers["foo"] = "bar"; - const unsigned char kPri = (spdy_version_ != 2) ? 0xE0 : 0xC0; + const unsigned char kPri = (IsSpdy2()) ? 0xC0 : 0xE0; + const unsigned char kCre = (IsSpdy2()) ? 0 : 2; const unsigned char kV2FrameData[] = { 0x80, spdy_version_, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, @@ -1393,7 +1445,7 @@ TEST_P(SpdyFramerTest, CreateSynStreamUncompressed) { 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, - kPri, 0x00, 0x00, 0x00, + kPri, kCre, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 'b', 'a', 'r', 0x00, 0x00, 0x00, @@ -1403,8 +1455,14 @@ TEST_P(SpdyFramerTest, CreateSynStreamUncompressed) { 0x00, 0x00, 0x03, 'b', 'a', 'r' }; - scoped_ptr<SpdySynStreamControlFrame> frame(framer.CreateSynStream( - 1, 0, framer.GetLowestPriority(), CONTROL_FLAG_NONE, false, &headers)); + scoped_ptr<SpdySynStreamControlFrame> frame( + framer.CreateSynStream(1, // stream id + 0, // associated stream id + framer.GetLowestPriority(), + kCre, // credential slot + CONTROL_FLAG_NONE, + false, // compress + &headers)); CompareFrame(kDescription, *frame, IsSpdy2() ? kV2FrameData : kV3FrameData, @@ -1447,9 +1505,14 @@ TEST_P(SpdyFramerTest, CreateSynStreamUncompressed) { 0x00, 0x00, 0x00, 0x03, 'b', 'a', 'r' }; - scoped_ptr<SpdyFrame> frame(framer.CreateSynStream( - 0x7fffffff, 0x7fffffff, framer.GetHighestPriority(), CONTROL_FLAG_FIN, - false, &headers)); + scoped_ptr<SpdyFrame> frame( + framer.CreateSynStream(0x7fffffff, // stream id + 0x7fffffff, // associated stream id + framer.GetHighestPriority(), + 0, // credential slot + CONTROL_FLAG_FIN, + false, // compress + &headers)); CompareFrame(kDescription, *frame, IsSpdy2() ? kV2FrameData : kV3FrameData, @@ -1492,8 +1555,14 @@ TEST_P(SpdyFramerTest, CreateSynStreamUncompressed) { 'f', 'o', 'o', 0x00, 0x00, 0x00, 0x00 }; - scoped_ptr<SpdyFrame> frame(framer.CreateSynStream( - 0x7fffffff, 0x7fffffff, 1, CONTROL_FLAG_FIN, false, &headers)); + scoped_ptr<SpdyFrame> frame( + framer.CreateSynStream(0x7fffffff, // stream id + 0x7fffffff, // associated stream id + 1, // priority + 0, // credential slot + CONTROL_FLAG_FIN, + false, // compress + &headers)); CompareFrame(kDescription, *frame, IsSpdy2() ? kV2FrameData : kV3FrameData, @@ -1542,8 +1611,14 @@ TEST_P(SpdyFramerTest, CreateSynStreamCompressed) { 0x28, 0x08, 0x00, 0x00, 0x00, 0xFF, 0xFF }; - scoped_ptr<SpdyFrame> frame(framer.CreateSynStream( - 1, 0, priority, CONTROL_FLAG_NONE, true, &headers)); + scoped_ptr<SpdyFrame> frame( + framer.CreateSynStream(1, // stream id + 0, // associated stream id + priority, + 0, // credential slot + CONTROL_FLAG_NONE, + true, // compress + &headers)); CompareFrame(kDescription, *frame, IsSpdy2() ? kV2FrameData : kV3FrameData, @@ -2207,6 +2282,7 @@ TEST_P(SpdyFramerTest, ExpandBuffer_HeapSmash) { framer.CreateSynStream(1, // stream_id 0, // associated_stream_id 1, // priority + 0, // credential slot CONTROL_FLAG_NONE, false, // compress &headers)); diff --git a/net/spdy/spdy_protocol.h b/net/spdy/spdy_protocol.h index fa00d54..81562a56 100644 --- a/net/spdy/spdy_protocol.h +++ b/net/spdy/spdy_protocol.h @@ -487,7 +487,7 @@ struct SpdySynStreamControlFrameBlock : SpdyFrameBlock { SpdyStreamId stream_id_; SpdyStreamId associated_stream_id_; SpdyPriority priority_; - uint8 unused_; + uint8 credential_slot_; }; // A SYN_REPLY Control Frame structure. @@ -731,6 +731,19 @@ class SpdySynStreamControlFrame : public SpdyControlFrame { } } + uint8 credential_slot() const { + if (version() < 3) { + return 0; + } else { + return block()->credential_slot_; + } + } + + void set_credential_slot(uint8 credential_slot) { + DCHECK(version() >= 3); + mutable_block()->credential_slot_ = credential_slot; + } + // The number of bytes in the header block beyond the frame header length. int header_block_len() const { return length() - (size() - SpdyFrame::kHeaderSize); diff --git a/net/spdy/spdy_protocol_test.cc b/net/spdy/spdy_protocol_test.cc index 8362be9..c955d3b 100644 --- a/net/spdy/spdy_protocol_test.cc +++ b/net/spdy/spdy_protocol_test.cc @@ -92,14 +92,17 @@ TEST_P(SpdyProtocolTest, ControlFrameStructs) { SpdyFramer framer(spdy_version_); SpdyHeaderBlock headers; - scoped_ptr<SpdySynStreamControlFrame> syn_frame( - framer.CreateSynStream(123, 456, 2, CONTROL_FLAG_FIN, false, &headers)); + const uint8 credential_slot = (IsSpdy2()) ? 0 : 5; + + scoped_ptr<SpdySynStreamControlFrame> syn_frame(framer.CreateSynStream( + 123, 456, 2, credential_slot, CONTROL_FLAG_FIN, false, &headers)); EXPECT_EQ(framer.protocol_version(), syn_frame->version()); EXPECT_TRUE(syn_frame->is_control_frame()); EXPECT_EQ(SYN_STREAM, syn_frame->type()); EXPECT_EQ(123u, syn_frame->stream_id()); EXPECT_EQ(456u, syn_frame->associated_stream_id()); EXPECT_EQ(2u, syn_frame->priority()); + EXPECT_EQ(credential_slot, syn_frame->credential_slot()); EXPECT_EQ(IsSpdy2() ? 2 : 4, syn_frame->header_block_len()); EXPECT_EQ(1u, syn_frame->flags()); syn_frame->set_associated_stream_id(999u); diff --git a/net/spdy/spdy_session.cc b/net/spdy/spdy_session.cc index 7767e4f..af44065 100644 --- a/net/spdy/spdy_session.cc +++ b/net/spdy/spdy_session.cc @@ -631,7 +631,7 @@ int SpdySession::WriteSynStream( scoped_ptr<SpdySynStreamControlFrame> syn_frame( buffered_spdy_framer_->CreateSynStream( stream_id, 0, - ConvertRequestPriorityToSpdyPriority(priority), + ConvertRequestPriorityToSpdyPriority(priority), 0, flags, false, headers.get())); QueueFrame(syn_frame.get(), priority, stream); diff --git a/net/spdy/spdy_test_util_spdy2.cc b/net/spdy/spdy_test_util_spdy2.cc index a4706a7..30d2f1b 100644 --- a/net/spdy/spdy_test_util_spdy2.cc +++ b/net/spdy/spdy_test_util_spdy2.cc @@ -167,7 +167,7 @@ SpdyFrame* ConstructSpdyPacket(const SpdyHeaderInfo& header_info, switch (header_info.kind) { case SYN_STREAM: frame = framer.CreateSynStream(header_info.id, header_info.assoc_id, - header_info.priority, + header_info.priority, 0, header_info.control_flags, header_info.compressed, &headers); break; diff --git a/net/spdy/spdy_test_util_spdy3.cc b/net/spdy/spdy_test_util_spdy3.cc index 81d3c3f..798b098 100644 --- a/net/spdy/spdy_test_util_spdy3.cc +++ b/net/spdy/spdy_test_util_spdy3.cc @@ -167,7 +167,7 @@ SpdyFrame* ConstructSpdyPacket(const SpdyHeaderInfo& header_info, switch (header_info.kind) { case SYN_STREAM: frame = framer.CreateSynStream(header_info.id, header_info.assoc_id, - header_info.priority, + header_info.priority, 0, header_info.control_flags, header_info.compressed, &headers); break; diff --git a/net/tools/flip_server/spdy_interface.cc b/net/tools/flip_server/spdy_interface.cc index 6ef3a2d..385cc26 100644 --- a/net/tools/flip_server/spdy_interface.cc +++ b/net/tools/flip_server/spdy_interface.cc @@ -423,7 +423,7 @@ size_t SpdySM::SendSynStreamImpl(uint32 stream_id, CopyHeaders(block, headers); SpdySynStreamControlFrame* fsrcf = buffered_spdy_framer_->CreateSynStream( - stream_id, 0, 0, CONTROL_FLAG_NONE, true, &block); + stream_id, 0, 0, 0, CONTROL_FLAG_NONE, true, &block); size_t df_size = fsrcf->length() + SpdyFrame::kHeaderSize; EnqueueDataFrame(new SpdyFrameDataFrame(fsrcf)); |