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 server specific QuicSession subclass.
7 #ifndef NET_TOOLS_QUIC_QUIC_SERVER_SESSION_H_
8 #define NET_TOOLS_QUIC_QUIC_SERVER_SESSION_H_
14 #include "base/basictypes.h"
15 #include "base/containers/hash_tables.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "net/quic/quic_crypto_server_stream.h"
18 #include "net/quic/quic_protocol.h"
19 #include "net/quic/quic_spdy_session.h"
23 class QuicBlockedWriterInterface
;
26 class QuicCryptoServerConfig
;
27 class ReliableQuicStream
;
32 class QuicServerSessionPeer
;
35 // An interface from the session to the entity owning the session.
36 // This lets the session notify its owner (the Dispatcher) when the connection
37 // is closed, blocked, or added/removed from the time-wait list.
38 class QuicServerSessionVisitor
{
40 virtual ~QuicServerSessionVisitor() {}
42 virtual void OnConnectionClosed(QuicConnectionId connection_id
,
43 QuicErrorCode error
) = 0;
44 virtual void OnWriteBlocked(QuicBlockedWriterInterface
* blocked_writer
) = 0;
45 // Called after the given connection is added to the time-wait list.
46 virtual void OnConnectionAddedToTimeWaitList(QuicConnectionId connection_id
) {
48 // Called after the given connection is removed from the time-wait list.
49 virtual void OnConnectionRemovedFromTimeWaitList(
50 QuicConnectionId connection_id
) {}
53 class QuicServerSession
: public QuicSpdySession
{
55 // |crypto_config| must outlive the session.
56 QuicServerSession(const QuicConfig
& config
,
57 QuicConnection
* connection
,
58 QuicServerSessionVisitor
* visitor
,
59 const QuicCryptoServerConfig
* crypto_config
);
61 // Override the base class to notify the owner of the connection close.
62 void OnConnectionClosed(QuicErrorCode error
, bool from_peer
) override
;
63 void OnWriteBlocked() override
;
65 // Sends a server config update to the client, containing new bandwidth
67 void OnCongestionWindowChange(QuicTime now
) override
;
69 ~QuicServerSession() override
;
71 void Initialize() override
;
73 const QuicCryptoServerStream
* crypto_stream() const {
74 return crypto_stream_
.get();
77 // Override base class to process FEC config received from client.
78 void OnConfigNegotiated() override
;
80 bool UsingStatelessRejectsIfPeerSupported() {
81 if (GetCryptoStream() == nullptr) {
84 return GetCryptoStream()->use_stateless_rejects_if_peer_supported();
87 bool PeerSupportsStatelessRejects() {
88 if (GetCryptoStream() == nullptr) {
91 return GetCryptoStream()->peer_supports_stateless_rejects();
94 void set_serving_region(std::string serving_region
) {
95 serving_region_
= serving_region
;
98 void set_use_stateless_rejects_if_peer_supported(
99 bool use_stateless_rejects_if_peer_supported
) {
100 DCHECK(GetCryptoStream() != nullptr);
101 GetCryptoStream()->set_use_stateless_rejects_if_peer_supported(
102 use_stateless_rejects_if_peer_supported
);
106 // QuicSession methods:
107 QuicDataStream
* CreateIncomingDynamicStream(QuicStreamId id
) override
;
108 QuicDataStream
* CreateOutgoingDynamicStream() override
;
109 QuicCryptoServerStream
* GetCryptoStream() override
;
111 // If we should create an incoming stream, returns true. Otherwise
112 // does error handling, including communicating the error to the client and
113 // possibly closing the connection, and returns false.
114 virtual bool ShouldCreateIncomingDynamicStream(QuicStreamId id
);
116 virtual QuicCryptoServerStream
* CreateQuicCryptoServerStream(
117 const QuicCryptoServerConfig
* crypto_config
);
120 friend class test::QuicServerSessionPeer
;
122 const QuicCryptoServerConfig
* crypto_config_
;
123 scoped_ptr
<QuicCryptoServerStream
> crypto_stream_
;
124 QuicServerSessionVisitor
* visitor_
;
126 // Whether bandwidth resumption is enabled for this connection.
127 bool bandwidth_resumption_enabled_
;
129 // The most recent bandwidth estimate sent to the client.
130 QuicBandwidth bandwidth_estimate_sent_to_client_
;
132 // Text describing server location. Sent to the client as part of the bandwith
133 // estimate in the source-address token. Optional, can be left empty.
134 std::string serving_region_
;
136 // Time at which we send the last SCUP to the client.
137 QuicTime last_scup_time_
;
139 // Number of packets sent to the peer, at the time we last sent a SCUP.
140 int64 last_scup_packet_number_
;
142 DISALLOW_COPY_AND_ASSIGN(QuicServerSession
);
148 #endif // NET_TOOLS_QUIC_QUIC_SERVER_SESSION_H_