| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 // | |
| 5 // A toy server, which listens on a specified address for QUIC traffic and | |
| 6 // handles incoming responses. | |
| 7 | |
| 8 #ifndef NET_QUIC_QUIC_SERVER_H_ | |
| 9 #define NET_QUIC_QUIC_SERVER_H_ | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "net/base/io_buffer.h" | |
| 14 #include "net/base/ip_endpoint.h" | |
| 15 #include "net/base/net_log.h" | |
| 16 #include "net/quic/crypto/quic_crypto_server_config.h" | |
| 17 #include "net/quic/quic_clock.h" | |
| 18 #include "net/quic/quic_config.h" | |
| 19 #include "net/quic/quic_connection_helper.h" | |
| 20 | |
| 21 namespace net { | |
| 22 | |
| 23 | |
| 24 namespace test { | |
| 25 class QuicServerPeer; | |
| 26 } // namespace test | |
| 27 | |
| 28 namespace tools { | |
| 29 class QuicDispatcher; | |
| 30 } // namespace tools | |
| 31 | |
| 32 class UDPServerSocket; | |
| 33 | |
| 34 class QuicServer { | |
| 35 public: | |
| 36 QuicServer(const QuicConfig& config, | |
| 37 const QuicVersionVector& supported_versions); | |
| 38 | |
| 39 virtual ~QuicServer(); | |
| 40 | |
| 41 // Start listening on the specified address. Returns an error code. | |
| 42 int Listen(const IPEndPoint& address); | |
| 43 | |
| 44 // Server deletion is imminent. Start cleaning up. | |
| 45 void Shutdown(); | |
| 46 | |
| 47 // Start reading on the socket. On asynchronous reads, this registers | |
| 48 // OnReadComplete as the callback, which will then call StartReading again. | |
| 49 void StartReading(); | |
| 50 | |
| 51 // Called on reads that complete asynchronously. Dispatches the packet and | |
| 52 // continues the read loop. | |
| 53 void OnReadComplete(int result); | |
| 54 | |
| 55 void SetStrikeRegisterNoStartupPeriod() { | |
| 56 crypto_config_.set_strike_register_no_startup_period(); | |
| 57 } | |
| 58 | |
| 59 // SetProofSource sets the ProofSource that will be used to verify the | |
| 60 // server's certificate, and takes ownership of |source|. | |
| 61 void SetProofSource(ProofSource* source) { | |
| 62 crypto_config_.SetProofSource(source); | |
| 63 } | |
| 64 | |
| 65 tools::QuicDispatcher* dispatcher() { return dispatcher_.get(); } | |
| 66 | |
| 67 private: | |
| 68 friend class net::test::QuicServerPeer; | |
| 69 | |
| 70 // Initialize the internal state of the server. | |
| 71 void Initialize(); | |
| 72 | |
| 73 // Accepts data from the framer and demuxes clients to sessions. | |
| 74 scoped_ptr<tools::QuicDispatcher> dispatcher_; | |
| 75 | |
| 76 // Used by the helper_ to time alarms. | |
| 77 QuicClock clock_; | |
| 78 | |
| 79 // Used to manage the message loop. | |
| 80 QuicConnectionHelper helper_; | |
| 81 | |
| 82 // Listening socket. Also used for outbound client communication. | |
| 83 scoped_ptr<UDPServerSocket> socket_; | |
| 84 | |
| 85 // config_ contains non-crypto parameters that are negotiated in the crypto | |
| 86 // handshake. | |
| 87 QuicConfig config_; | |
| 88 // crypto_config_ contains crypto parameters for the handshake. | |
| 89 QuicCryptoServerConfig crypto_config_; | |
| 90 | |
| 91 // This vector contains QUIC versions which we currently support. | |
| 92 // This should be ordered such that the highest supported version is the first | |
| 93 // element, with subsequent elements in descending order (versions can be | |
| 94 // skipped as necessary). | |
| 95 QuicVersionVector supported_versions_; | |
| 96 | |
| 97 // The address that the server listens on. | |
| 98 IPEndPoint server_address_; | |
| 99 | |
| 100 // Keeps track of whether a read is currently in flight, after which | |
| 101 // OnReadComplete will be called. | |
| 102 bool read_pending_; | |
| 103 | |
| 104 // The number of iterations of the read loop that have completed synchronously | |
| 105 // and without posting a new task to the message loop. | |
| 106 int synchronous_read_count_; | |
| 107 | |
| 108 // The target buffer of the current read. | |
| 109 scoped_refptr<IOBufferWithSize> read_buffer_; | |
| 110 | |
| 111 // The source address of the current read. | |
| 112 IPEndPoint client_address_; | |
| 113 | |
| 114 // The log to use for the socket. | |
| 115 NetLog net_log_; | |
| 116 | |
| 117 base::WeakPtrFactory<QuicServer> weak_factory_; | |
| 118 | |
| 119 DISALLOW_COPY_AND_ASSIGN(QuicServer); | |
| 120 }; | |
| 121 | |
| 122 } // namespace net | |
| 123 | |
| 124 #endif // NET_QUIC_QUIC_SERVER_H_ | |
| OLD | NEW |