| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 config.SetDefaults(); | 91 config.SetDefaults(); |
| 92 if (enable_time_based_loss_detection) | 92 if (enable_time_based_loss_detection) |
| 93 config.SetLossDetectionToSend(kTIME); | 93 config.SetLossDetectionToSend(kTIME); |
| 94 config.set_idle_connection_state_lifetime( | 94 config.set_idle_connection_state_lifetime( |
| 95 QuicTime::Delta::FromSeconds(kIdleConnectionTimeoutSeconds), | 95 QuicTime::Delta::FromSeconds(kIdleConnectionTimeoutSeconds), |
| 96 QuicTime::Delta::FromSeconds(kIdleConnectionTimeoutSeconds)); | 96 QuicTime::Delta::FromSeconds(kIdleConnectionTimeoutSeconds)); |
| 97 config.SetConnectionOptionsToSend(connection_options); | 97 config.SetConnectionOptionsToSend(connection_options); |
| 98 return config; | 98 return config; |
| 99 } | 99 } |
| 100 | 100 |
| 101 class DefaultPacketWriterFactory : public QuicConnection::PacketWriterFactory { |
| 102 public: |
| 103 explicit DefaultPacketWriterFactory(DatagramClientSocket* socket) |
| 104 : socket_(socket) {} |
| 105 virtual ~DefaultPacketWriterFactory() {} |
| 106 |
| 107 virtual QuicPacketWriter* Create(QuicConnection* connection) const OVERRIDE; |
| 108 |
| 109 private: |
| 110 DatagramClientSocket* socket_; |
| 111 }; |
| 112 |
| 113 QuicPacketWriter* DefaultPacketWriterFactory::Create( |
| 114 QuicConnection* connection) const { |
| 115 scoped_ptr<QuicDefaultPacketWriter> writer( |
| 116 new QuicDefaultPacketWriter(socket_)); |
| 117 writer->SetConnection(connection); |
| 118 return writer.release(); |
| 119 } |
| 120 |
| 101 } // namespace | 121 } // namespace |
| 102 | 122 |
| 103 QuicStreamFactory::IpAliasKey::IpAliasKey() {} | 123 QuicStreamFactory::IpAliasKey::IpAliasKey() {} |
| 104 | 124 |
| 105 QuicStreamFactory::IpAliasKey::IpAliasKey(IPEndPoint ip_endpoint, | 125 QuicStreamFactory::IpAliasKey::IpAliasKey(IPEndPoint ip_endpoint, |
| 106 bool is_https) | 126 bool is_https) |
| 107 : ip_endpoint(ip_endpoint), | 127 : ip_endpoint(ip_endpoint), |
| 108 is_https(is_https) {} | 128 is_https(is_https) {} |
| 109 | 129 |
| 110 QuicStreamFactory::IpAliasKey::~IpAliasKey() {} | 130 QuicStreamFactory::IpAliasKey::~IpAliasKey() {} |
| (...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 } | 833 } |
| 814 // Set a buffer large enough to contain the initial CWND's worth of packet | 834 // Set a buffer large enough to contain the initial CWND's worth of packet |
| 815 // to work around the problem with CHLO packets being sent out with the | 835 // to work around the problem with CHLO packets being sent out with the |
| 816 // wrong encryption level, when the send buffer is full. | 836 // wrong encryption level, when the send buffer is full. |
| 817 rv = socket->SetSendBufferSize(kMaxPacketSize * 20); | 837 rv = socket->SetSendBufferSize(kMaxPacketSize * 20); |
| 818 if (rv != OK) { | 838 if (rv != OK) { |
| 819 HistogramCreateSessionFailure(CREATION_ERROR_SETTING_SEND_BUFFER); | 839 HistogramCreateSessionFailure(CREATION_ERROR_SETTING_SEND_BUFFER); |
| 820 return rv; | 840 return rv; |
| 821 } | 841 } |
| 822 | 842 |
| 823 scoped_ptr<QuicDefaultPacketWriter> writer( | 843 DefaultPacketWriterFactory packet_writer_factory(socket.get()); |
| 824 new QuicDefaultPacketWriter(socket.get())); | |
| 825 | 844 |
| 826 if (!helper_.get()) { | 845 if (!helper_.get()) { |
| 827 helper_.reset(new QuicConnectionHelper( | 846 helper_.reset(new QuicConnectionHelper( |
| 828 base::MessageLoop::current()->message_loop_proxy().get(), | 847 base::MessageLoop::current()->message_loop_proxy().get(), |
| 829 clock_.get(), random_generator_)); | 848 clock_.get(), random_generator_)); |
| 830 } | 849 } |
| 831 | 850 |
| 832 QuicConnection* connection = new QuicConnection(connection_id, | 851 QuicConnection* connection = new QuicConnection(connection_id, |
| 833 addr, | 852 addr, |
| 834 helper_.get(), | 853 helper_.get(), |
| 835 writer.get(), | 854 packet_writer_factory, |
| 836 false /* owns_writer */, | 855 true /* owns_writer */, |
| 837 false /* is_server */, | 856 false /* is_server */, |
| 838 supported_versions_); | 857 supported_versions_); |
| 839 writer->SetConnection(connection); | |
| 840 connection->set_max_packet_length(max_packet_length_); | 858 connection->set_max_packet_length(max_packet_length_); |
| 841 | 859 |
| 842 InitializeCachedStateInCryptoConfig(server_id, server_info); | 860 InitializeCachedStateInCryptoConfig(server_id, server_info); |
| 843 | 861 |
| 844 QuicConfig config = config_; | 862 QuicConfig config = config_; |
| 845 config.SetInitialCongestionWindowToSend( | 863 config.SetInitialCongestionWindowToSend( |
| 846 server_id.is_https() ? kServerSecureInitialCongestionWindow | 864 server_id.is_https() ? kServerSecureInitialCongestionWindow |
| 847 : kServerInecureInitialCongestionWindow); | 865 : kServerInecureInitialCongestionWindow); |
| 848 config.SetInitialFlowControlWindowToSend(kInitialReceiveWindowSize); | 866 config.SetInitialFlowControlWindowToSend(kInitialReceiveWindowSize); |
| 849 config.SetInitialStreamFlowControlWindowToSend(kInitialReceiveWindowSize); | 867 config.SetInitialStreamFlowControlWindowToSend(kInitialReceiveWindowSize); |
| 850 config.SetInitialSessionFlowControlWindowToSend(kInitialReceiveWindowSize); | 868 config.SetInitialSessionFlowControlWindowToSend(kInitialReceiveWindowSize); |
| 851 if (http_server_properties_) { | 869 if (http_server_properties_) { |
| 852 const HttpServerProperties::NetworkStats* stats = | 870 const HttpServerProperties::NetworkStats* stats = |
| 853 http_server_properties_->GetServerNetworkStats( | 871 http_server_properties_->GetServerNetworkStats( |
| 854 server_id.host_port_pair()); | 872 server_id.host_port_pair()); |
| 855 if (stats != NULL) { | 873 if (stats != NULL) { |
| 856 config.SetInitialRoundTripTimeUsToSend(stats->srtt.InMicroseconds()); | 874 config.SetInitialRoundTripTimeUsToSend(stats->srtt.InMicroseconds()); |
| 857 } | 875 } |
| 858 } | 876 } |
| 859 | 877 |
| 860 *session = new QuicClientSession( | 878 *session = new QuicClientSession( |
| 861 connection, socket.Pass(), writer.Pass(), this, | 879 connection, socket.Pass(), this, |
| 862 quic_crypto_client_stream_factory_, transport_security_state_, | 880 quic_crypto_client_stream_factory_, transport_security_state_, |
| 863 server_info.Pass(), server_id, config, &crypto_config_, | 881 server_info.Pass(), server_id, config, &crypto_config_, |
| 864 base::MessageLoop::current()->message_loop_proxy().get(), | 882 base::MessageLoop::current()->message_loop_proxy().get(), |
| 865 net_log.net_log()); | 883 net_log.net_log()); |
| 866 (*session)->InitializeSession(); | 884 (*session)->InitializeSession(); |
| 867 all_sessions_[*session] = server_id; // owning pointer | 885 all_sessions_[*session] = server_id; // owning pointer |
| 868 return OK; | 886 return OK; |
| 869 } | 887 } |
| 870 | 888 |
| 871 bool QuicStreamFactory::HasActiveJob(const QuicServerId& key) const { | 889 bool QuicStreamFactory::HasActiveJob(const QuicServerId& key) const { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 958 http_server_properties_->ClearAlternateProtocol(server); | 976 http_server_properties_->ClearAlternateProtocol(server); |
| 959 http_server_properties_->SetAlternateProtocol( | 977 http_server_properties_->SetAlternateProtocol( |
| 960 server, alternate.port, alternate.protocol, 1); | 978 server, alternate.port, alternate.protocol, 1); |
| 961 DCHECK_EQ(QUIC, | 979 DCHECK_EQ(QUIC, |
| 962 http_server_properties_->GetAlternateProtocol(server).protocol); | 980 http_server_properties_->GetAlternateProtocol(server).protocol); |
| 963 DCHECK(http_server_properties_->WasAlternateProtocolRecentlyBroken( | 981 DCHECK(http_server_properties_->WasAlternateProtocolRecentlyBroken( |
| 964 server)); | 982 server)); |
| 965 } | 983 } |
| 966 | 984 |
| 967 } // namespace net | 985 } // namespace net |
| OLD | NEW |