OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "net/tools/quic/test_tools/quic_test_server.h" |
| 6 |
| 7 namespace net { |
| 8 |
| 9 namespace tools { |
| 10 |
| 11 namespace test { |
| 12 |
| 13 class QuicTestDispatcher : public QuicDispatcher { |
| 14 public: |
| 15 QuicTestDispatcher(const QuicConfig& config, |
| 16 const QuicCryptoServerConfig& crypto_config, |
| 17 const QuicVersionVector& versions, |
| 18 PacketWriterFactory* factory, |
| 19 EpollServer* eps) |
| 20 : QuicDispatcher(config, crypto_config, versions, factory, eps) {} |
| 21 QuicSession* CreateQuicSession(QuicConnectionId id, |
| 22 const IPEndPoint& server, |
| 23 const IPEndPoint& client) override { |
| 24 if (session_creator_ == nullptr) { |
| 25 return QuicDispatcher::CreateQuicSession(id, server, client); |
| 26 } else { |
| 27 QuicConnection* connection = CreateQuicConnection(id, server, client); |
| 28 QuicServerSession* session = |
| 29 (session_creator_)(config(), connection, this); |
| 30 session->InitializeSession(crypto_config()); |
| 31 return session; |
| 32 } |
| 33 } |
| 34 |
| 35 void set_session_creator( |
| 36 const QuicTestServer::SessionCreationFunction& function) { |
| 37 session_creator_ = function; |
| 38 } |
| 39 |
| 40 private: |
| 41 QuicTestServer::SessionCreationFunction session_creator_; |
| 42 }; |
| 43 |
| 44 QuicDispatcher* QuicTestServer::CreateQuicDispatcher() { |
| 45 return new QuicTestDispatcher( |
| 46 config(), crypto_config(), supported_versions(), |
| 47 new QuicDispatcher::DefaultPacketWriterFactory(), epoll_server()); |
| 48 } |
| 49 |
| 50 void QuicTestServer::SetSessionCreator( |
| 51 const SessionCreationFunction& function) { |
| 52 static_cast<QuicTestDispatcher*>(dispatcher())->set_session_creator(function); |
| 53 } |
| 54 |
| 55 /////////////////////////// TEST SESSIONS /////////////////////////////// |
| 56 |
| 57 ImmediateGoAwaySession::ImmediateGoAwaySession( |
| 58 const QuicConfig& config, |
| 59 QuicConnection* connection, |
| 60 QuicServerSessionVisitor* visitor) |
| 61 : QuicServerSession(config, connection, visitor) { |
| 62 SendGoAway(QUIC_PEER_GOING_AWAY, ""); |
| 63 } |
| 64 |
| 65 } // namespace test |
| 66 |
| 67 } // namespace tools |
| 68 |
| 69 } // namespace net |
OLD | NEW |