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 <memory> | 7 #include <memory> |
8 #include <ostream> | 8 #include <ostream> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "net/quic/core/crypto/crypto_handshake.h" | 13 #include "net/quic/core/crypto/crypto_handshake.h" |
14 #include "net/quic/core/crypto/quic_crypto_server_config.h" | 14 #include "net/quic/core/crypto/quic_crypto_server_config.h" |
15 #include "net/quic/core/crypto/quic_random.h" | 15 #include "net/quic/core/crypto/quic_random.h" |
16 #include "net/quic/core/quic_crypto_stream.h" | 16 #include "net/quic/core/quic_crypto_stream.h" |
17 #include "net/quic/core/quic_flags.h" | 17 #include "net/quic/core/quic_flags.h" |
18 #include "net/quic/core/quic_utils.h" | 18 #include "net/quic/core/quic_utils.h" |
19 #include "net/quic/test_tools/crypto_test_utils.h" | 19 #include "net/quic/test_tools/crypto_test_utils.h" |
20 #include "net/quic/test_tools/quic_buffered_packet_store_peer.h" | 20 #include "net/quic/test_tools/quic_buffered_packet_store_peer.h" |
21 #include "net/quic/test_tools/quic_test_utils.h" | 21 #include "net/quic/test_tools/quic_test_utils.h" |
22 #include "net/test/gtest_util.h" | 22 #include "net/test/gtest_util.h" |
23 #include "net/tools/epoll_server/epoll_server.h" | 23 #include "net/tools/epoll_server/epoll_server.h" |
24 #include "net/tools/quic/chlo_extractor.h" | 24 #include "net/tools/quic/chlo_extractor.h" |
25 #include "net/tools/quic/quic_epoll_alarm_factory.h" | 25 #include "net/tools/quic/quic_epoll_alarm_factory.h" |
26 #include "net/tools/quic/quic_epoll_connection_helper.h" | 26 #include "net/tools/quic/quic_epoll_connection_helper.h" |
27 #include "net/tools/quic/quic_packet_writer_wrapper.h" | 27 #include "net/tools/quic/quic_packet_writer_wrapper.h" |
28 #include "net/tools/quic/quic_simple_server_session_helper.h" | 28 #include "net/tools/quic/quic_simple_crypto_server_stream_helper.h" |
29 #include "net/tools/quic/quic_time_wait_list_manager.h" | 29 #include "net/tools/quic/quic_time_wait_list_manager.h" |
30 #include "net/tools/quic/stateless_rejector.h" | 30 #include "net/tools/quic/stateless_rejector.h" |
31 #include "net/tools/quic/test_tools/mock_quic_time_wait_list_manager.h" | 31 #include "net/tools/quic/test_tools/mock_quic_time_wait_list_manager.h" |
32 #include "net/tools/quic/test_tools/quic_dispatcher_peer.h" | 32 #include "net/tools/quic/test_tools/quic_dispatcher_peer.h" |
33 #include "testing/gmock/include/gmock/gmock.h" | 33 #include "testing/gmock/include/gmock/gmock.h" |
34 #include "testing/gmock_mutant.h" | 34 #include "testing/gmock_mutant.h" |
35 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
36 | 36 |
37 using base::IntToString; | 37 using base::IntToString; |
38 using base::StringPiece; | 38 using base::StringPiece; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 ConnectionCloseSource source)); | 82 ConnectionCloseSource source)); |
83 MOCK_METHOD1(CreateIncomingDynamicStream, QuicSpdyStream*(QuicStreamId id)); | 83 MOCK_METHOD1(CreateIncomingDynamicStream, QuicSpdyStream*(QuicStreamId id)); |
84 MOCK_METHOD1(CreateOutgoingDynamicStream, | 84 MOCK_METHOD1(CreateOutgoingDynamicStream, |
85 QuicSpdyStream*(SpdyPriority priority)); | 85 QuicSpdyStream*(SpdyPriority priority)); |
86 | 86 |
87 QuicCryptoServerStreamBase* CreateQuicCryptoServerStream( | 87 QuicCryptoServerStreamBase* CreateQuicCryptoServerStream( |
88 const QuicCryptoServerConfig* crypto_config, | 88 const QuicCryptoServerConfig* crypto_config, |
89 QuicCompressedCertsCache* compressed_certs_cache) override { | 89 QuicCompressedCertsCache* compressed_certs_cache) override { |
90 return new QuicCryptoServerStream( | 90 return new QuicCryptoServerStream( |
91 crypto_config, compressed_certs_cache, | 91 crypto_config, compressed_certs_cache, |
92 FLAGS_enable_quic_stateless_reject_support, this); | 92 FLAGS_enable_quic_stateless_reject_support, this, stream_helper()); |
93 } | 93 } |
94 | 94 |
95 void SetCryptoStream(QuicCryptoServerStream* crypto_stream) { | 95 void SetCryptoStream(QuicCryptoServerStream* crypto_stream) { |
96 crypto_stream_ = crypto_stream; | 96 crypto_stream_ = crypto_stream; |
97 } | 97 } |
98 | 98 |
99 QuicCryptoServerStreamBase* GetCryptoStream() override { | 99 QuicCryptoServerStreamBase* GetCryptoStream() override { |
100 return crypto_stream_; | 100 return crypto_stream_; |
101 } | 101 } |
102 | 102 |
| 103 QuicCryptoServerStream::Helper* stream_helper() { |
| 104 return QuicServerSessionBase::stream_helper(); |
| 105 } |
| 106 |
103 private: | 107 private: |
104 QuicCryptoServerStreamBase* crypto_stream_; | 108 QuicCryptoServerStreamBase* crypto_stream_; |
105 | 109 |
106 DISALLOW_COPY_AND_ASSIGN(TestQuicSpdyServerSession); | 110 DISALLOW_COPY_AND_ASSIGN(TestQuicSpdyServerSession); |
107 }; | 111 }; |
108 | 112 |
109 class TestDispatcher : public QuicDispatcher { | 113 class TestDispatcher : public QuicDispatcher { |
110 public: | 114 public: |
111 TestDispatcher(const QuicConfig& config, | 115 TestDispatcher(const QuicConfig& config, |
112 const QuicCryptoServerConfig* crypto_config, | 116 const QuicCryptoServerConfig* crypto_config, |
113 QuicVersionManager* version_manager, | 117 QuicVersionManager* version_manager, |
114 EpollServer* eps) | 118 EpollServer* eps) |
115 : QuicDispatcher( | 119 : QuicDispatcher( |
116 config, | 120 config, |
117 crypto_config, | 121 crypto_config, |
118 version_manager, | 122 version_manager, |
119 std::unique_ptr<QuicEpollConnectionHelper>( | 123 std::unique_ptr<QuicEpollConnectionHelper>( |
120 new QuicEpollConnectionHelper(eps, QuicAllocator::BUFFER_POOL)), | 124 new QuicEpollConnectionHelper(eps, QuicAllocator::BUFFER_POOL)), |
121 std::unique_ptr<QuicServerSessionBase::Helper>( | 125 std::unique_ptr<QuicCryptoServerStream::Helper>( |
122 new QuicSimpleServerSessionHelper(QuicRandom::GetInstance())), | 126 new QuicSimpleCryptoServerStreamHelper( |
| 127 QuicRandom::GetInstance())), |
123 std::unique_ptr<QuicEpollAlarmFactory>( | 128 std::unique_ptr<QuicEpollAlarmFactory>( |
124 new QuicEpollAlarmFactory(eps))) {} | 129 new QuicEpollAlarmFactory(eps))) {} |
125 | 130 |
126 MOCK_METHOD2(CreateQuicSession, | 131 MOCK_METHOD2(CreateQuicSession, |
127 QuicServerSessionBase*(QuicConnectionId connection_id, | 132 QuicServerSessionBase*(QuicConnectionId connection_id, |
128 const IPEndPoint& client_address)); | 133 const IPEndPoint& client_address)); |
129 | 134 |
130 MOCK_METHOD1(OnNewConnectionAdded, void(QuicConnectionId connection_id)); | 135 MOCK_METHOD1(OnNewConnectionAdded, void(QuicConnectionId connection_id)); |
131 | 136 |
132 using QuicDispatcher::current_server_address; | 137 using QuicDispatcher::current_server_address; |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, | 526 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, |
522 kDefaultPathId, | 527 kDefaultPathId, |
523 QuicDispatcher::kMaxReasonableInitialPacketNumber + 1); | 528 QuicDispatcher::kMaxReasonableInitialPacketNumber + 1); |
524 } | 529 } |
525 | 530 |
526 // Enables mocking of the handshake-confirmation for stateless rejects. | 531 // Enables mocking of the handshake-confirmation for stateless rejects. |
527 class MockQuicCryptoServerStream : public QuicCryptoServerStream { | 532 class MockQuicCryptoServerStream : public QuicCryptoServerStream { |
528 public: | 533 public: |
529 MockQuicCryptoServerStream(const QuicCryptoServerConfig& crypto_config, | 534 MockQuicCryptoServerStream(const QuicCryptoServerConfig& crypto_config, |
530 QuicCompressedCertsCache* compressed_certs_cache, | 535 QuicCompressedCertsCache* compressed_certs_cache, |
531 QuicServerSessionBase* session) | 536 QuicServerSessionBase* session, |
| 537 QuicCryptoServerStream::Helper* helper) |
532 : QuicCryptoServerStream(&crypto_config, | 538 : QuicCryptoServerStream(&crypto_config, |
533 compressed_certs_cache, | 539 compressed_certs_cache, |
534 FLAGS_enable_quic_stateless_reject_support, | 540 FLAGS_enable_quic_stateless_reject_support, |
535 session) {} | 541 session, |
| 542 helper) {} |
536 void set_handshake_confirmed_for_testing(bool handshake_confirmed) { | 543 void set_handshake_confirmed_for_testing(bool handshake_confirmed) { |
537 handshake_confirmed_ = handshake_confirmed; | 544 handshake_confirmed_ = handshake_confirmed; |
538 } | 545 } |
539 | 546 |
540 private: | 547 private: |
541 DISALLOW_COPY_AND_ASSIGN(MockQuicCryptoServerStream); | 548 DISALLOW_COPY_AND_ASSIGN(MockQuicCryptoServerStream); |
542 }; | 549 }; |
543 | 550 |
544 struct StatelessRejectTestParams { | 551 struct StatelessRejectTestParams { |
545 StatelessRejectTestParams(bool enable_stateless_rejects_via_flag, | 552 StatelessRejectTestParams(bool enable_stateless_rejects_via_flag, |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 } | 613 } |
607 | 614 |
608 // Returns true or false, depending on whether the server will emit | 615 // Returns true or false, depending on whether the server will emit |
609 // a stateless reject, depending upon the parameters of the test. | 616 // a stateless reject, depending upon the parameters of the test. |
610 bool ExpectStatelessReject() { | 617 bool ExpectStatelessReject() { |
611 return GetParam().enable_stateless_rejects_via_flag && | 618 return GetParam().enable_stateless_rejects_via_flag && |
612 !GetParam().crypto_handshake_successful && | 619 !GetParam().crypto_handshake_successful && |
613 GetParam().client_supports_statelesss_rejects; | 620 GetParam().client_supports_statelesss_rejects; |
614 } | 621 } |
615 | 622 |
616 // Sets up dispatcher_, sesession1_, and crypto_stream1_ based on | 623 // Sets up dispatcher_, session1_, and crypto_stream1_ based on |
617 // the test parameters. | 624 // the test parameters. |
618 QuicServerSessionBase* CreateSessionBasedOnTestParams( | 625 QuicServerSessionBase* CreateSessionBasedOnTestParams( |
619 QuicConnectionId connection_id, | 626 QuicConnectionId connection_id, |
620 const IPEndPoint& client_address) { | 627 const IPEndPoint& client_address) { |
621 CreateSession(dispatcher_.get(), config_, connection_id, client_address, | 628 CreateSession(dispatcher_.get(), config_, connection_id, client_address, |
622 &mock_helper_, &mock_alarm_factory_, &crypto_config_, | 629 &mock_helper_, &mock_alarm_factory_, &crypto_config_, |
623 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_); | 630 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_); |
624 | 631 |
625 crypto_stream1_ = new MockQuicCryptoServerStream( | 632 crypto_stream1_ = new MockQuicCryptoServerStream( |
626 crypto_config_, QuicDispatcherPeer::GetCache(dispatcher_.get()), | 633 crypto_config_, QuicDispatcherPeer::GetCache(dispatcher_.get()), |
627 session1_); | 634 session1_, session1_->stream_helper()); |
628 session1_->SetCryptoStream(crypto_stream1_); | 635 session1_->SetCryptoStream(crypto_stream1_); |
629 crypto_stream1_->set_handshake_confirmed_for_testing( | 636 crypto_stream1_->set_handshake_confirmed_for_testing( |
630 GetParam().crypto_handshake_successful); | 637 GetParam().crypto_handshake_successful); |
631 crypto_stream1_->SetPeerSupportsStatelessRejects( | 638 crypto_stream1_->SetPeerSupportsStatelessRejects( |
632 GetParam().client_supports_statelesss_rejects); | 639 GetParam().client_supports_statelesss_rejects); |
633 return session1_; | 640 return session1_; |
634 } | 641 } |
635 | 642 |
636 MockQuicCryptoServerStream* crypto_stream1_; | 643 MockQuicCryptoServerStream* crypto_stream1_; |
637 }; | 644 }; |
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1489 | 1496 |
1490 // CHLO on connection 1 should still be buffered. | 1497 // CHLO on connection 1 should still be buffered. |
1491 ProcessPacket(client_addr_, /*connection_id=*/1, true, false, | 1498 ProcessPacket(client_addr_, /*connection_id=*/1, true, false, |
1492 SerializeFullCHLO()); | 1499 SerializeFullCHLO()); |
1493 EXPECT_TRUE(store->HasChloForConnection(/*connection_id=*/1)); | 1500 EXPECT_TRUE(store->HasChloForConnection(/*connection_id=*/1)); |
1494 } | 1501 } |
1495 | 1502 |
1496 } // namespace | 1503 } // namespace |
1497 } // namespace test | 1504 } // namespace test |
1498 } // namespace net | 1505 } // namespace net |
OLD | NEW |