OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "net/quic/test_tools/quic_stream_factory_peer.h" |
| 6 |
| 7 #include "net/quic/crypto/quic_crypto_client_config.h" |
| 8 #include "net/quic/quic_chromium_client_session.h" |
| 9 #include "net/quic/quic_clock.h" |
| 10 #include "net/quic/quic_http_stream.h" |
| 11 #include "net/quic/quic_stream_factory.h" |
| 12 |
| 13 using std::string; |
| 14 using std::vector; |
| 15 |
| 16 namespace net { |
| 17 namespace test { |
| 18 |
| 19 const QuicConfig* QuicStreamFactoryPeer::GetConfig(QuicStreamFactory* factory) { |
| 20 return &factory->config_; |
| 21 } |
| 22 |
| 23 QuicCryptoClientConfig* QuicStreamFactoryPeer::GetCryptoConfig( |
| 24 QuicStreamFactory* factory) { |
| 25 return &factory->crypto_config_; |
| 26 } |
| 27 |
| 28 bool QuicStreamFactoryPeer::HasActiveSession( |
| 29 QuicStreamFactory* factory, |
| 30 const HostPortPair& host_port_pair) { |
| 31 QuicServerId server_id(host_port_pair, PRIVACY_MODE_DISABLED); |
| 32 return factory->HasActiveSession(server_id); |
| 33 } |
| 34 |
| 35 QuicChromiumClientSession* QuicStreamFactoryPeer::GetActiveSession( |
| 36 QuicStreamFactory* factory, |
| 37 const HostPortPair& host_port_pair) { |
| 38 QuicServerId server_id(host_port_pair, PRIVACY_MODE_DISABLED); |
| 39 DCHECK(factory->HasActiveSession(server_id)); |
| 40 return factory->active_sessions_[server_id]; |
| 41 } |
| 42 |
| 43 scoped_ptr<QuicHttpStream> QuicStreamFactoryPeer::CreateFromSession( |
| 44 QuicStreamFactory* factory, |
| 45 QuicChromiumClientSession* session) { |
| 46 return factory->CreateFromSession(session); |
| 47 } |
| 48 |
| 49 bool QuicStreamFactoryPeer::IsLiveSession(QuicStreamFactory* factory, |
| 50 QuicChromiumClientSession* session) { |
| 51 for (QuicStreamFactory::SessionIdMap::iterator it = |
| 52 factory->all_sessions_.begin(); |
| 53 it != factory->all_sessions_.end(); ++it) { |
| 54 if (it->first == session) |
| 55 return true; |
| 56 } |
| 57 return false; |
| 58 } |
| 59 |
| 60 void QuicStreamFactoryPeer::SetTaskRunner(QuicStreamFactory* factory, |
| 61 base::TaskRunner* task_runner) { |
| 62 factory->task_runner_ = task_runner; |
| 63 } |
| 64 |
| 65 int QuicStreamFactoryPeer::GetNumberOfLossyConnections( |
| 66 QuicStreamFactory* factory, |
| 67 uint16 port) { |
| 68 return factory->number_of_lossy_connections_[port]; |
| 69 } |
| 70 |
| 71 bool QuicStreamFactoryPeer::IsQuicDisabled(QuicStreamFactory* factory, |
| 72 uint16 port) { |
| 73 return factory->IsQuicDisabled(port); |
| 74 } |
| 75 |
| 76 bool QuicStreamFactoryPeer::GetDelayTcpRace(QuicStreamFactory* factory) { |
| 77 return factory->delay_tcp_race_; |
| 78 } |
| 79 |
| 80 void QuicStreamFactoryPeer::SetDelayTcpRace(QuicStreamFactory* factory, |
| 81 bool delay_tcp_race) { |
| 82 factory->delay_tcp_race_ = delay_tcp_race; |
| 83 } |
| 84 |
| 85 void QuicStreamFactoryPeer::SetYieldAfterPackets(QuicStreamFactory* factory, |
| 86 int yield_after_packets) { |
| 87 factory->yield_after_packets_ = yield_after_packets; |
| 88 } |
| 89 |
| 90 void QuicStreamFactoryPeer::SetYieldAfterDuration( |
| 91 QuicStreamFactory* factory, |
| 92 QuicTime::Delta yield_after_duration) { |
| 93 factory->yield_after_duration_ = yield_after_duration; |
| 94 } |
| 95 |
| 96 size_t QuicStreamFactoryPeer::GetNumberOfActiveJobs( |
| 97 QuicStreamFactory* factory, |
| 98 const QuicServerId& server_id) { |
| 99 return (factory->active_jobs_[server_id]).size(); |
| 100 } |
| 101 |
| 102 int QuicStreamFactoryPeer::GetNumTimeoutsWithOpenStreams( |
| 103 QuicStreamFactory* factory) { |
| 104 return factory->num_timeouts_with_open_streams_; |
| 105 } |
| 106 |
| 107 int QuicStreamFactoryPeer::GetNumPublicResetsPostHandshake( |
| 108 QuicStreamFactory* factory) { |
| 109 return factory->num_public_resets_post_handshake_; |
| 110 } |
| 111 |
| 112 void QuicStreamFactoryPeer::MaybeInitialize(QuicStreamFactory* factory) { |
| 113 factory->MaybeInitialize(); |
| 114 } |
| 115 |
| 116 bool QuicStreamFactoryPeer::HasInitializedData(QuicStreamFactory* factory) { |
| 117 return factory->has_initialized_data_; |
| 118 } |
| 119 |
| 120 bool QuicStreamFactoryPeer::SupportsQuicAtStartUp(QuicStreamFactory* factory, |
| 121 HostPortPair host_port_pair) { |
| 122 return ContainsKey(factory->quic_supported_servers_at_startup_, |
| 123 host_port_pair); |
| 124 } |
| 125 |
| 126 bool QuicStreamFactoryPeer::CryptoConfigCacheIsEmpty( |
| 127 QuicStreamFactory* factory, |
| 128 QuicServerId& quic_server_id) { |
| 129 return factory->CryptoConfigCacheIsEmpty(quic_server_id); |
| 130 } |
| 131 |
| 132 void QuicStreamFactoryPeer::CacheDummyServerConfig( |
| 133 QuicStreamFactory* factory, |
| 134 const QuicServerId& quic_server_id) { |
| 135 // Minimum SCFG that passes config validation checks. |
| 136 const char scfg[] = {// SCFG |
| 137 0x53, 0x43, 0x46, 0x47, |
| 138 // num entries |
| 139 0x01, 0x00, |
| 140 // padding |
| 141 0x00, 0x00, |
| 142 // EXPY |
| 143 0x45, 0x58, 0x50, 0x59, |
| 144 // EXPY end offset |
| 145 0x08, 0x00, 0x00, 0x00, |
| 146 // Value |
| 147 '1', '2', '3', '4', '5', '6', '7', '8'}; |
| 148 |
| 149 string server_config(reinterpret_cast<const char*>(&scfg), sizeof(scfg)); |
| 150 string source_address_token("test_source_address_token"); |
| 151 string signature("test_signature"); |
| 152 string test_cert("test_cert"); |
| 153 vector<string> certs; |
| 154 certs.push_back(test_cert); |
| 155 |
| 156 QuicCryptoClientConfig* crypto_config = &factory->crypto_config_; |
| 157 QuicCryptoClientConfig::CachedState* cached = |
| 158 crypto_config->LookupOrCreate(quic_server_id); |
| 159 QuicClock clock; |
| 160 cached->Initialize(server_config, source_address_token, certs, "", signature, |
| 161 clock.WallNow()); |
| 162 } |
| 163 |
| 164 } // namespace test |
| 165 } // namespace net |
OLD | NEW |