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.
5 // A toy server, which listens on a specified address for QUIC traffic and
6 // handles incoming responses.
8 #ifndef NET_TOOLS_QUIC_QUIC_SERVER_H_
9 #define NET_TOOLS_QUIC_QUIC_SERVER_H_
11 #include "base/memory/scoped_ptr.h"
12 #include "net/base/ip_endpoint.h"
13 #include "net/quic/crypto/quic_crypto_server_config.h"
14 #include "net/quic/quic_config.h"
15 #include "net/quic/quic_framer.h"
16 #include "net/tools/epoll_server/epoll_server.h"
17 #include "net/tools/quic/quic_dispatcher.h"
29 class QuicServer
: public EpollCallbackInterface
{
32 QuicServer(const QuicConfig
& config
,
33 const QuicVersionVector
& supported_versions
);
35 virtual ~QuicServer();
37 // Start listening on the specified address.
38 bool Listen(const IPEndPoint
& address
);
40 // Wait up to 50ms, and handle any events which occur.
43 // Server deletion is imminent. Start cleaning up the epoll server.
46 // From EpollCallbackInterface
47 virtual void OnRegistration(
48 EpollServer
* eps
, int fd
, int event_mask
) OVERRIDE
{}
49 virtual void OnModification(int fd
, int event_mask
) OVERRIDE
{}
50 virtual void OnEvent(int fd
, EpollEvent
* event
) OVERRIDE
;
51 virtual void OnUnregistration(int fd
, bool replaced
) OVERRIDE
{}
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
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
59 static bool ReadAndDispatchSinglePacket(int fd
, int port
,
60 QuicDispatcher
* dispatcher
,
61 int* packets_dropped
);
63 virtual void OnShutdown(EpollServer
* eps
, int fd
) OVERRIDE
{}
65 void SetStrikeRegisterNoStartupPeriod() {
66 crypto_config_
.set_strike_register_no_startup_period();
69 bool overflow_supported() { return overflow_supported_
; }
71 int packets_dropped() { return packets_dropped_
; }
73 int port() { return port_
; }
76 friend class net::tools::test::QuicServerPeer
;
78 // Initialize the internal state of the server.
81 // Accepts data from the framer and demuxes clients to sessions.
82 scoped_ptr
<QuicDispatcher
> dispatcher_
;
83 // Frames incoming packets and hands them to the dispatcher.
84 EpollServer epoll_server_
;
86 // The port the server is listening on.
89 // Listening connection. Also used for outbound client communication.
92 // If overflow_supported_ is true this will be the number of packets dropped
93 // during the lifetime of the server. This may overflow if enough packets
97 // True if the kernel supports SO_RXQ_OVFL, the number of packets dropped
98 // because the socket would otherwise overflow.
99 bool overflow_supported_
;
101 // If true, use recvmmsg for reading.
104 // config_ contains non-crypto parameters that are negotiated in the crypto
107 // crypto_config_ contains crypto parameters for the handshake.
108 QuicCryptoServerConfig crypto_config_
;
110 // This vector contains QUIC versions which we currently support.
111 // This should be ordered such that the highest supported version is the first
112 // element, with subsequent elements in descending order (versions can be
113 // skipped as necessary).
114 QuicVersionVector supported_versions_
;
116 DISALLOW_COPY_AND_ASSIGN(QuicServer
);
122 #endif // NET_TOOLS_QUIC_QUIC_SERVER_H_