diff options
Diffstat (limited to 'net/tools')
-rw-r--r-- | net/tools/quic/end_to_end_test.cc | 3 | ||||
-rw-r--r-- | net/tools/quic/quic_server.h | 2 | ||||
-rw-r--r-- | net/tools/quic/test_tools/quic_test_server.cc | 69 | ||||
-rw-r--r-- | net/tools/quic/test_tools/quic_test_server.h | 51 |
4 files changed, 122 insertions, 3 deletions
diff --git a/net/tools/quic/end_to_end_test.cc b/net/tools/quic/end_to_end_test.cc index 9e7605f..2478b84 100644 --- a/net/tools/quic/end_to_end_test.cc +++ b/net/tools/quic/end_to_end_test.cc @@ -1406,9 +1406,6 @@ TEST_P(EndToEndTest, AckNotifierWithPacketLossAndBlockedSocket) { // socket, an AckNotifierDelegate will get informed that the data it is // interested in has been ACKed. This tests end-to-end ACK notification, and // demonstrates that retransmissions do not break this functionality. - ValueRestore<bool> old_flag(&FLAGS_quic_attach_ack_notifiers_to_packets, - true); - SetPacketLossPercentage(5); ASSERT_TRUE(Initialize()); diff --git a/net/tools/quic/quic_server.h b/net/tools/quic/quic_server.h index f8a5533..31e5988 100644 --- a/net/tools/quic/quic_server.h +++ b/net/tools/quic/quic_server.h @@ -90,6 +90,8 @@ class QuicServer : public EpollCallbackInterface { } EpollServer* epoll_server() { return &epoll_server_; } + QuicDispatcher* dispatcher() { return dispatcher_.get(); } + private: friend class net::tools::test::QuicServerPeer; diff --git a/net/tools/quic/test_tools/quic_test_server.cc b/net/tools/quic/test_tools/quic_test_server.cc new file mode 100644 index 0000000..3d6c247 --- /dev/null +++ b/net/tools/quic/test_tools/quic_test_server.cc @@ -0,0 +1,69 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "net/tools/quic/test_tools/quic_test_server.h" + +namespace net { + +namespace tools { + +namespace test { + +class QuicTestDispatcher : public QuicDispatcher { + public: + QuicTestDispatcher(const QuicConfig& config, + const QuicCryptoServerConfig& crypto_config, + const QuicVersionVector& versions, + PacketWriterFactory* factory, + EpollServer* eps) + : QuicDispatcher(config, crypto_config, versions, factory, eps) {} + QuicSession* CreateQuicSession(QuicConnectionId id, + const IPEndPoint& server, + const IPEndPoint& client) override { + if (session_creator_ == nullptr) { + return QuicDispatcher::CreateQuicSession(id, server, client); + } else { + QuicConnection* connection = CreateQuicConnection(id, server, client); + QuicServerSession* session = + (session_creator_)(config(), connection, this); + session->InitializeSession(crypto_config()); + return session; + } + } + + void set_session_creator( + const QuicTestServer::SessionCreationFunction& function) { + session_creator_ = function; + } + + private: + QuicTestServer::SessionCreationFunction session_creator_; +}; + +QuicDispatcher* QuicTestServer::CreateQuicDispatcher() { + return new QuicTestDispatcher( + config(), crypto_config(), supported_versions(), + new QuicDispatcher::DefaultPacketWriterFactory(), epoll_server()); +} + +void QuicTestServer::SetSessionCreator( + const SessionCreationFunction& function) { + static_cast<QuicTestDispatcher*>(dispatcher())->set_session_creator(function); +} + +/////////////////////////// TEST SESSIONS /////////////////////////////// + +ImmediateGoAwaySession::ImmediateGoAwaySession( + const QuicConfig& config, + QuicConnection* connection, + QuicServerSessionVisitor* visitor) + : QuicServerSession(config, connection, visitor) { + SendGoAway(QUIC_PEER_GOING_AWAY, ""); +} + +} // namespace test + +} // namespace tools + +} // namespace net diff --git a/net/tools/quic/test_tools/quic_test_server.h b/net/tools/quic/test_tools/quic_test_server.h new file mode 100644 index 0000000..1e56e43 --- /dev/null +++ b/net/tools/quic/test_tools/quic_test_server.h @@ -0,0 +1,51 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_SERVER_H_ +#define NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_SERVER_H_ + +#include "net/tools/quic/quic_dispatcher.h" +#include "net/tools/quic/quic_server.h" +#include "net/tools/quic/quic_server_session.h" + +namespace net { + +namespace tools { + +namespace test { + +// A test server which enables easy creation of custom QuicServerSessions +// +// Eventually this may be extended to allow custom QuicConnections etc. +class QuicTestServer : public QuicServer { + public: + typedef std::function<QuicServerSession*(const QuicConfig& config, + QuicConnection* connection, + QuicServerSessionVisitor* visitor)> + SessionCreationFunction; + + // Create a custom dispatcher which creates custom sessions. + QuicDispatcher* CreateQuicDispatcher() override; + + void SetSessionCreator(const SessionCreationFunction& function); +}; + +// Useful test sessions for the QuicTestServer. + +// Test session which sends a GOAWAY immedaitely on creation, before crypto +// credentials have even been established. +class ImmediateGoAwaySession : public QuicServerSession { + public: + ImmediateGoAwaySession(const QuicConfig& config, + QuicConnection* connection, + QuicServerSessionVisitor* visitor); +}; + +} // namespace test + +} // namespace tools + +} // namespace net + +#endif // NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_SERVER_H_ |