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 <map> | 7 #include <map> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
293 const SpdyStreamId last_stream_id_; | 293 const SpdyStreamId last_stream_id_; |
294 const int active_streams_; | 294 const int active_streams_; |
295 const int unclaimed_streams_; | 295 const int unclaimed_streams_; |
296 | 296 |
297 DISALLOW_COPY_AND_ASSIGN(NetLogSpdyGoAwayParameter); | 297 DISALLOW_COPY_AND_ASSIGN(NetLogSpdyGoAwayParameter); |
298 }; | 298 }; |
299 | 299 |
300 NextProto g_default_protocol = kProtoUnknown; | 300 NextProto g_default_protocol = kProtoUnknown; |
301 size_t g_init_max_concurrent_streams = 10; | 301 size_t g_init_max_concurrent_streams = 10; |
302 size_t g_max_concurrent_stream_limit = 256; | 302 size_t g_max_concurrent_stream_limit = 256; |
303 size_t g_default_initial_rcv_window_size = 10 * 1024 * 1024; // 10MB | |
303 bool g_enable_ping_based_connection_checking = true; | 304 bool g_enable_ping_based_connection_checking = true; |
304 | 305 |
305 } // namespace | 306 } // namespace |
306 | 307 |
307 // static | 308 // static |
308 void SpdySession::set_default_protocol(NextProto default_protocol) { | 309 void SpdySession::set_default_protocol(NextProto default_protocol) { |
309 g_default_protocol = default_protocol; | 310 g_default_protocol = default_protocol; |
310 } | 311 } |
311 | 312 |
312 // static | 313 // static |
313 void SpdySession::set_max_concurrent_streams(size_t value) { | 314 void SpdySession::set_max_concurrent_streams(size_t value) { |
314 g_max_concurrent_stream_limit = value; | 315 g_max_concurrent_stream_limit = value; |
315 } | 316 } |
316 | 317 |
317 // static | 318 // static |
319 void SpdySession::set_default_initial_recv_window_size(size_t value) { | |
320 g_default_initial_rcv_window_size = value; | |
321 } | |
322 | |
323 // static | |
318 void SpdySession::set_enable_ping_based_connection_checking(bool enable) { | 324 void SpdySession::set_enable_ping_based_connection_checking(bool enable) { |
319 g_enable_ping_based_connection_checking = enable; | 325 g_enable_ping_based_connection_checking = enable; |
320 } | 326 } |
321 | 327 |
322 // static | 328 // static |
323 void SpdySession::set_init_max_concurrent_streams(size_t value) { | 329 void SpdySession::set_init_max_concurrent_streams(size_t value) { |
324 g_init_max_concurrent_streams = | 330 g_init_max_concurrent_streams = |
325 std::min(value, g_max_concurrent_stream_limit); | 331 std::min(value, g_max_concurrent_stream_limit); |
326 } | 332 } |
327 | 333 |
328 // static | 334 // static |
329 void SpdySession::ResetStaticSettingsToInit() { | 335 void SpdySession::ResetStaticSettingsToInit() { |
330 // WARNING: These must match the initializers above. | 336 // WARNING: These must match the initializers above. |
331 g_default_protocol = kProtoUnknown; | 337 g_default_protocol = kProtoUnknown; |
332 g_init_max_concurrent_streams = 10; | 338 g_init_max_concurrent_streams = 10; |
333 g_max_concurrent_stream_limit = 256; | 339 g_max_concurrent_stream_limit = 256; |
340 g_default_initial_rcv_window_size = kSpdyStreamInitialWindowSize; | |
334 g_enable_ping_based_connection_checking = true; | 341 g_enable_ping_based_connection_checking = true; |
335 } | 342 } |
336 | 343 |
337 SpdySession::SpdySession(const HostPortProxyPair& host_port_proxy_pair, | 344 SpdySession::SpdySession(const HostPortProxyPair& host_port_proxy_pair, |
338 SpdySessionPool* spdy_session_pool, | 345 SpdySessionPool* spdy_session_pool, |
339 HttpServerProperties* http_server_properties, | 346 HttpServerProperties* http_server_properties, |
340 bool verify_domain_authentication, | 347 bool verify_domain_authentication, |
341 const HostPortPair& trusted_spdy_proxy, | 348 const HostPortPair& trusted_spdy_proxy, |
342 NetLog* net_log) | 349 NetLog* net_log) |
343 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 350 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
(...skipping 18 matching lines...) Expand all Loading... | |
362 bytes_received_(0), | 369 bytes_received_(0), |
363 sent_settings_(false), | 370 sent_settings_(false), |
364 received_settings_(false), | 371 received_settings_(false), |
365 stalled_streams_(0), | 372 stalled_streams_(0), |
366 pings_in_flight_(0), | 373 pings_in_flight_(0), |
367 next_ping_id_(1), | 374 next_ping_id_(1), |
368 last_activity_time_(base::TimeTicks::Now()), | 375 last_activity_time_(base::TimeTicks::Now()), |
369 check_ping_status_pending_(false), | 376 check_ping_status_pending_(false), |
370 flow_control_(false), | 377 flow_control_(false), |
371 initial_send_window_size_(kSpdyStreamInitialWindowSize), | 378 initial_send_window_size_(kSpdyStreamInitialWindowSize), |
372 initial_recv_window_size_(kSpdyStreamInitialWindowSize), | 379 initial_recv_window_size_(g_default_initial_rcv_window_size), |
373 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SPDY_SESSION)), | 380 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SPDY_SESSION)), |
374 verify_domain_authentication_(verify_domain_authentication), | 381 verify_domain_authentication_(verify_domain_authentication), |
375 credential_state_(SpdyCredentialState::kDefaultNumSlots), | 382 credential_state_(SpdyCredentialState::kDefaultNumSlots), |
376 connection_at_risk_of_loss_time_( | 383 connection_at_risk_of_loss_time_( |
377 base::TimeDelta::FromSeconds(kDefaultConnectionAtRiskOfLossSeconds)), | 384 base::TimeDelta::FromSeconds(kDefaultConnectionAtRiskOfLossSeconds)), |
378 hung_interval_( | 385 hung_interval_( |
379 base::TimeDelta::FromSeconds(kHungIntervalSeconds)), | 386 base::TimeDelta::FromSeconds(kHungIntervalSeconds)), |
380 trusted_spdy_proxy_(trusted_spdy_proxy) { | 387 trusted_spdy_proxy_(trusted_spdy_proxy) { |
381 DCHECK(HttpStreamFactory::spdy_enabled()); | 388 DCHECK(HttpStreamFactory::spdy_enabled()); |
382 net_log_.BeginEvent( | 389 net_log_.BeginEvent( |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
440 host_port_pair().ToString())); | 447 host_port_pair().ToString())); |
441 } | 448 } |
442 | 449 |
443 DCHECK(protocol >= kProtoSPDY2); | 450 DCHECK(protocol >= kProtoSPDY2); |
444 DCHECK(protocol <= kProtoSPDY3); | 451 DCHECK(protocol <= kProtoSPDY3); |
445 int version = (protocol == kProtoSPDY3) ? 3 : 2; | 452 int version = (protocol == kProtoSPDY3) ? 3 : 2; |
446 flow_control_ = (protocol >= kProtoSPDY3); | 453 flow_control_ = (protocol >= kProtoSPDY3); |
447 | 454 |
448 buffered_spdy_framer_.reset(new BufferedSpdyFramer(version)); | 455 buffered_spdy_framer_.reset(new BufferedSpdyFramer(version)); |
449 buffered_spdy_framer_->set_visitor(this); | 456 buffered_spdy_framer_->set_visitor(this); |
450 SendSettings(); | 457 SendInitialSettings(); |
451 | 458 |
452 // Write out any data that we might have to send, such as the settings frame. | 459 // Write out any data that we might have to send, such as the settings frame. |
453 WriteSocketLater(); | 460 WriteSocketLater(); |
454 net::Error error = ReadSocket(); | 461 net::Error error = ReadSocket(); |
455 if (error == ERR_IO_PENDING) | 462 if (error == ERR_IO_PENDING) |
456 return OK; | 463 return OK; |
457 return error; | 464 return error; |
458 } | 465 } |
459 | 466 |
460 bool SpdySession::VerifyDomainAuthentication(const std::string& domain) { | 467 bool SpdySession::VerifyDomainAuthentication(const std::string& domain) { |
(...skipping 1228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1689 else if (trial->group_name() == "cwndMin16") | 1696 else if (trial->group_name() == "cwndMin16") |
1690 return std::max(cwnd, 16); | 1697 return std::max(cwnd, 16); |
1691 else if (trial->group_name() == "cwndMin10") | 1698 else if (trial->group_name() == "cwndMin10") |
1692 return std::max(cwnd, 10); | 1699 return std::max(cwnd, 10); |
1693 else if (trial->group_name() == "cwndDynamic") | 1700 else if (trial->group_name() == "cwndDynamic") |
1694 return cwnd; | 1701 return cwnd; |
1695 NOTREACHED(); | 1702 NOTREACHED(); |
1696 return cwnd; | 1703 return cwnd; |
1697 } | 1704 } |
1698 | 1705 |
1699 void SpdySession::SendSettings() { | 1706 void SpdySession::SendInitialSettings() { |
1707 SettingsMap settings_to_send; | |
1708 | |
1709 // First notify the server about the settings they should use when | |
1710 // communicating with use. | |
1711 if (GetProtocolVersion() > 2 && | |
1712 initial_recv_window_size_ != kSpdyStreamInitialWindowSize) { | |
1713 // Create a new settings frame notifying the sever of our | |
1714 // initial window size. | |
ramant (doing other things)
2012/06/04 20:22:35
nit: could we update the comment (because initial
Ryan Hamilton
2012/06/04 20:48:50
Ugh. That would be a bug. We do not want to over
| |
1715 settings_to_send[SETTINGS_INITIAL_WINDOW_SIZE] = | |
1716 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, initial_recv_window_size_); | |
1717 /* | |
1718 net_log_.AddEvent( | |
1719 NetLog::TYPE_SPDY_SESSION_SEND_SETTINGS, | |
1720 make_scoped_refptr(new NetLogSpdySettingsParameter(settings_map))); | |
1721 | |
1722 // Create the SETTINGS frame and send it. | |
1723 DCHECK(buffered_spdy_framer_.get()); | |
1724 scoped_ptr<SpdySettingsControlFrame> settings_frame( | |
1725 buffered_spdy_framer_->CreateSettings(settings_map)); | |
1726 sent_settings_ = true; | |
1727 QueueFrame(settings_frame.get(), HIGHEST, NULL); | |
ramant (doing other things)
2012/06/04 20:22:35
nit: Should we delete the commented out code?
Ryan Hamilton
2012/06/04 20:48:50
Whoops! Done. (Now factored into a new helper me
| |
1728 */ | |
1729 } | |
1730 | |
1700 const SettingsMap& settings_map = | 1731 const SettingsMap& settings_map = |
1701 http_server_properties_->GetSpdySettings(host_port_pair()); | 1732 http_server_properties_->GetSpdySettings(host_port_pair()); |
1702 if (settings_map.empty()) | |
1703 return; | |
1704 | 1733 |
1705 // Record Histogram Data and Apply the SpdyCwnd FieldTrial if applicable. | 1734 // Next notify the server about the settings they have previously |
1706 const SpdySettingsIds id = SETTINGS_CURRENT_CWND; | 1735 // told use to use when communicating with them. |
ramant (doing other things)
2012/06/04 20:22:35
nit: could we update this comment because we are n
Ryan Hamilton
2012/06/04 20:48:50
Since I had to change the code, I kept the comment
| |
1707 SettingsMap::const_iterator it = settings_map.find(id); | 1736 if (!settings_map.empty()) { |
1708 uint32 value = 0; | 1737 // Record Histogram Data and Apply the SpdyCwnd FieldTrial if applicable. |
1709 if (it != settings_map.end()) | 1738 const SpdySettingsIds id = SETTINGS_CURRENT_CWND; |
1710 value = it->second.second; | 1739 SettingsMap::const_iterator it = settings_map.find(id); |
1711 uint32 cwnd = ApplyCwndFieldTrialPolicy(value); | 1740 uint32 value = 0; |
1712 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwndSent", cwnd, 1, 200, 100); | 1741 if (it != settings_map.end()) |
1713 if (cwnd != value) { | 1742 value = it->second.second; |
1714 http_server_properties_->SetSpdySetting( | 1743 uint32 cwnd = ApplyCwndFieldTrialPolicy(value); |
1715 host_port_pair(), id, SETTINGS_FLAG_PLEASE_PERSIST, cwnd); | 1744 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySettingsCwndSent", cwnd, 1, 200, 100); |
1745 if (cwnd != value) { | |
1746 http_server_properties_->SetSpdySetting( | |
1747 host_port_pair(), id, SETTINGS_FLAG_PLEASE_PERSIST, cwnd); | |
1748 } | |
1749 | |
1750 const SettingsMap& settings_map_new = | |
1751 http_server_properties_->GetSpdySettings(host_port_pair()); | |
1752 for (SettingsMap::const_iterator i = settings_map_new.begin(), | |
1753 end = settings_map_new.end(); i != end; ++i) { | |
1754 const SpdySettingsIds new_id = i->first; | |
1755 const uint32 new_val = i->second.second; | |
1756 HandleSetting(new_id, new_val); | |
1757 settings_to_send[i->first] = i->second; | |
1758 } | |
1716 } | 1759 } |
1717 | 1760 |
1718 const SettingsMap& settings_map_new = | 1761 if (settings_to_send.empty()) |
1719 http_server_properties_->GetSpdySettings(host_port_pair()); | 1762 return; |
1720 for (SettingsMap::const_iterator i = settings_map_new.begin(), | |
1721 end = settings_map_new.end(); i != end; ++i) { | |
1722 const SpdySettingsIds new_id = i->first; | |
1723 const uint32 new_val = i->second.second; | |
1724 HandleSetting(new_id, new_val); | |
1725 } | |
1726 | 1763 |
1727 net_log_.AddEvent( | 1764 net_log_.AddEvent( |
1728 NetLog::TYPE_SPDY_SESSION_SEND_SETTINGS, | 1765 NetLog::TYPE_SPDY_SESSION_SEND_SETTINGS, |
1729 make_scoped_refptr(new NetLogSpdySettingsParameter(settings_map_new))); | 1766 make_scoped_refptr(new NetLogSpdySettingsParameter(settings_to_send))); |
1730 | 1767 |
1731 // Create the SETTINGS frame and send it. | 1768 // Create the SETTINGS frame and send it. |
1732 DCHECK(buffered_spdy_framer_.get()); | 1769 DCHECK(buffered_spdy_framer_.get()); |
1733 scoped_ptr<SpdySettingsControlFrame> settings_frame( | 1770 scoped_ptr<SpdySettingsControlFrame> settings_frame( |
1734 buffered_spdy_framer_->CreateSettings(settings_map_new)); | 1771 buffered_spdy_framer_->CreateSettings(settings_to_send)); |
1735 sent_settings_ = true; | 1772 sent_settings_ = true; |
1736 QueueFrame(settings_frame.get(), HIGHEST, NULL); | 1773 QueueFrame(settings_frame.get(), HIGHEST, NULL); |
1737 } | 1774 } |
1738 | 1775 |
1739 void SpdySession::HandleSetting(uint32 id, uint32 value) { | 1776 void SpdySession::HandleSetting(uint32 id, uint32 value) { |
1740 switch (id) { | 1777 switch (id) { |
1741 case SETTINGS_MAX_CONCURRENT_STREAMS: | 1778 case SETTINGS_MAX_CONCURRENT_STREAMS: |
1742 max_concurrent_streams_ = std::min(static_cast<size_t>(value), | 1779 max_concurrent_streams_ = std::min(static_cast<size_t>(value), |
1743 g_max_concurrent_stream_limit); | 1780 g_max_concurrent_stream_limit); |
1744 ProcessPendingCreateStreams(); | 1781 ProcessPendingCreateStreams(); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1946 SSLClientSocket* SpdySession::GetSSLClientSocket() const { | 1983 SSLClientSocket* SpdySession::GetSSLClientSocket() const { |
1947 if (!is_secure_) | 1984 if (!is_secure_) |
1948 return NULL; | 1985 return NULL; |
1949 SSLClientSocket* ssl_socket = | 1986 SSLClientSocket* ssl_socket = |
1950 reinterpret_cast<SSLClientSocket*>(connection_->socket()); | 1987 reinterpret_cast<SSLClientSocket*>(connection_->socket()); |
1951 DCHECK(ssl_socket); | 1988 DCHECK(ssl_socket); |
1952 return ssl_socket; | 1989 return ssl_socket; |
1953 } | 1990 } |
1954 | 1991 |
1955 } // namespace net | 1992 } // namespace net |
OLD | NEW |