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 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 return; | 330 return; |
331 } | 331 } |
332 if (!connection_->CanWriteStreamData()) { | 332 if (!connection_->CanWriteStreamData()) { |
333 return; | 333 return; |
334 } | 334 } |
335 QuicStreamId stream_id = write_blocked_streams_.PopFront(); | 335 QuicStreamId stream_id = write_blocked_streams_.PopFront(); |
336 if (stream_id == kCryptoStreamId) { | 336 if (stream_id == kCryptoStreamId) { |
337 has_pending_handshake_ = false; // We just popped it. | 337 has_pending_handshake_ = false; // We just popped it. |
338 } | 338 } |
339 ReliableQuicStream* stream = GetStream(stream_id); | 339 ReliableQuicStream* stream = GetStream(stream_id); |
340 if (stream != NULL && !stream->flow_controller()->IsBlocked()) { | 340 if (stream != nullptr && !stream->flow_controller()->IsBlocked()) { |
341 // If the stream can't write all bytes, it'll re-add itself to the blocked | 341 // If the stream can't write all bytes, it'll re-add itself to the blocked |
342 // list. | 342 // list. |
343 stream->OnCanWrite(); | 343 stream->OnCanWrite(); |
344 } | 344 } |
345 } | 345 } |
346 } | 346 } |
347 | 347 |
348 bool QuicSession::WillingAndAbleToWrite() const { | 348 bool QuicSession::WillingAndAbleToWrite() const { |
349 // If the crypto or headers streams are blocked, we want to schedule a write - | 349 // If the crypto or headers streams are blocked, we want to schedule a write - |
350 // they don't get blocked by connection level flow control. Otherwise only | 350 // they don't get blocked by connection level flow control. Otherwise only |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 } | 614 } |
615 if (stream_id == kHeadersStreamId) { | 615 if (stream_id == kHeadersStreamId) { |
616 return headers_stream_.get(); | 616 return headers_stream_.get(); |
617 } | 617 } |
618 return GetDataStream(stream_id); | 618 return GetDataStream(stream_id); |
619 } | 619 } |
620 | 620 |
621 QuicDataStream* QuicSession::GetDataStream(const QuicStreamId stream_id) { | 621 QuicDataStream* QuicSession::GetDataStream(const QuicStreamId stream_id) { |
622 if (stream_id == kCryptoStreamId) { | 622 if (stream_id == kCryptoStreamId) { |
623 DLOG(FATAL) << "Attempt to call GetDataStream with the crypto stream id"; | 623 DLOG(FATAL) << "Attempt to call GetDataStream with the crypto stream id"; |
624 return NULL; | 624 return nullptr; |
625 } | 625 } |
626 if (stream_id == kHeadersStreamId) { | 626 if (stream_id == kHeadersStreamId) { |
627 DLOG(FATAL) << "Attempt to call GetDataStream with the headers stream id"; | 627 DLOG(FATAL) << "Attempt to call GetDataStream with the headers stream id"; |
628 return NULL; | 628 return nullptr; |
629 } | 629 } |
630 | 630 |
631 DataStreamMap::iterator it = stream_map_.find(stream_id); | 631 DataStreamMap::iterator it = stream_map_.find(stream_id); |
632 if (it != stream_map_.end()) { | 632 if (it != stream_map_.end()) { |
633 return it->second; | 633 return it->second; |
634 } | 634 } |
635 | 635 |
636 if (IsClosedStream(stream_id)) { | 636 if (IsClosedStream(stream_id)) { |
637 return NULL; | 637 return nullptr; |
638 } | 638 } |
639 | 639 |
640 if (stream_id % 2 == next_stream_id_ % 2) { | 640 if (stream_id % 2 == next_stream_id_ % 2) { |
641 // We've received a frame for a locally-created stream that is not | 641 // We've received a frame for a locally-created stream that is not |
642 // currently active. This is an error. | 642 // currently active. This is an error. |
643 if (connection()->connected()) { | 643 if (connection()->connected()) { |
644 connection()->SendConnectionClose(QUIC_PACKET_FOR_NONEXISTENT_STREAM); | 644 connection()->SendConnectionClose(QUIC_PACKET_FOR_NONEXISTENT_STREAM); |
645 } | 645 } |
646 return NULL; | 646 return nullptr; |
647 } | 647 } |
648 | 648 |
649 return GetIncomingDataStream(stream_id); | 649 return GetIncomingDataStream(stream_id); |
650 } | 650 } |
651 | 651 |
652 QuicDataStream* QuicSession::GetIncomingDataStream(QuicStreamId stream_id) { | 652 QuicDataStream* QuicSession::GetIncomingDataStream(QuicStreamId stream_id) { |
653 if (IsClosedStream(stream_id)) { | 653 if (IsClosedStream(stream_id)) { |
654 return NULL; | 654 return nullptr; |
655 } | 655 } |
656 | 656 |
657 implicitly_created_streams_.erase(stream_id); | 657 implicitly_created_streams_.erase(stream_id); |
658 if (stream_id > largest_peer_created_stream_id_) { | 658 if (stream_id > largest_peer_created_stream_id_) { |
659 if (stream_id - largest_peer_created_stream_id_ > kMaxStreamIdDelta) { | 659 if (stream_id - largest_peer_created_stream_id_ > kMaxStreamIdDelta) { |
660 // We may already have sent a connection close due to multiple reset | 660 // We may already have sent a connection close due to multiple reset |
661 // streams in the same packet. | 661 // streams in the same packet. |
662 if (connection()->connected()) { | 662 if (connection()->connected()) { |
663 LOG(ERROR) << "Trying to get stream: " << stream_id | 663 LOG(ERROR) << "Trying to get stream: " << stream_id |
664 << ", largest peer created stream: " | 664 << ", largest peer created stream: " |
665 << largest_peer_created_stream_id_ | 665 << largest_peer_created_stream_id_ |
666 << ", max delta: " << kMaxStreamIdDelta; | 666 << ", max delta: " << kMaxStreamIdDelta; |
667 connection()->SendConnectionClose(QUIC_INVALID_STREAM_ID); | 667 connection()->SendConnectionClose(QUIC_INVALID_STREAM_ID); |
668 } | 668 } |
669 return NULL; | 669 return nullptr; |
670 } | 670 } |
671 if (largest_peer_created_stream_id_ == 0) { | 671 if (largest_peer_created_stream_id_ == 0) { |
672 if (is_server()) { | 672 if (is_server()) { |
673 largest_peer_created_stream_id_= 3; | 673 largest_peer_created_stream_id_= 3; |
674 } else { | 674 } else { |
675 largest_peer_created_stream_id_= 1; | 675 largest_peer_created_stream_id_= 1; |
676 } | 676 } |
677 } | 677 } |
678 for (QuicStreamId id = largest_peer_created_stream_id_ + 2; | 678 for (QuicStreamId id = largest_peer_created_stream_id_ + 2; |
679 id < stream_id; | 679 id < stream_id; |
680 id += 2) { | 680 id += 2) { |
681 implicitly_created_streams_.insert(id); | 681 implicitly_created_streams_.insert(id); |
682 } | 682 } |
683 largest_peer_created_stream_id_ = stream_id; | 683 largest_peer_created_stream_id_ = stream_id; |
684 } | 684 } |
685 QuicDataStream* stream = CreateIncomingDataStream(stream_id); | 685 QuicDataStream* stream = CreateIncomingDataStream(stream_id); |
686 if (stream == NULL) { | 686 if (stream == nullptr) { |
687 return NULL; | 687 return nullptr; |
688 } | 688 } |
689 ActivateStream(stream); | 689 ActivateStream(stream); |
690 return stream; | 690 return stream; |
691 } | 691 } |
692 | 692 |
693 void QuicSession::set_max_open_streams(size_t max_open_streams) { | 693 void QuicSession::set_max_open_streams(size_t max_open_streams) { |
694 DVLOG(1) << "Setting max_open_streams_ to " << max_open_streams; | 694 DVLOG(1) << "Setting max_open_streams_ to " << max_open_streams; |
695 max_open_streams_ = max_open_streams; | 695 max_open_streams_ = max_open_streams; |
696 } | 696 } |
697 | 697 |
(...skipping 20 matching lines...) Expand all Loading... |
718 implicitly_created_streams_.count(id) == 0; | 718 implicitly_created_streams_.count(id) == 0; |
719 } | 719 } |
720 | 720 |
721 size_t QuicSession::GetNumOpenStreams() const { | 721 size_t QuicSession::GetNumOpenStreams() const { |
722 return stream_map_.size() + implicitly_created_streams_.size(); | 722 return stream_map_.size() + implicitly_created_streams_.size(); |
723 } | 723 } |
724 | 724 |
725 void QuicSession::MarkWriteBlocked(QuicStreamId id, QuicPriority priority) { | 725 void QuicSession::MarkWriteBlocked(QuicStreamId id, QuicPriority priority) { |
726 #ifndef NDEBUG | 726 #ifndef NDEBUG |
727 ReliableQuicStream* stream = GetStream(id); | 727 ReliableQuicStream* stream = GetStream(id); |
728 if (stream != NULL) { | 728 if (stream != nullptr) { |
729 LOG_IF(DFATAL, priority != stream->EffectivePriority()) | 729 LOG_IF(DFATAL, priority != stream->EffectivePriority()) |
730 << ENDPOINT << "Stream " << id | 730 << ENDPOINT << "Stream " << id |
731 << "Priorities do not match. Got: " << priority | 731 << "Priorities do not match. Got: " << priority |
732 << " Expected: " << stream->EffectivePriority(); | 732 << " Expected: " << stream->EffectivePriority(); |
733 } else { | 733 } else { |
734 LOG(DFATAL) << "Marking unknown stream " << id << " blocked."; | 734 LOG(DFATAL) << "Marking unknown stream " << id << " blocked."; |
735 } | 735 } |
736 #endif | 736 #endif |
737 | 737 |
738 if (id == kCryptoStreamId) { | 738 if (id == kCryptoStreamId) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 | 776 |
777 // Disable stream level flow control based on negotiated version. Streams may | 777 // Disable stream level flow control based on negotiated version. Streams may |
778 // have been created with a different version. | 778 // have been created with a different version. |
779 if (version < QUIC_VERSION_21) { | 779 if (version < QUIC_VERSION_21) { |
780 GetCryptoStream()->flow_controller()->Disable(); | 780 GetCryptoStream()->flow_controller()->Disable(); |
781 headers_stream_->flow_controller()->Disable(); | 781 headers_stream_->flow_controller()->Disable(); |
782 } | 782 } |
783 } | 783 } |
784 | 784 |
785 } // namespace net | 785 } // namespace net |
OLD | NEW |