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_QUIC_SERVER_H_
9 #define NET_QUIC_QUIC_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/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"
29 class UDPServerSocket
;
33 QuicServer(const QuicConfig
& config
,
34 const QuicVersionVector
& supported_versions
);
36 virtual ~QuicServer();
38 // Start listening on the specified address. Returns an error code.
39 int Listen(const IPEndPoint
& address
);
41 // Server deletion is imminent. Start cleaning up.
44 // Start reading on the socket. On asynchronous reads, this registers
45 // OnReadComplete as the callback, which will then call StartReading again.
48 // Called on reads that complete asynchronously. Dispatches the packet and
49 // continues the read loop.
50 void OnReadComplete(int result
);
52 void SetStrikeRegisterNoStartupPeriod() {
53 crypto_config_
.set_strike_register_no_startup_period();
56 // SetProofSource sets the ProofSource that will be used to verify the
57 // server's certificate, and takes ownership of |source|.
58 void SetProofSource(ProofSource
* source
) {
59 crypto_config_
.SetProofSource(source
);
63 friend class net::test::QuicServerPeer
;
65 // Initialize the internal state of the server.
68 // Accepts data from the framer and demuxes clients to sessions.
69 scoped_ptr
<QuicDispatcher
> dispatcher_
;
71 // Used by the helper_ to time alarms.
74 // Used to manage the message loop.
75 QuicConnectionHelper helper_
;
77 // Listening socket. Also used for outbound client communication.
78 scoped_ptr
<UDPServerSocket
> socket_
;
80 // config_ contains non-crypto parameters that are negotiated in the crypto
83 // crypto_config_ contains crypto parameters for the handshake.
84 QuicCryptoServerConfig crypto_config_
;
86 // This vector contains QUIC versions which we currently support.
87 // This should be ordered such that the highest supported version is the first
88 // element, with subsequent elements in descending order (versions can be
89 // skipped as necessary).
90 QuicVersionVector supported_versions_
;
92 // The address that the server listens on.
93 IPEndPoint server_address_
;
95 // Keeps track of whether a read is currently in flight, after which
96 // OnReadComplete will be called.
99 // The number of iterations of the read loop that have completed synchronously
100 // and without posting a new task to the message loop.
101 int synchronous_read_count_
;
103 // The target buffer of the current read.
104 scoped_refptr
<IOBufferWithSize
> read_buffer_
;
106 // The source address of the current read.
107 IPEndPoint client_address_
;
109 // The log to use for the socket.
112 base::WeakPtrFactory
<QuicServer
> weak_factory_
;
114 DISALLOW_COPY_AND_ASSIGN(QuicServer
);
119 #endif // NET_QUIC_QUIC_SERVER_H_