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, |
| 93 stream_helper()); |
93 } | 94 } |
94 | 95 |
95 void SetCryptoStream(QuicCryptoServerStream* crypto_stream) { | 96 void SetCryptoStream(QuicCryptoServerStream* crypto_stream) { |
96 crypto_stream_ = crypto_stream; | 97 crypto_stream_ = crypto_stream; |
97 } | 98 } |
98 | 99 |
99 QuicCryptoServerStreamBase* GetCryptoStream() override { | 100 QuicCryptoServerStreamBase* GetCryptoStream() override { |
100 return crypto_stream_; | 101 return crypto_stream_; |
101 } | 102 } |
102 | 103 |
| 104 QuicCryptoServerStream::Helper* stream_helper() { |
| 105 return QuicServerSessionBase::stream_helper(); |
| 106 } |
| 107 |
103 private: | 108 private: |
104 QuicCryptoServerStreamBase* crypto_stream_; | 109 QuicCryptoServerStreamBase* crypto_stream_; |
105 | 110 |
106 DISALLOW_COPY_AND_ASSIGN(TestQuicSpdyServerSession); | 111 DISALLOW_COPY_AND_ASSIGN(TestQuicSpdyServerSession); |
107 }; | 112 }; |
108 | 113 |
109 class TestDispatcher : public QuicDispatcher { | 114 class TestDispatcher : public QuicDispatcher { |
110 public: | 115 public: |
111 TestDispatcher(const QuicConfig& config, | 116 TestDispatcher(const QuicConfig& config, |
112 const QuicCryptoServerConfig* crypto_config, | 117 const QuicCryptoServerConfig* crypto_config, |
113 QuicVersionManager* version_manager, | 118 QuicVersionManager* version_manager, |
114 EpollServer* eps) | 119 EpollServer* eps) |
115 : QuicDispatcher( | 120 : QuicDispatcher( |
116 config, | 121 config, |
117 crypto_config, | 122 crypto_config, |
118 version_manager, | 123 version_manager, |
119 std::unique_ptr<QuicEpollConnectionHelper>( | 124 std::unique_ptr<QuicEpollConnectionHelper>( |
120 new QuicEpollConnectionHelper(eps, QuicAllocator::BUFFER_POOL)), | 125 new QuicEpollConnectionHelper(eps, QuicAllocator::BUFFER_POOL)), |
121 std::unique_ptr<QuicServerSessionBase::Helper>( | 126 std::unique_ptr<QuicCryptoServerStream::Helper>( |
122 new QuicSimpleServerSessionHelper(QuicRandom::GetInstance())), | 127 new QuicSimpleCryptoServerStreamHelper( |
| 128 QuicRandom::GetInstance())), |
123 std::unique_ptr<QuicEpollAlarmFactory>( | 129 std::unique_ptr<QuicEpollAlarmFactory>( |
124 new QuicEpollAlarmFactory(eps))) {} | 130 new QuicEpollAlarmFactory(eps))) {} |
125 | 131 |
126 MOCK_METHOD2(CreateQuicSession, | 132 MOCK_METHOD2(CreateQuicSession, |
127 QuicServerSessionBase*(QuicConnectionId connection_id, | 133 QuicServerSessionBase*(QuicConnectionId connection_id, |
128 const IPEndPoint& client_address)); | 134 const IPEndPoint& client_address)); |
129 | 135 |
130 MOCK_METHOD1(OnNewConnectionAdded, void(QuicConnectionId connection_id)); | 136 MOCK_METHOD1(OnNewConnectionAdded, void(QuicConnectionId connection_id)); |
131 | 137 |
132 using QuicDispatcher::current_server_address; | 138 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, | 527 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, |
522 kDefaultPathId, | 528 kDefaultPathId, |
523 QuicDispatcher::kMaxReasonableInitialPacketNumber + 1); | 529 QuicDispatcher::kMaxReasonableInitialPacketNumber + 1); |
524 } | 530 } |
525 | 531 |
526 // Enables mocking of the handshake-confirmation for stateless rejects. | 532 // Enables mocking of the handshake-confirmation for stateless rejects. |
527 class MockQuicCryptoServerStream : public QuicCryptoServerStream { | 533 class MockQuicCryptoServerStream : public QuicCryptoServerStream { |
528 public: | 534 public: |
529 MockQuicCryptoServerStream(const QuicCryptoServerConfig& crypto_config, | 535 MockQuicCryptoServerStream(const QuicCryptoServerConfig& crypto_config, |
530 QuicCompressedCertsCache* compressed_certs_cache, | 536 QuicCompressedCertsCache* compressed_certs_cache, |
531 QuicServerSessionBase* session) | 537 QuicServerSessionBase* session, |
| 538 QuicCryptoServerStream::Helper* helper) |
532 : QuicCryptoServerStream(&crypto_config, | 539 : QuicCryptoServerStream(&crypto_config, |
533 compressed_certs_cache, | 540 compressed_certs_cache, |
534 FLAGS_enable_quic_stateless_reject_support, | 541 FLAGS_enable_quic_stateless_reject_support, |
535 session) {} | 542 session, |
| 543 helper) {} |
536 void set_handshake_confirmed_for_testing(bool handshake_confirmed) { | 544 void set_handshake_confirmed_for_testing(bool handshake_confirmed) { |
537 handshake_confirmed_ = handshake_confirmed; | 545 handshake_confirmed_ = handshake_confirmed; |
538 } | 546 } |
539 | 547 |
540 private: | 548 private: |
541 DISALLOW_COPY_AND_ASSIGN(MockQuicCryptoServerStream); | 549 DISALLOW_COPY_AND_ASSIGN(MockQuicCryptoServerStream); |
542 }; | 550 }; |
543 | 551 |
544 struct StatelessRejectTestParams { | 552 struct StatelessRejectTestParams { |
545 StatelessRejectTestParams(bool enable_stateless_rejects_via_flag, | 553 StatelessRejectTestParams(bool enable_stateless_rejects_via_flag, |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 } | 614 } |
607 | 615 |
608 // Returns true or false, depending on whether the server will emit | 616 // Returns true or false, depending on whether the server will emit |
609 // a stateless reject, depending upon the parameters of the test. | 617 // a stateless reject, depending upon the parameters of the test. |
610 bool ExpectStatelessReject() { | 618 bool ExpectStatelessReject() { |
611 return GetParam().enable_stateless_rejects_via_flag && | 619 return GetParam().enable_stateless_rejects_via_flag && |
612 !GetParam().crypto_handshake_successful && | 620 !GetParam().crypto_handshake_successful && |
613 GetParam().client_supports_statelesss_rejects; | 621 GetParam().client_supports_statelesss_rejects; |
614 } | 622 } |
615 | 623 |
616 // Sets up dispatcher_, sesession1_, and crypto_stream1_ based on | 624 // Sets up dispatcher_, session1_, and crypto_stream1_ based on |
617 // the test parameters. | 625 // the test parameters. |
618 QuicServerSessionBase* CreateSessionBasedOnTestParams( | 626 QuicServerSessionBase* CreateSessionBasedOnTestParams( |
619 QuicConnectionId connection_id, | 627 QuicConnectionId connection_id, |
620 const IPEndPoint& client_address) { | 628 const IPEndPoint& client_address) { |
621 CreateSession(dispatcher_.get(), config_, connection_id, client_address, | 629 CreateSession(dispatcher_.get(), config_, connection_id, client_address, |
622 &mock_helper_, &mock_alarm_factory_, &crypto_config_, | 630 &mock_helper_, &mock_alarm_factory_, &crypto_config_, |
623 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_); | 631 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_); |
624 | 632 |
625 crypto_stream1_ = new MockQuicCryptoServerStream( | 633 crypto_stream1_ = new MockQuicCryptoServerStream( |
626 crypto_config_, QuicDispatcherPeer::GetCache(dispatcher_.get()), | 634 crypto_config_, QuicDispatcherPeer::GetCache(dispatcher_.get()), |
627 session1_); | 635 session1_, session1_->stream_helper()); |
628 session1_->SetCryptoStream(crypto_stream1_); | 636 session1_->SetCryptoStream(crypto_stream1_); |
629 crypto_stream1_->set_handshake_confirmed_for_testing( | 637 crypto_stream1_->set_handshake_confirmed_for_testing( |
630 GetParam().crypto_handshake_successful); | 638 GetParam().crypto_handshake_successful); |
631 crypto_stream1_->SetPeerSupportsStatelessRejects( | 639 crypto_stream1_->SetPeerSupportsStatelessRejects( |
632 GetParam().client_supports_statelesss_rejects); | 640 GetParam().client_supports_statelesss_rejects); |
633 return session1_; | 641 return session1_; |
634 } | 642 } |
635 | 643 |
636 MockQuicCryptoServerStream* crypto_stream1_; | 644 MockQuicCryptoServerStream* crypto_stream1_; |
637 }; | 645 }; |
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1489 | 1497 |
1490 // CHLO on connection 1 should still be buffered. | 1498 // CHLO on connection 1 should still be buffered. |
1491 ProcessPacket(client_addr_, /*connection_id=*/1, true, false, | 1499 ProcessPacket(client_addr_, /*connection_id=*/1, true, false, |
1492 SerializeFullCHLO()); | 1500 SerializeFullCHLO()); |
1493 EXPECT_TRUE(store->HasChloForConnection(/*connection_id=*/1)); | 1501 EXPECT_TRUE(store->HasChloForConnection(/*connection_id=*/1)); |
1494 } | 1502 } |
1495 | 1503 |
1496 } // namespace | 1504 } // namespace |
1497 } // namespace test | 1505 } // namespace test |
1498 } // namespace net | 1506 } // namespace net |
OLD | NEW |