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
3 // found in the LICENSE file.
5 #include "net/quic/quic_session.h"
7 #include "base/stl_util.h"
8 #include "net/quic/crypto/proof_verifier.h"
9 #include "net/quic/quic_connection.h"
10 #include "net/quic/quic_flags.h"
11 #include "net/quic/quic_flow_controller.h"
12 #include "net/quic/quic_headers_stream.h"
13 #include "net/ssl/ssl_info.h"
15 using base::StringPiece;
23 #define ENDPOINT (is_server() ? "Server: " : " Client: ")
25 // We want to make sure we delete any closed streams in a safe manner.
26 // To avoid deleting a stream in mid-operation, we have a simple shim between
27 // us and the stream, so we can delete any streams when we return from
30 // We could just override the base methods, but this makes it easier to make
31 // sure we don't miss any.
32 class VisitorShim : public QuicConnectionVisitorInterface {
34 explicit VisitorShim(QuicSession* session) : session_(session) {}
36 virtual void OnStreamFrames(const vector<QuicStreamFrame>& frames) OVERRIDE {
37 session_->OnStreamFrames(frames);
38 session_->PostProcessAfterData();
40 virtual void OnRstStream(const QuicRstStreamFrame& frame) OVERRIDE {
41 session_->OnRstStream(frame);
42 session_->PostProcessAfterData();
45 virtual void OnGoAway(const QuicGoAwayFrame& frame) OVERRIDE {
46 session_->OnGoAway(frame);
47 session_->PostProcessAfterData();
50 virtual void OnWindowUpdateFrames(const vector<QuicWindowUpdateFrame>& frames)
52 session_->OnWindowUpdateFrames(frames);
53 session_->PostProcessAfterData();
56 virtual void OnBlockedFrames(const vector<QuicBlockedFrame>& frames)
58 session_->OnBlockedFrames(frames);
59 session_->PostProcessAfterData();
62 virtual void OnCanWrite() OVERRIDE {
63 session_->OnCanWrite();
64 session_->PostProcessAfterData();
67 virtual void OnCongestionWindowChange(QuicTime now) OVERRIDE {
68 session_->OnCongestionWindowChange(now);
71 virtual void OnSuccessfulVersionNegotiation(
72 const QuicVersion& version) OVERRIDE {
73 session_->OnSuccessfulVersionNegotiation(version);
76 virtual void OnConnectionClosed(
77 QuicErrorCode error, bool from_peer) OVERRIDE {
78 session_->OnConnectionClosed(error, from_peer);
79 // The session will go away, so don't bother with cleanup.
82 virtual void OnWriteBlocked() OVERRIDE {
83 session_->OnWriteBlocked();
86 virtual bool WillingAndAbleToWrite() const OVERRIDE {
87 return session_->WillingAndAbleToWrite();
90 virtual bool HasPendingHandshake() const OVERRIDE {
91 return session_->HasPendingHandshake();
94 virtual bool HasOpenDataStreams() const OVERRIDE {
95 return session_->HasOpenDataStreams();
99 QuicSession* session_;
102 QuicSession::QuicSession(QuicConnection* connection, const QuicConfig& config)
103 : connection_(connection),
104 visitor_shim_(new VisitorShim(this)),
106 max_open_streams_(config_.max_streams_per_connection()),
107 next_stream_id_(is_server() ? 2 : 5),
108 largest_peer_created_stream_id_(0),
109 error_(QUIC_NO_ERROR),
110 goaway_received_(false),
112 has_pending_handshake_(false) {
113 if (connection_->version() <= QUIC_VERSION_19) {
114 flow_controller_.reset(new QuicFlowController(
115 connection_.get(), 0, is_server(), kDefaultFlowControlSendWindow,
116 config_.GetInitialFlowControlWindowToSend(),
117 config_.GetInitialFlowControlWindowToSend()));
119 flow_controller_.reset(new QuicFlowController(
120 connection_.get(), 0, is_server(), kDefaultFlowControlSendWindow,
121 config_.GetInitialSessionFlowControlWindowToSend(),
122 config_.GetInitialSessionFlowControlWindowToSend()));
126 void QuicSession::InitializeSession() {
127 connection_->set_visitor(visitor_shim_.get());
128 connection_->SetFromConfig(config_);
129 if (connection_->connected()) {
130 connection_->SetOverallConnectionTimeout(
131 config_.max_time_before_crypto_handshake());
133 headers_stream_.reset(new QuicHeadersStream(this));
136 QuicSession::~QuicSession() {
137 STLDeleteElements(&closed_streams_);
138 STLDeleteValues(&stream_map_);
141 locally_closed_streams_highest_offset_.size() > max_open_streams_)
142 << "Surprisingly high number of locally closed streams still waiting for "
143 "final byte offset: " << locally_closed_streams_highest_offset_.size();
146 void QuicSession::OnStreamFrames(const vector<QuicStreamFrame>& frames) {
147 for (size_t i = 0; i < frames.size(); ++i) {
148 // TODO(rch) deal with the error case of stream id 0.
149 const QuicStreamFrame& frame = frames[i];
150 QuicStreamId stream_id = frame.stream_id;
151 ReliableQuicStream* stream = GetStream(stream_id);
153 // The stream no longer exists, but we may still be interested in the
154 // final stream byte offset sent by the peer. A frame with a FIN can give
157 QuicStreamOffset final_byte_offset =
158 frame.offset + frame.data.TotalBufferSize();
159 UpdateFlowControlOnFinalReceivedByteOffset(stream_id,
165 stream->OnStreamFrame(frames[i]);
169 void QuicSession::OnStreamHeaders(QuicStreamId stream_id,
170 StringPiece headers_data) {
171 QuicDataStream* stream = GetDataStream(stream_id);
173 // It's quite possible to receive headers after a stream has been reset.
176 stream->OnStreamHeaders(headers_data);
179 void QuicSession::OnStreamHeadersPriority(QuicStreamId stream_id,
180 QuicPriority priority) {
181 QuicDataStream* stream = GetDataStream(stream_id);
183 // It's quite possible to receive headers after a stream has been reset.
186 stream->OnStreamHeadersPriority(priority);
189 void QuicSession::OnStreamHeadersComplete(QuicStreamId stream_id,
192 QuicDataStream* stream = GetDataStream(stream_id);
194 // It's quite possible to receive headers after a stream has been reset.
197 stream->OnStreamHeadersComplete(fin, frame_len);
200 void QuicSession::OnRstStream(const QuicRstStreamFrame& frame) {
201 if (frame.stream_id == kCryptoStreamId) {
202 connection()->SendConnectionCloseWithDetails(
203 QUIC_INVALID_STREAM_ID,
204 "Attempt to reset the crypto stream");
207 if (frame.stream_id == kHeadersStreamId) {
208 connection()->SendConnectionCloseWithDetails(
209 QUIC_INVALID_STREAM_ID,
210 "Attempt to reset the headers stream");
214 QuicDataStream* stream = GetDataStream(frame.stream_id);
216 // The RST frame contains the final byte offset for the stream: we can now
217 // update the connection level flow controller if needed.
218 UpdateFlowControlOnFinalReceivedByteOffset(frame.stream_id,
220 return; // Errors are handled by GetStream.
223 stream->OnStreamReset(frame);
226 void QuicSession::OnGoAway(const QuicGoAwayFrame& frame) {
227 DCHECK(frame.last_good_stream_id < next_stream_id_);
228 goaway_received_ = true;
231 void QuicSession::OnConnectionClosed(QuicErrorCode error, bool from_peer) {
232 DCHECK(!connection_->connected());
233 if (error_ == QUIC_NO_ERROR) {
237 while (!stream_map_.empty()) {
238 DataStreamMap::iterator it = stream_map_.begin();
239 QuicStreamId id = it->first;
240 it->second->OnConnectionClosed(error, from_peer);
241 // The stream should call CloseStream as part of OnConnectionClosed.
242 if (stream_map_.find(id) != stream_map_.end()) {
243 LOG(DFATAL) << ENDPOINT
244 << "Stream failed to close under OnConnectionClosed";
250 void QuicSession::OnWindowUpdateFrames(
251 const vector<QuicWindowUpdateFrame>& frames) {
252 bool connection_window_updated = false;
253 for (size_t i = 0; i < frames.size(); ++i) {
254 // Stream may be closed by the time we receive a WINDOW_UPDATE, so we can't
255 // assume that it still exists.
256 QuicStreamId stream_id = frames[i].stream_id;
257 if (stream_id == kConnectionLevelId) {
258 // This is a window update that applies to the connection, rather than an
259 // individual stream.
261 << "Received connection level flow control window update with "
262 "byte offset: " << frames[i].byte_offset;
263 if (flow_controller_->UpdateSendWindowOffset(frames[i].byte_offset)) {
264 connection_window_updated = true;
269 if (connection_->version() < QUIC_VERSION_21 &&
270 (stream_id == kCryptoStreamId || stream_id == kHeadersStreamId)) {
271 DLOG(DFATAL) << "WindowUpdate for stream " << stream_id << " in version "
272 << QuicVersionToString(connection_->version());
276 ReliableQuicStream* stream = GetStream(stream_id);
278 stream->OnWindowUpdateFrame(frames[i]);
282 // Connection level flow control window has increased, so blocked streams can
284 if (connection_window_updated) {
289 void QuicSession::OnBlockedFrames(const vector<QuicBlockedFrame>& frames) {
290 for (size_t i = 0; i < frames.size(); ++i) {
291 // TODO(rjshade): Compare our flow control receive windows for specified
292 // streams: if we have a large window then maybe something
293 // had gone wrong with the flow control accounting.
294 DVLOG(1) << ENDPOINT << "Received BLOCKED frame with stream id: "
295 << frames[i].stream_id;
299 void QuicSession::OnCanWrite() {
300 // We limit the number of writes to the number of pending streams. If more
301 // streams become pending, WillingAndAbleToWrite will be true, which will
302 // cause the connection to request resumption before yielding to other
304 size_t num_writes = write_blocked_streams_.NumBlockedStreams();
305 if (flow_controller_->IsBlocked()) {
306 // If we are connection level flow control blocked, then only allow the
307 // crypto and headers streams to try writing as all other streams will be
310 if (write_blocked_streams_.crypto_stream_blocked()) {
313 if (write_blocked_streams_.headers_stream_blocked()) {
317 if (num_writes == 0) {
321 QuicConnection::ScopedPacketBundler ack_bundler(
322 connection_.get(), QuicConnection::NO_ACK);
323 for (size_t i = 0; i < num_writes; ++i) {
324 if (!(write_blocked_streams_.HasWriteBlockedCryptoOrHeadersStream() ||
325 write_blocked_streams_.HasWriteBlockedDataStreams())) {
326 // Writing one stream removed another!? Something's broken.
327 LOG(DFATAL) << "WriteBlockedStream is missing";
328 connection_->CloseConnection(QUIC_INTERNAL_ERROR, false);
331 if (!connection_->CanWriteStreamData()) {
334 QuicStreamId stream_id = write_blocked_streams_.PopFront();
335 if (stream_id == kCryptoStreamId) {
336 has_pending_handshake_ = false; // We just popped it.
338 ReliableQuicStream* stream = GetStream(stream_id);
339 if (stream != NULL && !stream->flow_controller()->IsBlocked()) {
340 // If the stream can't write all bytes, it'll re-add itself to the blocked
342 stream->OnCanWrite();
347 bool QuicSession::WillingAndAbleToWrite() const {
348 // If the crypto or headers streams are blocked, we want to schedule a write -
349 // they don't get blocked by connection level flow control. Otherwise only
350 // schedule a write if we are not flow control blocked at the connection
352 return write_blocked_streams_.HasWriteBlockedCryptoOrHeadersStream() ||
353 (!flow_controller_->IsBlocked() &&
354 write_blocked_streams_.HasWriteBlockedDataStreams());
357 bool QuicSession::HasPendingHandshake() const {
358 return has_pending_handshake_;
361 bool QuicSession::HasOpenDataStreams() const {
362 return GetNumOpenStreams() > 0;
365 QuicConsumedData QuicSession::WritevData(
367 const IOVector& data,
368 QuicStreamOffset offset,
370 FecProtection fec_protection,
371 QuicAckNotifier::DelegateInterface* ack_notifier_delegate) {
372 return connection_->SendStreamData(id, data, offset, fin, fec_protection,
373 ack_notifier_delegate);
376 size_t QuicSession::WriteHeaders(
378 const SpdyHeaderBlock& headers,
380 QuicAckNotifier::DelegateInterface* ack_notifier_delegate) {
381 return headers_stream_->WriteHeaders(id, headers, fin, ack_notifier_delegate);
384 void QuicSession::SendRstStream(QuicStreamId id,
385 QuicRstStreamErrorCode error,
386 QuicStreamOffset bytes_written) {
387 if (connection()->connected()) {
388 // Only send a RST_STREAM frame if still connected.
389 connection_->SendRstStream(id, error, bytes_written);
391 CloseStreamInner(id, true);
394 void QuicSession::SendGoAway(QuicErrorCode error_code, const string& reason) {
399 connection_->SendGoAway(error_code, largest_peer_created_stream_id_, reason);
402 void QuicSession::CloseStream(QuicStreamId stream_id) {
403 CloseStreamInner(stream_id, false);
406 void QuicSession::CloseStreamInner(QuicStreamId stream_id,
407 bool locally_reset) {
408 DVLOG(1) << ENDPOINT << "Closing stream " << stream_id;
410 DataStreamMap::iterator it = stream_map_.find(stream_id);
411 if (it == stream_map_.end()) {
412 DVLOG(1) << ENDPOINT << "Stream is already closed: " << stream_id;
415 QuicDataStream* stream = it->second;
417 // Tell the stream that a RST has been sent.
419 stream->set_rst_sent(true);
422 closed_streams_.push_back(it->second);
424 // If we haven't received a FIN or RST for this stream, we need to keep track
425 // of the how many bytes the stream's flow controller believes it has
426 // received, for accurate connection level flow control accounting.
427 if (!stream->HasFinalReceivedByteOffset() &&
428 stream->flow_controller()->IsEnabled()) {
429 locally_closed_streams_highest_offset_[stream_id] =
430 stream->flow_controller()->highest_received_byte_offset();
433 stream_map_.erase(it);
437 void QuicSession::UpdateFlowControlOnFinalReceivedByteOffset(
438 QuicStreamId stream_id, QuicStreamOffset final_byte_offset) {
439 map<QuicStreamId, QuicStreamOffset>::iterator it =
440 locally_closed_streams_highest_offset_.find(stream_id);
441 if (it == locally_closed_streams_highest_offset_.end()) {
445 DVLOG(1) << ENDPOINT << "Received final byte offset " << final_byte_offset
446 << " for stream " << stream_id;
447 uint64 offset_diff = final_byte_offset - it->second;
448 if (flow_controller_->UpdateHighestReceivedOffset(
449 flow_controller_->highest_received_byte_offset() + offset_diff)) {
450 // If the final offset violates flow control, close the connection now.
451 if (flow_controller_->FlowControlViolation()) {
452 connection_->SendConnectionClose(
453 QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA);
458 flow_controller_->AddBytesConsumed(offset_diff);
459 locally_closed_streams_highest_offset_.erase(it);
462 bool QuicSession::IsEncryptionEstablished() {
463 return GetCryptoStream()->encryption_established();
466 bool QuicSession::IsCryptoHandshakeConfirmed() {
467 return GetCryptoStream()->handshake_confirmed();
470 void QuicSession::OnConfigNegotiated() {
471 connection_->SetFromConfig(config_);
472 QuicVersion version = connection()->version();
474 // A server should accept a small number of additional streams beyond the
475 // limit sent to the client. This helps avoid early connection termination
476 // when FIN/RSTs for old streams are lost or arrive out of order.
477 if (FLAGS_quic_allow_more_open_streams) {
478 set_max_open_streams((is_server() ? kMaxStreamsMultiplier : 1.0) *
479 config_.max_streams_per_connection());
482 if (version <= QUIC_VERSION_16) {
486 if (version <= QUIC_VERSION_19) {
487 // QUIC_VERSION_17,18,19 don't support independent stream/session flow
489 if (config_.HasReceivedInitialFlowControlWindowBytes()) {
490 // Streams which were created before the SHLO was received (0-RTT
491 // requests) are now informed of the peer's initial flow control window.
492 uint32 new_window = config_.ReceivedInitialFlowControlWindowBytes();
493 OnNewStreamFlowControlWindow(new_window);
494 OnNewSessionFlowControlWindow(new_window);
500 // QUIC_VERSION_21 and higher can have independent stream and session flow
502 if (config_.HasReceivedInitialStreamFlowControlWindowBytes()) {
503 // Streams which were created before the SHLO was received (0-RTT
504 // requests) are now informed of the peer's initial flow control window.
505 OnNewStreamFlowControlWindow(
506 config_.ReceivedInitialStreamFlowControlWindowBytes());
508 if (config_.HasReceivedInitialSessionFlowControlWindowBytes()) {
509 OnNewSessionFlowControlWindow(
510 config_.ReceivedInitialSessionFlowControlWindowBytes());
514 void QuicSession::OnNewStreamFlowControlWindow(uint32 new_window) {
515 if (new_window < kDefaultFlowControlSendWindow) {
517 << "Peer sent us an invalid stream flow control send window: "
518 << new_window << ", below default: " << kDefaultFlowControlSendWindow;
519 if (connection_->connected()) {
520 connection_->SendConnectionClose(QUIC_FLOW_CONTROL_INVALID_WINDOW);
525 // Inform all existing streams about the new window.
526 if (connection_->version() >= QUIC_VERSION_21) {
527 GetCryptoStream()->flow_controller()->UpdateSendWindowOffset(new_window);
528 headers_stream_->flow_controller()->UpdateSendWindowOffset(new_window);
530 for (DataStreamMap::iterator it = stream_map_.begin();
531 it != stream_map_.end(); ++it) {
532 it->second->flow_controller()->UpdateSendWindowOffset(new_window);
536 void QuicSession::OnNewSessionFlowControlWindow(uint32 new_window) {
537 if (new_window < kDefaultFlowControlSendWindow) {
539 << "Peer sent us an invalid session flow control send window: "
540 << new_window << ", below default: " << kDefaultFlowControlSendWindow;
541 if (connection_->connected()) {
542 connection_->SendConnectionClose(QUIC_FLOW_CONTROL_INVALID_WINDOW);
547 flow_controller_->UpdateSendWindowOffset(new_window);
550 void QuicSession::OnCryptoHandshakeEvent(CryptoHandshakeEvent event) {
552 // TODO(satyamshekhar): Move the logic of setting the encrypter/decrypter
553 // to QuicSession since it is the glue.
554 case ENCRYPTION_FIRST_ESTABLISHED:
557 case ENCRYPTION_REESTABLISHED:
558 // Retransmit originally packets that were sent, since they can't be
559 // decrypted by the peer.
560 connection_->RetransmitUnackedPackets(ALL_INITIAL_RETRANSMISSION);
563 case HANDSHAKE_CONFIRMED:
564 LOG_IF(DFATAL, !config_.negotiated()) << ENDPOINT
565 << "Handshake confirmed without parameter negotiation.";
566 // Discard originally encrypted packets, since they can't be decrypted by
568 connection_->NeuterUnencryptedPackets();
569 connection_->SetOverallConnectionTimeout(QuicTime::Delta::Infinite());
570 if (!FLAGS_quic_allow_more_open_streams) {
571 max_open_streams_ = config_.max_streams_per_connection();
576 LOG(ERROR) << ENDPOINT << "Got unknown handshake event: " << event;
580 void QuicSession::OnCryptoHandshakeMessageSent(
581 const CryptoHandshakeMessage& message) {
584 void QuicSession::OnCryptoHandshakeMessageReceived(
585 const CryptoHandshakeMessage& message) {
588 QuicConfig* QuicSession::config() {
592 void QuicSession::ActivateStream(QuicDataStream* stream) {
593 DVLOG(1) << ENDPOINT << "num_streams: " << stream_map_.size()
594 << ". activating " << stream->id();
595 DCHECK_EQ(stream_map_.count(stream->id()), 0u);
596 stream_map_[stream->id()] = stream;
599 QuicStreamId QuicSession::GetNextStreamId() {
600 QuicStreamId id = next_stream_id_;
601 next_stream_id_ += 2;
605 ReliableQuicStream* QuicSession::GetStream(const QuicStreamId stream_id) {
606 if (stream_id == kCryptoStreamId) {
607 return GetCryptoStream();
609 if (stream_id == kHeadersStreamId) {
610 return headers_stream_.get();
612 return GetDataStream(stream_id);
615 QuicDataStream* QuicSession::GetDataStream(const QuicStreamId stream_id) {
616 if (stream_id == kCryptoStreamId) {
617 DLOG(FATAL) << "Attempt to call GetDataStream with the crypto stream id";
620 if (stream_id == kHeadersStreamId) {
621 DLOG(FATAL) << "Attempt to call GetDataStream with the headers stream id";
625 DataStreamMap::iterator it = stream_map_.find(stream_id);
626 if (it != stream_map_.end()) {
630 if (IsClosedStream(stream_id)) {
634 if (stream_id % 2 == next_stream_id_ % 2) {
635 // We've received a frame for a locally-created stream that is not
636 // currently active. This is an error.
637 if (connection()->connected()) {
638 connection()->SendConnectionClose(QUIC_PACKET_FOR_NONEXISTENT_STREAM);
643 return GetIncomingDataStream(stream_id);
646 QuicDataStream* QuicSession::GetIncomingDataStream(QuicStreamId stream_id) {
647 if (IsClosedStream(stream_id)) {
651 implicitly_created_streams_.erase(stream_id);
652 if (stream_id > largest_peer_created_stream_id_) {
653 if (stream_id - largest_peer_created_stream_id_ > kMaxStreamIdDelta) {
654 // We may already have sent a connection close due to multiple reset
655 // streams in the same packet.
656 if (connection()->connected()) {
657 LOG(ERROR) << "Trying to get stream: " << stream_id
658 << ", largest peer created stream: "
659 << largest_peer_created_stream_id_
660 << ", max delta: " << kMaxStreamIdDelta;
661 connection()->SendConnectionClose(QUIC_INVALID_STREAM_ID);
665 if (largest_peer_created_stream_id_ == 0) {
667 largest_peer_created_stream_id_= 3;
669 largest_peer_created_stream_id_= 1;
672 for (QuicStreamId id = largest_peer_created_stream_id_ + 2;
675 implicitly_created_streams_.insert(id);
677 largest_peer_created_stream_id_ = stream_id;
679 QuicDataStream* stream = CreateIncomingDataStream(stream_id);
680 if (stream == NULL) {
683 ActivateStream(stream);
687 void QuicSession::set_max_open_streams(size_t max_open_streams) {
688 DVLOG(1) << "Setting max_open_streams_ to " << max_open_streams;
689 max_open_streams_ = max_open_streams;
692 bool QuicSession::IsClosedStream(QuicStreamId id) {
694 if (id == kCryptoStreamId) {
697 if (id == kHeadersStreamId) {
700 if (ContainsKey(stream_map_, id)) {
704 if (id % 2 == next_stream_id_ % 2) {
705 // Locally created streams are strictly in-order. If the id is in the
706 // range of created streams and it's not active, it must have been closed.
707 return id < next_stream_id_;
709 // For peer created streams, we also need to consider implicitly created
711 return id <= largest_peer_created_stream_id_ &&
712 implicitly_created_streams_.count(id) == 0;
715 size_t QuicSession::GetNumOpenStreams() const {
716 return stream_map_.size() + implicitly_created_streams_.size();
719 void QuicSession::MarkWriteBlocked(QuicStreamId id, QuicPriority priority) {
721 ReliableQuicStream* stream = GetStream(id);
722 if (stream != NULL) {
723 LOG_IF(DFATAL, priority != stream->EffectivePriority())
724 << ENDPOINT << "Stream " << id
725 << "Priorities do not match. Got: " << priority
726 << " Expected: " << stream->EffectivePriority();
728 LOG(DFATAL) << "Marking unknown stream " << id << " blocked.";
732 if (id == kCryptoStreamId) {
733 DCHECK(!has_pending_handshake_);
734 has_pending_handshake_ = true;
735 // TODO(jar): Be sure to use the highest priority for the crypto stream,
736 // perhaps by adding a "special" priority for it that is higher than
738 priority = kHighestPriority;
740 write_blocked_streams_.PushBack(id, priority);
743 bool QuicSession::HasDataToWrite() const {
744 return write_blocked_streams_.HasWriteBlockedCryptoOrHeadersStream() ||
745 write_blocked_streams_.HasWriteBlockedDataStreams() ||
746 connection_->HasQueuedData();
749 bool QuicSession::GetSSLInfo(SSLInfo* ssl_info) const {
754 void QuicSession::PostProcessAfterData() {
755 STLDeleteElements(&closed_streams_);
756 closed_streams_.clear();
758 if (FLAGS_close_quic_connection_unfinished_streams_2 &&
759 connection()->connected() &&
760 locally_closed_streams_highest_offset_.size() > max_open_streams_) {
761 // A buggy client may fail to send FIN/RSTs. Don't tolerate this.
762 connection_->SendConnectionClose(QUIC_TOO_MANY_UNFINISHED_STREAMS);
766 void QuicSession::OnSuccessfulVersionNegotiation(const QuicVersion& version) {
767 if (version < QUIC_VERSION_19) {
768 flow_controller_->Disable();
771 // Disable stream level flow control based on negotiated version. Streams may
772 // have been created with a different version.
773 if (version < QUIC_VERSION_21) {
774 GetCryptoStream()->flow_controller()->Disable();
775 headers_stream_->flow_controller()->Disable();
777 for (DataStreamMap::iterator it = stream_map_.begin();
778 it != stream_map_.end(); ++it) {
779 if (version <= QUIC_VERSION_16) {
780 it->second->flow_controller()->Disable();