| 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_stream_factory.h" | 5 #include "net/quic/quic_stream_factory.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/cpu.h" | 9 #include "base/cpu.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 CREATION_ERROR_SETTING_SEND_BUFFER, | 53 CREATION_ERROR_SETTING_SEND_BUFFER, |
| 54 CREATION_ERROR_MAX | 54 CREATION_ERROR_MAX |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 // When a connection is idle for 30 seconds it will be closed. | 57 // When a connection is idle for 30 seconds it will be closed. |
| 58 const int kIdleConnectionTimeoutSeconds = 30; | 58 const int kIdleConnectionTimeoutSeconds = 30; |
| 59 | 59 |
| 60 // The initial receive window size for both streams and sessions. | 60 // The initial receive window size for both streams and sessions. |
| 61 const int32 kInitialReceiveWindowSize = 10 * 1024 * 1024; // 10MB | 61 const int32 kInitialReceiveWindowSize = 10 * 1024 * 1024; // 10MB |
| 62 | 62 |
| 63 // The suggested initial congestion windows for a server to use. | |
| 64 // TODO: This should be tested and optimized, and even better, suggest a window | |
| 65 // that corresponds to historical bandwidth and min-RTT. | |
| 66 // Larger initial congestion windows can, if we don't overshoot, reduce latency | |
| 67 // by avoiding the RTT needed for slow start to double (and re-double) from a | |
| 68 // default of 10. | |
| 69 // We match SPDY's use of 32 when secure (since we'd compete with SPDY). | |
| 70 const int32 kServerSecureInitialCongestionWindow = 32; | |
| 71 // Be conservative, and just use double a typical TCP ICWND for HTTP. | |
| 72 const int32 kServerInecureInitialCongestionWindow = 20; | |
| 73 // Set the maximum number of undecryptable packets the connection will store. | 63 // Set the maximum number of undecryptable packets the connection will store. |
| 74 const int32 kMaxUndecryptablePackets = 100; | 64 const int32 kMaxUndecryptablePackets = 100; |
| 75 | 65 |
| 76 const char kDummyHostname[] = "quic.global.props"; | 66 const char kDummyHostname[] = "quic.global.props"; |
| 77 const uint16 kDummyPort = 0; | 67 const uint16 kDummyPort = 0; |
| 78 | 68 |
| 79 void HistogramCreateSessionFailure(enum CreateSessionFailure error) { | 69 void HistogramCreateSessionFailure(enum CreateSessionFailure error) { |
| 80 UMA_HISTOGRAM_ENUMERATION("Net.QuicSession.CreationError", error, | 70 UMA_HISTOGRAM_ENUMERATION("Net.QuicSession.CreationError", error, |
| 81 CREATION_ERROR_MAX); | 71 CREATION_ERROR_MAX); |
| 82 } | 72 } |
| (...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 915 base::MessageLoop::current()->message_loop_proxy().get(), | 905 base::MessageLoop::current()->message_loop_proxy().get(), |
| 916 clock_.get(), random_generator_)); | 906 clock_.get(), random_generator_)); |
| 917 } | 907 } |
| 918 | 908 |
| 919 QuicConnection* connection = new QuicConnection(connection_id, | 909 QuicConnection* connection = new QuicConnection(connection_id, |
| 920 addr, | 910 addr, |
| 921 helper_.get(), | 911 helper_.get(), |
| 922 packet_writer_factory, | 912 packet_writer_factory, |
| 923 true /* owns_writer */, | 913 true /* owns_writer */, |
| 924 false /* is_server */, | 914 false /* is_server */, |
| 915 server_id.is_https(), |
| 925 supported_versions_); | 916 supported_versions_); |
| 926 connection->set_max_packet_length(max_packet_length_); | 917 connection->set_max_packet_length(max_packet_length_); |
| 927 | 918 |
| 928 InitializeCachedStateInCryptoConfig(server_id, server_info); | 919 InitializeCachedStateInCryptoConfig(server_id, server_info); |
| 929 | 920 |
| 930 QuicConfig config = config_; | 921 QuicConfig config = config_; |
| 931 config.SetInitialCongestionWindowToSend( | |
| 932 server_id.is_https() ? kServerSecureInitialCongestionWindow | |
| 933 : kServerInecureInitialCongestionWindow); | |
| 934 config.set_max_undecryptable_packets(kMaxUndecryptablePackets); | 922 config.set_max_undecryptable_packets(kMaxUndecryptablePackets); |
| 935 config.SetInitialFlowControlWindowToSend(kInitialReceiveWindowSize); | 923 config.SetInitialFlowControlWindowToSend(kInitialReceiveWindowSize); |
| 936 config.SetInitialStreamFlowControlWindowToSend(kInitialReceiveWindowSize); | 924 config.SetInitialStreamFlowControlWindowToSend(kInitialReceiveWindowSize); |
| 937 config.SetInitialSessionFlowControlWindowToSend(kInitialReceiveWindowSize); | 925 config.SetInitialSessionFlowControlWindowToSend(kInitialReceiveWindowSize); |
| 938 if (http_server_properties_) { | 926 if (http_server_properties_) { |
| 939 const HttpServerProperties::NetworkStats* stats = | 927 const HttpServerProperties::NetworkStats* stats = |
| 940 http_server_properties_->GetServerNetworkStats( | 928 http_server_properties_->GetServerNetworkStats( |
| 941 server_id.host_port_pair()); | 929 server_id.host_port_pair()); |
| 942 if (stats != nullptr) { | 930 if (stats != nullptr) { |
| 943 config.SetInitialRoundTripTimeUsToSend(stats->srtt.InMicroseconds()); | 931 config.SetInitialRoundTripTimeUsToSend(stats->srtt.InMicroseconds()); |
| 944 } | 932 } |
| 945 } | 933 } |
| 946 | 934 |
| 947 if (quic_server_info_factory_ && !server_info) { | 935 if (quic_server_info_factory_ && !server_info) { |
| 948 // Start the disk cache loading so that we can persist the newer QUIC server | 936 // Start the disk cache loading so that we can persist the newer QUIC server |
| 949 // information and/or inform the disk cache that we have reused | 937 // information and/or inform the disk cache that we have reused |
| 950 // |server_info|. | 938 // |server_info|. |
| 951 server_info.reset(quic_server_info_factory_->GetForServer(server_id)); | 939 server_info.reset(quic_server_info_factory_->GetForServer(server_id)); |
| 952 server_info->Start(); | 940 server_info->Start(); |
| 953 } | 941 } |
| 954 | 942 |
| 955 *session = new QuicClientSession( | 943 *session = new QuicClientSession( |
| 956 connection, socket.Pass(), this, transport_security_state_, | 944 connection, socket.Pass(), this, transport_security_state_, |
| 957 server_info.Pass(), config, server_id.is_https(), | 945 server_info.Pass(), config, |
| 958 base::MessageLoop::current()->message_loop_proxy().get(), | 946 base::MessageLoop::current()->message_loop_proxy().get(), |
| 959 net_log.net_log()); | 947 net_log.net_log()); |
| 960 all_sessions_[*session] = server_id; // owning pointer | 948 all_sessions_[*session] = server_id; // owning pointer |
| 961 (*session)->InitializeSession(server_id, &crypto_config_, | 949 (*session)->InitializeSession(server_id, &crypto_config_, |
| 962 quic_crypto_client_stream_factory_); | 950 quic_crypto_client_stream_factory_); |
| 963 bool closed_during_initialize = | 951 bool closed_during_initialize = |
| 964 !ContainsKey(all_sessions_, *session) || | 952 !ContainsKey(all_sessions_, *session) || |
| 965 !(*session)->connection()->connected(); | 953 !(*session)->connection()->connected(); |
| 966 UMA_HISTOGRAM_BOOLEAN("Net.QuicSession.ClosedDuringInitializeSession", | 954 UMA_HISTOGRAM_BOOLEAN("Net.QuicSession.ClosedDuringInitializeSession", |
| 967 closed_during_initialize); | 955 closed_during_initialize); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1086 http_server_properties_->ClearAlternateProtocol(server); | 1074 http_server_properties_->ClearAlternateProtocol(server); |
| 1087 http_server_properties_->SetAlternateProtocol( | 1075 http_server_properties_->SetAlternateProtocol( |
| 1088 server, alternate.port, alternate.protocol, 1); | 1076 server, alternate.port, alternate.protocol, 1); |
| 1089 DCHECK_EQ(QUIC, | 1077 DCHECK_EQ(QUIC, |
| 1090 http_server_properties_->GetAlternateProtocol(server).protocol); | 1078 http_server_properties_->GetAlternateProtocol(server).protocol); |
| 1091 DCHECK(http_server_properties_->WasAlternateProtocolRecentlyBroken( | 1079 DCHECK(http_server_properties_->WasAlternateProtocolRecentlyBroken( |
| 1092 server)); | 1080 server)); |
| 1093 } | 1081 } |
| 1094 | 1082 |
| 1095 } // namespace net | 1083 } // namespace net |
| OLD | NEW |