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
);
62 QuicDispatcher
* dispatcher() { return dispatcher_
.get(); }
65 friend class net::test::QuicServerPeer
;
67 // Initialize the internal state of the server.
70 // Accepts data from the framer and demuxes clients to sessions.
71 scoped_ptr
<QuicDispatcher
> dispatcher_
;
73 // Used by the helper_ to time alarms.
76 // Used to manage the message loop.
77 QuicConnectionHelper helper_
;
79 // Listening socket. Also used for outbound client communication.
80 scoped_ptr
<UDPServerSocket
> socket_
;
82 // config_ contains non-crypto parameters that are negotiated in the crypto
85 // crypto_config_ contains crypto parameters for the handshake.
86 QuicCryptoServerConfig crypto_config_
;
88 // This vector contains QUIC versions which we currently support.
89 // This should be ordered such that the highest supported version is the first
90 // element, with subsequent elements in descending order (versions can be
91 // skipped as necessary).
92 QuicVersionVector supported_versions_
;
94 // The address that the server listens on.
95 IPEndPoint server_address_
;
97 // Keeps track of whether a read is currently in flight, after which
98 // OnReadComplete will be called.
101 // The number of iterations of the read loop that have completed synchronously
102 // and without posting a new task to the message loop.
103 int synchronous_read_count_
;
105 // The target buffer of the current read.
106 scoped_refptr
<IOBufferWithSize
> read_buffer_
;
108 // The source address of the current read.
109 IPEndPoint client_address_
;
111 // The log to use for the socket.
114 base::WeakPtrFactory
<QuicServer
> weak_factory_
;
116 DISALLOW_COPY_AND_ASSIGN(QuicServer
);
121 #endif // NET_QUIC_QUIC_SERVER_H_