| 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" | |
| 12 #include "net/quic/platform/api/quic_bug_tracker.h" | 11 #include "net/quic/platform/api/quic_bug_tracker.h" |
| 13 #include "net/quic/platform/api/quic_logging.h" | 12 #include "net/quic/platform/api/quic_logging.h" |
| 14 #include "net/quic/platform/api/quic_ptr_util.h" | 13 #include "net/quic/platform/api/quic_ptr_util.h" |
| 15 #include "net/tools/quic/quic_spdy_client_stream.h" | 14 #include "net/tools/quic/quic_spdy_client_stream.h" |
| 16 | 15 |
| 17 using std::string; | 16 using std::string; |
| 18 | 17 |
| 19 namespace net { | 18 namespace net { |
| 20 | 19 |
| 21 QuicClientSession::QuicClientSession( | 20 QuicClientSession::QuicClientSession( |
| 22 const QuicConfig& config, | 21 const QuicConfig& config, |
| 23 QuicConnection* connection, | 22 QuicConnection* connection, |
| 24 const QuicServerId& server_id, | 23 const QuicServerId& server_id, |
| 25 QuicCryptoClientConfig* crypto_config, | 24 QuicCryptoClientConfig* crypto_config, |
| 26 QuicClientPushPromiseIndex* push_promise_index) | 25 QuicClientPushPromiseIndex* push_promise_index) |
| 27 : QuicClientSessionBase(connection, push_promise_index, config), | 26 : QuicClientSessionBase(connection, push_promise_index, config), |
| 28 server_id_(server_id), | 27 server_id_(server_id), |
| 29 crypto_config_(crypto_config) {} | 28 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); | |
| 46 if (!crypto_stream_->encryption_established()) { | 45 if (!crypto_stream_->encryption_established()) { |
| 47 QUIC_DLOG(INFO) << "Encryption not active so no outgoing stream created."; | 46 QUIC_DLOG(INFO) << "Encryption not active so no outgoing stream created."; |
| 48 return false; | 47 return false; |
| 49 } | 48 } |
| 50 if (GetNumOpenOutgoingStreams() >= max_open_outgoing_streams()) { | 49 if (GetNumOpenOutgoingStreams() >= max_open_outgoing_streams()) { |
| 51 QUIC_DLOG(INFO) << "Failed to create a new outgoing stream. " | 50 QUIC_DLOG(INFO) << "Failed to create a new outgoing stream. " |
| 52 << "Already " << GetNumOpenOutgoingStreams() << " open."; | 51 << "Already " << GetNumOpenOutgoingStreams() << " open."; |
| 53 return false; | 52 return false; |
| 54 } | 53 } |
| 55 if (goaway_received() && respect_goaway()) { | 54 if (goaway_received() && respect_goaway_) { |
| 56 QUIC_DLOG(INFO) << "Failed to create a new outgoing stream. " | 55 QUIC_DLOG(INFO) << "Failed to create a new outgoing stream. " |
| 57 << "Already received goaway."; | 56 << "Already received goaway."; |
| 58 return false; | 57 return false; |
| 59 } | 58 } |
| 60 return true; | 59 return true; |
| 61 } | 60 } |
| 62 | 61 |
| 63 QuicSpdyClientStream* QuicClientSession::CreateOutgoingDynamicStream( | 62 QuicSpdyClientStream* QuicClientSession::CreateOutgoingDynamicStream( |
| 64 SpdyPriority priority) { | 63 SpdyPriority priority) { |
| 65 if (!ShouldCreateOutgoingDynamicStream()) { | 64 if (!ShouldCreateOutgoingDynamicStream()) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 91 | 90 |
| 92 int QuicClientSession::GetNumSentClientHellos() const { | 91 int QuicClientSession::GetNumSentClientHellos() const { |
| 93 return crypto_stream_->num_sent_client_hellos(); | 92 return crypto_stream_->num_sent_client_hellos(); |
| 94 } | 93 } |
| 95 | 94 |
| 96 int QuicClientSession::GetNumReceivedServerConfigUpdates() const { | 95 int QuicClientSession::GetNumReceivedServerConfigUpdates() const { |
| 97 return crypto_stream_->num_scup_messages_received(); | 96 return crypto_stream_->num_scup_messages_received(); |
| 98 } | 97 } |
| 99 | 98 |
| 100 bool QuicClientSession::ShouldCreateIncomingDynamicStream(QuicStreamId id) { | 99 bool QuicClientSession::ShouldCreateIncomingDynamicStream(QuicStreamId id) { |
| 101 DCHECK(!FLAGS_quic_reloadable_flag_quic_refactor_stream_creation); | |
| 102 if (!connection()->connected()) { | 100 if (!connection()->connected()) { |
| 103 QUIC_BUG << "ShouldCreateIncomingDynamicStream called when disconnected"; | 101 QUIC_BUG << "ShouldCreateIncomingDynamicStream called when disconnected"; |
| 104 return false; | 102 return false; |
| 105 } | 103 } |
| 106 if (goaway_received() && respect_goaway()) { | 104 if (goaway_received() && respect_goaway_) { |
| 107 QUIC_DLOG(INFO) << "Failed to create a new outgoing stream. " | 105 QUIC_DLOG(INFO) << "Failed to create a new outgoing stream. " |
| 108 << "Already received goaway."; | 106 << "Already received goaway."; |
| 109 return false; | 107 return false; |
| 110 } | 108 } |
| 111 if (id % 2 != 0) { | 109 if (id % 2 != 0) { |
| 112 QUIC_LOG(WARNING) << "Received invalid push stream id " << id; | 110 QUIC_LOG(WARNING) << "Received invalid push stream id " << id; |
| 113 connection()->CloseConnection( | 111 connection()->CloseConnection( |
| 114 QUIC_INVALID_STREAM_ID, "Server created odd numbered stream", | 112 QUIC_INVALID_STREAM_ID, "Server created odd numbered stream", |
| 115 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); | 113 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); |
| 116 return false; | 114 return false; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 133 QuicClientSession::CreateQuicCryptoStream() { | 131 QuicClientSession::CreateQuicCryptoStream() { |
| 134 return QuicMakeUnique<QuicCryptoClientStream>( | 132 return QuicMakeUnique<QuicCryptoClientStream>( |
| 135 server_id_, this, new ProofVerifyContextChromium(0, NetLogWithSource()), | 133 server_id_, this, new ProofVerifyContextChromium(0, NetLogWithSource()), |
| 136 crypto_config_, this); | 134 crypto_config_, this); |
| 137 } | 135 } |
| 138 | 136 |
| 139 bool QuicClientSession::IsAuthorized(const string& authority) { | 137 bool QuicClientSession::IsAuthorized(const string& authority) { |
| 140 return true; | 138 return true; |
| 141 } | 139 } |
| 142 | 140 |
| 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 | |
| 164 } // namespace net | 141 } // namespace net |
| OLD | NEW |