| 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 // A toy server, which listens on a specified address for QUIC traffic and | 5 // A toy server, which listens on a specified address for QUIC traffic and |
| 6 // handles incoming responses. | 6 // handles incoming responses. |
| 7 // | 7 // |
| 8 // Note that this server is intended to verify correctness of the client and is | 8 // Note that this server is intended to verify correctness of the client and is |
| 9 // in no way expected to be performant. | 9 // in no way expected to be performant. |
| 10 | 10 |
| 11 #ifndef NET_TOOLS_QUIC_QUIC_SERVER_H_ | 11 #ifndef NET_TOOLS_QUIC_QUIC_SERVER_H_ |
| 12 #define NET_TOOLS_QUIC_QUIC_SERVER_H_ | 12 #define NET_TOOLS_QUIC_QUIC_SERVER_H_ |
| 13 | 13 |
| 14 #include <stddef.h> | 14 #include <stddef.h> |
| 15 | 15 |
| 16 #include <memory> | 16 #include <memory> |
| 17 | 17 |
| 18 #include "base/macros.h" | 18 #include "base/macros.h" |
| 19 #include "net/quic/chromium/quic_chromium_connection_helper.h" | 19 #include "net/quic/chromium/quic_chromium_connection_helper.h" |
| 20 #include "net/quic/core/crypto/quic_crypto_server_config.h" | 20 #include "net/quic/core/crypto/quic_crypto_server_config.h" |
| 21 #include "net/quic/core/quic_config.h" | 21 #include "net/quic/core/quic_config.h" |
| 22 #include "net/quic/core/quic_framer.h" | 22 #include "net/quic/core/quic_framer.h" |
| 23 #include "net/quic/core/quic_version_manager.h" | 23 #include "net/quic/core/quic_version_manager.h" |
| 24 #include "net/quic/platform/api/quic_socket_address.h" | 24 #include "net/quic/platform/api/quic_socket_address.h" |
| 25 #include "net/tools/epoll_server/epoll_server.h" | 25 #include "net/tools/epoll_server/epoll_server.h" |
| 26 #include "net/tools/quic/quic_default_packet_writer.h" | 26 #include "net/tools/quic/quic_default_packet_writer.h" |
| 27 #include "net/tools/quic/quic_in_memory_cache.h" | 27 #include "net/tools/quic/quic_http_response_cache.h" |
| 28 | 28 |
| 29 namespace net { | 29 namespace net { |
| 30 | 30 |
| 31 namespace test { | 31 namespace test { |
| 32 class QuicServerPeer; | 32 class QuicServerPeer; |
| 33 } // namespace test | 33 } // namespace test |
| 34 | 34 |
| 35 class QuicDispatcher; | 35 class QuicDispatcher; |
| 36 class QuicPacketReader; | 36 class QuicPacketReader; |
| 37 | 37 |
| 38 class QuicServer : public EpollCallbackInterface { | 38 class QuicServer : public EpollCallbackInterface { |
| 39 public: | 39 public: |
| 40 QuicServer(std::unique_ptr<ProofSource> proof_source, | 40 QuicServer(std::unique_ptr<ProofSource> proof_source, |
| 41 QuicInMemoryCache* in_memory_cache); | 41 QuicHttpResponseCache* response_cache); |
| 42 QuicServer(std::unique_ptr<ProofSource> proof_source, | 42 QuicServer(std::unique_ptr<ProofSource> proof_source, |
| 43 const QuicConfig& config, | 43 const QuicConfig& config, |
| 44 const QuicCryptoServerConfig::ConfigOptions& server_config_options, | 44 const QuicCryptoServerConfig::ConfigOptions& server_config_options, |
| 45 const QuicVersionVector& supported_versions, | 45 const QuicVersionVector& supported_versions, |
| 46 QuicInMemoryCache* in_memory_cache); | 46 QuicHttpResponseCache* response_cache); |
| 47 | 47 |
| 48 ~QuicServer() override; | 48 ~QuicServer() override; |
| 49 | 49 |
| 50 // Start listening on the specified address. | 50 // Start listening on the specified address. |
| 51 bool CreateUDPSocketAndListen(const QuicSocketAddress& address); | 51 bool CreateUDPSocketAndListen(const QuicSocketAddress& address); |
| 52 | 52 |
| 53 // Wait up to 50ms, and handle any events which occur. | 53 // Wait up to 50ms, and handle any events which occur. |
| 54 void WaitForEvents(); | 54 void WaitForEvents(); |
| 55 | 55 |
| 56 // Server deletion is imminent. Start cleaning up the epoll server. | 56 // Server deletion is imminent. Start cleaning up the epoll server. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 80 virtual QuicDispatcher* CreateQuicDispatcher(); | 80 virtual QuicDispatcher* CreateQuicDispatcher(); |
| 81 | 81 |
| 82 const QuicConfig& config() const { return config_; } | 82 const QuicConfig& config() const { return config_; } |
| 83 const QuicCryptoServerConfig& crypto_config() const { return crypto_config_; } | 83 const QuicCryptoServerConfig& crypto_config() const { return crypto_config_; } |
| 84 EpollServer* epoll_server() { return &epoll_server_; } | 84 EpollServer* epoll_server() { return &epoll_server_; } |
| 85 | 85 |
| 86 QuicDispatcher* dispatcher() { return dispatcher_.get(); } | 86 QuicDispatcher* dispatcher() { return dispatcher_.get(); } |
| 87 | 87 |
| 88 QuicVersionManager* version_manager() { return &version_manager_; } | 88 QuicVersionManager* version_manager() { return &version_manager_; } |
| 89 | 89 |
| 90 QuicInMemoryCache* in_memory_cache() { return in_memory_cache_; } | 90 QuicHttpResponseCache* response_cache() { return response_cache_; } |
| 91 | 91 |
| 92 private: | 92 private: |
| 93 friend class net::test::QuicServerPeer; | 93 friend class net::test::QuicServerPeer; |
| 94 | 94 |
| 95 // Initialize the internal state of the server. | 95 // Initialize the internal state of the server. |
| 96 void Initialize(); | 96 void Initialize(); |
| 97 | 97 |
| 98 // Accepts data from the framer and demuxes clients to sessions. | 98 // Accepts data from the framer and demuxes clients to sessions. |
| 99 std::unique_ptr<QuicDispatcher> dispatcher_; | 99 std::unique_ptr<QuicDispatcher> dispatcher_; |
| 100 // Frames incoming packets and hands them to the dispatcher. | 100 // Frames incoming packets and hands them to the dispatcher. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 123 // crypto_config_options_ contains crypto parameters for the handshake. | 123 // crypto_config_options_ contains crypto parameters for the handshake. |
| 124 QuicCryptoServerConfig::ConfigOptions crypto_config_options_; | 124 QuicCryptoServerConfig::ConfigOptions crypto_config_options_; |
| 125 | 125 |
| 126 // Used to generate current supported versions. | 126 // Used to generate current supported versions. |
| 127 QuicVersionManager version_manager_; | 127 QuicVersionManager version_manager_; |
| 128 | 128 |
| 129 // Point to a QuicPacketReader object on the heap. The reader allocates more | 129 // Point to a QuicPacketReader object on the heap. The reader allocates more |
| 130 // space than allowed on the stack. | 130 // space than allowed on the stack. |
| 131 std::unique_ptr<QuicPacketReader> packet_reader_; | 131 std::unique_ptr<QuicPacketReader> packet_reader_; |
| 132 | 132 |
| 133 QuicInMemoryCache* in_memory_cache_; // unowned. | 133 QuicHttpResponseCache* response_cache_; // unowned. |
| 134 | 134 |
| 135 DISALLOW_COPY_AND_ASSIGN(QuicServer); | 135 DISALLOW_COPY_AND_ASSIGN(QuicServer); |
| 136 }; | 136 }; |
| 137 | 137 |
| 138 } // namespace net | 138 } // namespace net |
| 139 | 139 |
| 140 #endif // NET_TOOLS_QUIC_QUIC_SERVER_H_ | 140 #endif // NET_TOOLS_QUIC_QUIC_SERVER_H_ |
| OLD | NEW |