| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef NET_QUIC_QUIC_SERVER_H_ | 8 #ifndef NET_QUIC_TOOLS_QUIC_SIMPLE_SERVER_H_ |
| 9 #define NET_QUIC_QUIC_SERVER_H_ | 9 #define NET_QUIC_TOOLS_QUIC_SIMPLE_SERVER_H_ |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "net/base/io_buffer.h" | 13 #include "net/base/io_buffer.h" |
| 14 #include "net/base/ip_endpoint.h" | 14 #include "net/base/ip_endpoint.h" |
| 15 #include "net/base/net_log.h" | 15 #include "net/base/net_log.h" |
| 16 #include "net/quic/crypto/quic_crypto_server_config.h" | 16 #include "net/quic/crypto/quic_crypto_server_config.h" |
| 17 #include "net/quic/quic_clock.h" | 17 #include "net/quic/quic_clock.h" |
| 18 #include "net/quic/quic_config.h" | 18 #include "net/quic/quic_config.h" |
| 19 #include "net/quic/quic_connection_helper.h" | 19 #include "net/quic/quic_connection_helper.h" |
| 20 | 20 |
| 21 namespace net { | 21 namespace net { |
| 22 | 22 |
| 23 class UDPServerSocket; |
| 24 |
| 25 namespace tools { |
| 26 |
| 27 class QuicDispatcher; |
| 23 | 28 |
| 24 namespace test { | 29 namespace test { |
| 25 class QuicServerPeer; | 30 class QuicSimpleServerPeer; |
| 26 } // namespace test | 31 } // namespace test |
| 27 | 32 |
| 28 namespace tools { | 33 class QuicSimpleServer { |
| 29 class QuicDispatcher; | 34 public: |
| 30 } // namespace tools | 35 QuicSimpleServer(const QuicConfig& config, |
| 36 const QuicVersionVector& supported_versions); |
| 31 | 37 |
| 32 class UDPServerSocket; | 38 virtual ~QuicSimpleServer(); |
| 33 | |
| 34 class QuicServer { | |
| 35 public: | |
| 36 QuicServer(const QuicConfig& config, | |
| 37 const QuicVersionVector& supported_versions); | |
| 38 | |
| 39 virtual ~QuicServer(); | |
| 40 | 39 |
| 41 // Start listening on the specified address. Returns an error code. | 40 // Start listening on the specified address. Returns an error code. |
| 42 int Listen(const IPEndPoint& address); | 41 int Listen(const IPEndPoint& address); |
| 43 | 42 |
| 44 // Server deletion is imminent. Start cleaning up. | 43 // Server deletion is imminent. Start cleaning up. |
| 45 void Shutdown(); | 44 void Shutdown(); |
| 46 | 45 |
| 47 // Start reading on the socket. On asynchronous reads, this registers | 46 // Start reading on the socket. On asynchronous reads, this registers |
| 48 // OnReadComplete as the callback, which will then call StartReading again. | 47 // OnReadComplete as the callback, which will then call StartReading again. |
| 49 void StartReading(); | 48 void StartReading(); |
| 50 | 49 |
| 51 // Called on reads that complete asynchronously. Dispatches the packet and | 50 // Called on reads that complete asynchronously. Dispatches the packet and |
| 52 // continues the read loop. | 51 // continues the read loop. |
| 53 void OnReadComplete(int result); | 52 void OnReadComplete(int result); |
| 54 | 53 |
| 55 void SetStrikeRegisterNoStartupPeriod() { | 54 void SetStrikeRegisterNoStartupPeriod() { |
| 56 crypto_config_.set_strike_register_no_startup_period(); | 55 crypto_config_.set_strike_register_no_startup_period(); |
| 57 } | 56 } |
| 58 | 57 |
| 59 // SetProofSource sets the ProofSource that will be used to verify the | 58 // SetProofSource sets the ProofSource that will be used to verify the |
| 60 // server's certificate, and takes ownership of |source|. | 59 // server's certificate, and takes ownership of |source|. |
| 61 void SetProofSource(ProofSource* source) { | 60 void SetProofSource(ProofSource* source) { |
| 62 crypto_config_.SetProofSource(source); | 61 crypto_config_.SetProofSource(source); |
| 63 } | 62 } |
| 64 | 63 |
| 65 tools::QuicDispatcher* dispatcher() { return dispatcher_.get(); } | 64 QuicDispatcher* dispatcher() { return dispatcher_.get(); } |
| 66 | 65 |
| 67 private: | 66 private: |
| 68 friend class net::test::QuicServerPeer; | 67 friend class test::QuicSimpleServerPeer; |
| 69 | 68 |
| 70 // Initialize the internal state of the server. | 69 // Initialize the internal state of the server. |
| 71 void Initialize(); | 70 void Initialize(); |
| 72 | 71 |
| 73 // Accepts data from the framer and demuxes clients to sessions. | 72 // Accepts data from the framer and demuxes clients to sessions. |
| 74 scoped_ptr<tools::QuicDispatcher> dispatcher_; | 73 scoped_ptr<QuicDispatcher> dispatcher_; |
| 75 | 74 |
| 76 // Used by the helper_ to time alarms. | 75 // Used by the helper_ to time alarms. |
| 77 QuicClock clock_; | 76 QuicClock clock_; |
| 78 | 77 |
| 79 // Used to manage the message loop. | 78 // Used to manage the message loop. |
| 80 QuicConnectionHelper helper_; | 79 QuicConnectionHelper helper_; |
| 81 | 80 |
| 82 // Listening socket. Also used for outbound client communication. | 81 // Listening socket. Also used for outbound client communication. |
| 83 scoped_ptr<UDPServerSocket> socket_; | 82 scoped_ptr<UDPServerSocket> socket_; |
| 84 | 83 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 107 | 106 |
| 108 // The target buffer of the current read. | 107 // The target buffer of the current read. |
| 109 scoped_refptr<IOBufferWithSize> read_buffer_; | 108 scoped_refptr<IOBufferWithSize> read_buffer_; |
| 110 | 109 |
| 111 // The source address of the current read. | 110 // The source address of the current read. |
| 112 IPEndPoint client_address_; | 111 IPEndPoint client_address_; |
| 113 | 112 |
| 114 // The log to use for the socket. | 113 // The log to use for the socket. |
| 115 NetLog net_log_; | 114 NetLog net_log_; |
| 116 | 115 |
| 117 base::WeakPtrFactory<QuicServer> weak_factory_; | 116 base::WeakPtrFactory<QuicSimpleServer> weak_factory_; |
| 118 | 117 |
| 119 DISALLOW_COPY_AND_ASSIGN(QuicServer); | 118 DISALLOW_COPY_AND_ASSIGN(QuicSimpleServer); |
| 120 }; | 119 }; |
| 121 | 120 |
| 121 } // namespace tools |
| 122 } // namespace net | 122 } // namespace net |
| 123 | 123 |
| 124 #endif // NET_QUIC_QUIC_SERVER_H_ | 124 #endif // NET_QUIC_TOOLS_QUIC_SIMPLE_SERVER_H_ |
| OLD | NEW |