Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(379)

Side by Side Diff: net/quic/test_tools/quic_test_utils.cc

Issue 1139183002: Flag-protected. Add stateless reject support to crypto streams. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@QuicCryptoClientConfig_ProcessRejection_92637704
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/test_tools/quic_test_utils.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/test_tools/quic_test_utils.h" 5 #include "net/quic/test_tools/quic_test_utils.h"
6 6
7 #include "base/sha1.h" 7 #include "base/sha1.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "net/quic/crypto/crypto_framer.h" 10 #include "net/quic/crypto/crypto_framer.h"
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 TestClientSession::~TestClientSession() {} 374 TestClientSession::~TestClientSession() {}
375 375
376 void TestClientSession::SetCryptoStream(QuicCryptoStream* stream) { 376 void TestClientSession::SetCryptoStream(QuicCryptoStream* stream) {
377 crypto_stream_ = stream; 377 crypto_stream_ = stream;
378 } 378 }
379 379
380 QuicCryptoStream* TestClientSession::GetCryptoStream() { 380 QuicCryptoStream* TestClientSession::GetCryptoStream() {
381 return crypto_stream_; 381 return crypto_stream_;
382 } 382 }
383 383
384 TestServerSession::TestServerSession(const QuicConfig& config,
385 QuicConnection* connection)
386 : QuicServerSession(config, connection, nullptr) {
387 }
388
389 TestServerSession::~TestServerSession() {
390 }
391
384 MockPacketWriter::MockPacketWriter() { 392 MockPacketWriter::MockPacketWriter() {
385 } 393 }
386 394
387 MockPacketWriter::~MockPacketWriter() { 395 MockPacketWriter::~MockPacketWriter() {
388 } 396 }
389 397
390 MockSendAlgorithm::MockSendAlgorithm() { 398 MockSendAlgorithm::MockSendAlgorithm() {
391 } 399 }
392 400
393 MockSendAlgorithm::~MockSendAlgorithm() { 401 MockSendAlgorithm::~MockSendAlgorithm() {
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 712
705 QuicConfig DefaultQuicConfig() { 713 QuicConfig DefaultQuicConfig() {
706 QuicConfig config; 714 QuicConfig config;
707 config.SetInitialStreamFlowControlWindowToSend( 715 config.SetInitialStreamFlowControlWindowToSend(
708 kInitialStreamFlowControlWindowForTest); 716 kInitialStreamFlowControlWindowForTest);
709 config.SetInitialSessionFlowControlWindowToSend( 717 config.SetInitialSessionFlowControlWindowToSend(
710 kInitialSessionFlowControlWindowForTest); 718 kInitialSessionFlowControlWindowForTest);
711 return config; 719 return config;
712 } 720 }
713 721
722 QuicConfig DefaultQuicConfigStatelessRejects() {
723 QuicConfig config = DefaultQuicConfig();
724 QuicTagVector copt;
725 copt.push_back(kSREJ);
726 config.SetConnectionOptionsToSend(copt);
727 return config;
728 }
729
714 QuicVersionVector SupportedVersions(QuicVersion version) { 730 QuicVersionVector SupportedVersions(QuicVersion version) {
715 QuicVersionVector versions; 731 QuicVersionVector versions;
716 versions.push_back(version); 732 versions.push_back(version);
717 return versions; 733 return versions;
718 } 734 }
719 735
720 TestWriterFactory::TestWriterFactory() : current_writer_(nullptr) {} 736 TestWriterFactory::TestWriterFactory() : current_writer_(nullptr) {}
721 TestWriterFactory::~TestWriterFactory() {} 737 TestWriterFactory::~TestWriterFactory() {}
722 738
723 QuicPacketWriter* TestWriterFactory::Create(QuicPacketWriter* writer, 739 QuicPacketWriter* TestWriterFactory::Create(QuicPacketWriter* writer,
(...skipping 29 matching lines...) Expand all
753 WriteResult TestWriterFactory::PerConnectionPacketWriter::WritePacket( 769 WriteResult TestWriterFactory::PerConnectionPacketWriter::WritePacket(
754 const char* buffer, 770 const char* buffer,
755 size_t buf_len, 771 size_t buf_len,
756 const IPAddressNumber& self_address, 772 const IPAddressNumber& self_address,
757 const IPEndPoint& peer_address) { 773 const IPEndPoint& peer_address) {
758 // A DCHECK(factory_current_writer_ == nullptr) would be wrong here -- this 774 // A DCHECK(factory_current_writer_ == nullptr) would be wrong here -- this
759 // class may be used in a setting where connection()->OnPacketSent() is called 775 // class may be used in a setting where connection()->OnPacketSent() is called
760 // in a different way, so TestWriterFactory::OnPacketSent might never be 776 // in a different way, so TestWriterFactory::OnPacketSent might never be
761 // called. 777 // called.
762 factory_->current_writer_ = this; 778 factory_->current_writer_ = this;
763 return tools::QuicPerConnectionPacketWriter::WritePacket(buffer, 779 return tools::QuicPerConnectionPacketWriter::WritePacket(
764 buf_len, 780 buffer, buf_len, self_address, peer_address);
765 self_address,
766 peer_address);
767 } 781 }
768 782
769 MockQuicConnectionDebugVisitor::MockQuicConnectionDebugVisitor() { 783 MockQuicConnectionDebugVisitor::MockQuicConnectionDebugVisitor() {
770 } 784 }
771 785
772 MockQuicConnectionDebugVisitor::~MockQuicConnectionDebugVisitor() { 786 MockQuicConnectionDebugVisitor::~MockQuicConnectionDebugVisitor() {
773 } 787 }
774 788
789 void SetupCryptoClientStreamForTest(
790 QuicServerId server_id,
791 bool supports_stateless_rejects,
792 QuicTime::Delta connection_start_time,
793 QuicCryptoClientConfig* crypto_client_config,
794 PacketSavingConnection** client_connection,
795 TestClientSession** client_session,
796 QuicCryptoClientStream** client_stream) {
797 CHECK(crypto_client_config);
798 CHECK(client_connection);
799 CHECK(client_session);
800 CHECK(client_stream);
801 CHECK(!connection_start_time.IsZero())
802 << "Connections must start at non-zero times, otherwise the "
803 << "strike-register will be unhappy.";
804
805 QuicConfig config = supports_stateless_rejects
806 ? DefaultQuicConfigStatelessRejects()
807 : DefaultQuicConfig();
808 *client_connection = new PacketSavingConnection(Perspective::IS_CLIENT);
809 *client_session = new TestClientSession(*client_connection, config);
810 *client_stream = new QuicCryptoClientStream(server_id, *client_session,
811 nullptr, crypto_client_config);
812 (*client_session)->SetCryptoStream(*client_stream);
813 (*client_connection)->AdvanceTime(connection_start_time);
814 }
815
816 // Setup or create?
817 void SetupCryptoServerStreamForTest(
818 QuicServerId server_id,
819 QuicTime::Delta connection_start_time,
820 QuicCryptoServerConfig* server_crypto_config,
821 PacketSavingConnection** server_connection,
822 TestServerSession** server_session,
823 QuicCryptoServerStream** server_stream) {
824 CHECK(server_crypto_config);
825 CHECK(server_connection);
826 CHECK(server_session);
827 CHECK(server_stream);
828 CHECK(!connection_start_time.IsZero())
829 << "Connections must start at non-zero times, otherwise the "
830 << "strike-register will be unhappy.";
831
832 *server_connection = new PacketSavingConnection(Perspective::IS_SERVER);
833 *server_session =
834 new TestServerSession(DefaultQuicConfig(), *server_connection);
835 *server_stream =
836 new QuicCryptoServerStream(server_crypto_config, *server_session);
837 (*server_session)->InitializeSession(server_crypto_config);
838
839 // We advance the clock initially because the default time is zero and the
840 // strike register worries that we've just overflowed a uint32 time.
841 (*server_connection)->AdvanceTime(connection_start_time);
842 }
843
775 } // namespace test 844 } // namespace test
776 } // namespace net 845 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/test_tools/quic_test_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698