| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/tools/quic/quic_client_session.h" | 5 #include "net/tools/quic/quic_client_session.h" |
| 6 | 6 |
| 7 #include "net/log/net_log_with_source.h" | 7 #include "net/log/net_log_with_source.h" |
| 8 #include "net/quic/chromium/crypto/proof_verifier_chromium.h" | 8 #include "net/quic/chromium/crypto/proof_verifier_chromium.h" |
| 9 #include "net/quic/core/crypto/crypto_protocol.h" | 9 #include "net/quic/core/crypto/crypto_protocol.h" |
| 10 #include "net/quic/core/quic_server_id.h" | 10 #include "net/quic/core/quic_server_id.h" |
| 11 #include "net/quic/core/spdy_utils.h" |
| 11 #include "net/quic/platform/api/quic_bug_tracker.h" | 12 #include "net/quic/platform/api/quic_bug_tracker.h" |
| 12 #include "net/quic/platform/api/quic_logging.h" | 13 #include "net/quic/platform/api/quic_logging.h" |
| 13 #include "net/quic/platform/api/quic_ptr_util.h" | 14 #include "net/quic/platform/api/quic_ptr_util.h" |
| 14 #include "net/tools/quic/quic_spdy_client_stream.h" | 15 #include "net/tools/quic/quic_spdy_client_stream.h" |
| 15 | 16 |
| 16 using std::string; | 17 using std::string; |
| 17 | 18 |
| 18 namespace net { | 19 namespace net { |
| 19 | 20 |
| 20 QuicClientSession::QuicClientSession( | 21 QuicClientSession::QuicClientSession( |
| 21 const QuicConfig& config, | 22 const QuicConfig& config, |
| 22 QuicConnection* connection, | 23 QuicConnection* connection, |
| 23 const QuicServerId& server_id, | 24 const QuicServerId& server_id, |
| 24 QuicCryptoClientConfig* crypto_config, | 25 QuicCryptoClientConfig* crypto_config, |
| 25 QuicClientPushPromiseIndex* push_promise_index) | 26 QuicClientPushPromiseIndex* push_promise_index) |
| 26 : QuicClientSessionBase(connection, push_promise_index, config), | 27 : QuicClientSessionBase(connection, push_promise_index, config), |
| 27 server_id_(server_id), | 28 server_id_(server_id), |
| 28 crypto_config_(crypto_config), | 29 crypto_config_(crypto_config) {} |
| 29 respect_goaway_(true) {} | |
| 30 | 30 |
| 31 QuicClientSession::~QuicClientSession() {} | 31 QuicClientSession::~QuicClientSession() {} |
| 32 | 32 |
| 33 void QuicClientSession::Initialize() { | 33 void QuicClientSession::Initialize() { |
| 34 crypto_stream_ = CreateQuicCryptoStream(); | 34 crypto_stream_ = CreateQuicCryptoStream(); |
| 35 QuicClientSessionBase::Initialize(); | 35 QuicClientSessionBase::Initialize(); |
| 36 } | 36 } |
| 37 | 37 |
| 38 void QuicClientSession::OnProofValid( | 38 void QuicClientSession::OnProofValid( |
| 39 const QuicCryptoClientConfig::CachedState& /*cached*/) {} | 39 const QuicCryptoClientConfig::CachedState& /*cached*/) {} |
| 40 | 40 |
| 41 void QuicClientSession::OnProofVerifyDetailsAvailable( | 41 void QuicClientSession::OnProofVerifyDetailsAvailable( |
| 42 const ProofVerifyDetails& /*verify_details*/) {} | 42 const ProofVerifyDetails& /*verify_details*/) {} |
| 43 | 43 |
| 44 bool QuicClientSession::ShouldCreateOutgoingDynamicStream() { | 44 bool QuicClientSession::ShouldCreateOutgoingDynamicStream() { |
| 45 DCHECK(!FLAGS_quic_reloadable_flag_quic_refactor_stream_creation); |
| 45 if (!crypto_stream_->encryption_established()) { | 46 if (!crypto_stream_->encryption_established()) { |
| 46 QUIC_DLOG(INFO) << "Encryption not active so no outgoing stream created."; | 47 QUIC_DLOG(INFO) << "Encryption not active so no outgoing stream created."; |
| 47 return false; | 48 return false; |
| 48 } | 49 } |
| 49 if (GetNumOpenOutgoingStreams() >= max_open_outgoing_streams()) { | 50 if (GetNumOpenOutgoingStreams() >= max_open_outgoing_streams()) { |
| 50 QUIC_DLOG(INFO) << "Failed to create a new outgoing stream. " | 51 QUIC_DLOG(INFO) << "Failed to create a new outgoing stream. " |
| 51 << "Already " << GetNumOpenOutgoingStreams() << " open."; | 52 << "Already " << GetNumOpenOutgoingStreams() << " open."; |
| 52 return false; | 53 return false; |
| 53 } | 54 } |
| 54 if (goaway_received() && respect_goaway_) { | 55 if (goaway_received() && respect_goaway()) { |
| 55 QUIC_DLOG(INFO) << "Failed to create a new outgoing stream. " | 56 QUIC_DLOG(INFO) << "Failed to create a new outgoing stream. " |
| 56 << "Already received goaway."; | 57 << "Already received goaway."; |
| 57 return false; | 58 return false; |
| 58 } | 59 } |
| 59 return true; | 60 return true; |
| 60 } | 61 } |
| 61 | 62 |
| 62 QuicSpdyClientStream* QuicClientSession::CreateOutgoingDynamicStream( | 63 QuicSpdyClientStream* QuicClientSession::CreateOutgoingDynamicStream( |
| 63 SpdyPriority priority) { | 64 SpdyPriority priority) { |
| 64 if (!ShouldCreateOutgoingDynamicStream()) { | 65 if (!ShouldCreateOutgoingDynamicStream()) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 90 | 91 |
| 91 int QuicClientSession::GetNumSentClientHellos() const { | 92 int QuicClientSession::GetNumSentClientHellos() const { |
| 92 return crypto_stream_->num_sent_client_hellos(); | 93 return crypto_stream_->num_sent_client_hellos(); |
| 93 } | 94 } |
| 94 | 95 |
| 95 int QuicClientSession::GetNumReceivedServerConfigUpdates() const { | 96 int QuicClientSession::GetNumReceivedServerConfigUpdates() const { |
| 96 return crypto_stream_->num_scup_messages_received(); | 97 return crypto_stream_->num_scup_messages_received(); |
| 97 } | 98 } |
| 98 | 99 |
| 99 bool QuicClientSession::ShouldCreateIncomingDynamicStream(QuicStreamId id) { | 100 bool QuicClientSession::ShouldCreateIncomingDynamicStream(QuicStreamId id) { |
| 101 DCHECK(!FLAGS_quic_reloadable_flag_quic_refactor_stream_creation); |
| 100 if (!connection()->connected()) { | 102 if (!connection()->connected()) { |
| 101 QUIC_BUG << "ShouldCreateIncomingDynamicStream called when disconnected"; | 103 QUIC_BUG << "ShouldCreateIncomingDynamicStream called when disconnected"; |
| 102 return false; | 104 return false; |
| 103 } | 105 } |
| 104 if (goaway_received() && respect_goaway_) { | 106 if (goaway_received() && respect_goaway()) { |
| 105 QUIC_DLOG(INFO) << "Failed to create a new outgoing stream. " | 107 QUIC_DLOG(INFO) << "Failed to create a new outgoing stream. " |
| 106 << "Already received goaway."; | 108 << "Already received goaway."; |
| 107 return false; | 109 return false; |
| 108 } | 110 } |
| 109 if (id % 2 != 0) { | 111 if (id % 2 != 0) { |
| 110 QUIC_LOG(WARNING) << "Received invalid push stream id " << id; | 112 QUIC_LOG(WARNING) << "Received invalid push stream id " << id; |
| 111 connection()->CloseConnection( | 113 connection()->CloseConnection( |
| 112 QUIC_INVALID_STREAM_ID, "Server created odd numbered stream", | 114 QUIC_INVALID_STREAM_ID, "Server created odd numbered stream", |
| 113 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); | 115 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); |
| 114 return false; | 116 return false; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 131 QuicClientSession::CreateQuicCryptoStream() { | 133 QuicClientSession::CreateQuicCryptoStream() { |
| 132 return QuicMakeUnique<QuicCryptoClientStream>( | 134 return QuicMakeUnique<QuicCryptoClientStream>( |
| 133 server_id_, this, new ProofVerifyContextChromium(0, NetLogWithSource()), | 135 server_id_, this, new ProofVerifyContextChromium(0, NetLogWithSource()), |
| 134 crypto_config_, this); | 136 crypto_config_, this); |
| 135 } | 137 } |
| 136 | 138 |
| 137 bool QuicClientSession::IsAuthorized(const string& authority) { | 139 bool QuicClientSession::IsAuthorized(const string& authority) { |
| 138 return true; | 140 return true; |
| 139 } | 141 } |
| 140 | 142 |
| 143 QuicSpdyClientStream* QuicClientSession::MaybeCreateOutgoingDynamicStream( |
| 144 SpdyPriority priority) { |
| 145 return static_cast<QuicSpdyClientStream*>( |
| 146 QuicSpdySession::MaybeCreateOutgoingDynamicStream(priority)); |
| 147 } |
| 148 |
| 149 QuicSpdyStream* QuicClientSession::MaybeCreateIncomingDynamicStream( |
| 150 QuicStreamId id) { |
| 151 QuicSpdyStream* stream = |
| 152 QuicSpdySession::MaybeCreateIncomingDynamicStream(id); |
| 153 if (stream) { |
| 154 // Push streams start half-closed. |
| 155 stream->CloseWriteSide(); |
| 156 } |
| 157 return stream; |
| 158 } |
| 159 |
| 160 std::unique_ptr<QuicStream> QuicClientSession::CreateStream(QuicStreamId id) { |
| 161 return QuicMakeUnique<QuicSpdyClientStream>(id, this); |
| 162 } |
| 163 |
| 141 } // namespace net | 164 } // namespace net |
| OLD | NEW |