diff options
Diffstat (limited to 'net')
53 files changed, 590 insertions, 458 deletions
diff --git a/net/net.gypi b/net/net.gypi index 05cfef9..d469ebd 100644 --- a/net/net.gypi +++ b/net/net.gypi @@ -970,6 +970,8 @@ 'quic/quic_session.h', 'quic/quic_socket_address_coder.cc', 'quic/quic_socket_address_coder.h', + 'quic/quic_spdy_session.cc', + 'quic/quic_spdy_session.h', 'quic/quic_stream_factory.cc', 'quic/quic_stream_factory.h', 'quic/quic_stream_sequencer.cc', @@ -1609,6 +1611,8 @@ 'quic/test_tools/quic_sent_packet_manager_peer.h', 'quic/test_tools/quic_session_peer.cc', 'quic/test_tools/quic_session_peer.h', + 'quic/test_tools/quic_spdy_session_peer.cc', + 'quic/test_tools/quic_spdy_session_peer.h', 'quic/test_tools/quic_stream_sequencer_peer.cc', 'quic/test_tools/quic_stream_sequencer_peer.h', 'quic/test_tools/quic_sustained_bandwidth_recorder_peer.cc', diff --git a/net/quic/quic_client_session.cc b/net/quic/quic_client_session.cc index 72dc6af..9caf71a 100644 --- a/net/quic/quic_client_session.cc +++ b/net/quic/quic_client_session.cc @@ -203,18 +203,17 @@ QuicClientSession::QuicClientSession( } QuicClientSession::~QuicClientSession() { - if (!streams()->empty()) + if (!dynamic_streams().empty()) RecordUnexpectedOpenStreams(DESTRUCTOR); if (!observers_.empty()) RecordUnexpectedObservers(DESTRUCTOR); if (!going_away_) RecordUnexpectedNotGoingAway(DESTRUCTOR); - while (!streams()->empty() || - !observers_.empty() || + while (!dynamic_streams().empty() || !observers_.empty() || !stream_requests_.empty()) { // The session must be closed before it is destroyed. - DCHECK(streams()->empty()); + DCHECK(dynamic_streams().empty()); CloseAllStreams(ERR_UNEXPECTED); DCHECK(observers_.empty()); CloseAllObservers(ERR_UNEXPECTED); @@ -400,7 +399,7 @@ void QuicClientSession::CancelRequest(StreamRequest* request) { } } -QuicReliableClientStream* QuicClientSession::CreateOutgoingDataStream() { +QuicReliableClientStream* QuicClientSession::CreateOutgoingDynamicStream() { if (!crypto_stream_->encryption_established()) { DVLOG(1) << "Encryption not active so no outgoing stream created."; return nullptr; @@ -552,7 +551,7 @@ bool QuicClientSession::CanPool(const std::string& hostname, server_id_.host(), hostname); } -QuicDataStream* QuicClientSession::CreateIncomingDataStream( +QuicDataStream* QuicClientSession::CreateIncomingDynamicStream( QuicStreamId id) { DLOG(ERROR) << "Server push not supported"; return nullptr; @@ -730,7 +729,7 @@ void QuicClientSession::OnConnectionClosed(QuicErrorCode error, } socket_->Close(); QuicSession::OnConnectionClosed(error, from_peer); - DCHECK(streams()->empty()); + DCHECK(dynamic_streams().empty()); CloseAllStreams(ERR_UNEXPECTED); CloseAllObservers(ERR_UNEXPECTED); NotifyFactoryOfSessionClosedLater(); @@ -811,8 +810,8 @@ void QuicClientSession::CloseSessionOnErrorInner(int net_error, } void QuicClientSession::CloseAllStreams(int net_error) { - while (!streams()->empty()) { - ReliableQuicStream* stream = streams()->begin()->second; + while (!dynamic_streams().empty()) { + ReliableQuicStream* stream = dynamic_streams().begin()->second; QuicStreamId id = stream->id(); static_cast<QuicReliableClientStream*>(stream)->OnError(net_error); CloseStream(id); @@ -833,10 +832,9 @@ scoped_ptr<base::Value> QuicClientSession::GetInfoAsValue( dict->SetString("version", QuicVersionToString(connection()->version())); dict->SetInteger("open_streams", GetNumOpenStreams()); scoped_ptr<base::ListValue> stream_list(new base::ListValue()); - for (base::hash_map<QuicStreamId, QuicDataStream*>::const_iterator it - = streams()->begin(); - it != streams()->end(); - ++it) { + for (base::hash_map<QuicStreamId, ReliableQuicStream*>::const_iterator it = + dynamic_streams().begin(); + it != dynamic_streams().end(); ++it) { stream_list->Append(new base::StringValue( base::Uint64ToString(it->second->id()))); } @@ -893,7 +891,7 @@ void QuicClientSession::NotifyFactoryOfSessionGoingAway() { } void QuicClientSession::NotifyFactoryOfSessionClosedLater() { - if (!streams()->empty()) + if (!dynamic_streams().empty()) RecordUnexpectedOpenStreams(NOTIFY_FACTORY_OF_SESSION_CLOSED_LATER); if (!going_away_) @@ -908,7 +906,7 @@ void QuicClientSession::NotifyFactoryOfSessionClosedLater() { } void QuicClientSession::NotifyFactoryOfSessionClosed() { - if (!streams()->empty()) + if (!dynamic_streams().empty()) RecordUnexpectedOpenStreams(NOTIFY_FACTORY_OF_SESSION_CLOSED); if (!going_away_) diff --git a/net/quic/quic_client_session.h b/net/quic/quic_client_session.h index fe7033d..d8b35a8 100644 --- a/net/quic/quic_client_session.h +++ b/net/quic/quic_client_session.h @@ -125,7 +125,7 @@ class NET_EXPORT_PRIVATE QuicClientSession : public QuicClientSessionBase, // QuicSession methods: void OnStreamFrames(const std::vector<QuicStreamFrame>& frames) override; - QuicReliableClientStream* CreateOutgoingDataStream() override; + QuicReliableClientStream* CreateOutgoingDynamicStream() override; QuicCryptoClientStream* GetCryptoStream() override; void CloseStream(QuicStreamId stream_id) override; void SendRstStream(QuicStreamId id, @@ -195,7 +195,7 @@ class NET_EXPORT_PRIVATE QuicClientSession : public QuicClientSessionBase, protected: // QuicSession methods: - QuicDataStream* CreateIncomingDataStream(QuicStreamId id) override; + QuicDataStream* CreateIncomingDynamicStream(QuicStreamId id) override; private: friend class test::QuicClientSessionPeer; diff --git a/net/quic/quic_client_session_base.cc b/net/quic/quic_client_session_base.cc index 40d4b86..12173e5 100644 --- a/net/quic/quic_client_session_base.cc +++ b/net/quic/quic_client_session_base.cc @@ -8,10 +8,10 @@ namespace net { -QuicClientSessionBase::QuicClientSessionBase( - QuicConnection* connection, - const QuicConfig& config) - : QuicSession(connection, config) {} +QuicClientSessionBase::QuicClientSessionBase(QuicConnection* connection, + const QuicConfig& config) + : QuicSpdySession(connection, config) { +} QuicClientSessionBase::~QuicClientSessionBase() {} @@ -27,7 +27,7 @@ void QuicClientSessionBase::OnCryptoHandshakeEvent(CryptoHandshakeEvent event) { } // kFHDR config maps to FEC protection always for headers stream. // TODO(jri): Add crypto stream in addition to headers for kHDR. - headers_stream_->set_fec_policy(FEC_PROTECT_ALWAYS); + headers_stream()->set_fec_policy(FEC_PROTECT_ALWAYS); } } // namespace net diff --git a/net/quic/quic_client_session_base.h b/net/quic/quic_client_session_base.h index d72996c..0e3c0fa 100644 --- a/net/quic/quic_client_session_base.h +++ b/net/quic/quic_client_session_base.h @@ -6,12 +6,12 @@ #define NET_QUIC_QUIC_CLIENT_SESSION_BASE_H_ #include "net/quic/quic_crypto_client_stream.h" -#include "net/quic/quic_session.h" +#include "net/quic/quic_spdy_session.h" namespace net { // Base class for all client-specific QuicSession subclasses. -class NET_EXPORT_PRIVATE QuicClientSessionBase : public QuicSession { +class NET_EXPORT_PRIVATE QuicClientSessionBase : public QuicSpdySession { public: QuicClientSessionBase(QuicConnection* connection, const QuicConfig& config); diff --git a/net/quic/quic_client_session_test.cc b/net/quic/quic_client_session_test.cc index 4c3179f..6bd6e28 100644 --- a/net/quic/quic_client_session_test.cc +++ b/net/quic/quic_client_session_test.cc @@ -23,6 +23,7 @@ #include "net/quic/crypto/quic_server_info.h" #include "net/quic/test_tools/crypto_test_utils.h" #include "net/quic/test_tools/quic_client_session_peer.h" +#include "net/quic/test_tools/quic_spdy_session_peer.h" #include "net/quic/test_tools/quic_test_utils.h" #include "net/quic/test_tools/simple_quic_framer.h" #include "net/socket/socket_test_util.h" @@ -109,15 +110,15 @@ TEST_P(QuicClientSessionTest, MaxNumStreams) { std::vector<QuicReliableClientStream*> streams; for (size_t i = 0; i < kDefaultMaxStreamsPerConnection; i++) { - QuicReliableClientStream* stream = session_.CreateOutgoingDataStream(); + QuicReliableClientStream* stream = session_.CreateOutgoingDynamicStream(); EXPECT_TRUE(stream); streams.push_back(stream); } - EXPECT_FALSE(session_.CreateOutgoingDataStream()); + EXPECT_FALSE(session_.CreateOutgoingDynamicStream()); // Close a stream and ensure I can now open a new one. session_.CloseStream(streams[0]->id()); - EXPECT_TRUE(session_.CreateOutgoingDataStream()); + EXPECT_TRUE(session_.CreateOutgoingDynamicStream()); } TEST_P(QuicClientSessionTest, MaxNumStreamsViaRequest) { @@ -125,7 +126,7 @@ TEST_P(QuicClientSessionTest, MaxNumStreamsViaRequest) { std::vector<QuicReliableClientStream*> streams; for (size_t i = 0; i < kDefaultMaxStreamsPerConnection; i++) { - QuicReliableClientStream* stream = session_.CreateOutgoingDataStream(); + QuicReliableClientStream* stream = session_.CreateOutgoingDynamicStream(); EXPECT_TRUE(stream); streams.push_back(stream); } @@ -150,7 +151,7 @@ TEST_P(QuicClientSessionTest, GoAwayReceived) { // After receiving a GoAway, I should no longer be able to create outgoing // streams. session_.OnGoAway(QuicGoAwayFrame(QUIC_PEER_GOING_AWAY, 1u, "Going away.")); - EXPECT_EQ(nullptr, session_.CreateOutgoingDataStream()); + EXPECT_EQ(nullptr, session_.CreateOutgoingDynamicStream()); } TEST_P(QuicClientSessionTest, CanPool) { diff --git a/net/quic/quic_connection.cc b/net/quic/quic_connection.cc index 95d0e48..e18166e 100644 --- a/net/quic/quic_connection.cc +++ b/net/quic/quic_connection.cc @@ -2101,7 +2101,7 @@ void QuicConnection::SetPingAlarm() { // Only clients send pings. return; } - if (!visitor_->HasOpenDataStreams()) { + if (!visitor_->HasOpenDynamicStreams()) { ping_alarm_->Cancel(); // Don't send a ping unless there are open streams. return; diff --git a/net/quic/quic_connection.h b/net/quic/quic_connection.h index 7e49127..134d126 100644 --- a/net/quic/quic_connection.h +++ b/net/quic/quic_connection.h @@ -113,7 +113,7 @@ class NET_EXPORT_PRIVATE QuicConnectionVisitorInterface { // Called to ask if any streams are open in this visitor, excluding the // reserved crypto and headers stream. - virtual bool HasOpenDataStreams() const = 0; + virtual bool HasOpenDynamicStreams() const = 0; }; // Interface which gets callbacks from the QuicConnection at interesting diff --git a/net/quic/quic_connection_logger.cc b/net/quic/quic_connection_logger.cc index ae6a264..b1e8c56 100644 --- a/net/quic/quic_connection_logger.cc +++ b/net/quic/quic_connection_logger.cc @@ -281,7 +281,7 @@ AddressFamily GetRealAddressFamily(const IPAddressNumber& address) { } // namespace QuicConnectionLogger::QuicConnectionLogger( - QuicSession* session, + QuicSpdySession* session, const char* const connection_description, const BoundNetLog& net_log) : net_log_(net_log), diff --git a/net/quic/quic_connection_logger.h b/net/quic/quic_connection_logger.h index 4812596..6e81e217 100644 --- a/net/quic/quic_connection_logger.h +++ b/net/quic/quic_connection_logger.h @@ -12,7 +12,7 @@ #include "net/log/net_log.h" #include "net/quic/quic_connection.h" #include "net/quic/quic_protocol.h" -#include "net/quic/quic_session.h" +#include "net/quic/quic_spdy_session.h" namespace net { namespace test { @@ -27,7 +27,7 @@ class CertVerifyResult; class NET_EXPORT_PRIVATE QuicConnectionLogger : public QuicConnectionDebugVisitor { public: - QuicConnectionLogger(QuicSession* session, + QuicConnectionLogger(QuicSpdySession* session, const char* const connection_description, const BoundNetLog& net_log); @@ -118,7 +118,7 @@ class NET_EXPORT_PRIVATE QuicConnectionLogger void RecordLossHistograms() const; BoundNetLog net_log_; - QuicSession* session_; // Unowned. + QuicSpdySession* session_; // Unowned. // The last packet sequence number received. QuicPacketSequenceNumber last_received_packet_sequence_number_; // The size of the most recently received packet. diff --git a/net/quic/quic_connection_logger_unittest.cc b/net/quic/quic_connection_logger_unittest.cc index 9f14a09e..8bdb78e 100644 --- a/net/quic/quic_connection_logger_unittest.cc +++ b/net/quic/quic_connection_logger_unittest.cc @@ -36,7 +36,7 @@ class QuicConnectionLoggerTest : public ::testing::Test { logger_(&session_, "CONNECTION_UNKNOWN", net_log_) {} BoundNetLog net_log_; - MockSession session_; + MockQuicSpdySession session_; QuicConnectionLogger logger_; }; diff --git a/net/quic/quic_connection_test.cc b/net/quic/quic_connection_test.cc index 53bbd30..d587bca 100644 --- a/net/quic/quic_connection_test.cc +++ b/net/quic/quic_connection_test.cc @@ -638,7 +638,8 @@ class QuicConnectionTest : public ::testing::TestWithParam<QuicVersion> { EXPECT_CALL(visitor_, WillingAndAbleToWrite()).Times(AnyNumber()); EXPECT_CALL(visitor_, HasPendingHandshake()).Times(AnyNumber()); EXPECT_CALL(visitor_, OnCanWrite()).Times(AnyNumber()); - EXPECT_CALL(visitor_, HasOpenDataStreams()).WillRepeatedly(Return(false)); + EXPECT_CALL(visitor_, HasOpenDynamicStreams()) + .WillRepeatedly(Return(false)); EXPECT_CALL(visitor_, OnCongestionWindowChange(_)).Times(AnyNumber()); EXPECT_CALL(*loss_algorithm_, GetLossTimeout()) @@ -3122,7 +3123,7 @@ TEST_P(QuicConnectionTest, OverallTimeout) { TEST_P(QuicConnectionTest, PingAfterSend) { EXPECT_TRUE(connection_.connected()); - EXPECT_CALL(visitor_, HasOpenDataStreams()).WillRepeatedly(Return(true)); + EXPECT_CALL(visitor_, HasOpenDynamicStreams()).WillRepeatedly(Return(true)); EXPECT_FALSE(connection_.GetPingAlarm()->IsSet()); // Advance to 5ms, and send a packet to the peer, which will set @@ -3155,7 +3156,7 @@ TEST_P(QuicConnectionTest, PingAfterSend) { ASSERT_EQ(1u, writer_->ping_frames().size()); writer_->Reset(); - EXPECT_CALL(visitor_, HasOpenDataStreams()).WillRepeatedly(Return(false)); + EXPECT_CALL(visitor_, HasOpenDynamicStreams()).WillRepeatedly(Return(false)); clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); SendAckPacketToPeer(); diff --git a/net/quic/quic_crypto_client_stream_test.cc b/net/quic/quic_crypto_client_stream_test.cc index 2dcf783..72bf40f 100644 --- a/net/quic/quic_crypto_client_stream_test.cc +++ b/net/quic/quic_crypto_client_stream_test.cc @@ -39,8 +39,8 @@ class QuicCryptoClientStreamTest : public ::testing::Test { // Advance the time, because timers do not like uninitialized times. connection_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); - session_.reset(new TestClientSession(connection_, DefaultQuicConfig(), - server_id_, &crypto_config_)); + session_.reset(new TestQuicSpdyClientSession( + connection_, DefaultQuicConfig(), server_id_, &crypto_config_)); } void CompleteCryptoHandshake() { @@ -56,7 +56,7 @@ class QuicCryptoClientStreamTest : public ::testing::Test { QuicCryptoClientStream* stream() { return session_->GetCryptoStream(); } PacketSavingConnection* connection_; - scoped_ptr<TestClientSession> session_; + scoped_ptr<TestQuicSpdyClientSession> session_; QuicServerId server_id_; CryptoHandshakeMessage message_; scoped_ptr<QuicData> message_data_; @@ -204,7 +204,7 @@ class QuicCryptoClientStreamStatelessTest : public ::testing::Test { : server_crypto_config_(QuicCryptoServerConfig::TESTING, QuicRandom::GetInstance()), server_id_(kServerHostname, kServerPort, false, PRIVACY_MODE_DISABLED) { - TestClientSession* client_session = nullptr; + TestQuicSpdyClientSession* client_session = nullptr; CreateClientSessionForTest(server_id_, /* supports_stateless_rejects= */ true, QuicTime::Delta::FromSeconds(100000), @@ -227,7 +227,7 @@ class QuicCryptoClientStreamStatelessTest : public ::testing::Test { // Initializes the server_stream_ for stateless rejects. void InitializeFakeStatelessRejectServer() { - TestServerSession* server_session = nullptr; + TestQuicSpdyServerSession* server_session = nullptr; CreateServerSessionForTest(server_id_, QuicTime::Delta::FromSeconds(100000), &server_crypto_config_, &server_connection_, &server_session); @@ -241,12 +241,12 @@ class QuicCryptoClientStreamStatelessTest : public ::testing::Test { // Client crypto stream state PacketSavingConnection* client_connection_; - scoped_ptr<TestClientSession> client_session_; + scoped_ptr<TestQuicSpdyClientSession> client_session_; QuicCryptoClientConfig client_crypto_config_; // Server crypto stream state PacketSavingConnection* server_connection_; - scoped_ptr<TestServerSession> server_session_; + scoped_ptr<TestQuicSpdyServerSession> server_session_; QuicCryptoServerConfig server_crypto_config_; QuicServerId server_id_; }; diff --git a/net/quic/quic_crypto_server_stream_test.cc b/net/quic/quic_crypto_server_stream_test.cc index f47c03b..aa3828b 100644 --- a/net/quic/quic_crypto_server_stream_test.cc +++ b/net/quic/quic_crypto_server_stream_test.cc @@ -95,7 +95,7 @@ class QuicCryptoServerStreamTest : public ::testing::TestWithParam<bool> { // Initializes the crypto server stream state for testing. May be // called multiple times. void InitializeServer() { - TestServerSession* server_session = nullptr; + TestQuicSpdyServerSession* server_session = nullptr; CreateServerSessionForTest(server_id_, QuicTime::Delta::FromSeconds(100000), &server_crypto_config_, &server_connection_, &server_session); @@ -117,7 +117,7 @@ class QuicCryptoServerStreamTest : public ::testing::TestWithParam<bool> { // Initializes a fake client, and all its associated state, for // testing. May be called multiple times. void InitializeFakeClient(bool supports_stateless_rejects) { - TestClientSession* client_session = nullptr; + TestQuicSpdyClientSession* client_session = nullptr; CreateClientSessionForTest(server_id_, supports_stateless_rejects, QuicTime::Delta::FromSeconds(100000), &client_crypto_config_, &client_connection_, @@ -157,14 +157,14 @@ class QuicCryptoServerStreamTest : public ::testing::TestWithParam<bool> { protected: // Server state PacketSavingConnection* server_connection_; - scoped_ptr<TestServerSession> server_session_; + scoped_ptr<TestQuicSpdyServerSession> server_session_; QuicCryptoServerConfig server_crypto_config_; QuicServerId server_id_; // Client state PacketSavingConnection* client_connection_; QuicCryptoClientConfig client_crypto_config_; - scoped_ptr<TestClientSession> client_session_; + scoped_ptr<TestQuicSpdyClientSession> client_session_; CryptoHandshakeMessage message_; scoped_ptr<QuicData> message_data_; diff --git a/net/quic/quic_crypto_stream_test.cc b/net/quic/quic_crypto_stream_test.cc index 8c83e92..5d70019 100644 --- a/net/quic/quic_crypto_stream_test.cc +++ b/net/quic/quic_crypto_stream_test.cc @@ -62,7 +62,7 @@ class QuicCryptoStreamTest : public ::testing::Test { protected: MockConnection* connection_; - MockSession session_; + MockQuicSpdySession session_; MockQuicCryptoStream stream_; CryptoHandshakeMessage message_; scoped_ptr<QuicData> message_data_; diff --git a/net/quic/quic_data_stream.cc b/net/quic/quic_data_stream.cc index 3701327..56622de 100644 --- a/net/quic/quic_data_stream.cc +++ b/net/quic/quic_data_stream.cc @@ -5,7 +5,7 @@ #include "net/quic/quic_data_stream.h" #include "base/logging.h" -#include "net/quic/quic_session.h" +#include "net/quic/quic_spdy_session.h" #include "net/quic/quic_utils.h" #include "net/quic/quic_write_blocked_list.h" @@ -28,8 +28,9 @@ QuicPriority kDefaultPriority = 3; } // namespace -QuicDataStream::QuicDataStream(QuicStreamId id, QuicSession* session) - : ReliableQuicStream(id, session), +QuicDataStream::QuicDataStream(QuicStreamId id, QuicSpdySession* spdy_session) + : ReliableQuicStream(id, spdy_session), + spdy_session_(spdy_session), visitor_(nullptr), headers_decompressed_(false), priority_(kDefaultPriority) { @@ -46,7 +47,7 @@ size_t QuicDataStream::WriteHeaders( const SpdyHeaderBlock& header_block, bool fin, QuicAckNotifier::DelegateInterface* ack_notifier_delegate) { - size_t bytes_written = session()->WriteHeaders( + size_t bytes_written = spdy_session_->WriteHeaders( id(), header_block, fin, priority_, ack_notifier_delegate); if (fin) { // TODO(rch): Add test to ensure fin_sent_ is set whenever a fin is sent. diff --git a/net/quic/quic_data_stream.h b/net/quic/quic_data_stream.h index 496145c..64ef45c 100644 --- a/net/quic/quic_data_stream.h +++ b/net/quic/quic_data_stream.h @@ -32,9 +32,9 @@ class QuicDataStreamPeer; class ReliableQuicStreamPeer; } // namespace test -class QuicSession; +class QuicSpdySession; -// All this does right now is send data to subclasses via the sequencer. +// A QUIC data stream that can also send and receive headers. class NET_EXPORT_PRIVATE QuicDataStream : public ReliableQuicStream { public: // Visitor receives callbacks from the stream. @@ -52,8 +52,7 @@ class NET_EXPORT_PRIVATE QuicDataStream : public ReliableQuicStream { DISALLOW_COPY_AND_ASSIGN(Visitor); }; - QuicDataStream(QuicStreamId id, QuicSession* session); - + QuicDataStream(QuicStreamId id, QuicSpdySession* spdy_session); ~QuicDataStream() override; // ReliableQuicStream implementation @@ -122,8 +121,10 @@ class NET_EXPORT_PRIVATE QuicDataStream : public ReliableQuicStream { bool FinishedReadingHeaders(); + QuicSpdySession* spdy_session_; + Visitor* visitor_; - // True if the headers have been completely decompresssed. + // True if the headers have been completely decompressed. bool headers_decompressed_; // The priority of the stream, once parsed. QuicPriority priority_; diff --git a/net/quic/quic_data_stream_test.cc b/net/quic/quic_data_stream_test.cc index bafde2f..3cd89c4 100644 --- a/net/quic/quic_data_stream_test.cc +++ b/net/quic/quic_data_stream_test.cc @@ -35,7 +35,7 @@ const bool kShouldProcessData = true; class TestStream : public QuicDataStream { public: TestStream(QuicStreamId id, - QuicSession* session, + QuicSpdySession* session, bool should_process_data) : QuicDataStream(id, session), should_process_data_(should_process_data) {} @@ -93,7 +93,7 @@ class QuicDataStreamTest : public ::testing::TestWithParam<QuicVersion> { void Initialize(bool stream_should_process_data) { connection_ = new testing::StrictMock<MockConnection>( Perspective::IS_SERVER, SupportedVersions(GetParam())); - session_.reset(new testing::StrictMock<MockSession>(connection_)); + session_.reset(new testing::StrictMock<MockQuicSpdySession>(connection_)); stream_.reset(new TestStream(kClientDataStreamId1, session_.get(), stream_should_process_data)); stream2_.reset(new TestStream(kClientDataStreamId2, session_.get(), @@ -104,7 +104,7 @@ class QuicDataStreamTest : public ::testing::TestWithParam<QuicVersion> { protected: MockConnection* connection_; - scoped_ptr<MockSession> session_; + scoped_ptr<MockQuicSpdySession> session_; scoped_ptr<TestStream> stream_; scoped_ptr<TestStream> stream2_; SpdyHeaderBlock headers_; diff --git a/net/quic/quic_headers_stream.cc b/net/quic/quic_headers_stream.cc index f1d972c..3fbb876 100644 --- a/net/quic/quic_headers_stream.cc +++ b/net/quic/quic_headers_stream.cc @@ -5,7 +5,7 @@ #include "net/quic/quic_headers_stream.h" #include "base/strings/stringprintf.h" -#include "net/quic/quic_session.h" +#include "net/quic/quic_spdy_session.h" using base::StringPiece; using std::string; @@ -169,8 +169,9 @@ class QuicHeadersStream::SpdyFramerVisitor DISALLOW_COPY_AND_ASSIGN(SpdyFramerVisitor); }; -QuicHeadersStream::QuicHeadersStream(QuicSession* session) +QuicHeadersStream::QuicHeadersStream(QuicSpdySession* session) : ReliableQuicStream(kHeadersStreamId, session), + spdy_session_(session), stream_id_(kInvalidStreamId), fin_(false), frame_len_(0), @@ -223,7 +224,7 @@ void QuicHeadersStream::OnSynStream(SpdyStreamId stream_id, DCHECK_EQ(kInvalidStreamId, stream_id_); stream_id_ = stream_id; fin_ = fin; - session()->OnStreamHeadersPriority(stream_id, priority); + spdy_session_->OnStreamHeadersPriority(stream_id, priority); } void QuicHeadersStream::OnSynReply(SpdyStreamId stream_id, bool fin) { @@ -245,13 +246,13 @@ void QuicHeadersStream::OnControlFrameHeaderData(SpdyStreamId stream_id, if (len == 0) { DCHECK_NE(0u, stream_id_); DCHECK_NE(0u, frame_len_); - session()->OnStreamHeadersComplete(stream_id_, fin_, frame_len_); + spdy_session_->OnStreamHeadersComplete(stream_id_, fin_, frame_len_); // Reset state for the next frame. stream_id_ = kInvalidStreamId; fin_ = false; frame_len_ = 0; } else { - session()->OnStreamHeaders(stream_id_, StringPiece(header_data, len)); + spdy_session_->OnStreamHeaders(stream_id_, StringPiece(header_data, len)); } } diff --git a/net/quic/quic_headers_stream.h b/net/quic/quic_headers_stream.h index a918473..4e23a8f 100644 --- a/net/quic/quic_headers_stream.h +++ b/net/quic/quic_headers_stream.h @@ -14,13 +14,15 @@ namespace net { +class QuicSpdySession; + // Headers in QUIC are sent as SPDY SYN_STREAM or SYN_REPLY frames // over a reserved reliable stream with the id 2. Each endpoint (client // and server) will allocate an instance of QuicHeadersStream to send // and receive headers. class NET_EXPORT_PRIVATE QuicHeadersStream : public ReliableQuicStream { public: - explicit QuicHeadersStream(QuicSession* session); + explicit QuicHeadersStream(QuicSpdySession* session); ~QuicHeadersStream() override; // Writes |headers| for |stream_id| in a SYN_STREAM or SYN_REPLY @@ -67,6 +69,8 @@ class NET_EXPORT_PRIVATE QuicHeadersStream : public ReliableQuicStream { // Returns true if the session is still connected. bool IsConnected(); + QuicSpdySession* spdy_session_; + // Data about the stream whose headers are being processed. QuicStreamId stream_id_; bool fin_; diff --git a/net/quic/quic_headers_stream_test.cc b/net/quic/quic_headers_stream_test.cc index 8916340..bf66d34 100644 --- a/net/quic/quic_headers_stream_test.cc +++ b/net/quic/quic_headers_stream_test.cc @@ -7,7 +7,7 @@ #include "net/quic/quic_utils.h" #include "net/quic/spdy_utils.h" #include "net/quic/test_tools/quic_connection_peer.h" -#include "net/quic/test_tools/quic_session_peer.h" +#include "net/quic/test_tools/quic_spdy_session_peer.h" #include "net/quic/test_tools/quic_test_utils.h" #include "net/quic/test_tools/reliable_quic_stream_peer.h" #include "net/spdy/spdy_protocol.h" @@ -106,7 +106,7 @@ class QuicHeadersStreamTest : public ::testing::TestWithParam<TestParams> { : connection_( new StrictMock<MockConnection>(perspective(), GetVersion())), session_(connection_), - headers_stream_(QuicSessionPeer::GetHeadersStream(&session_)), + headers_stream_(QuicSpdySessionPeer::GetHeadersStream(&session_)), body_("hello world"), framer_(SPDY4) { headers_[":version"] = "HTTP/1.1"; @@ -206,7 +206,7 @@ class QuicHeadersStreamTest : public ::testing::TestWithParam<TestParams> { static const bool kHasPriority = true; StrictMock<MockConnection>* connection_; - StrictMock<MockSession> session_; + StrictMock<MockQuicSpdySession> session_; QuicHeadersStream* headers_stream_; SpdyHeaderBlock headers_; string body_; diff --git a/net/quic/quic_reliable_client_stream.cc b/net/quic/quic_reliable_client_stream.cc index 68651cb..399a918 100644 --- a/net/quic/quic_reliable_client_stream.cc +++ b/net/quic/quic_reliable_client_stream.cc @@ -6,17 +6,15 @@ #include "base/callback_helpers.h" #include "net/base/net_errors.h" -#include "net/quic/quic_session.h" +#include "net/quic/quic_spdy_session.h" #include "net/quic/quic_write_blocked_list.h" namespace net { QuicReliableClientStream::QuicReliableClientStream(QuicStreamId id, - QuicSession* session, + QuicSpdySession* session, const BoundNetLog& net_log) - : QuicDataStream(id, session), - net_log_(net_log), - delegate_(nullptr) { + : QuicDataStream(id, session), net_log_(net_log), delegate_(nullptr) { } QuicReliableClientStream::~QuicReliableClientStream() { diff --git a/net/quic/quic_reliable_client_stream.h b/net/quic/quic_reliable_client_stream.h index 48f5cc9..7221a6a 100644 --- a/net/quic/quic_reliable_client_stream.h +++ b/net/quic/quic_reliable_client_stream.h @@ -16,7 +16,7 @@ namespace net { -class QuicClientSession; +class QuicSpdySession; // A client-initiated ReliableQuicStream. Instances of this class // are owned by the QuicClientSession which created them. @@ -48,7 +48,7 @@ class NET_EXPORT_PRIVATE QuicReliableClientStream : public QuicDataStream { }; QuicReliableClientStream(QuicStreamId id, - QuicSession* session, + QuicSpdySession* session, const BoundNetLog& net_log); ~QuicReliableClientStream() override; diff --git a/net/quic/quic_reliable_client_stream_test.cc b/net/quic/quic_reliable_client_stream_test.cc index 7ffead9..c414058 100644 --- a/net/quic/quic_reliable_client_stream_test.cc +++ b/net/quic/quic_reliable_client_stream_test.cc @@ -80,7 +80,7 @@ class QuicReliableClientStreamTest } testing::StrictMock<MockDelegate> delegate_; - MockSession session_; + MockQuicSpdySession session_; QuicReliableClientStream* stream_; QuicCryptoClientConfig crypto_config_; SpdyHeaderBlock headers_; diff --git a/net/quic/quic_session.cc b/net/quic/quic_session.cc index fc0365b..9f35ba0 100644 --- a/net/quic/quic_session.cc +++ b/net/quic/quic_session.cc @@ -8,7 +8,6 @@ #include "net/quic/crypto/proof_verifier.h" #include "net/quic/quic_connection.h" #include "net/quic/quic_flow_controller.h" -#include "net/quic/quic_headers_stream.h" #include "net/ssl/ssl_info.h" using base::StringPiece; @@ -89,8 +88,8 @@ class VisitorShim : public QuicConnectionVisitorInterface { return session_->HasPendingHandshake(); } - bool HasOpenDataStreams() const override { - return session_->HasOpenDataStreams(); + bool HasOpenDynamicStreams() const override { + return session_->HasOpenDynamicStreams(); } private: @@ -102,8 +101,9 @@ QuicSession::QuicSession(QuicConnection* connection, const QuicConfig& config) visitor_shim_(new VisitorShim(this)), config_(config), max_open_streams_(config_.MaxStreamsPerConnection()), - next_stream_id_(perspective() == Perspective::IS_SERVER ? 2 : 5), - largest_peer_created_stream_id_(0), + next_stream_id_(perspective() == Perspective::IS_SERVER ? 2 : 3), + largest_peer_created_stream_id_( + perspective() == Perspective::IS_SERVER ? 1 : 0), error_(QUIC_NO_ERROR), flow_controller_(connection_.get(), 0, @@ -117,17 +117,16 @@ QuicSession::QuicSession(QuicConnection* connection, const QuicConfig& config) } void QuicSession::Initialize() { - // Crypto stream must exist when Initialize is called. - DCHECK(GetCryptoStream()); - connection_->set_visitor(visitor_shim_.get()); connection_->SetFromConfig(config_); - headers_stream_.reset(new QuicHeadersStream(this)); + + DCHECK_EQ(kCryptoStreamId, GetCryptoStream()->id()); + static_stream_map_[kCryptoStreamId] = GetCryptoStream(); } QuicSession::~QuicSession() { STLDeleteElements(&closed_streams_); - STLDeleteValues(&stream_map_); + STLDeleteValues(&dynamic_stream_map_); DLOG_IF(WARNING, locally_closed_streams_highest_offset_.size() > max_open_streams_) @@ -157,52 +156,14 @@ void QuicSession::OnStreamFrames(const vector<QuicStreamFrame>& frames) { } } -void QuicSession::OnStreamHeaders(QuicStreamId stream_id, - StringPiece headers_data) { - QuicDataStream* stream = GetDataStream(stream_id); - if (!stream) { - // It's quite possible to receive headers after a stream has been reset. - return; - } - stream->OnStreamHeaders(headers_data); -} - -void QuicSession::OnStreamHeadersPriority(QuicStreamId stream_id, - QuicPriority priority) { - QuicDataStream* stream = GetDataStream(stream_id); - if (!stream) { - // It's quite possible to receive headers after a stream has been reset. - return; - } - stream->OnStreamHeadersPriority(priority); -} - -void QuicSession::OnStreamHeadersComplete(QuicStreamId stream_id, - bool fin, - size_t frame_len) { - QuicDataStream* stream = GetDataStream(stream_id); - if (!stream) { - // It's quite possible to receive headers after a stream has been reset. - return; - } - stream->OnStreamHeadersComplete(fin, frame_len); -} - void QuicSession::OnRstStream(const QuicRstStreamFrame& frame) { - if (frame.stream_id == kCryptoStreamId) { + if (ContainsKey(static_stream_map_, frame.stream_id)) { connection()->SendConnectionCloseWithDetails( - QUIC_INVALID_STREAM_ID, - "Attempt to reset the crypto stream"); - return; - } - if (frame.stream_id == kHeadersStreamId) { - connection()->SendConnectionCloseWithDetails( - QUIC_INVALID_STREAM_ID, - "Attempt to reset the headers stream"); + QUIC_INVALID_STREAM_ID, "Attempt to reset a static stream"); return; } - QuicDataStream* stream = GetDataStream(frame.stream_id); + ReliableQuicStream* stream = GetDynamicStream(frame.stream_id); if (!stream) { // The RST frame contains the final byte offset for the stream: we can now // update the connection level flow controller if needed. @@ -225,12 +186,12 @@ void QuicSession::OnConnectionClosed(QuicErrorCode error, bool from_peer) { error_ = error; } - while (!stream_map_.empty()) { - DataStreamMap::iterator it = stream_map_.begin(); + while (!dynamic_stream_map_.empty()) { + StreamMap::iterator it = dynamic_stream_map_.begin(); QuicStreamId id = it->first; it->second->OnConnectionClosed(error, from_peer); // The stream should call CloseStream as part of OnConnectionClosed. - if (stream_map_.find(id) != stream_map_.end()) { + if (dynamic_stream_map_.find(id) != dynamic_stream_map_.end()) { LOG(DFATAL) << ENDPOINT << "Stream failed to close under OnConnectionClosed"; CloseStream(id); @@ -345,7 +306,7 @@ bool QuicSession::HasPendingHandshake() const { return has_pending_handshake_; } -bool QuicSession::HasOpenDataStreams() const { +bool QuicSession::HasOpenDynamicStreams() const { return GetNumOpenStreams() > 0; } @@ -360,19 +321,14 @@ QuicConsumedData QuicSession::WritevData( ack_notifier_delegate); } -size_t QuicSession::WriteHeaders( - QuicStreamId id, - const SpdyHeaderBlock& headers, - bool fin, - QuicPriority priority, - QuicAckNotifier::DelegateInterface* ack_notifier_delegate) { - return headers_stream_->WriteHeaders(id, headers, fin, priority, - ack_notifier_delegate); -} - void QuicSession::SendRstStream(QuicStreamId id, QuicRstStreamErrorCode error, QuicStreamOffset bytes_written) { + if (ContainsKey(static_stream_map_, id)) { + LOG(DFATAL) << "Cannot send RST for a static stream with ID " << id; + return; + } + if (connection()->connected()) { // Only send a RST_STREAM frame if still connected. connection_->SendRstStream(id, error, bytes_written); @@ -396,12 +352,12 @@ void QuicSession::CloseStreamInner(QuicStreamId stream_id, bool locally_reset) { DVLOG(1) << ENDPOINT << "Closing stream " << stream_id; - DataStreamMap::iterator it = stream_map_.find(stream_id); - if (it == stream_map_.end()) { + StreamMap::iterator it = dynamic_stream_map_.find(stream_id); + if (it == dynamic_stream_map_.end()) { DVLOG(1) << ENDPOINT << "Stream is already closed: " << stream_id; return; } - QuicDataStream* stream = it->second; + ReliableQuicStream* stream = it->second; // Tell the stream that a RST has been sent. if (locally_reset) { @@ -418,10 +374,10 @@ void QuicSession::CloseStreamInner(QuicStreamId stream_id, stream->flow_controller()->highest_received_byte_offset(); } - stream_map_.erase(it); + dynamic_stream_map_.erase(it); stream->OnClose(); // Decrease the number of streams being emulated when a new one is opened. - connection_->SetNumOpenStreams(stream_map_.size()); + connection_->SetNumOpenStreams(dynamic_stream_map_.size()); } void QuicSession::UpdateFlowControlOnFinalReceivedByteOffset( @@ -493,9 +449,10 @@ void QuicSession::OnConfigNegotiated() { void QuicSession::EnableAutoTuneReceiveWindow() { flow_controller_.set_auto_tune_receive_window(true); // Inform all existing streams about the new window. - GetCryptoStream()->flow_controller()->set_auto_tune_receive_window(true); - headers_stream_->flow_controller()->set_auto_tune_receive_window(true); - for (auto const& kv : stream_map_) { + for (auto const& kv : static_stream_map_) { + kv.second->flow_controller()->set_auto_tune_receive_window(true); + } + for (auto const& kv : dynamic_stream_map_) { kv.second->flow_controller()->set_auto_tune_receive_window(true); } } @@ -512,9 +469,10 @@ void QuicSession::OnNewStreamFlowControlWindow(QuicStreamOffset new_window) { } // Inform all existing streams about the new window. - GetCryptoStream()->UpdateSendWindowOffset(new_window); - headers_stream_->UpdateSendWindowOffset(new_window); - for (auto const& kv : stream_map_) { + for (auto const& kv : static_stream_map_) { + kv.second->UpdateSendWindowOffset(new_window); + } + for (auto const& kv : dynamic_stream_map_) { kv.second->UpdateSendWindowOffset(new_window); } } @@ -571,13 +529,13 @@ QuicConfig* QuicSession::config() { return &config_; } -void QuicSession::ActivateStream(QuicDataStream* stream) { - DVLOG(1) << ENDPOINT << "num_streams: " << stream_map_.size() +void QuicSession::ActivateStream(ReliableQuicStream* stream) { + DVLOG(1) << ENDPOINT << "num_streams: " << dynamic_stream_map_.size() << ". activating " << stream->id(); - DCHECK_EQ(stream_map_.count(stream->id()), 0u); - stream_map_[stream->id()] = stream; + DCHECK_EQ(dynamic_stream_map_.count(stream->id()), 0u); + dynamic_stream_map_[stream->id()] = stream; // Increase the number of streams being emulated when a new one is opened. - connection_->SetNumOpenStreams(stream_map_.size()); + connection_->SetNumOpenStreams(dynamic_stream_map_.size()); } QuicStreamId QuicSession::GetNextStreamId() { @@ -587,27 +545,22 @@ QuicStreamId QuicSession::GetNextStreamId() { } ReliableQuicStream* QuicSession::GetStream(const QuicStreamId stream_id) { - if (stream_id == kCryptoStreamId) { - return GetCryptoStream(); - } - if (stream_id == kHeadersStreamId) { - return headers_stream_.get(); + StreamMap::iterator it = static_stream_map_.find(stream_id); + if (it != static_stream_map_.end()) { + return it->second; } - return GetDataStream(stream_id); + return GetDynamicStream(stream_id); } -QuicDataStream* QuicSession::GetDataStream(const QuicStreamId stream_id) { - if (stream_id == kCryptoStreamId) { - DLOG(FATAL) << "Attempt to call GetDataStream with the crypto stream id"; - return nullptr; - } - if (stream_id == kHeadersStreamId) { - DLOG(FATAL) << "Attempt to call GetDataStream with the headers stream id"; +ReliableQuicStream* QuicSession::GetDynamicStream( + const QuicStreamId stream_id) { + if (static_stream_map_.find(stream_id) != static_stream_map_.end()) { + DLOG(FATAL) << "Attempt to call GetDynamicStream for a static stream"; return nullptr; } - DataStreamMap::iterator it = stream_map_.find(stream_id); - if (it != stream_map_.end()) { + StreamMap::iterator it = dynamic_stream_map_.find(stream_id); + if (it != dynamic_stream_map_.end()) { return it->second; } @@ -624,10 +577,11 @@ QuicDataStream* QuicSession::GetDataStream(const QuicStreamId stream_id) { return nullptr; } - return GetIncomingDataStream(stream_id); + return GetIncomingDynamicStream(stream_id); } -QuicDataStream* QuicSession::GetIncomingDataStream(QuicStreamId stream_id) { +ReliableQuicStream* QuicSession::GetIncomingDynamicStream( + QuicStreamId stream_id) { if (IsClosedStream(stream_id)) { return nullptr; } @@ -646,10 +600,6 @@ QuicDataStream* QuicSession::GetIncomingDataStream(QuicStreamId stream_id) { } return nullptr; } - if (largest_peer_created_stream_id_ == 0 && - perspective() == Perspective::IS_SERVER) { - largest_peer_created_stream_id_ = 3; - } for (QuicStreamId id = largest_peer_created_stream_id_ + 2; id < stream_id; id += 2) { @@ -657,7 +607,7 @@ QuicDataStream* QuicSession::GetIncomingDataStream(QuicStreamId stream_id) { } largest_peer_created_stream_id_ = stream_id; } - QuicDataStream* stream = CreateIncomingDataStream(stream_id); + ReliableQuicStream* stream = CreateIncomingDynamicStream(stream_id); if (stream == nullptr) { return nullptr; } @@ -672,13 +622,8 @@ void QuicSession::set_max_open_streams(size_t max_open_streams) { bool QuicSession::IsClosedStream(QuicStreamId id) { DCHECK_NE(0u, id); - if (id == kCryptoStreamId) { - return false; - } - if (id == kHeadersStreamId) { - return false; - } - if (ContainsKey(stream_map_, id)) { + if (ContainsKey(static_stream_map_, id) || + ContainsKey(dynamic_stream_map_, id)) { // Stream is active return false; } @@ -694,7 +639,7 @@ bool QuicSession::IsClosedStream(QuicStreamId id) { } size_t QuicSession::GetNumOpenStreams() const { - return stream_map_.size() + implicitly_created_streams_.size(); + return dynamic_stream_map_.size() + implicitly_created_streams_.size(); } void QuicSession::MarkWriteBlocked(QuicStreamId id, QuicPriority priority) { @@ -742,11 +687,12 @@ bool QuicSession::IsConnectionFlowControlBlocked() const { } bool QuicSession::IsStreamFlowControlBlocked() { - if (headers_stream_->flow_controller()->IsBlocked() || - GetCryptoStream()->flow_controller()->IsBlocked()) { - return true; + for (auto const& kv : static_stream_map_) { + if (kv.second->flow_controller()->IsBlocked()) { + return true; + } } - for (auto const& kv : stream_map_) { + for (auto const& kv : dynamic_stream_map_) { if (kv.second->flow_controller()->IsBlocked()) { return true; } diff --git a/net/quic/quic_session.h b/net/quic/quic_session.h index 912783d..5320784 100644 --- a/net/quic/quic_session.h +++ b/net/quic/quic_session.h @@ -18,8 +18,6 @@ #include "net/base/ip_endpoint.h" #include "net/quic/quic_connection.h" #include "net/quic/quic_crypto_stream.h" -#include "net/quic/quic_data_stream.h" -#include "net/quic/quic_headers_stream.h" #include "net/quic/quic_packet_creator.h" #include "net/quic/quic_protocol.h" #include "net/quic/quic_write_blocked_list.h" @@ -56,10 +54,11 @@ class NET_EXPORT_PRIVATE QuicSession : public QuicConnectionVisitorInterface { }; QuicSession(QuicConnection* connection, const QuicConfig& config); - virtual void Initialize(); ~QuicSession() override; + virtual void Initialize(); + // QuicConnectionVisitorInterface methods: void OnStreamFrames(const std::vector<QuicStreamFrame>& frames) override; void OnRstStream(const QuicRstStreamFrame& frame) override; @@ -74,22 +73,7 @@ class NET_EXPORT_PRIVATE QuicSession : public QuicConnectionVisitorInterface { void OnCongestionWindowChange(QuicTime now) override {} bool WillingAndAbleToWrite() const override; bool HasPendingHandshake() const override; - bool HasOpenDataStreams() const override; - - // Called by the headers stream when headers have been received for a stream. - virtual void OnStreamHeaders(QuicStreamId stream_id, - base::StringPiece headers_data); - // Called by the headers stream when headers with a priority have been - // received for this stream. This method will only be called for server - // streams. - virtual void OnStreamHeadersPriority(QuicStreamId stream_id, - QuicPriority priority); - // Called by the headers stream when headers have been completely received - // for a stream. |fin| will be true if the fin flag was set in the headers - // frame. - virtual void OnStreamHeadersComplete(QuicStreamId stream_id, - bool fin, - size_t frame_len); + bool HasOpenDynamicStreams() const override; // Called by streams when they want to write data to the peer. // Returns a pair with the number of bytes consumed from data, and a boolean @@ -109,17 +93,6 @@ class NET_EXPORT_PRIVATE QuicSession : public QuicConnectionVisitorInterface { FecProtection fec_protection, QuicAckNotifier::DelegateInterface* ack_notifier_delegate); - // Writes |headers| for the stream |id| to the dedicated headers stream. - // If |fin| is true, then no more data will be sent for the stream |id|. - // If provided, |ack_notifier_delegate| will be registered to be notified when - // we have seen ACKs for all packets resulting from this call. - size_t WriteHeaders( - QuicStreamId id, - const SpdyHeaderBlock& headers, - bool fin, - QuicPriority priority, - QuicAckNotifier::DelegateInterface* ack_notifier_delegate); - // Called by streams when they want to close the stream in both directions. virtual void SendRstStream(QuicStreamId id, QuicRstStreamErrorCode error, @@ -171,7 +144,7 @@ class NET_EXPORT_PRIVATE QuicSession : public QuicConnectionVisitorInterface { QuicConnection* connection() { return connection_.get(); } const QuicConnection* connection() const { return connection_.get(); } - size_t num_active_requests() const { return stream_map_.size(); } + size_t num_active_requests() const { return dynamic_stream_map_.size(); } const IPEndPoint& peer_address() const { return connection_->peer_address(); } @@ -211,35 +184,32 @@ class NET_EXPORT_PRIVATE QuicSession : public QuicConnectionVisitorInterface { size_t get_max_open_streams() const { return max_open_streams_; } - // Used in Chrome. - const QuicHeadersStream* headers_stream() { return headers_stream_.get(); } - ReliableQuicStream* GetStream(const QuicStreamId stream_id); protected: - typedef base::hash_map<QuicStreamId, QuicDataStream*> DataStreamMap; + typedef base::hash_map<QuicStreamId, ReliableQuicStream*> StreamMap; // Creates a new stream, owned by the caller, to handle a peer-initiated // stream. Returns nullptr and does error handling if the stream can not be // created. - virtual QuicDataStream* CreateIncomingDataStream(QuicStreamId id) = 0; + virtual ReliableQuicStream* CreateIncomingDynamicStream(QuicStreamId id) = 0; // Create a new stream, owned by the caller, to handle a locally-initiated // stream. Returns nullptr if max streams have already been opened. - virtual QuicDataStream* CreateOutgoingDataStream() = 0; + virtual ReliableQuicStream* CreateOutgoingDynamicStream() = 0; // Return the reserved crypto stream. virtual QuicCryptoStream* GetCryptoStream() = 0; // Adds 'stream' to the active stream map. - virtual void ActivateStream(QuicDataStream* stream); + virtual void ActivateStream(ReliableQuicStream* stream); // Returns the stream id for a new stream. QuicStreamId GetNextStreamId(); - QuicDataStream* GetIncomingDataStream(QuicStreamId stream_id); + ReliableQuicStream* GetIncomingDynamicStream(QuicStreamId stream_id); - QuicDataStream* GetDataStream(const QuicStreamId stream_id); + ReliableQuicStream* GetDynamicStream(const QuicStreamId stream_id); // This is called after every call other than OnConnectionClose from the // QuicConnectionVisitor to allow post-processing once the work has been done. @@ -247,19 +217,22 @@ class NET_EXPORT_PRIVATE QuicSession : public QuicConnectionVisitorInterface { // operations are being done on the streams at this time) virtual void PostProcessAfterData(); - base::hash_map<QuicStreamId, QuicDataStream*>* streams() { - return &stream_map_; - } + StreamMap& static_streams() { return static_stream_map_; } + const StreamMap& static_streams() const { return static_stream_map_; } - const base::hash_map<QuicStreamId, QuicDataStream*>* streams() const { - return &stream_map_; - } + StreamMap& dynamic_streams() { return dynamic_stream_map_; } + const StreamMap& dynamic_streams() const { return dynamic_stream_map_; } - std::vector<QuicDataStream*>* closed_streams() { return &closed_streams_; } + std::vector<ReliableQuicStream*>* closed_streams() { + return &closed_streams_; + } void set_max_open_streams(size_t max_open_streams); - scoped_ptr<QuicHeadersStream> headers_stream_; + void set_largest_peer_created_stream_id( + QuicStreamId largest_peer_created_stream_id) { + largest_peer_created_stream_id_ = largest_peer_created_stream_id; + } private: friend class test::QuicSessionPeer; @@ -299,15 +272,19 @@ class NET_EXPORT_PRIVATE QuicSession : public QuicConnectionVisitorInterface { // deletions. scoped_ptr<VisitorShim> visitor_shim_; - std::vector<QuicDataStream*> closed_streams_; + std::vector<ReliableQuicStream*> closed_streams_; QuicConfig config_; // Returns the maximum number of streams this connection can open. size_t max_open_streams_; + // Static streams, such as crypto and header streams. Owned by child classes + // that create these streams. + StreamMap static_stream_map_; + // Map from StreamId to pointers to streams that are owned by the caller. - DataStreamMap stream_map_; + StreamMap dynamic_stream_map_; QuicStreamId next_stream_id_; // Set of stream ids that have been "implicitly created" by receipt diff --git a/net/quic/quic_session_test.cc b/net/quic/quic_session_test.cc index e2226167..90d67e7 100644 --- a/net/quic/quic_session_test.cc +++ b/net/quic/quic_session_test.cc @@ -22,6 +22,7 @@ #include "net/quic/test_tools/quic_data_stream_peer.h" #include "net/quic/test_tools/quic_flow_controller_peer.h" #include "net/quic/test_tools/quic_session_peer.h" +#include "net/quic/test_tools/quic_spdy_session_peer.h" #include "net/quic/test_tools/quic_test_utils.h" #include "net/quic/test_tools/reliable_quic_stream_peer.h" #include "net/spdy/spdy_framer.h" @@ -76,18 +77,16 @@ class TestCryptoStream : public QuicCryptoStream { class TestHeadersStream : public QuicHeadersStream { public: - explicit TestHeadersStream(QuicSession* session) - : QuicHeadersStream(session) { - } + explicit TestHeadersStream(QuicSpdySession* session) + : QuicHeadersStream(session) {} MOCK_METHOD0(OnCanWrite, void()); }; class TestStream : public QuicDataStream { public: - TestStream(QuicStreamId id, QuicSession* session) - : QuicDataStream(id, session) { - } + TestStream(QuicStreamId id, QuicSpdySession* session) + : QuicDataStream(id, session) {} using ReliableQuicStream::CloseWriteSide; @@ -119,10 +118,10 @@ class StreamBlocker { const QuicStreamId stream_id_; }; -class TestSession : public QuicSession { +class TestSession : public QuicSpdySession { public: explicit TestSession(QuicConnection* connection) - : QuicSession(connection, DefaultQuicConfig()), + : QuicSpdySession(connection, DefaultQuicConfig()), crypto_stream_(this), writev_consumes_all_data_(false) { Initialize(); @@ -130,13 +129,13 @@ class TestSession : public QuicSession { TestCryptoStream* GetCryptoStream() override { return &crypto_stream_; } - TestStream* CreateOutgoingDataStream() override { + TestStream* CreateOutgoingDynamicStream() override { TestStream* stream = new TestStream(GetNextStreamId(), this); ActivateStream(stream); return stream; } - TestStream* CreateIncomingDataStream(QuicStreamId id) override { + TestStream* CreateIncomingDynamicStream(QuicStreamId id) override { return new TestStream(id, this); } @@ -144,8 +143,8 @@ class TestSession : public QuicSession { return QuicSession::IsClosedStream(id); } - QuicDataStream* GetIncomingDataStream(QuicStreamId stream_id) { - return QuicSession::GetIncomingDataStream(stream_id); + ReliableQuicStream* GetIncomingDynamicStream(QuicStreamId stream_id) { + return QuicSpdySession::GetIncomingDynamicStream(stream_id); } QuicConsumedData WritevData( @@ -274,18 +273,18 @@ TEST_P(QuicSessionTestServer, IsClosedStreamDefault) { } TEST_P(QuicSessionTestServer, ImplicitlyCreatedStreams) { - ASSERT_TRUE(session_.GetIncomingDataStream(9) != nullptr); + ASSERT_TRUE(session_.GetIncomingDynamicStream(9) != nullptr); // Both 5 and 7 should be implicitly created. EXPECT_TRUE(QuicSessionPeer::IsStreamImplicitlyCreated(&session_, 5)); EXPECT_TRUE(QuicSessionPeer::IsStreamImplicitlyCreated(&session_, 7)); - ASSERT_TRUE(session_.GetIncomingDataStream(7) != nullptr); - ASSERT_TRUE(session_.GetIncomingDataStream(5) != nullptr); + ASSERT_TRUE(session_.GetIncomingDynamicStream(7) != nullptr); + ASSERT_TRUE(session_.GetIncomingDynamicStream(5) != nullptr); } TEST_P(QuicSessionTestServer, IsClosedStreamLocallyCreated) { - TestStream* stream2 = session_.CreateOutgoingDataStream(); + TestStream* stream2 = session_.CreateOutgoingDynamicStream(); EXPECT_EQ(2u, stream2->id()); - TestStream* stream4 = session_.CreateOutgoingDataStream(); + TestStream* stream4 = session_.CreateOutgoingDynamicStream(); EXPECT_EQ(4u, stream4->id()); CheckClosedStreams(); @@ -298,18 +297,16 @@ TEST_P(QuicSessionTestServer, IsClosedStreamLocallyCreated) { TEST_P(QuicSessionTestServer, IsClosedStreamPeerCreated) { QuicStreamId stream_id1 = kClientDataStreamId1; QuicStreamId stream_id2 = kClientDataStreamId2; - QuicDataStream* stream1 = session_.GetIncomingDataStream(stream_id1); - QuicDataStreamPeer::SetHeadersDecompressed(stream1, true); - QuicDataStream* stream2 = session_.GetIncomingDataStream(stream_id2); - QuicDataStreamPeer::SetHeadersDecompressed(stream2, true); + session_.GetIncomingDynamicStream(stream_id1); + session_.GetIncomingDynamicStream(stream_id2); CheckClosedStreams(); CloseStream(stream_id1); CheckClosedStreams(); CloseStream(stream_id2); // Create a stream explicitly, and another implicitly. - QuicDataStream* stream3 = session_.GetIncomingDataStream(stream_id2 + 4); - QuicDataStreamPeer::SetHeadersDecompressed(stream3, true); + ReliableQuicStream* stream3 = + session_.GetIncomingDynamicStream(stream_id2 + 4); CheckClosedStreams(); // Close one, but make sure the other is still not closed CloseStream(stream3->id()); @@ -318,13 +315,13 @@ TEST_P(QuicSessionTestServer, IsClosedStreamPeerCreated) { TEST_P(QuicSessionTestServer, StreamIdTooLarge) { QuicStreamId stream_id = kClientDataStreamId1; - session_.GetIncomingDataStream(stream_id); + session_.GetIncomingDynamicStream(stream_id); EXPECT_CALL(*connection_, SendConnectionClose(QUIC_INVALID_STREAM_ID)); - session_.GetIncomingDataStream(stream_id + kMaxStreamIdDelta + 2); + session_.GetIncomingDynamicStream(stream_id + kMaxStreamIdDelta + 2); } TEST_P(QuicSessionTestServer, DebugDFatalIfMarkingClosedStreamWriteBlocked) { - TestStream* stream2 = session_.CreateOutgoingDataStream(); + TestStream* stream2 = session_.CreateOutgoingDynamicStream(); QuicStreamId kClosedStreamId = stream2->id(); // Close the stream. EXPECT_CALL(*connection_, SendRstStream(kClosedStreamId, _, _)); @@ -338,7 +335,7 @@ TEST_P(QuicSessionTestServer, DebugDFatalIfMarkWriteBlockedCalledWithWrongPriority) { const QuicPriority kDifferentPriority = 0; - TestStream* stream2 = session_.CreateOutgoingDataStream(); + TestStream* stream2 = session_.CreateOutgoingDynamicStream(); EXPECT_NE(kDifferentPriority, stream2->EffectivePriority()); EXPECT_DEBUG_DFATAL( session_.MarkWriteBlocked(stream2->id(), kDifferentPriority), @@ -346,9 +343,9 @@ TEST_P(QuicSessionTestServer, } TEST_P(QuicSessionTestServer, OnCanWrite) { - TestStream* stream2 = session_.CreateOutgoingDataStream(); - TestStream* stream4 = session_.CreateOutgoingDataStream(); - TestStream* stream6 = session_.CreateOutgoingDataStream(); + TestStream* stream2 = session_.CreateOutgoingDynamicStream(); + TestStream* stream4 = session_.CreateOutgoingDynamicStream(); + TestStream* stream6 = session_.CreateOutgoingDynamicStream(); session_.MarkWriteBlocked(stream2->id(), kSomeMiddlePriority); session_.MarkWriteBlocked(stream6->id(), kSomeMiddlePriority); @@ -370,9 +367,9 @@ TEST_P(QuicSessionTestServer, OnCanWriteBundlesStreams) { MockSendAlgorithm* send_algorithm = new StrictMock<MockSendAlgorithm>; QuicConnectionPeer::SetSendAlgorithm(session_.connection(), send_algorithm); - TestStream* stream2 = session_.CreateOutgoingDataStream(); - TestStream* stream4 = session_.CreateOutgoingDataStream(); - TestStream* stream6 = session_.CreateOutgoingDataStream(); + TestStream* stream2 = session_.CreateOutgoingDynamicStream(); + TestStream* stream4 = session_.CreateOutgoingDynamicStream(); + TestStream* stream6 = session_.CreateOutgoingDynamicStream(); session_.MarkWriteBlocked(stream2->id(), kSomeMiddlePriority); session_.MarkWriteBlocked(stream6->id(), kSomeMiddlePriority); @@ -411,9 +408,9 @@ TEST_P(QuicSessionTestServer, OnCanWriteCongestionControlBlocks) { MockSendAlgorithm* send_algorithm = new StrictMock<MockSendAlgorithm>; QuicConnectionPeer::SetSendAlgorithm(session_.connection(), send_algorithm); - TestStream* stream2 = session_.CreateOutgoingDataStream(); - TestStream* stream4 = session_.CreateOutgoingDataStream(); - TestStream* stream6 = session_.CreateOutgoingDataStream(); + TestStream* stream2 = session_.CreateOutgoingDynamicStream(); + TestStream* stream4 = session_.CreateOutgoingDynamicStream(); + TestStream* stream6 = session_.CreateOutgoingDynamicStream(); session_.MarkWriteBlocked(stream2->id(), kSomeMiddlePriority); session_.MarkWriteBlocked(stream6->id(), kSomeMiddlePriority); @@ -452,12 +449,12 @@ TEST_P(QuicSessionTestServer, BufferedHandshake) { EXPECT_FALSE(session_.HasPendingHandshake()); // Default value. // Test that blocking other streams does not change our status. - TestStream* stream2 = session_.CreateOutgoingDataStream(); + TestStream* stream2 = session_.CreateOutgoingDynamicStream(); StreamBlocker stream2_blocker(&session_, stream2->id()); stream2_blocker.MarkWriteBlocked(); EXPECT_FALSE(session_.HasPendingHandshake()); - TestStream* stream3 = session_.CreateOutgoingDataStream(); + TestStream* stream3 = session_.CreateOutgoingDynamicStream(); StreamBlocker stream3_blocker(&session_, stream3->id()); stream3_blocker.MarkWriteBlocked(); EXPECT_FALSE(session_.HasPendingHandshake()); @@ -466,7 +463,7 @@ TEST_P(QuicSessionTestServer, BufferedHandshake) { session_.MarkWriteBlocked(kCryptoStreamId, kHighestPriority); EXPECT_TRUE(session_.HasPendingHandshake()); - TestStream* stream4 = session_.CreateOutgoingDataStream(); + TestStream* stream4 = session_.CreateOutgoingDynamicStream(); StreamBlocker stream4_blocker(&session_, stream4->id()); stream4_blocker.MarkWriteBlocked(); EXPECT_TRUE(session_.HasPendingHandshake()); @@ -495,9 +492,9 @@ TEST_P(QuicSessionTestServer, BufferedHandshake) { } TEST_P(QuicSessionTestServer, OnCanWriteWithClosedStream) { - TestStream* stream2 = session_.CreateOutgoingDataStream(); - TestStream* stream4 = session_.CreateOutgoingDataStream(); - TestStream* stream6 = session_.CreateOutgoingDataStream(); + TestStream* stream2 = session_.CreateOutgoingDynamicStream(); + TestStream* stream4 = session_.CreateOutgoingDynamicStream(); + TestStream* stream6 = session_.CreateOutgoingDynamicStream(); session_.MarkWriteBlocked(stream2->id(), kSomeMiddlePriority); session_.MarkWriteBlocked(stream6->id(), kSomeMiddlePriority); @@ -525,7 +522,7 @@ TEST_P(QuicSessionTestServer, OnCanWriteLimitsNumWritesIfFlowControlBlocked) { // Create a data stream, and although it is write blocked we never expect it // to be allowed to write as we are connection level flow control blocked. - TestStream* stream = session_.CreateOutgoingDataStream(); + TestStream* stream = session_.CreateOutgoingDynamicStream(); session_.MarkWriteBlocked(stream->id(), kSomeMiddlePriority); EXPECT_CALL(*stream, OnCanWrite()).Times(0); @@ -534,7 +531,7 @@ TEST_P(QuicSessionTestServer, OnCanWriteLimitsNumWritesIfFlowControlBlocked) { TestCryptoStream* crypto_stream = session_.GetCryptoStream(); EXPECT_CALL(*crypto_stream, OnCanWrite()).Times(1); TestHeadersStream* headers_stream = new TestHeadersStream(&session_); - QuicSessionPeer::SetHeadersStream(&session_, headers_stream); + QuicSpdySessionPeer::SetHeadersStream(&session_, headers_stream); EXPECT_CALL(*headers_stream, OnCanWrite()).Times(1); session_.OnCanWrite(); @@ -543,18 +540,18 @@ TEST_P(QuicSessionTestServer, OnCanWriteLimitsNumWritesIfFlowControlBlocked) { TEST_P(QuicSessionTestServer, SendGoAway) { EXPECT_CALL(*connection_, - SendGoAway(QUIC_PEER_GOING_AWAY, 0u, "Going Away.")); + SendGoAway(QUIC_PEER_GOING_AWAY, 3u, "Going Away.")); session_.SendGoAway(QUIC_PEER_GOING_AWAY, "Going Away."); EXPECT_TRUE(session_.goaway_sent()); EXPECT_CALL(*connection_, SendRstStream(3u, QUIC_STREAM_PEER_GOING_AWAY, 0)).Times(0); - EXPECT_TRUE(session_.GetIncomingDataStream(3u)); + EXPECT_TRUE(session_.GetIncomingDynamicStream(3u)); } TEST_P(QuicSessionTestServer, DoNotSendGoAwayTwice) { - EXPECT_CALL(*connection_, - SendGoAway(QUIC_PEER_GOING_AWAY, 0u, "Going Away.")).Times(1); + EXPECT_CALL(*connection_, SendGoAway(QUIC_PEER_GOING_AWAY, 3u, "Going Away.")) + .Times(1); session_.SendGoAway(QUIC_PEER_GOING_AWAY, "Going Away."); EXPECT_TRUE(session_.goaway_sent()); session_.SendGoAway(QUIC_PEER_GOING_AWAY, "Going Away."); @@ -621,7 +618,7 @@ TEST_P(QuicSessionTestServer, HandshakeUnblocksFlowControlBlockedStream) { session_.set_writev_consumes_all_data(true); // Create a stream, and send enough data to make it flow control blocked. - TestStream* stream2 = session_.CreateOutgoingDataStream(); + TestStream* stream2 = session_.CreateOutgoingDynamicStream(); string body(kMinimumFlowControlSendWindow, '.'); EXPECT_FALSE(stream2->flow_controller()->IsBlocked()); EXPECT_FALSE(session_.IsConnectionFlowControlBlocked()); @@ -656,7 +653,7 @@ TEST_P(QuicSessionTestServer, HandshakeUnblocksFlowControlBlockedCryptoStream) { EXPECT_FALSE(session_.IsConnectionFlowControlBlocked()); EXPECT_FALSE(session_.IsStreamFlowControlBlocked()); QuicHeadersStream* headers_stream = - QuicSessionPeer::GetHeadersStream(&session_); + QuicSpdySessionPeer::GetHeadersStream(&session_); EXPECT_FALSE(headers_stream->flow_controller()->IsBlocked()); EXPECT_FALSE(session_.IsConnectionFlowControlBlocked()); EXPECT_FALSE(session_.IsStreamFlowControlBlocked()); @@ -703,7 +700,7 @@ TEST_P(QuicSessionTestServer, EXPECT_FALSE(session_.IsConnectionFlowControlBlocked()); EXPECT_FALSE(session_.IsStreamFlowControlBlocked()); QuicHeadersStream* headers_stream = - QuicSessionPeer::GetHeadersStream(&session_); + QuicSpdySessionPeer::GetHeadersStream(&session_); EXPECT_FALSE(headers_stream->flow_controller()->IsBlocked()); EXPECT_FALSE(session_.IsConnectionFlowControlBlocked()); EXPECT_FALSE(session_.IsStreamFlowControlBlocked()); @@ -748,7 +745,7 @@ TEST_P(QuicSessionTestServer, ConnectionFlowControlAccountingRstOutOfOrder) { // our connection level flow control receive window. // On close, the stream should mark as consumed all bytes between the highest // byte consumed so far and the final byte offset from the RST frame. - TestStream* stream = session_.CreateOutgoingDataStream(); + TestStream* stream = session_.CreateOutgoingDynamicStream(); const QuicStreamOffset kByteOffset = 1 + kInitialSessionFlowControlWindowForTest / 2; @@ -774,7 +771,7 @@ TEST_P(QuicSessionTestServer, ConnectionFlowControlAccountingFinAndLocalReset) { // The bytes between highest consumed byte, and the final byte offset that we // determined when the FIN arrived, should be marked as consumed at the // connection level flow controller when the stream is reset. - TestStream* stream = session_.CreateOutgoingDataStream(); + TestStream* stream = session_.CreateOutgoingDynamicStream(); const QuicStreamOffset kByteOffset = kInitialSessionFlowControlWindowForTest / 2; @@ -811,7 +808,7 @@ TEST_P(QuicSessionTestServer, ConnectionFlowControlAccountingFinAfterRst) { session_.flow_controller()->AddBytesConsumed(kInitialConnectionBytesConsumed); // Reset our stream: this results in the stream being closed locally. - TestStream* stream = session_.CreateOutgoingDataStream(); + TestStream* stream = session_.CreateOutgoingDynamicStream(); EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _)); stream->Reset(QUIC_STREAM_CANCELLED); @@ -850,7 +847,7 @@ TEST_P(QuicSessionTestServer, ConnectionFlowControlAccountingRstAfterRst) { session_.flow_controller()->AddBytesConsumed(kInitialConnectionBytesConsumed); // Reset our stream: this results in the stream being closed locally. - TestStream* stream = session_.CreateOutgoingDataStream(); + TestStream* stream = session_.CreateOutgoingDynamicStream(); EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _)); stream->Reset(QUIC_STREAM_CANCELLED); @@ -901,7 +898,7 @@ TEST_P(QuicSessionTestServer, FlowControlWithInvalidFinalOffset) { .Times(2); // Check that stream frame + FIN results in connection close. - TestStream* stream = session_.CreateOutgoingDataStream(); + TestStream* stream = session_.CreateOutgoingDynamicStream(); EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _)); stream->Reset(QUIC_STREAM_CANCELLED); QuicStreamFrame frame(stream->id(), true, kLargeOffset, StringPiece()); @@ -921,7 +918,7 @@ TEST_P(QuicSessionTestServer, WindowUpdateUnblocksHeadersStream) { // Set the headers stream to be flow control blocked. QuicHeadersStream* headers_stream = - QuicSessionPeer::GetHeadersStream(&session_); + QuicSpdySessionPeer::GetHeadersStream(&session_); QuicFlowControllerPeer::SetSendWindowOffset(headers_stream->flow_controller(), 0); EXPECT_TRUE(headers_stream->flow_controller()->IsBlocked()); @@ -977,12 +974,12 @@ INSTANTIATE_TEST_CASE_P(Tests, ::testing::ValuesIn(QuicSupportedVersions())); TEST_P(QuicSessionTestClient, ImplicitlyCreatedStreamsClient) { - ASSERT_TRUE(session_.GetIncomingDataStream(6) != nullptr); + ASSERT_TRUE(session_.GetIncomingDynamicStream(6) != nullptr); // Both 2 and 4 should be implicitly created. EXPECT_TRUE(QuicSessionPeer::IsStreamImplicitlyCreated(&session_, 2)); EXPECT_TRUE(QuicSessionPeer::IsStreamImplicitlyCreated(&session_, 4)); - ASSERT_TRUE(session_.GetIncomingDataStream(2) != nullptr); - ASSERT_TRUE(session_.GetIncomingDataStream(4) != nullptr); + ASSERT_TRUE(session_.GetIncomingDynamicStream(2) != nullptr); + ASSERT_TRUE(session_.GetIncomingDynamicStream(4) != nullptr); // And 5 should be not implicitly created. EXPECT_FALSE(QuicSessionPeer::IsStreamImplicitlyCreated(&session_, 5)); } diff --git a/net/quic/quic_spdy_session.cc b/net/quic/quic_spdy_session.cc new file mode 100644 index 0000000..0a8dda6 --- /dev/null +++ b/net/quic/quic_spdy_session.cc @@ -0,0 +1,80 @@ +// Copyright (c) 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "net/quic/quic_spdy_session.h" + +#include "net/quic/quic_headers_stream.h" + +namespace net { + +QuicSpdySession::QuicSpdySession(QuicConnection* connection, + const QuicConfig& config) + : QuicSession(connection, config) { +} + +QuicSpdySession::~QuicSpdySession() { +} + +void QuicSpdySession::Initialize() { + QuicSession::Initialize(); + + if (perspective() == Perspective::IS_SERVER) { + set_largest_peer_created_stream_id(kHeadersStreamId); + } else { + QuicStreamId headers_stream_id = GetNextStreamId(); + DCHECK_EQ(headers_stream_id, kHeadersStreamId); + } + + headers_stream_.reset(new QuicHeadersStream(this)); + DCHECK_EQ(kHeadersStreamId, headers_stream_->id()); + static_streams()[kHeadersStreamId] = headers_stream_.get(); +} + +void QuicSpdySession::OnStreamHeaders(QuicStreamId stream_id, + StringPiece headers_data) { + QuicDataStream* stream = GetSpdyDataStream(stream_id); + if (!stream) { + // It's quite possible to receive headers after a stream has been reset. + return; + } + stream->OnStreamHeaders(headers_data); +} + +void QuicSpdySession::OnStreamHeadersPriority(QuicStreamId stream_id, + QuicPriority priority) { + QuicDataStream* stream = GetSpdyDataStream(stream_id); + if (!stream) { + // It's quite possible to receive headers after a stream has been reset. + return; + } + stream->OnStreamHeadersPriority(priority); +} + +void QuicSpdySession::OnStreamHeadersComplete(QuicStreamId stream_id, + bool fin, + size_t frame_len) { + QuicDataStream* stream = GetSpdyDataStream(stream_id); + if (!stream) { + // It's quite possible to receive headers after a stream has been reset. + return; + } + stream->OnStreamHeadersComplete(fin, frame_len); +} + +size_t QuicSpdySession::WriteHeaders( + QuicStreamId id, + const SpdyHeaderBlock& headers, + bool fin, + QuicPriority priority, + QuicAckNotifier::DelegateInterface* ack_notifier_delegate) { + return headers_stream_->WriteHeaders(id, headers, fin, priority, + ack_notifier_delegate); +} + +QuicDataStream* QuicSpdySession::GetSpdyDataStream( + const QuicStreamId stream_id) { + return static_cast<QuicDataStream*>(GetDynamicStream(stream_id)); +} + +} // namespace net diff --git a/net/quic/quic_spdy_session.h b/net/quic/quic_spdy_session.h new file mode 100644 index 0000000..b59eb63 --- /dev/null +++ b/net/quic/quic_spdy_session.h @@ -0,0 +1,76 @@ +// Copyright (c) 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NET_QUIC_QUIC_SPDY_SESSION_H_ +#define NET_QUIC_QUIC_SPDY_SESSION_H_ + +#include "base/basictypes.h" +#include "base/memory/scoped_ptr.h" +#include "net/quic/quic_data_stream.h" +#include "net/quic/quic_headers_stream.h" +#include "net/quic/quic_session.h" + +namespace net { + +namespace test { +class QuicSpdySessionPeer; +} // namespace test + +// A QUIC session with a headers stream. +class NET_EXPORT_PRIVATE QuicSpdySession : public QuicSession { + public: + QuicSpdySession(QuicConnection* connection, const QuicConfig& config); + + ~QuicSpdySession() override; + + void Initialize() override; + + // Called by |headers_stream_| when headers have been received for a stream. + virtual void OnStreamHeaders(QuicStreamId stream_id, + StringPiece headers_data); + // Called by |headers_stream_| when headers with a priority have been + // received for this stream. This method will only be called for server + // streams. + virtual void OnStreamHeadersPriority(QuicStreamId stream_id, + QuicPriority priority); + // Called by |headers_stream_| when headers have been completely received + // for a stream. |fin| will be true if the fin flag was set in the headers + // frame. + virtual void OnStreamHeadersComplete(QuicStreamId stream_id, + bool fin, + size_t frame_len); + + // Writes |headers| for the stream |id| to the dedicated headers stream. + // If |fin| is true, then no more data will be sent for the stream |id|. + // If provided, |ack_notifier_delegate| will be registered to be notified when + // we have seen ACKs for all packets resulting from this call. + size_t WriteHeaders( + QuicStreamId id, + const SpdyHeaderBlock& headers, + bool fin, + QuicPriority priority, + QuicAckNotifier::DelegateInterface* ack_notifier_delegate); + + QuicHeadersStream* headers_stream() { return headers_stream_.get(); } + + protected: + // Override CreateIncomingDynamicStream() and CreateOutgoingDynamicStream() + // with QuicDataStream return type to make sure that all data streams are + // QuicDataStreams. + QuicDataStream* CreateIncomingDynamicStream(QuicStreamId id) override = 0; + QuicDataStream* CreateOutgoingDynamicStream() override = 0; + + QuicDataStream* GetSpdyDataStream(const QuicStreamId stream_id); + + private: + friend class test::QuicSpdySessionPeer; + + scoped_ptr<QuicHeadersStream> headers_stream_; + + DISALLOW_COPY_AND_ASSIGN(QuicSpdySession); +}; + +} // namespace net + +#endif // NET_QUIC_QUIC_SPDY_SESSION_H_ diff --git a/net/quic/quic_stream_sequencer_test.cc b/net/quic/quic_stream_sequencer_test.cc index 0f328c9..7ff719e 100644 --- a/net/quic/quic_stream_sequencer_test.cc +++ b/net/quic/quic_stream_sequencer_test.cc @@ -101,7 +101,7 @@ class QuicStreamSequencerTest : public ::testing::Test { } MockConnection* connection_; - MockSession session_; + MockQuicSpdySession session_; testing::StrictMock<MockStream> stream_; scoped_ptr<QuicStreamSequencer> sequencer_; map<QuicStreamOffset, string>* buffered_frames_; diff --git a/net/quic/quic_unacked_packet_map.cc b/net/quic/quic_unacked_packet_map.cc index 87a733b..690d2bb6 100644 --- a/net/quic/quic_unacked_packet_map.cc +++ b/net/quic/quic_unacked_packet_map.cc @@ -302,10 +302,6 @@ void QuicUnackedPacketMap::RemoveFromInFlight( void QuicUnackedPacketMap::CancelRetransmissionsForStream( QuicStreamId stream_id) { - if (stream_id == kCryptoStreamId || stream_id == kHeadersStreamId) { - LOG(DFATAL) << "Special streams must always retransmit data: " << stream_id; - return; - } QuicPacketSequenceNumber sequence_number = least_unacked_; for (UnackedPacketMap::const_iterator it = unacked_packets_.begin(); it != unacked_packets_.end(); ++it, ++sequence_number) { diff --git a/net/quic/reliable_quic_stream_test.cc b/net/quic/reliable_quic_stream_test.cc index acc256f..2de7b9d 100644 --- a/net/quic/reliable_quic_stream_test.cc +++ b/net/quic/reliable_quic_stream_test.cc @@ -107,7 +107,7 @@ class ReliableQuicStreamTest : public ::testing::TestWithParam<bool> { void Initialize(bool stream_should_process_data) { connection_ = new StrictMock<MockConnection>(Perspective::IS_SERVER, supported_versions_); - session_.reset(new StrictMock<MockSession>(connection_)); + session_.reset(new StrictMock<MockQuicSpdySession>(connection_)); // New streams rely on having the peer's flow control receive window // negotiated in the config. @@ -134,7 +134,7 @@ class ReliableQuicStreamTest : public ::testing::TestWithParam<bool> { protected: MockConnection* connection_; - scoped_ptr<MockSession> session_; + scoped_ptr<MockQuicSpdySession> session_; scoped_ptr<TestStream> stream_; SpdyHeaderBlock headers_; QuicWriteBlockedList* write_blocked_list_; diff --git a/net/quic/test_tools/crypto_test_utils.cc b/net/quic/test_tools/crypto_test_utils.cc index ba3bce7..811da80 100644 --- a/net/quic/test_tools/crypto_test_utils.cc +++ b/net/quic/test_tools/crypto_test_utils.cc @@ -189,7 +189,7 @@ int CryptoTestUtils::HandshakeWithFakeServer( server_conn->random_generator(), &config, &crypto_config); - TestServerSession server_session(server_conn, config, &crypto_config); + TestQuicSpdyServerSession server_session(server_conn, config, &crypto_config); // The client's handshake must have been started already. CHECK_NE(0u, client_conn->encrypted_packets_.size()); @@ -232,8 +232,8 @@ int CryptoTestUtils::HandshakeWithFakeClient( // a working ProofSourceForTesting(). crypto_config.SetProofVerifier(FakeProofVerifierForTesting()); } - TestClientSession client_session(client_conn, DefaultQuicConfig(), server_id, - &crypto_config); + TestQuicSpdyClientSession client_session(client_conn, DefaultQuicConfig(), + server_id, &crypto_config); client_session.GetCryptoStream()->CryptoConnect(); CHECK_EQ(1u, client_conn->encrypted_packets_.size()); diff --git a/net/quic/test_tools/quic_session_peer.cc b/net/quic/test_tools/quic_session_peer.cc index 7b52b41..36fb9e8 100644 --- a/net/quic/test_tools/quic_session_peer.cc +++ b/net/quic/test_tools/quic_session_peer.cc @@ -30,27 +30,16 @@ QuicCryptoStream* QuicSessionPeer::GetCryptoStream(QuicSession* session) { } // static -QuicHeadersStream* QuicSessionPeer::GetHeadersStream(QuicSession* session) { - return session->headers_stream_.get(); -} - -// static -void QuicSessionPeer::SetHeadersStream(QuicSession* session, - QuicHeadersStream* headers_stream) { - session->headers_stream_.reset(headers_stream); -} - -// static QuicWriteBlockedList* QuicSessionPeer::GetWriteBlockedStreams( QuicSession* session) { return &session->write_blocked_streams_; } // static -QuicDataStream* QuicSessionPeer::GetIncomingDataStream( +ReliableQuicStream* QuicSessionPeer::GetIncomingDynamicStream( QuicSession* session, QuicStreamId stream_id) { - return session->GetIncomingDataStream(stream_id); + return session->GetIncomingDynamicStream(stream_id); } // static @@ -68,7 +57,7 @@ bool QuicSessionPeer::IsStreamClosed(QuicSession* session, QuicStreamId id) { // static bool QuicSessionPeer::IsStreamCreated(QuicSession* session, QuicStreamId id) { DCHECK_NE(0u, id); - return ContainsKey(session->stream_map_, id); + return ContainsKey(session->dynamic_streams(), id); } // static diff --git a/net/quic/test_tools/quic_session_peer.h b/net/quic/test_tools/quic_session_peer.h index a57cab54..9e06411 100644 --- a/net/quic/test_tools/quic_session_peer.h +++ b/net/quic/test_tools/quic_session_peer.h @@ -16,6 +16,7 @@ class QuicCryptoStream; class QuicDataStream; class QuicHeadersStream; class QuicSession; +class ReliableQuicStream; namespace test { @@ -24,12 +25,9 @@ class QuicSessionPeer { static void SetNextStreamId(QuicSession* session, QuicStreamId id); static void SetMaxOpenStreams(QuicSession* session, uint32 max_streams); static QuicCryptoStream* GetCryptoStream(QuicSession* session); - static QuicHeadersStream* GetHeadersStream(QuicSession* session); - static void SetHeadersStream(QuicSession* session, - QuicHeadersStream* headers_stream); static QuicWriteBlockedList* GetWriteBlockedStreams(QuicSession* session); - static QuicDataStream* GetIncomingDataStream(QuicSession* session, - QuicStreamId stream_id); + static ReliableQuicStream* GetIncomingDynamicStream(QuicSession* session, + QuicStreamId stream_id); static std::map<QuicStreamId, QuicStreamOffset>& GetLocallyClosedStreamsHighestOffset(QuicSession* session); diff --git a/net/quic/test_tools/quic_spdy_session_peer.cc b/net/quic/test_tools/quic_spdy_session_peer.cc new file mode 100644 index 0000000..e13e477 --- /dev/null +++ b/net/quic/test_tools/quic_spdy_session_peer.cc @@ -0,0 +1,26 @@ +// Copyright (c) 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "net/quic/test_tools/quic_spdy_session_peer.h" + +#include "net/quic/quic_spdy_session.h" + +namespace net { +namespace test { + +// static +QuicHeadersStream* QuicSpdySessionPeer::GetHeadersStream( + QuicSpdySession* session) { + return session->headers_stream_.get(); +} + +// static +void QuicSpdySessionPeer::SetHeadersStream(QuicSpdySession* session, + QuicHeadersStream* headers_stream) { + session->headers_stream_.reset(headers_stream); + session->static_streams()[headers_stream->id()] = headers_stream; +} + +} // namespace test +} // namespace net diff --git a/net/quic/test_tools/quic_spdy_session_peer.h b/net/quic/test_tools/quic_spdy_session_peer.h new file mode 100644 index 0000000..840f3dc --- /dev/null +++ b/net/quic/test_tools/quic_spdy_session_peer.h @@ -0,0 +1,32 @@ +// Copyright (c) 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NET_QUIC_TEST_TOOLS_QUIC_SPDY_SESSION_PEER_H_ +#define NET_QUIC_TEST_TOOLS_QUIC_SPDY_SESSION_PEER_H_ + +#include "net/quic/quic_protocol.h" +#include "net/quic/quic_write_blocked_list.h" + +namespace net { + +class QuicHeadersStream; +class QuicSpdySession; + +namespace test { + +class QuicSpdySessionPeer { + public: + static QuicHeadersStream* GetHeadersStream(QuicSpdySession* session); + static void SetHeadersStream(QuicSpdySession* session, + QuicHeadersStream* headers_stream); + + private: + DISALLOW_COPY_AND_ASSIGN(QuicSpdySessionPeer); +}; + +} // namespace test + +} // namespace net + +#endif // NET_QUIC_TEST_TOOLS_QUIC_SPDY_SESSION_PEER_H_ diff --git a/net/quic/test_tools/quic_test_utils.cc b/net/quic/test_tools/quic_test_utils.cc index 05784f5..c38be57 100644 --- a/net/quic/test_tools/quic_test_utils.cc +++ b/net/quic/test_tools/quic_test_utils.cc @@ -338,37 +338,38 @@ void PacketSavingConnection::SendOrQueuePacket(QueuedPacket packet) { NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA); } -MockSession::MockSession(QuicConnection* connection) - : QuicSession(connection, DefaultQuicConfig()) { +MockQuicSpdySession::MockQuicSpdySession(QuicConnection* connection) + : QuicSpdySession(connection, DefaultQuicConfig()) { crypto_stream_.reset(new QuicCryptoStream(this)); Initialize(); ON_CALL(*this, WritevData(_, _, _, _, _, _)) .WillByDefault(testing::Return(QuicConsumedData(0, false))); } -MockSession::~MockSession() { +MockQuicSpdySession::~MockQuicSpdySession() { } -TestServerSession::TestServerSession( +TestQuicSpdyServerSession::TestQuicSpdyServerSession( QuicConnection* connection, const QuicConfig& config, const QuicCryptoServerConfig* crypto_config) - : QuicSession(connection, config) { + : QuicSpdySession(connection, config) { crypto_stream_.reset(new QuicCryptoServerStream(crypto_config, this)); Initialize(); } -TestServerSession::~TestServerSession() { +TestQuicSpdyServerSession::~TestQuicSpdyServerSession() { } -QuicCryptoServerStream* TestServerSession::GetCryptoStream() { +QuicCryptoServerStream* TestQuicSpdyServerSession::GetCryptoStream() { return crypto_stream_.get(); } -TestClientSession::TestClientSession(QuicConnection* connection, - const QuicConfig& config, - const QuicServerId& server_id, - QuicCryptoClientConfig* crypto_config) +TestQuicSpdyClientSession::TestQuicSpdyClientSession( + QuicConnection* connection, + const QuicConfig& config, + const QuicServerId& server_id, + QuicCryptoClientConfig* crypto_config) : QuicClientSessionBase(connection, config) { crypto_stream_.reset(new QuicCryptoClientStream( server_id, this, CryptoTestUtils::ProofVerifyContextForTesting(), @@ -376,9 +377,10 @@ TestClientSession::TestClientSession(QuicConnection* connection, Initialize(); } -TestClientSession::~TestClientSession() {} +TestQuicSpdyClientSession::~TestQuicSpdyClientSession() { +} -QuicCryptoClientStream* TestClientSession::GetCryptoStream() { +QuicCryptoClientStream* TestQuicSpdyClientSession::GetCryptoStream() { return crypto_stream_.get(); } @@ -793,7 +795,7 @@ void CreateClientSessionForTest(QuicServerId server_id, QuicTime::Delta connection_start_time, QuicCryptoClientConfig* crypto_client_config, PacketSavingConnection** client_connection, - TestClientSession** client_session) { + TestQuicSpdyClientSession** client_session) { CHECK(crypto_client_config); CHECK(client_connection); CHECK(client_session); @@ -805,8 +807,8 @@ void CreateClientSessionForTest(QuicServerId server_id, ? DefaultQuicConfigStatelessRejects() : DefaultQuicConfig(); *client_connection = new PacketSavingConnection(Perspective::IS_CLIENT); - *client_session = new TestClientSession(*client_connection, config, server_id, - crypto_client_config); + *client_session = new TestQuicSpdyClientSession( + *client_connection, config, server_id, crypto_client_config); (*client_connection)->AdvanceTime(connection_start_time); } @@ -814,7 +816,7 @@ void CreateServerSessionForTest(QuicServerId server_id, QuicTime::Delta connection_start_time, QuicCryptoServerConfig* server_crypto_config, PacketSavingConnection** server_connection, - TestServerSession** server_session) { + TestQuicSpdyServerSession** server_session) { CHECK(server_crypto_config); CHECK(server_connection); CHECK(server_session); @@ -823,7 +825,7 @@ void CreateServerSessionForTest(QuicServerId server_id, << "strike-register will be unhappy."; *server_connection = new PacketSavingConnection(Perspective::IS_SERVER); - *server_session = new TestServerSession( + *server_session = new TestQuicSpdyServerSession( *server_connection, DefaultQuicConfig(), server_crypto_config); // We advance the clock initially because the default time is zero and the diff --git a/net/quic/test_tools/quic_test_utils.h b/net/quic/test_tools/quic_test_utils.h index fa97422..04143a6 100644 --- a/net/quic/test_tools/quic_test_utils.h +++ b/net/quic/test_tools/quic_test_utils.h @@ -289,7 +289,7 @@ class MockConnectionVisitor : public QuicConnectionVisitorInterface { MOCK_METHOD1(OnCongestionWindowChange, void(QuicTime now)); MOCK_CONST_METHOD0(WillingAndAbleToWrite, bool()); MOCK_CONST_METHOD0(HasPendingHandshake, bool()); - MOCK_CONST_METHOD0(HasOpenDataStreams, bool()); + MOCK_CONST_METHOD0(HasOpenDynamicStreams, bool()); MOCK_METHOD1(OnSuccessfulVersionNegotiation, void(const QuicVersion& version)); MOCK_METHOD0(OnConfigNegotiated, void()); @@ -422,16 +422,16 @@ class PacketSavingConnection : public MockConnection { DISALLOW_COPY_AND_ASSIGN(PacketSavingConnection); }; -class MockSession : public QuicSession { +class MockQuicSpdySession : public QuicSpdySession { public: - explicit MockSession(QuicConnection* connection); - ~MockSession() override; + explicit MockQuicSpdySession(QuicConnection* connection); + ~MockQuicSpdySession() override; QuicCryptoStream* GetCryptoStream() { return crypto_stream_.get(); } MOCK_METHOD2(OnConnectionClosed, void(QuicErrorCode error, bool from_peer)); - MOCK_METHOD1(CreateIncomingDataStream, QuicDataStream*(QuicStreamId id)); - MOCK_METHOD0(CreateOutgoingDataStream, QuicDataStream*()); + MOCK_METHOD1(CreateIncomingDynamicStream, QuicDataStream*(QuicStreamId id)); + MOCK_METHOD0(CreateOutgoingDynamicStream, QuicDataStream*()); MOCK_METHOD6(WritevData, QuicConsumedData(QuicStreamId id, const IOVector& data, @@ -456,34 +456,34 @@ class MockSession : public QuicSession { private: scoped_ptr<QuicCryptoStream> crypto_stream_; - DISALLOW_COPY_AND_ASSIGN(MockSession); + DISALLOW_COPY_AND_ASSIGN(MockQuicSpdySession); }; -class TestServerSession : public QuicSession { +class TestQuicSpdyServerSession : public QuicSpdySession { public: - TestServerSession(QuicConnection* connection, - const QuicConfig& config, - const QuicCryptoServerConfig* crypto_config); - ~TestServerSession() override; + TestQuicSpdyServerSession(QuicConnection* connection, + const QuicConfig& config, + const QuicCryptoServerConfig* crypto_config); + ~TestQuicSpdyServerSession() override; - MOCK_METHOD1(CreateIncomingDataStream, QuicDataStream*(QuicStreamId id)); - MOCK_METHOD0(CreateOutgoingDataStream, QuicDataStream*()); + MOCK_METHOD1(CreateIncomingDynamicStream, QuicDataStream*(QuicStreamId id)); + MOCK_METHOD0(CreateOutgoingDynamicStream, QuicDataStream*()); QuicCryptoServerStream* GetCryptoStream() override; private: scoped_ptr<QuicCryptoServerStream> crypto_stream_; - DISALLOW_COPY_AND_ASSIGN(TestServerSession); + DISALLOW_COPY_AND_ASSIGN(TestQuicSpdyServerSession); }; -class TestClientSession : public QuicClientSessionBase { +class TestQuicSpdyClientSession : public QuicClientSessionBase { public: - TestClientSession(QuicConnection* connection, - const QuicConfig& config, - const QuicServerId& server_id, - QuicCryptoClientConfig* crypto_config); - ~TestClientSession() override; + TestQuicSpdyClientSession(QuicConnection* connection, + const QuicConfig& config, + const QuicServerId& server_id, + QuicCryptoClientConfig* crypto_config); + ~TestQuicSpdyClientSession() override; // QuicClientSessionBase MOCK_METHOD1(OnProofValid, @@ -491,16 +491,16 @@ class TestClientSession : public QuicClientSessionBase { MOCK_METHOD1(OnProofVerifyDetailsAvailable, void(const ProofVerifyDetails& verify_details)); - // TestClientSession - MOCK_METHOD1(CreateIncomingDataStream, QuicDataStream*(QuicStreamId id)); - MOCK_METHOD0(CreateOutgoingDataStream, QuicDataStream*()); + // TestQuicSpdyClientSession + MOCK_METHOD1(CreateIncomingDynamicStream, QuicDataStream*(QuicStreamId id)); + MOCK_METHOD0(CreateOutgoingDynamicStream, QuicDataStream*()); QuicCryptoClientStream* GetCryptoStream() override; private: scoped_ptr<QuicCryptoClientStream> crypto_stream_; - DISALLOW_COPY_AND_ASSIGN(TestClientSession); + DISALLOW_COPY_AND_ASSIGN(TestQuicSpdyClientSession); }; class MockPacketWriter : public QuicPacketWriter { @@ -739,7 +739,7 @@ void CreateClientSessionForTest(QuicServerId server_id, QuicTime::Delta connection_start_time, QuicCryptoClientConfig* crypto_client_config, PacketSavingConnection** client_connection, - TestClientSession** client_session); + TestQuicSpdyClientSession** client_session); // Creates a server session for testing. // @@ -758,7 +758,7 @@ void CreateServerSessionForTest(QuicServerId server_id, QuicTime::Delta connection_start_time, QuicCryptoServerConfig* crypto_server_config, PacketSavingConnection** server_connection, - TestServerSession** server_session); + TestQuicSpdyServerSession** server_session); } // namespace test } // namespace net diff --git a/net/tools/quic/end_to_end_test.cc b/net/tools/quic/end_to_end_test.cc index 430dbe0..e6d8a38 100644 --- a/net/tools/quic/end_to_end_test.cc +++ b/net/tools/quic/end_to_end_test.cc @@ -28,6 +28,7 @@ #include "net/quic/test_tools/quic_flow_controller_peer.h" #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" #include "net/quic/test_tools/quic_session_peer.h" +#include "net/quic/test_tools/quic_spdy_session_peer.h" #include "net/quic/test_tools/quic_test_utils.h" #include "net/quic/test_tools/reliable_quic_stream_peer.h" #include "net/test/gtest_util.h" @@ -58,6 +59,7 @@ using net::test::QuicConnectionPeer; using net::test::QuicFlowControllerPeer; using net::test::QuicSentPacketManagerPeer; using net::test::QuicSessionPeer; +using net::test::QuicSpdySessionPeer; using net::test::ReliableQuicStreamPeer; using net::test::ValueRestore; using net::test::kClientDataStreamId1; @@ -699,15 +701,14 @@ TEST_P(EndToEndTest, CorrectlyConfiguredFec) { QuicDispatcher* dispatcher = QuicServerPeer::GetDispatcher(server_thread_->server()); ASSERT_EQ(1u, dispatcher->session_map().size()); - QuicSession* session = dispatcher->session_map().begin()->second; + QuicSpdySession* session = dispatcher->session_map().begin()->second; EXPECT_EQ(expected_policy, - QuicSessionPeer::GetHeadersStream(session)->fec_policy()); + QuicSpdySessionPeer::GetHeadersStream(session)->fec_policy()); server_thread_->Resume(); // Verify that client's FEC configuration is correct. - EXPECT_EQ(expected_policy, - QuicSessionPeer::GetHeadersStream( - client_->client()->session())->fec_policy()); + EXPECT_EQ(expected_policy, QuicSpdySessionPeer::GetHeadersStream( + client_->client()->session())->fec_policy()); EXPECT_EQ(expected_policy, client_->GetOrCreateStream()->fec_policy()); } @@ -1291,7 +1292,7 @@ TEST_P(EndToEndTest, HeadersAndCryptoStreamsNoConnectionFlowControl) { EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); QuicHeadersStream* headers_stream = - QuicSessionPeer::GetHeadersStream(client_->client()->session()); + QuicSpdySessionPeer::GetHeadersStream(client_->client()->session()); EXPECT_LT( QuicFlowControllerPeer::SendWindowSize(headers_stream->flow_controller()), kStreamIFCW); diff --git a/net/tools/quic/quic_client.cc b/net/tools/quic/quic_client.cc index 24ce0007..73648d9 100644 --- a/net/tools/quic/quic_client.cc +++ b/net/tools/quic/quic_client.cc @@ -295,7 +295,7 @@ QuicSpdyClientStream* QuicClient::CreateReliableClientStream() { return nullptr; } - return session_->CreateOutgoingDataStream(); + return session_->CreateOutgoingDynamicStream(); } void QuicClient::WaitForStreamToClose(QuicStreamId id) { diff --git a/net/tools/quic/quic_client_session.cc b/net/tools/quic/quic_client_session.cc index 0b99420..48b3077 100644 --- a/net/tools/quic/quic_client_session.cc +++ b/net/tools/quic/quic_client_session.cc @@ -33,7 +33,7 @@ void QuicClientSession::OnProofValid( void QuicClientSession::OnProofVerifyDetailsAvailable( const ProofVerifyDetails& /*verify_details*/) {} -QuicSpdyClientStream* QuicClientSession::CreateOutgoingDataStream() { +QuicSpdyClientStream* QuicClientSession::CreateOutgoingDynamicStream() { if (!crypto_stream_->encryption_established()) { DVLOG(1) << "Encryption not active so no outgoing stream created."; return nullptr; @@ -67,7 +67,7 @@ int QuicClientSession::GetNumSentClientHellos() const { return crypto_stream_->num_sent_client_hellos(); } -QuicDataStream* QuicClientSession::CreateIncomingDataStream( +QuicDataStream* QuicClientSession::CreateIncomingDynamicStream( QuicStreamId id) { DLOG(ERROR) << "Server push not supported"; return nullptr; diff --git a/net/tools/quic/quic_client_session.h b/net/tools/quic/quic_client_session.h index 3722868..f630fd3 100644 --- a/net/tools/quic/quic_client_session.h +++ b/net/tools/quic/quic_client_session.h @@ -32,7 +32,7 @@ class QuicClientSession : public QuicClientSessionBase { ~QuicClientSession() override; // QuicSession methods: - QuicSpdyClientStream* CreateOutgoingDataStream() override; + QuicSpdyClientStream* CreateOutgoingDynamicStream() override; QuicCryptoClientStream* GetCryptoStream() override; // QuicClientSessionBase methods: @@ -54,7 +54,7 @@ class QuicClientSession : public QuicClientSessionBase { protected: // QuicSession methods: - QuicDataStream* CreateIncomingDataStream(QuicStreamId id) override; + QuicDataStream* CreateIncomingDynamicStream(QuicStreamId id) override; private: scoped_ptr<QuicCryptoClientStream> crypto_stream_; diff --git a/net/tools/quic/quic_client_session_test.cc b/net/tools/quic/quic_client_session_test.cc index d7f4101..1543f56 100644 --- a/net/tools/quic/quic_client_session_test.cc +++ b/net/tools/quic/quic_client_session_test.cc @@ -10,7 +10,7 @@ #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" #include "net/quic/quic_flags.h" #include "net/quic/test_tools/crypto_test_utils.h" -#include "net/quic/test_tools/quic_session_peer.h" +#include "net/quic/test_tools/quic_spdy_session_peer.h" #include "net/quic/test_tools/quic_test_utils.h" #include "net/tools/quic/quic_spdy_client_stream.h" #include "testing/gtest/include/gtest/gtest.h" @@ -21,7 +21,7 @@ using net::test::CryptoTestUtils; using net::test::DefaultQuicConfig; using net::test::MockConnection; using net::test::PacketSavingConnection; -using net::test::QuicSessionPeer; +using net::test::QuicSpdySessionPeer; using net::test::SupportedVersions; using net::test::TestPeerIPAddress; using net::test::ValueRestore; @@ -80,13 +80,13 @@ TEST_P(ToolsQuicClientSessionTest, MaxNumStreams) { // Initialize crypto before the client session will create a stream. CompleteCryptoHandshake(); - QuicSpdyClientStream* stream = session_->CreateOutgoingDataStream(); + QuicSpdyClientStream* stream = session_->CreateOutgoingDynamicStream(); ASSERT_TRUE(stream); - EXPECT_FALSE(session_->CreateOutgoingDataStream()); + EXPECT_FALSE(session_->CreateOutgoingDynamicStream()); // Close a stream and ensure I can now open a new one. session_->CloseStream(stream->id()); - stream = session_->CreateOutgoingDataStream(); + stream = session_->CreateOutgoingDynamicStream(); EXPECT_TRUE(stream); } @@ -96,7 +96,7 @@ TEST_P(ToolsQuicClientSessionTest, GoAwayReceived) { // After receiving a GoAway, I should no longer be able to create outgoing // streams. session_->OnGoAway(QuicGoAwayFrame(QUIC_PEER_GOING_AWAY, 1u, "Going away.")); - EXPECT_EQ(nullptr, session_->CreateOutgoingDataStream()); + EXPECT_EQ(nullptr, session_->CreateOutgoingDynamicStream()); } TEST_P(ToolsQuicClientSessionTest, SetFecProtectionFromConfig) { @@ -112,9 +112,9 @@ TEST_P(ToolsQuicClientSessionTest, SetFecProtectionFromConfig) { // Verify that headers stream is always protected and data streams are // optionally protected. - EXPECT_EQ(FEC_PROTECT_ALWAYS, - QuicSessionPeer::GetHeadersStream(session_.get())->fec_policy()); - QuicSpdyClientStream* stream = session_->CreateOutgoingDataStream(); + EXPECT_EQ(FEC_PROTECT_ALWAYS, QuicSpdySessionPeer::GetHeadersStream( + session_.get())->fec_policy()); + QuicSpdyClientStream* stream = session_->CreateOutgoingDynamicStream(); ASSERT_TRUE(stream); EXPECT_EQ(FEC_PROTECT_OPTIONAL, stream->fec_policy()); } diff --git a/net/tools/quic/quic_dispatcher_test.cc b/net/tools/quic/quic_dispatcher_test.cc index bf94210..af9d45e 100644 --- a/net/tools/quic/quic_dispatcher_test.cc +++ b/net/tools/quic/quic_dispatcher_test.cc @@ -29,7 +29,6 @@ using base::StringPiece; using net::EpollServer; using net::test::ConstructEncryptedPacket; using net::test::MockConnection; -using net::test::MockSession; using net::test::ValueRestore; using std::string; using std::vector; @@ -44,18 +43,18 @@ namespace tools { namespace test { namespace { -class TestServerSession : public QuicServerSession { +class TestQuicSpdyServerSession : public QuicServerSession { public: - TestServerSession(const QuicConfig& config, - QuicConnection* connection, - const QuicCryptoServerConfig* crypto_config) + TestQuicSpdyServerSession(const QuicConfig& config, + QuicConnection* connection, + const QuicCryptoServerConfig* crypto_config) : QuicServerSession(config, connection, nullptr, crypto_config), crypto_stream_(QuicServerSession::GetCryptoStream()) {} - ~TestServerSession() override{}; + ~TestQuicSpdyServerSession() override{}; MOCK_METHOD2(OnConnectionClosed, void(QuicErrorCode error, bool from_peer)); - MOCK_METHOD1(CreateIncomingDataStream, QuicDataStream*(QuicStreamId id)); - MOCK_METHOD0(CreateOutgoingDataStream, QuicDataStream*()); + MOCK_METHOD1(CreateIncomingDynamicStream, QuicDataStream*(QuicStreamId id)); + MOCK_METHOD0(CreateOutgoingDynamicStream, QuicDataStream*()); void SetCryptoStream(QuicCryptoServerStream* crypto_stream) { crypto_stream_ = crypto_stream; @@ -66,7 +65,7 @@ class TestServerSession : public QuicServerSession { private: QuicCryptoServerStream* crypto_stream_; - DISALLOW_COPY_AND_ASSIGN(TestServerSession); + DISALLOW_COPY_AND_ASSIGN(TestQuicSpdyServerSession); }; class TestDispatcher : public QuicDispatcher { @@ -114,10 +113,10 @@ QuicServerSession* CreateSession(QuicDispatcher* dispatcher, QuicConnectionId connection_id, const IPEndPoint& client_address, const QuicCryptoServerConfig* crypto_config, - TestServerSession** session) { + TestQuicSpdyServerSession** session) { MockServerConnection* connection = new MockServerConnection(connection_id, dispatcher); - *session = new TestServerSession(config, connection, crypto_config); + *session = new TestQuicSpdyServerSession(config, connection, crypto_config); connection->set_visitor(*session); ON_CALL(*connection, SendConnectionClose(_)).WillByDefault( WithoutArgs(Invoke( @@ -203,8 +202,8 @@ class QuicDispatcherTest : public ::testing::Test { IPEndPoint server_address_; TestDispatcher dispatcher_; MockTimeWaitListManager* time_wait_list_manager_; - TestServerSession* session1_; - TestServerSession* session2_; + TestQuicSpdyServerSession* session1_; + TestQuicSpdyServerSession* session2_; string data_; }; diff --git a/net/tools/quic/quic_server_session.cc b/net/tools/quic/quic_server_session.cc index 10d95e8..fb9996a 100644 --- a/net/tools/quic/quic_server_session.cc +++ b/net/tools/quic/quic_server_session.cc @@ -8,6 +8,7 @@ #include "net/quic/proto/cached_network_parameters.pb.h" #include "net/quic/quic_connection.h" #include "net/quic/quic_flags.h" +#include "net/quic/quic_spdy_session.h" #include "net/quic/reliable_quic_stream.h" #include "net/tools/quic/quic_spdy_server_stream.h" @@ -19,7 +20,7 @@ QuicServerSession::QuicServerSession( QuicConnection* connection, QuicServerSessionVisitor* visitor, const QuicCryptoServerConfig* crypto_config) - : QuicSession(connection, config), + : QuicSpdySession(connection, config), crypto_config_(crypto_config), visitor_(visitor), bandwidth_resumption_enabled_(false), @@ -32,7 +33,7 @@ QuicServerSession::~QuicServerSession() {} void QuicServerSession::Initialize() { crypto_stream_.reset(CreateQuicCryptoServerStream(crypto_config_)); - QuicSession::Initialize(); + QuicSpdySession::Initialize(); } QuicCryptoServerStream* QuicServerSession::CreateQuicCryptoServerStream( @@ -68,7 +69,7 @@ void QuicServerSession::OnConfigNegotiated() { ContainsQuicTag(config()->ReceivedConnectionOptions(), kFHDR)) { // kFHDR config maps to FEC protection always for headers stream. // TODO(jri): Add crypto stream in addition to headers for kHDR. - headers_stream_->set_fec_policy(FEC_PROTECT_ALWAYS); + headers_stream()->set_fec_policy(FEC_PROTECT_ALWAYS); } } @@ -176,9 +177,9 @@ void QuicServerSession::OnCongestionWindowChange(QuicTime now) { connection()->sequence_number_of_last_sent_packet(); } -bool QuicServerSession::ShouldCreateIncomingDataStream(QuicStreamId id) { +bool QuicServerSession::ShouldCreateIncomingDynamicStream(QuicStreamId id) { if (!connection()->connected()) { - LOG(DFATAL) << "ShouldCreateIncomingDataStream called when disconnected"; + LOG(DFATAL) << "ShouldCreateIncomingDynamicStream called when disconnected"; return false; } @@ -197,16 +198,16 @@ bool QuicServerSession::ShouldCreateIncomingDataStream(QuicStreamId id) { return true; } -QuicDataStream* QuicServerSession::CreateIncomingDataStream( +QuicDataStream* QuicServerSession::CreateIncomingDynamicStream( QuicStreamId id) { - if (!ShouldCreateIncomingDataStream(id)) { + if (!ShouldCreateIncomingDynamicStream(id)) { return nullptr; } return new QuicSpdyServerStream(id, this); } -QuicDataStream* QuicServerSession::CreateOutgoingDataStream() { +QuicDataStream* QuicServerSession::CreateOutgoingDynamicStream() { DLOG(ERROR) << "Server push not yet supported"; return nullptr; } diff --git a/net/tools/quic/quic_server_session.h b/net/tools/quic/quic_server_session.h index 757cab6..16f08bd 100644 --- a/net/tools/quic/quic_server_session.h +++ b/net/tools/quic/quic_server_session.h @@ -16,7 +16,7 @@ #include "base/memory/scoped_ptr.h" #include "net/quic/quic_crypto_server_stream.h" #include "net/quic/quic_protocol.h" -#include "net/quic/quic_session.h" +#include "net/quic/quic_spdy_session.h" namespace net { @@ -50,7 +50,7 @@ class QuicServerSessionVisitor { QuicConnectionId connection_id) {} }; -class QuicServerSession : public QuicSession { +class QuicServerSession : public QuicSpdySession { public: // |crypto_config| must outlive the session. QuicServerSession(const QuicConfig& config, @@ -104,14 +104,14 @@ class QuicServerSession : public QuicSession { protected: // QuicSession methods: - QuicDataStream* CreateIncomingDataStream(QuicStreamId id) override; - QuicDataStream* CreateOutgoingDataStream() override; + QuicDataStream* CreateIncomingDynamicStream(QuicStreamId id) override; + QuicDataStream* CreateOutgoingDynamicStream() override; QuicCryptoServerStream* GetCryptoStream() override; // If we should create an incoming stream, returns true. Otherwise // does error handling, including communicating the error to the client and // possibly closing the connection, and returns false. - virtual bool ShouldCreateIncomingDataStream(QuicStreamId id); + virtual bool ShouldCreateIncomingDynamicStream(QuicStreamId id); virtual QuicCryptoServerStream* CreateQuicCryptoServerStream( const QuicCryptoServerConfig* crypto_config); diff --git a/net/tools/quic/quic_server_session_test.cc b/net/tools/quic/quic_server_session_test.cc index 1df0dc6..a7ec9fe 100644 --- a/net/tools/quic/quic_server_session_test.cc +++ b/net/tools/quic/quic_server_session_test.cc @@ -16,6 +16,7 @@ #include "net/quic/test_tools/quic_data_stream_peer.h" #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" #include "net/quic/test_tools/quic_session_peer.h" +#include "net/quic/test_tools/quic_spdy_session_peer.h" #include "net/quic/test_tools/quic_sustained_bandwidth_recorder_peer.h" #include "net/quic/test_tools/quic_test_utils.h" #include "net/test/gtest_util.h" @@ -31,6 +32,7 @@ using net::test::QuicConnectionPeer; using net::test::QuicDataStreamPeer; using net::test::QuicSentPacketManagerPeer; using net::test::QuicSessionPeer; +using net::test::QuicSpdySessionPeer; using net::test::QuicSustainedBandwidthRecorderPeer; using net::test::SupportedVersions; using net::test::ValueRestore; @@ -47,13 +49,14 @@ namespace test { class QuicServerSessionPeer { public: - static QuicDataStream* GetIncomingDataStream( - QuicServerSession* s, QuicStreamId id) { - return s->GetIncomingDataStream(id); + static ReliableQuicStream* GetIncomingDynamicStream(QuicServerSession* s, + QuicStreamId id) { + return s->GetIncomingDynamicStream(id); } static void SetCryptoStream(QuicServerSession* s, QuicCryptoServerStream* crypto_stream) { s->crypto_stream_.reset(crypto_stream); + s->static_streams()[kCryptoStreamId] = crypto_stream; } static bool IsBandwidthResumptionEnabled(QuicServerSession* s) { return s->bandwidth_resumption_enabled_; @@ -207,23 +210,23 @@ TEST_P(QuicServerSessionTest, MaxOpenStreams) { QuicStreamId stream_id = kClientDataStreamId1; // Open the max configured number of streams, should be no problem. for (size_t i = 0; i < kMaxStreamsForTest; ++i) { - EXPECT_TRUE(QuicServerSessionPeer::GetIncomingDataStream(session_.get(), - stream_id)); + EXPECT_TRUE(QuicServerSessionPeer::GetIncomingDynamicStream(session_.get(), + stream_id)); stream_id += 2; } // Open more streams: server should accept slightly more than the limit. for (size_t i = 0; i < kMaxStreamsMinimumIncrement; ++i) { - EXPECT_TRUE(QuicServerSessionPeer::GetIncomingDataStream(session_.get(), - stream_id)); + EXPECT_TRUE(QuicServerSessionPeer::GetIncomingDynamicStream(session_.get(), + stream_id)); stream_id += 2; } // Now violate the server's internal stream limit. EXPECT_CALL(*connection_, SendConnectionClose(QUIC_TOO_MANY_OPEN_STREAMS)); stream_id += 2; - EXPECT_FALSE( - QuicServerSessionPeer::GetIncomingDataStream(session_.get(), stream_id)); + EXPECT_FALSE(QuicServerSessionPeer::GetIncomingDynamicStream(session_.get(), + stream_id)); } TEST_P(QuicServerSessionTest, MaxOpenStreamsImplicit) { @@ -241,19 +244,19 @@ TEST_P(QuicServerSessionTest, MaxOpenStreamsImplicit) { session_->get_max_open_streams()); EXPECT_EQ(0u, session_->GetNumOpenStreams()); - EXPECT_TRUE(QuicServerSessionPeer::GetIncomingDataStream( + EXPECT_TRUE(QuicServerSessionPeer::GetIncomingDynamicStream( session_.get(), kClientDataStreamId1)); // Implicitly open streams up to the server's limit. const int kActualMaxStreams = kMaxStreamsForTest + kMaxStreamsMinimumIncrement; const int kMaxValidStreamId = kClientDataStreamId1 + (kActualMaxStreams - 1) * 2; - EXPECT_TRUE(QuicServerSessionPeer::GetIncomingDataStream( + EXPECT_TRUE(QuicServerSessionPeer::GetIncomingDynamicStream( session_.get(), kMaxValidStreamId)); // Opening a further stream will result in connection close. EXPECT_CALL(*connection_, SendConnectionClose(QUIC_TOO_MANY_OPEN_STREAMS)); - EXPECT_FALSE(QuicServerSessionPeer::GetIncomingDataStream( + EXPECT_FALSE(QuicServerSessionPeer::GetIncomingDynamicStream( session_.get(), kMaxValidStreamId + 2)); } @@ -261,14 +264,15 @@ TEST_P(QuicServerSessionTest, GetEvenIncomingError) { // Incoming streams on the server session must be odd. EXPECT_CALL(*connection_, SendConnectionClose(QUIC_INVALID_STREAM_ID)); EXPECT_EQ(nullptr, - QuicServerSessionPeer::GetIncomingDataStream(session_.get(), 4)); + QuicServerSessionPeer::GetIncomingDynamicStream(session_.get(), 4)); } TEST_P(QuicServerSessionTest, GetStreamDisconnected) { // Don't create new streams if the connection is disconnected. QuicConnectionPeer::CloseConnection(connection_); - EXPECT_DFATAL(QuicServerSessionPeer::GetIncomingDataStream(session_.get(), 5), - "ShouldCreateIncomingDataStream called when disconnected"); + EXPECT_DFATAL( + QuicServerSessionPeer::GetIncomingDynamicStream(session_.get(), 5), + "ShouldCreateIncomingDynamicStream called when disconnected"); } TEST_P(QuicServerSessionTest, SetFecProtectionFromConfig) { @@ -282,9 +286,9 @@ TEST_P(QuicServerSessionTest, SetFecProtectionFromConfig) { // Verify that headers stream is always protected and data streams are // optionally protected. - EXPECT_EQ(FEC_PROTECT_ALWAYS, - QuicSessionPeer::GetHeadersStream(session_.get())->fec_policy()); - QuicDataStream* stream = QuicServerSessionPeer::GetIncomingDataStream( + EXPECT_EQ(FEC_PROTECT_ALWAYS, QuicSpdySessionPeer::GetHeadersStream( + session_.get())->fec_policy()); + ReliableQuicStream* stream = QuicServerSessionPeer::GetIncomingDynamicStream( session_.get(), kClientDataStreamId1); ASSERT_TRUE(stream); EXPECT_EQ(FEC_PROTECT_OPTIONAL, stream->fec_policy()); diff --git a/net/tools/quic/quic_simple_client.cc b/net/tools/quic/quic_simple_client.cc index 9ba6e69..bbd314e 100644 --- a/net/tools/quic/quic_simple_client.cc +++ b/net/tools/quic/quic_simple_client.cc @@ -232,7 +232,7 @@ QuicSpdyClientStream* QuicSimpleClient::CreateReliableClientStream() { return nullptr; } - return session_->CreateOutgoingDataStream(); + return session_->CreateOutgoingDynamicStream(); } void QuicSimpleClient::WaitForStreamToClose(QuicStreamId id) { diff --git a/net/tools/quic/quic_spdy_server_stream.cc b/net/tools/quic/quic_spdy_server_stream.cc index 4b53172..d43e65e 100644 --- a/net/tools/quic/quic_spdy_server_stream.cc +++ b/net/tools/quic/quic_spdy_server_stream.cc @@ -7,7 +7,8 @@ #include "base/logging.h" #include "base/stl_util.h" #include "base/strings/string_number_conversions.h" -#include "net/quic/quic_session.h" +#include "net/quic/quic_data_stream.h" +#include "net/quic/quic_spdy_session.h" #include "net/quic/spdy_utils.h" #include "net/spdy/spdy_protocol.h" #include "net/tools/quic/quic_in_memory_cache.h" @@ -20,9 +21,8 @@ namespace net { namespace tools { QuicSpdyServerStream::QuicSpdyServerStream(QuicStreamId id, - QuicSession* session) - : QuicDataStream(id, session), - content_length_(-1) { + QuicSpdySession* session) + : QuicDataStream(id, session), content_length_(-1) { } QuicSpdyServerStream::~QuicSpdyServerStream() { diff --git a/net/tools/quic/quic_spdy_server_stream.h b/net/tools/quic/quic_spdy_server_stream.h index 9420d3b..019bc03 100644 --- a/net/tools/quic/quic_spdy_server_stream.h +++ b/net/tools/quic/quic_spdy_server_stream.h @@ -14,7 +14,7 @@ namespace net { -class QuicSession; +class QuicSpdySession; namespace tools { @@ -26,7 +26,7 @@ class QuicSpdyServerStreamPeer; // response. class QuicSpdyServerStream : public QuicDataStream { public: - QuicSpdyServerStream(QuicStreamId id, QuicSession* session); + QuicSpdyServerStream(QuicStreamId id, QuicSpdySession* session); ~QuicSpdyServerStream() override; // ReliableQuicStream implementation called by the session when there's diff --git a/net/tools/quic/quic_spdy_server_stream_test.cc b/net/tools/quic/quic_spdy_server_stream_test.cc index 9290a79..b58a311 100644 --- a/net/tools/quic/quic_spdy_server_stream_test.cc +++ b/net/tools/quic/quic_spdy_server_stream_test.cc @@ -20,7 +20,7 @@ using base::StringPiece; using net::test::MockConnection; -using net::test::MockSession; +using net::test::MockQuicSpdySession; using net::test::SupportedVersions; using net::test::kInitialSessionFlowControlWindowForTest; using net::test::kInitialStreamFlowControlWindowForTest; @@ -40,9 +40,8 @@ namespace test { class QuicSpdyServerStreamPeer : public QuicSpdyServerStream { public: - QuicSpdyServerStreamPeer(QuicStreamId stream_id, QuicSession* session) - : QuicSpdyServerStream(stream_id, session) { - } + QuicSpdyServerStreamPeer(QuicStreamId stream_id, QuicSpdySession* session) + : QuicSpdyServerStream(stream_id, session) {} using QuicSpdyServerStream::SendResponse; using QuicSpdyServerStream::SendErrorResponse; @@ -120,7 +119,7 @@ class QuicSpdyServerStreamTest : public ::testing::TestWithParam<QuicVersion> { SpdyHeaderBlock response_headers_; StrictMock<MockConnection>* connection_; - StrictMock<MockSession> session_; + StrictMock<MockQuicSpdySession> session_; scoped_ptr<QuicSpdyServerStreamPeer> stream_; string headers_string_; string body_; diff --git a/net/tools/quic/test_tools/quic_test_client.cc b/net/tools/quic/test_tools/quic_test_client.cc index 35e7547..75e8728 100644 --- a/net/tools/quic/test_tools/quic_test_client.cc +++ b/net/tools/quic/test_tools/quic_test_client.cc @@ -12,7 +12,7 @@ #include "net/quic/crypto/proof_verifier.h" #include "net/quic/quic_server_id.h" #include "net/quic/test_tools/quic_connection_peer.h" -#include "net/quic/test_tools/quic_session_peer.h" +#include "net/quic/test_tools/quic_spdy_session_peer.h" #include "net/quic/test_tools/quic_test_utils.h" #include "net/quic/test_tools/reliable_quic_stream_peer.h" #include "net/tools/balsa/balsa_headers.h" @@ -27,7 +27,7 @@ using base::StringPiece; using net::QuicServerId; using net::test::QuicConnectionPeer; -using net::test::QuicSessionPeer; +using net::test::QuicSpdySessionPeer; using net::test::ReliableQuicStreamPeer; using std::string; using std::vector; @@ -558,7 +558,7 @@ void QuicTestClient::SetFecPolicy(FecPolicy fec_policy) { fec_policy_ = fec_policy; // Set policy for headers and crypto streams. ReliableQuicStreamPeer::SetFecPolicy( - QuicSessionPeer::GetHeadersStream(client()->session()), fec_policy); + QuicSpdySessionPeer::GetHeadersStream(client()->session()), fec_policy); ReliableQuicStreamPeer::SetFecPolicy(client()->session()->GetCryptoStream(), fec_policy); } |