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/spdy/spdy_session.h" | 5 #include "net/spdy/spdy_session.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <map> | 9 #include <map> |
10 #include <utility> | 10 #include <utility> |
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
648 | 648 |
649 return true; | 649 return true; |
650 } | 650 } |
651 | 651 |
652 SpdySession::SpdySession(const SpdySessionKey& spdy_session_key, | 652 SpdySession::SpdySession(const SpdySessionKey& spdy_session_key, |
653 HttpServerProperties* http_server_properties, | 653 HttpServerProperties* http_server_properties, |
654 TransportSecurityState* transport_security_state, | 654 TransportSecurityState* transport_security_state, |
655 bool enable_sending_initial_data, | 655 bool enable_sending_initial_data, |
656 bool enable_ping_based_connection_checking, | 656 bool enable_ping_based_connection_checking, |
657 size_t session_max_recv_window_size, | 657 size_t session_max_recv_window_size, |
658 size_t stream_max_recv_window_size, | 658 const SettingsMap& settings, |
659 TimeFunc time_func, | 659 TimeFunc time_func, |
660 ServerPushDelegate* push_delegate, | 660 ServerPushDelegate* push_delegate, |
661 ProxyDelegate* proxy_delegate, | 661 ProxyDelegate* proxy_delegate, |
662 NetLog* net_log) | 662 NetLog* net_log) |
663 : in_io_loop_(false), | 663 : in_io_loop_(false), |
664 spdy_session_key_(spdy_session_key), | 664 spdy_session_key_(spdy_session_key), |
665 pool_(NULL), | 665 pool_(NULL), |
666 http_server_properties_(http_server_properties), | 666 http_server_properties_(http_server_properties), |
667 transport_security_state_(transport_security_state), | 667 transport_security_state_(transport_security_state), |
668 read_buffer_(new IOBuffer(kReadBufferSize)), | 668 read_buffer_(new IOBuffer(kReadBufferSize)), |
669 stream_hi_water_mark_(kFirstStreamId), | 669 stream_hi_water_mark_(kFirstStreamId), |
670 last_accepted_push_stream_id_(0), | 670 last_accepted_push_stream_id_(0), |
671 unclaimed_pushed_streams_(this), | 671 unclaimed_pushed_streams_(this), |
672 push_delegate_(push_delegate), | 672 push_delegate_(push_delegate), |
673 num_pushed_streams_(0u), | 673 num_pushed_streams_(0u), |
674 num_active_pushed_streams_(0u), | 674 num_active_pushed_streams_(0u), |
675 bytes_pushed_count_(0u), | 675 bytes_pushed_count_(0u), |
676 bytes_pushed_and_unclaimed_count_(0u), | 676 bytes_pushed_and_unclaimed_count_(0u), |
677 in_flight_write_frame_type_(DATA), | 677 in_flight_write_frame_type_(DATA), |
678 in_flight_write_frame_size_(0), | 678 in_flight_write_frame_size_(0), |
679 is_secure_(false), | 679 is_secure_(false), |
680 availability_state_(STATE_AVAILABLE), | 680 availability_state_(STATE_AVAILABLE), |
681 read_state_(READ_STATE_DO_READ), | 681 read_state_(READ_STATE_DO_READ), |
682 write_state_(WRITE_STATE_IDLE), | 682 write_state_(WRITE_STATE_IDLE), |
683 error_on_close_(OK), | 683 error_on_close_(OK), |
684 settings_(settings), | |
684 max_concurrent_streams_(kInitialMaxConcurrentStreams), | 685 max_concurrent_streams_(kInitialMaxConcurrentStreams), |
685 max_concurrent_pushed_streams_(kMaxConcurrentPushedStreams), | 686 max_concurrent_pushed_streams_( |
687 settings.at(SETTINGS_MAX_CONCURRENT_STREAMS)), | |
686 streams_initiated_count_(0), | 688 streams_initiated_count_(0), |
687 streams_pushed_count_(0), | 689 streams_pushed_count_(0), |
688 streams_pushed_and_claimed_count_(0), | 690 streams_pushed_and_claimed_count_(0), |
689 streams_abandoned_count_(0), | 691 streams_abandoned_count_(0), |
690 pings_in_flight_(0), | 692 pings_in_flight_(0), |
691 next_ping_id_(1), | 693 next_ping_id_(1), |
692 last_activity_time_(time_func()), | 694 last_activity_time_(time_func()), |
693 last_compressed_frame_len_(0), | 695 last_compressed_frame_len_(0), |
694 check_ping_status_pending_(false), | 696 check_ping_status_pending_(false), |
695 session_send_window_size_(0), | 697 session_send_window_size_(0), |
696 session_max_recv_window_size_(session_max_recv_window_size), | 698 session_max_recv_window_size_(session_max_recv_window_size), |
697 session_recv_window_size_(0), | 699 session_recv_window_size_(0), |
698 session_unacked_recv_window_bytes_(0), | 700 session_unacked_recv_window_bytes_(0), |
699 stream_initial_send_window_size_(kDefaultInitialWindowSize), | 701 stream_initial_send_window_size_(kDefaultInitialWindowSize), |
700 stream_max_recv_window_size_(stream_max_recv_window_size), | 702 max_header_table_size_(settings.at(SETTINGS_HEADER_TABLE_SIZE)), |
703 stream_max_recv_window_size_(settings.at(SETTINGS_INITIAL_WINDOW_SIZE)), | |
701 net_log_( | 704 net_log_( |
702 NetLogWithSource::Make(net_log, NetLogSourceType::HTTP2_SESSION)), | 705 NetLogWithSource::Make(net_log, NetLogSourceType::HTTP2_SESSION)), |
703 enable_sending_initial_data_(enable_sending_initial_data), | 706 enable_sending_initial_data_(enable_sending_initial_data), |
704 enable_ping_based_connection_checking_( | 707 enable_ping_based_connection_checking_( |
705 enable_ping_based_connection_checking), | 708 enable_ping_based_connection_checking), |
706 connection_at_risk_of_loss_time_( | 709 connection_at_risk_of_loss_time_( |
707 base::TimeDelta::FromSeconds(kDefaultConnectionAtRiskOfLossSeconds)), | 710 base::TimeDelta::FromSeconds(kDefaultConnectionAtRiskOfLossSeconds)), |
708 hung_interval_(base::TimeDelta::FromSeconds(kHungIntervalSeconds)), | 711 hung_interval_(base::TimeDelta::FromSeconds(kHungIntervalSeconds)), |
709 proxy_delegate_(proxy_delegate), | 712 proxy_delegate_(proxy_delegate), |
710 time_func_(time_func), | 713 time_func_(time_func), |
711 weak_factory_(this) { | 714 weak_factory_(this) { |
712 net_log_.BeginEvent( | 715 net_log_.BeginEvent( |
713 NetLogEventType::HTTP2_SESSION, | 716 NetLogEventType::HTTP2_SESSION, |
714 base::Bind(&NetLogSpdySessionCallback, &host_port_proxy_pair())); | 717 base::Bind(&NetLogSpdySessionCallback, &host_port_proxy_pair())); |
715 next_unclaimed_push_stream_sweep_time_ = time_func_() + | 718 next_unclaimed_push_stream_sweep_time_ = time_func_() + |
716 base::TimeDelta::FromSeconds(kMinPushedStreamLifetimeSeconds); | 719 base::TimeDelta::FromSeconds(kMinPushedStreamLifetimeSeconds); |
720 | |
721 DCHECK(settings_.find(SETTINGS_HEADER_TABLE_SIZE) != settings_.end()); | |
Ryan Hamilton
2016/12/27 22:32:43
Consider base::ContainsKey(settings_, SETTINGS_foo
Bence
2016/12/28 00:53:24
Done.
| |
722 DCHECK(settings_.find(SETTINGS_MAX_CONCURRENT_STREAMS) != settings_.end()); | |
723 DCHECK(settings_.find(SETTINGS_INITIAL_WINDOW_SIZE) != settings_.end()); | |
724 | |
717 // TODO(mbelshe): consider randomization of the stream_hi_water_mark. | 725 // TODO(mbelshe): consider randomization of the stream_hi_water_mark. |
718 } | 726 } |
719 | 727 |
720 SpdySession::~SpdySession() { | 728 SpdySession::~SpdySession() { |
721 CHECK(!in_io_loop_); | 729 CHECK(!in_io_loop_); |
722 DcheckDraining(); | 730 DcheckDraining(); |
723 | 731 |
724 // TODO(akalin): Check connection->is_initialized() instead. This | 732 // TODO(akalin): Check connection->is_initialized() instead. This |
725 // requires re-working CreateFakeSpdySession(), though. | 733 // requires re-working CreateFakeSpdySession(), though. |
726 DCHECK(connection_->socket()); | 734 DCHECK(connection_->socket()); |
(...skipping 21 matching lines...) Expand all Loading... | |
748 | 756 |
749 connection_ = std::move(connection); | 757 connection_ = std::move(connection); |
750 is_secure_ = is_secure; | 758 is_secure_ = is_secure; |
751 | 759 |
752 session_send_window_size_ = kDefaultInitialWindowSize; | 760 session_send_window_size_ = kDefaultInitialWindowSize; |
753 session_recv_window_size_ = kDefaultInitialWindowSize; | 761 session_recv_window_size_ = kDefaultInitialWindowSize; |
754 | 762 |
755 buffered_spdy_framer_.reset(new BufferedSpdyFramer()); | 763 buffered_spdy_framer_.reset(new BufferedSpdyFramer()); |
756 buffered_spdy_framer_->set_visitor(this); | 764 buffered_spdy_framer_->set_visitor(this); |
757 buffered_spdy_framer_->set_debug_visitor(this); | 765 buffered_spdy_framer_->set_debug_visitor(this); |
758 buffered_spdy_framer_->UpdateHeaderDecoderTableSize(kMaxHeaderTableSize); | 766 buffered_spdy_framer_->UpdateHeaderDecoderTableSize(max_header_table_size_); |
759 | 767 |
760 net_log_.AddEvent(NetLogEventType::HTTP2_SESSION_INITIALIZED, | 768 net_log_.AddEvent(NetLogEventType::HTTP2_SESSION_INITIALIZED, |
761 base::Bind(&NetLogSpdyInitializedCallback, | 769 base::Bind(&NetLogSpdyInitializedCallback, |
762 connection_->socket()->NetLog().source())); | 770 connection_->socket()->NetLog().source())); |
763 | 771 |
764 DCHECK_EQ(availability_state_, STATE_AVAILABLE); | 772 DCHECK_EQ(availability_state_, STATE_AVAILABLE); |
765 connection_->AddHigherLayeredPool(this); | 773 connection_->AddHigherLayeredPool(this); |
766 if (enable_sending_initial_data_) | 774 if (enable_sending_initial_data_) |
767 SendInitialData(); | 775 SendInitialData(); |
768 pool_ = pool; | 776 pool_ = pool; |
(...skipping 1870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2639 | 2647 |
2640 std::unique_ptr<SpdySerializedFrame> connection_header_prefix_frame( | 2648 std::unique_ptr<SpdySerializedFrame> connection_header_prefix_frame( |
2641 new SpdySerializedFrame(const_cast<char*>(kHttp2ConnectionHeaderPrefix), | 2649 new SpdySerializedFrame(const_cast<char*>(kHttp2ConnectionHeaderPrefix), |
2642 kHttp2ConnectionHeaderPrefixSize, | 2650 kHttp2ConnectionHeaderPrefixSize, |
2643 false /* take_ownership */)); | 2651 false /* take_ownership */)); |
2644 // Count the prefix as part of the subsequent SETTINGS frame. | 2652 // Count the prefix as part of the subsequent SETTINGS frame. |
2645 EnqueueSessionWrite(HIGHEST, SETTINGS, | 2653 EnqueueSessionWrite(HIGHEST, SETTINGS, |
2646 std::move(connection_header_prefix_frame)); | 2654 std::move(connection_header_prefix_frame)); |
2647 | 2655 |
2648 // First, notify the server about the settings they should use when | 2656 // First, notify the server about the settings they should use when |
2649 // communicating with us. | 2657 // communicating with us. Only send settings that have a value different from |
2658 // the protocol default value. | |
2650 SettingsMap settings_map; | 2659 SettingsMap settings_map; |
2651 settings_map[SETTINGS_HEADER_TABLE_SIZE] = kMaxHeaderTableSize; | 2660 for (auto setting : settings_) { |
2652 settings_map[SETTINGS_MAX_CONCURRENT_STREAMS] = kMaxConcurrentPushedStreams; | 2661 switch (setting.first) { |
2653 if (stream_max_recv_window_size_ != kDefaultInitialWindowSize) { | 2662 case SETTINGS_HEADER_TABLE_SIZE: |
2654 settings_map[SETTINGS_INITIAL_WINDOW_SIZE] = stream_max_recv_window_size_; | 2663 if (setting.second == 4096) |
Ryan Hamilton
2016/12/27 22:32:43
Can we define these magic numbers somewhere?
Bence
2016/12/28 00:53:24
Done.
| |
2664 continue; | |
2665 break; | |
2666 case SETTINGS_ENABLE_PUSH: | |
2667 if (setting.second == 1) | |
2668 continue; | |
2669 break; | |
2670 case SETTINGS_MAX_CONCURRENT_STREAMS: | |
2671 break; | |
2672 case SETTINGS_INITIAL_WINDOW_SIZE: | |
2673 if (setting.second == 65535) | |
2674 continue; | |
2675 break; | |
2676 case SETTINGS_MAX_FRAME_SIZE: | |
2677 if (setting.second == 16384) | |
2678 continue; | |
2679 break; | |
2680 case SETTINGS_MAX_HEADER_LIST_SIZE: | |
2681 break; | |
2682 default: | |
2683 break; | |
2684 } | |
2685 settings_map.insert(setting); | |
2655 } | 2686 } |
2656 SendSettings(settings_map); | 2687 SendSettings(settings_map); |
2657 | 2688 |
2658 // Next, notify the server about our initial recv window size. | 2689 // Next, notify the server about our initial recv window size. |
2659 // Bump up the receive window size to the real initial value. This | 2690 // Bump up the receive window size to the real initial value. This |
2660 // has to go here since the WINDOW_UPDATE frame sent by | 2691 // has to go here since the WINDOW_UPDATE frame sent by |
2661 // IncreaseRecvWindowSize() call uses |buffered_spdy_framer_|. | 2692 // IncreaseRecvWindowSize() call uses |buffered_spdy_framer_|. |
2662 // This condition implies that |session_max_recv_window_size_| - | 2693 // This condition implies that |session_max_recv_window_size_| - |
2663 // |session_recv_window_size_| doesn't overflow. | 2694 // |session_recv_window_size_| doesn't overflow. |
2664 DCHECK_GE(session_max_recv_window_size_, session_recv_window_size_); | 2695 DCHECK_GE(session_max_recv_window_size_, session_recv_window_size_); |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3028 if (!queue->empty()) { | 3059 if (!queue->empty()) { |
3029 SpdyStreamId stream_id = queue->front(); | 3060 SpdyStreamId stream_id = queue->front(); |
3030 queue->pop_front(); | 3061 queue->pop_front(); |
3031 return stream_id; | 3062 return stream_id; |
3032 } | 3063 } |
3033 } | 3064 } |
3034 return 0; | 3065 return 0; |
3035 } | 3066 } |
3036 | 3067 |
3037 } // namespace net | 3068 } // namespace net |
OLD | NEW |