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