| 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/quic/quic_session.h" | 5 #include "net/quic/quic_session.h" |
| 6 | 6 |
| 7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
| 8 #include "net/quic/crypto/proof_verifier.h" | 8 #include "net/quic/crypto/proof_verifier.h" |
| 9 #include "net/quic/quic_connection.h" | 9 #include "net/quic/quic_connection.h" |
| 10 #include "net/quic/quic_flags.h" | 10 #include "net/quic/quic_flags.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 | 96 |
| 97 private: | 97 private: |
| 98 QuicSession* session_; | 98 QuicSession* session_; |
| 99 }; | 99 }; |
| 100 | 100 |
| 101 QuicSession::QuicSession(QuicConnection* connection, const QuicConfig& config) | 101 QuicSession::QuicSession(QuicConnection* connection, const QuicConfig& config) |
| 102 : connection_(connection), | 102 : connection_(connection), |
| 103 visitor_shim_(new VisitorShim(this)), | 103 visitor_shim_(new VisitorShim(this)), |
| 104 config_(config), | 104 config_(config), |
| 105 max_open_streams_(config_.MaxStreamsPerConnection()), | 105 max_open_streams_(config_.MaxStreamsPerConnection()), |
| 106 next_stream_id_(perspective() == Perspective::IS_SERVER ? 2 : 3), | 106 next_outgoing_stream_id_(perspective() == Perspective::IS_SERVER ? 2 : 3), |
| 107 largest_peer_created_stream_id_( | 107 largest_peer_created_stream_id_( |
| 108 perspective() == Perspective::IS_SERVER ? 1 : 0), | 108 perspective() == Perspective::IS_SERVER ? 1 : 0), |
| 109 error_(QUIC_NO_ERROR), | 109 error_(QUIC_NO_ERROR), |
| 110 flow_controller_(connection_.get(), | 110 flow_controller_(connection_.get(), |
| 111 0, | 111 0, |
| 112 perspective(), | 112 perspective(), |
| 113 kMinimumFlowControlSendWindow, | 113 kMinimumFlowControlSendWindow, |
| 114 config_.GetInitialSessionFlowControlWindowToSend(), | 114 config_.GetInitialSessionFlowControlWindowToSend(), |
| 115 false), | 115 false), |
| 116 has_pending_handshake_(false) { | 116 has_pending_handshake_(false) {} |
| 117 } | |
| 118 | 117 |
| 119 void QuicSession::Initialize() { | 118 void QuicSession::Initialize() { |
| 120 connection_->set_visitor(visitor_shim_.get()); | 119 connection_->set_visitor(visitor_shim_.get()); |
| 121 connection_->SetFromConfig(config_); | 120 connection_->SetFromConfig(config_); |
| 122 | 121 |
| 123 DCHECK_EQ(kCryptoStreamId, GetCryptoStream()->id()); | 122 DCHECK_EQ(kCryptoStreamId, GetCryptoStream()->id()); |
| 124 static_stream_map_[kCryptoStreamId] = GetCryptoStream(); | 123 static_stream_map_[kCryptoStreamId] = GetCryptoStream(); |
| 125 } | 124 } |
| 126 | 125 |
| 127 QuicSession::~QuicSession() { | 126 QuicSession::~QuicSession() { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 // update the connection level flow controller if needed. | 163 // update the connection level flow controller if needed. |
| 165 UpdateFlowControlOnFinalReceivedByteOffset(frame.stream_id, | 164 UpdateFlowControlOnFinalReceivedByteOffset(frame.stream_id, |
| 166 frame.byte_offset); | 165 frame.byte_offset); |
| 167 return; // Errors are handled by GetStream. | 166 return; // Errors are handled by GetStream. |
| 168 } | 167 } |
| 169 | 168 |
| 170 stream->OnStreamReset(frame); | 169 stream->OnStreamReset(frame); |
| 171 } | 170 } |
| 172 | 171 |
| 173 void QuicSession::OnGoAway(const QuicGoAwayFrame& frame) { | 172 void QuicSession::OnGoAway(const QuicGoAwayFrame& frame) { |
| 174 DCHECK(frame.last_good_stream_id < next_stream_id_); | 173 DCHECK(frame.last_good_stream_id < next_outgoing_stream_id_); |
| 175 } | 174 } |
| 176 | 175 |
| 177 void QuicSession::OnConnectionClosed(QuicErrorCode error, bool from_peer) { | 176 void QuicSession::OnConnectionClosed(QuicErrorCode error, bool from_peer) { |
| 178 DCHECK(!connection_->connected()); | 177 DCHECK(!connection_->connected()); |
| 179 if (error_ == QUIC_NO_ERROR) { | 178 if (error_ == QUIC_NO_ERROR) { |
| 180 error_ = error; | 179 error_ = error; |
| 181 } | 180 } |
| 182 | 181 |
| 183 while (!dynamic_stream_map_.empty()) { | 182 while (!dynamic_stream_map_.empty()) { |
| 184 StreamMap::iterator it = dynamic_stream_map_.begin(); | 183 StreamMap::iterator it = dynamic_stream_map_.begin(); |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 void QuicSession::ActivateStream(ReliableQuicStream* stream) { | 552 void QuicSession::ActivateStream(ReliableQuicStream* stream) { |
| 554 DVLOG(1) << ENDPOINT << "num_streams: " << dynamic_stream_map_.size() | 553 DVLOG(1) << ENDPOINT << "num_streams: " << dynamic_stream_map_.size() |
| 555 << ". activating " << stream->id(); | 554 << ". activating " << stream->id(); |
| 556 DCHECK(!ContainsKey(dynamic_stream_map_, stream->id())); | 555 DCHECK(!ContainsKey(dynamic_stream_map_, stream->id())); |
| 557 DCHECK(!ContainsKey(static_stream_map_, stream->id())); | 556 DCHECK(!ContainsKey(static_stream_map_, stream->id())); |
| 558 dynamic_stream_map_[stream->id()] = stream; | 557 dynamic_stream_map_[stream->id()] = stream; |
| 559 // Increase the number of streams being emulated when a new one is opened. | 558 // Increase the number of streams being emulated when a new one is opened. |
| 560 connection_->SetNumOpenStreams(dynamic_stream_map_.size()); | 559 connection_->SetNumOpenStreams(dynamic_stream_map_.size()); |
| 561 } | 560 } |
| 562 | 561 |
| 563 QuicStreamId QuicSession::GetNextStreamId() { | 562 QuicStreamId QuicSession::GetNextOutgoingStreamId() { |
| 564 QuicStreamId id = next_stream_id_; | 563 QuicStreamId id = next_outgoing_stream_id_; |
| 565 next_stream_id_ += 2; | 564 next_outgoing_stream_id_ += 2; |
| 566 return id; | 565 return id; |
| 567 } | 566 } |
| 568 | 567 |
| 569 ReliableQuicStream* QuicSession::GetStream(const QuicStreamId stream_id) { | 568 ReliableQuicStream* QuicSession::GetStream(const QuicStreamId stream_id) { |
| 570 StreamMap::iterator it = static_stream_map_.find(stream_id); | 569 StreamMap::iterator it = static_stream_map_.find(stream_id); |
| 571 if (it != static_stream_map_.end()) { | 570 if (it != static_stream_map_.end()) { |
| 572 return it->second; | 571 return it->second; |
| 573 } | 572 } |
| 574 return GetDynamicStream(stream_id); | 573 return GetDynamicStream(stream_id); |
| 575 } | 574 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 596 | 595 |
| 597 StreamMap::iterator it = dynamic_stream_map_.find(stream_id); | 596 StreamMap::iterator it = dynamic_stream_map_.find(stream_id); |
| 598 if (it != dynamic_stream_map_.end()) { | 597 if (it != dynamic_stream_map_.end()) { |
| 599 return it->second; | 598 return it->second; |
| 600 } | 599 } |
| 601 | 600 |
| 602 if (IsClosedStream(stream_id)) { | 601 if (IsClosedStream(stream_id)) { |
| 603 return nullptr; | 602 return nullptr; |
| 604 } | 603 } |
| 605 | 604 |
| 606 if (stream_id % 2 == next_stream_id_ % 2) { | 605 if (stream_id % 2 == next_outgoing_stream_id_ % 2) { |
| 607 // We've received a frame for a locally-created stream that is not | 606 // We've received a frame for a locally-created stream that is not |
| 608 // currently active. This is an error. | 607 // currently active. This is an error. |
| 609 CloseConnection(QUIC_PACKET_FOR_NONEXISTENT_STREAM); | 608 CloseConnection(QUIC_PACKET_FOR_NONEXISTENT_STREAM); |
| 610 return nullptr; | 609 return nullptr; |
| 611 } | 610 } |
| 612 | 611 |
| 613 return GetIncomingDynamicStream(stream_id); | 612 return GetIncomingDynamicStream(stream_id); |
| 614 } | 613 } |
| 615 | 614 |
| 616 ReliableQuicStream* QuicSession::GetIncomingDynamicStream( | 615 ReliableQuicStream* QuicSession::GetIncomingDynamicStream( |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 return connection_->goaway_received(); | 710 return connection_->goaway_received(); |
| 712 } | 711 } |
| 713 | 712 |
| 714 bool QuicSession::IsClosedStream(QuicStreamId id) { | 713 bool QuicSession::IsClosedStream(QuicStreamId id) { |
| 715 DCHECK_NE(0u, id); | 714 DCHECK_NE(0u, id); |
| 716 if (ContainsKey(static_stream_map_, id) || | 715 if (ContainsKey(static_stream_map_, id) || |
| 717 ContainsKey(dynamic_stream_map_, id)) { | 716 ContainsKey(dynamic_stream_map_, id)) { |
| 718 // Stream is active | 717 // Stream is active |
| 719 return false; | 718 return false; |
| 720 } | 719 } |
| 721 if (id % 2 == next_stream_id_ % 2) { | 720 if (id % 2 == next_outgoing_stream_id_ % 2) { |
| 722 // Locally created streams are strictly in-order. If the id is in the | 721 // Locally created streams are strictly in-order. If the id is in the |
| 723 // range of created streams and it's not active, it must have been closed. | 722 // range of created streams and it's not active, it must have been closed. |
| 724 return id < next_stream_id_; | 723 return id < next_outgoing_stream_id_; |
| 725 } | 724 } |
| 726 // For peer created streams, we also need to consider available streams. | 725 // For peer created streams, we also need to consider available streams. |
| 727 return id <= largest_peer_created_stream_id_ && | 726 return id <= largest_peer_created_stream_id_ && |
| 728 !ContainsKey(available_streams_, id); | 727 !ContainsKey(available_streams_, id); |
| 729 } | 728 } |
| 730 | 729 |
| 731 size_t QuicSession::GetNumOpenStreams() const { | 730 size_t QuicSession::GetNumOpenStreams() const { |
| 732 if (FLAGS_allow_many_available_streams) { | 731 if (FLAGS_allow_many_available_streams) { |
| 733 return dynamic_stream_map_.size() - draining_streams_.size(); | 732 return dynamic_stream_map_.size() - draining_streams_.size(); |
| 734 } else { | 733 } else { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 793 } | 792 } |
| 794 for (auto const& kv : dynamic_stream_map_) { | 793 for (auto const& kv : dynamic_stream_map_) { |
| 795 if (kv.second->flow_controller()->IsBlocked()) { | 794 if (kv.second->flow_controller()->IsBlocked()) { |
| 796 return true; | 795 return true; |
| 797 } | 796 } |
| 798 } | 797 } |
| 799 return false; | 798 return false; |
| 800 } | 799 } |
| 801 | 800 |
| 802 } // namespace net | 801 } // namespace net |
| OLD | NEW |