| OLD | NEW |
| (Empty) |
| 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 | |
| 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_TOOLS_QUIC_QUIC_SERVER_H_ | |
| 9 #define NET_TOOLS_QUIC_QUIC_SERVER_H_ | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "net/base/ip_endpoint.h" | |
| 14 #include "net/quic/crypto/quic_crypto_server_config.h" | |
| 15 #include "net/quic/quic_config.h" | |
| 16 #include "net/quic/quic_framer.h" | |
| 17 #include "net/tools/epoll_server/epoll_server.h" | |
| 18 | |
| 19 namespace net { | |
| 20 | |
| 21 namespace tools { | |
| 22 | |
| 23 namespace test { | |
| 24 class QuicServerPeer; | |
| 25 } // namespace test | |
| 26 | |
| 27 class ProcessPacketInterface; | |
| 28 class QuicDispatcher; | |
| 29 | |
| 30 class QuicServer : public EpollCallbackInterface { | |
| 31 public: | |
| 32 QuicServer(); | |
| 33 QuicServer(const QuicConfig& config, | |
| 34 const QuicVersionVector& supported_versions); | |
| 35 | |
| 36 ~QuicServer() override; | |
| 37 | |
| 38 // Start listening on the specified address. | |
| 39 bool Listen(const IPEndPoint& address); | |
| 40 | |
| 41 // Wait up to 50ms, and handle any events which occur. | |
| 42 void WaitForEvents(); | |
| 43 | |
| 44 // Server deletion is imminent. Start cleaning up the epoll server. | |
| 45 void Shutdown(); | |
| 46 | |
| 47 // From EpollCallbackInterface | |
| 48 void OnRegistration(EpollServer* eps, int fd, int event_mask) override {} | |
| 49 void OnModification(int fd, int event_mask) override {} | |
| 50 void OnEvent(int fd, EpollEvent* event) override; | |
| 51 void OnUnregistration(int fd, bool replaced) override {} | |
| 52 | |
| 53 // Reads a packet from the given fd, and then passes it off to | |
| 54 // the QuicDispatcher. Returns true if a packet is read, false | |
| 55 // otherwise. | |
| 56 // If packets_dropped is non-null, the socket is configured to track | |
| 57 // dropped packets, and some packets are read, it will be set to the number of | |
| 58 // dropped packets. | |
| 59 static bool ReadAndDispatchSinglePacket(int fd, int port, | |
| 60 ProcessPacketInterface* processor, | |
| 61 QuicPacketCount* packets_dropped); | |
| 62 | |
| 63 void OnShutdown(EpollServer* eps, int fd) override {} | |
| 64 | |
| 65 void SetStrikeRegisterNoStartupPeriod() { | |
| 66 crypto_config_.set_strike_register_no_startup_period(); | |
| 67 } | |
| 68 | |
| 69 // SetProofSource sets the ProofSource that will be used to verify the | |
| 70 // server's certificate, and takes ownership of |source|. | |
| 71 void SetProofSource(ProofSource* source) { | |
| 72 crypto_config_.SetProofSource(source); | |
| 73 } | |
| 74 | |
| 75 bool overflow_supported() { return overflow_supported_; } | |
| 76 | |
| 77 QuicPacketCount packets_dropped() { return packets_dropped_; } | |
| 78 | |
| 79 int port() { return port_; } | |
| 80 | |
| 81 protected: | |
| 82 virtual QuicDispatcher* CreateQuicDispatcher(); | |
| 83 | |
| 84 const QuicConfig& config() const { return config_; } | |
| 85 const QuicCryptoServerConfig& crypto_config() const { | |
| 86 return crypto_config_; | |
| 87 } | |
| 88 const QuicVersionVector& supported_versions() const { | |
| 89 return supported_versions_; | |
| 90 } | |
| 91 EpollServer* epoll_server() { return &epoll_server_; } | |
| 92 | |
| 93 private: | |
| 94 friend class net::tools::test::QuicServerPeer; | |
| 95 | |
| 96 // Initialize the internal state of the server. | |
| 97 void Initialize(); | |
| 98 | |
| 99 // Accepts data from the framer and demuxes clients to sessions. | |
| 100 scoped_ptr<QuicDispatcher> dispatcher_; | |
| 101 // Frames incoming packets and hands them to the dispatcher. | |
| 102 EpollServer epoll_server_; | |
| 103 | |
| 104 // The port the server is listening on. | |
| 105 int port_; | |
| 106 | |
| 107 // Listening connection. Also used for outbound client communication. | |
| 108 int fd_; | |
| 109 | |
| 110 // If overflow_supported_ is true this will be the number of packets dropped | |
| 111 // during the lifetime of the server. This may overflow if enough packets | |
| 112 // are dropped. | |
| 113 QuicPacketCount packets_dropped_; | |
| 114 | |
| 115 // True if the kernel supports SO_RXQ_OVFL, the number of packets dropped | |
| 116 // because the socket would otherwise overflow. | |
| 117 bool overflow_supported_; | |
| 118 | |
| 119 // If true, use recvmmsg for reading. | |
| 120 bool use_recvmmsg_; | |
| 121 | |
| 122 // config_ contains non-crypto parameters that are negotiated in the crypto | |
| 123 // handshake. | |
| 124 QuicConfig config_; | |
| 125 // crypto_config_ contains crypto parameters for the handshake. | |
| 126 QuicCryptoServerConfig crypto_config_; | |
| 127 | |
| 128 // This vector contains QUIC versions which we currently support. | |
| 129 // This should be ordered such that the highest supported version is the first | |
| 130 // element, with subsequent elements in descending order (versions can be | |
| 131 // skipped as necessary). | |
| 132 QuicVersionVector supported_versions_; | |
| 133 | |
| 134 // Size of flow control receive window to advertise to clients on new | |
| 135 // connections. | |
| 136 uint32 server_initial_flow_control_receive_window_; | |
| 137 | |
| 138 DISALLOW_COPY_AND_ASSIGN(QuicServer); | |
| 139 }; | |
| 140 | |
| 141 } // namespace tools | |
| 142 } // namespace net | |
| 143 | |
| 144 #endif // NET_TOOLS_QUIC_QUIC_SERVER_H_ | |
| OLD | NEW |