blob: 2a4e1166329df363c701b334cbe41b00c2139dfe [file] [log] [blame]
[email protected]519e49882013-03-27 08:45:321// 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.
rtennetie0ee6eb2015-05-01 00:55:097//
8// Note that this server is intended to verify correctness of the client and is
9// in no way expected to be performant.
[email protected]519e49882013-03-27 08:45:3210
11#ifndef NET_TOOLS_QUIC_QUIC_SERVER_H_
12#define NET_TOOLS_QUIC_QUIC_SERVER_H_
13
Avi Drissman13fc8932015-12-20 04:40:4614#include <stddef.h>
15
danakja9850e12016-04-18 22:28:0816#include <memory>
17
Avi Drissman13fc8932015-12-20 04:40:4618#include "base/macros.h"
[email protected]519e49882013-03-27 08:45:3219#include "net/base/ip_endpoint.h"
rch675757b2016-07-29 16:40:1120#include "net/quic/chromium/quic_chromium_connection_helper.h"
[email protected]8e01c062013-10-31 07:35:3121#include "net/quic/crypto/quic_crypto_server_config.h"
[email protected]ef95114d2013-04-17 17:57:0122#include "net/quic/quic_config.h"
[email protected]519e49882013-03-27 08:45:3223#include "net/quic/quic_framer.h"
[email protected]6c7e6522013-09-29 15:27:4424#include "net/tools/epoll_server/epoll_server.h"
rchc99f380c2015-03-26 19:50:5625#include "net/tools/quic/quic_default_packet_writer.h"
[email protected]519e49882013-03-27 08:45:3226
27namespace net {
28
[email protected]cbd731e2013-10-24 00:20:3929namespace test {
30class QuicServerPeer;
31} // namespace test
32
[email protected]519e49882013-03-27 08:45:3233class QuicDispatcher;
rtennetifb3fa6c2015-03-16 23:04:5534class QuicPacketReader;
[email protected]519e49882013-03-27 08:45:3235
36class QuicServer : public EpollCallbackInterface {
37 public:
fayang199cfb02016-07-13 03:56:3938 explicit QuicServer(std::unique_ptr<ProofSource> proof_source);
39 QuicServer(std::unique_ptr<ProofSource> proof_source,
rch1fe2eeb2015-10-26 14:45:5740 const QuicConfig& config,
nharperd5cddca2016-02-27 03:37:5241 const QuicCryptoServerConfig::ConfigOptions& server_config_options,
[email protected]a5b98172014-06-18 07:01:5942 const QuicVersionVector& supported_versions);
[email protected]0bbeb6972013-05-23 04:10:2143
dchengff0bb8c2014-10-27 21:58:5144 ~QuicServer() override;
[email protected]519e49882013-03-27 08:45:3245
46 // Start listening on the specified address.
danzh33407f12016-03-04 21:58:1647 bool CreateUDPSocketAndListen(const IPEndPoint& address);
[email protected]519e49882013-03-27 08:45:3248
49 // Wait up to 50ms, and handle any events which occur.
50 void WaitForEvents();
51
52 // Server deletion is imminent. Start cleaning up the epoll server.
53 void Shutdown();
54
55 // From EpollCallbackInterface
dchengff0bb8c2014-10-27 21:58:5156 void OnRegistration(EpollServer* eps, int fd, int event_mask) override {}
57 void OnModification(int fd, int event_mask) override {}
58 void OnEvent(int fd, EpollEvent* event) override;
59 void OnUnregistration(int fd, bool replaced) override {}
[email protected]519e49882013-03-27 08:45:3260
dchengff0bb8c2014-10-27 21:58:5161 void OnShutdown(EpollServer* eps, int fd) override {}
[email protected]519e49882013-03-27 08:45:3262
[email protected]97cf3022013-09-05 14:30:1663 void SetStrikeRegisterNoStartupPeriod() {
64 crypto_config_.set_strike_register_no_startup_period();
65 }
66
jri3285d93a2015-12-14 08:53:1967 void SetChloMultiplier(size_t multiplier) {
68 crypto_config_.set_chlo_multiplier(multiplier);
69 }
70
[email protected]519e49882013-03-27 08:45:3271 bool overflow_supported() { return overflow_supported_; }
72
pkasting57b688a32014-12-02 21:38:0173 QuicPacketCount packets_dropped() { return packets_dropped_; }
[email protected]519e49882013-03-27 08:45:3274
[email protected]e45d68892013-03-30 17:50:1075 int port() { return port_; }
76
[email protected]a5b98172014-06-18 07:01:5977 protected:
rchc99f380c2015-03-26 19:50:5678 virtual QuicDefaultPacketWriter* CreateWriter(int fd);
79
[email protected]a5b98172014-06-18 07:01:5980 virtual QuicDispatcher* CreateQuicDispatcher();
81
82 const QuicConfig& config() const { return config_; }
rjshaded5ced072015-12-18 19:26:0283 const QuicCryptoServerConfig& crypto_config() const { return crypto_config_; }
[email protected]a5b98172014-06-18 07:01:5984 const QuicVersionVector& supported_versions() const {
85 return supported_versions_;
86 }
87 EpollServer* epoll_server() { return &epoll_server_; }
88
rtenneti3183ac42015-02-28 03:39:4189 QuicDispatcher* dispatcher() { return dispatcher_.get(); }
90
[email protected]519e49882013-03-27 08:45:3291 private:
rch750447f92016-01-31 02:54:5392 friend class net::test::QuicServerPeer;
[email protected]cbd731e2013-10-24 00:20:3993
[email protected]0bbeb6972013-05-23 04:10:2194 // Initialize the internal state of the server.
95 void Initialize();
96
[email protected]519e49882013-03-27 08:45:3297 // Accepts data from the framer and demuxes clients to sessions.
danakja9850e12016-04-18 22:28:0898 std::unique_ptr<QuicDispatcher> dispatcher_;
[email protected]519e49882013-03-27 08:45:3299 // Frames incoming packets and hands them to the dispatcher.
100 EpollServer epoll_server_;
101
102 // The port the server is listening on.
103 int port_;
104
105 // Listening connection. Also used for outbound client communication.
106 int fd_;
107
108 // If overflow_supported_ is true this will be the number of packets dropped
109 // during the lifetime of the server. This may overflow if enough packets
110 // are dropped.
pkasting57b688a32014-12-02 21:38:01111 QuicPacketCount packets_dropped_;
[email protected]519e49882013-03-27 08:45:32112
113 // True if the kernel supports SO_RXQ_OVFL, the number of packets dropped
114 // because the socket would otherwise overflow.
115 bool overflow_supported_;
116
[email protected]ef95114d2013-04-17 17:57:01117 // config_ contains non-crypto parameters that are negotiated in the crypto
118 // handshake.
119 QuicConfig config_;
120 // crypto_config_ contains crypto parameters for the handshake.
121 QuicCryptoServerConfig crypto_config_;
nharperd5cddca2016-02-27 03:37:52122 // crypto_config_options_ contains crypto parameters for the handshake.
123 QuicCryptoServerConfig::ConfigOptions crypto_config_options_;
[email protected]ef95114d2013-04-17 17:57:01124
[email protected]b007e632013-10-28 08:39:25125 // This vector contains QUIC versions which we currently support.
126 // This should be ordered such that the highest supported version is the first
127 // element, with subsequent elements in descending order (versions can be
128 // skipped as necessary).
129 QuicVersionVector supported_versions_;
130
danzh33407f12016-03-04 21:58:16131 // Point to a QuicPacketReader object on the heap. The reader allocates more
132 // space than allowed on the stack.
danakja9850e12016-04-18 22:28:08133 std::unique_ptr<QuicPacketReader> packet_reader_;
rtennetifb3fa6c2015-03-16 23:04:55134
[email protected]519e49882013-03-27 08:45:32135 DISALLOW_COPY_AND_ASSIGN(QuicServer);
136};
137
[email protected]519e49882013-03-27 08:45:32138} // namespace net
139
140#endif // NET_TOOLS_QUIC_QUIC_SERVER_H_