| 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/tools/quic/quic_dispatcher.h" | 5 #include "net/tools/quic/quic_dispatcher.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/strings/string_piece.h" | 9 #include "base/strings/string_piece.h" |
| 10 #include "net/quic/crypto/crypto_handshake.h" | 10 #include "net/quic/crypto/crypto_handshake.h" |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 QuicConnectionId connection_id = 1; | 253 QuicConnectionId connection_id = 1; |
| 254 // Dispatcher forwards all packets for this connection_id to the time wait | 254 // Dispatcher forwards all packets for this connection_id to the time wait |
| 255 // list manager. | 255 // list manager. |
| 256 EXPECT_CALL(dispatcher_, CreateQuicSession(_, _, _)).Times(0); | 256 EXPECT_CALL(dispatcher_, CreateQuicSession(_, _, _)).Times(0); |
| 257 EXPECT_CALL(*time_wait_list_manager, | 257 EXPECT_CALL(*time_wait_list_manager, |
| 258 ProcessPacket(_, _, connection_id, _, _)).Times(1); | 258 ProcessPacket(_, _, connection_id, _, _)).Times(1); |
| 259 string data = "foo"; | 259 string data = "foo"; |
| 260 ProcessPacket(client_address, connection_id, false, "foo"); | 260 ProcessPacket(client_address, connection_id, false, "foo"); |
| 261 } | 261 } |
| 262 | 262 |
| 263 TEST(QuicDispatcherFlowControlTest, NoNewVersion17ConnectionsIfFlagDisabled) { | |
| 264 // If FLAGS_enable_quic_stream_flow_control_2 is disabled | |
| 265 // then the dispatcher should stop creating connections that support | |
| 266 // QUIC_VERSION_17 (existing connections will stay alive). | |
| 267 // TODO(rjshade): Remove once | |
| 268 // FLAGS_enable_quic_stream_flow_control_2 is removed. | |
| 269 | |
| 270 EpollServer eps; | |
| 271 QuicConfig config; | |
| 272 QuicCryptoServerConfig server_config(QuicCryptoServerConfig::TESTING, | |
| 273 QuicRandom::GetInstance()); | |
| 274 IPEndPoint client(net::test::Loopback4(), 1); | |
| 275 IPEndPoint server(net::test::Loopback4(), 1); | |
| 276 QuicConnectionId kCID = 1234; | |
| 277 | |
| 278 QuicVersion kTestQuicVersions[] = {QUIC_VERSION_17, | |
| 279 QUIC_VERSION_16, | |
| 280 QUIC_VERSION_15}; | |
| 281 QuicVersionVector kTestVersions; | |
| 282 for (size_t i = 0; i < arraysize(kTestQuicVersions); ++i) { | |
| 283 kTestVersions.push_back(kTestQuicVersions[i]); | |
| 284 } | |
| 285 | |
| 286 QuicDispatcher dispatcher(config, server_config, kTestVersions, &eps); | |
| 287 dispatcher.Initialize(0); | |
| 288 | |
| 289 // When flag is enabled, new connections should support QUIC_VERSION_17. | |
| 290 ValueRestore<bool> old_flag(&FLAGS_enable_quic_stream_flow_control_2, true); | |
| 291 scoped_ptr<QuicConnection> connection_1( | |
| 292 QuicDispatcherPeer::CreateQuicConnection(&dispatcher, kCID, client, | |
| 293 server)); | |
| 294 EXPECT_EQ(QUIC_VERSION_17, connection_1->version()); | |
| 295 | |
| 296 | |
| 297 // When flag is disabled, new connections should not support QUIC_VERSION_17. | |
| 298 FLAGS_enable_quic_stream_flow_control_2 = false; | |
| 299 scoped_ptr<QuicConnection> connection_2( | |
| 300 QuicDispatcherPeer::CreateQuicConnection(&dispatcher, kCID, client, | |
| 301 server)); | |
| 302 EXPECT_EQ(QUIC_VERSION_16, connection_2->version()); | |
| 303 } | |
| 304 | |
| 305 class BlockingWriter : public QuicPacketWriterWrapper { | 263 class BlockingWriter : public QuicPacketWriterWrapper { |
| 306 public: | 264 public: |
| 307 BlockingWriter() : write_blocked_(false) {} | 265 BlockingWriter() : write_blocked_(false) {} |
| 308 | 266 |
| 309 virtual bool IsWriteBlocked() const OVERRIDE { return write_blocked_; } | 267 virtual bool IsWriteBlocked() const OVERRIDE { return write_blocked_; } |
| 310 virtual void SetWritable() OVERRIDE { write_blocked_ = false; } | 268 virtual void SetWritable() OVERRIDE { write_blocked_ = false; } |
| 311 | 269 |
| 312 virtual WriteResult WritePacket( | 270 virtual WriteResult WritePacket( |
| 313 const char* buffer, | 271 const char* buffer, |
| 314 size_t buf_len, | 272 size_t buf_len, |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 // And we'll resume where we left off when we get another call. | 451 // And we'll resume where we left off when we get another call. |
| 494 EXPECT_CALL(*connection2(), OnCanWrite()); | 452 EXPECT_CALL(*connection2(), OnCanWrite()); |
| 495 dispatcher_.OnCanWrite(); | 453 dispatcher_.OnCanWrite(); |
| 496 EXPECT_FALSE(dispatcher_.HasPendingWrites()); | 454 EXPECT_FALSE(dispatcher_.HasPendingWrites()); |
| 497 } | 455 } |
| 498 | 456 |
| 499 } // namespace | 457 } // namespace |
| 500 } // namespace test | 458 } // namespace test |
| 501 } // namespace tools | 459 } // namespace tools |
| 502 } // namespace net | 460 } // namespace net |
| OLD | NEW |