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.
5 // A toy server, which listens on a specified address for QUIC traffic and
6 // handles incoming responses.
8 #ifndef NET_QUIC_TOOLS_QUIC_SIMPLE_SERVER_H_
9 #define NET_QUIC_TOOLS_QUIC_SIMPLE_SERVER_H_
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/log/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"
23 class UDPServerSocket
;
30 class QuicSimpleServerPeer
;
33 class QuicSimpleServer
{
35 QuicSimpleServer(const QuicConfig
& config
,
36 const QuicVersionVector
& supported_versions
);
38 virtual ~QuicSimpleServer();
40 // Start listening on the specified address. Returns an error code.
41 int Listen(const IPEndPoint
& address
);
43 // Server deletion is imminent. Start cleaning up.
46 // Start reading on the socket. On asynchronous reads, this registers
47 // OnReadComplete as the callback, which will then call StartReading again.
50 // Called on reads that complete asynchronously. Dispatches the packet and
51 // continues the read loop.
52 void OnReadComplete(int result
);
54 void SetStrikeRegisterNoStartupPeriod() {
55 crypto_config_
.set_strike_register_no_startup_period();
58 // SetProofSource sets the ProofSource that will be used to verify the
59 // server's certificate, and takes ownership of |source|.
60 void SetProofSource(ProofSource
* source
) {
61 crypto_config_
.SetProofSource(source
);
64 QuicDispatcher
* dispatcher() { return dispatcher_
.get(); }
67 friend class test::QuicSimpleServerPeer
;
69 // Initialize the internal state of the server.
72 // Accepts data from the framer and demuxes clients to sessions.
73 scoped_ptr
<QuicDispatcher
> dispatcher_
;
75 // Used by the helper_ to time alarms.
78 // Used to manage the message loop.
79 QuicConnectionHelper helper_
;
81 // Listening socket. Also used for outbound client communication.
82 scoped_ptr
<UDPServerSocket
> socket_
;
84 // config_ contains non-crypto parameters that are negotiated in the crypto
87 // crypto_config_ contains crypto parameters for the handshake.
88 QuicCryptoServerConfig crypto_config_
;
90 // This vector contains QUIC versions which we currently support.
91 // This should be ordered such that the highest supported version is the first
92 // element, with subsequent elements in descending order (versions can be
93 // skipped as necessary).
94 QuicVersionVector supported_versions_
;
96 // The address that the server listens on.
97 IPEndPoint server_address_
;
99 // Keeps track of whether a read is currently in flight, after which
100 // OnReadComplete will be called.
103 // The number of iterations of the read loop that have completed synchronously
104 // and without posting a new task to the message loop.
105 int synchronous_read_count_
;
107 // The target buffer of the current read.
108 scoped_refptr
<IOBufferWithSize
> read_buffer_
;
110 // The source address of the current read.
111 IPEndPoint client_address_
;
113 // The log to use for the socket.
116 base::WeakPtrFactory
<QuicSimpleServer
> weak_factory_
;
118 DISALLOW_COPY_AND_ASSIGN(QuicSimpleServer
);
124 #endif // NET_QUIC_TOOLS_QUIC_SIMPLE_SERVER_H_