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 #include "net/quic/quic_server_session.h"
7 #include "base/logging.h"
8 #include "net/quic/quic_connection.h"
9 #include "net/quic/quic_flags.h"
10 #include "net/quic/quic_spdy_server_stream.h"
11 #include "net/quic/reliable_quic_stream.h"
15 QuicServerSession::QuicServerSession(
16 const QuicConfig
& config
,
17 QuicConnection
* connection
,
18 QuicPerConnectionPacketWriter
* connection_packet_writer
,
19 QuicServerSessionVisitor
* visitor
)
20 : QuicSession(connection
, config
),
21 connection_packet_writer_(connection_packet_writer
),
24 QuicServerSession::~QuicServerSession() {}
26 void QuicServerSession::InitializeSession(
27 const QuicCryptoServerConfig
& crypto_config
) {
28 crypto_stream_
.reset(CreateQuicCryptoServerStream(crypto_config
));
31 QuicCryptoServerStream
* QuicServerSession::CreateQuicCryptoServerStream(
32 const QuicCryptoServerConfig
& crypto_config
) {
33 return new QuicCryptoServerStream(crypto_config
, this);
36 void QuicServerSession::OnConfigNegotiated() {
37 QuicSession::OnConfigNegotiated();
38 if (!FLAGS_enable_quic_fec
||
39 !config()->HasReceivedConnectionOptions() ||
40 !ContainsQuicTag(config()->ReceivedConnectionOptions(), kFHDR
)) {
43 // kFHDR config maps to FEC protection always for headers stream.
44 // TODO(jri): Add crypto stream in addition to headers for kHDR.
45 headers_stream_
->set_fec_policy(FEC_PROTECT_ALWAYS
);
48 void QuicServerSession::OnConnectionClosed(QuicErrorCode error
,
50 QuicSession::OnConnectionClosed(error
, from_peer
);
51 // In the unlikely event we get a connection close while doing an asynchronous
52 // crypto event, make sure we cancel the callback.
53 if (crypto_stream_
.get() != NULL
) {
54 crypto_stream_
->CancelOutstandingCallbacks();
56 visitor_
->OnConnectionClosed(connection()->connection_id(), error
);
59 void QuicServerSession::OnWriteBlocked() {
60 QuicSession::OnWriteBlocked();
61 visitor_
->OnWriteBlocked(connection());
64 bool QuicServerSession::ShouldCreateIncomingDataStream(QuicStreamId id
) {
66 DVLOG(1) << "Invalid incoming even stream_id:" << id
;
67 connection()->SendConnectionClose(QUIC_INVALID_STREAM_ID
);
70 if (GetNumOpenStreams() >= get_max_open_streams()) {
71 DVLOG(1) << "Failed to create a new incoming stream with id:" << id
72 << " Already " << GetNumOpenStreams() << " open.";
73 connection()->SendConnectionClose(QUIC_TOO_MANY_OPEN_STREAMS
);
79 QuicDataStream
* QuicServerSession::CreateIncomingDataStream(
81 if (!ShouldCreateIncomingDataStream(id
)) {
85 return new QuicSpdyServerStream(id
, this);
88 QuicDataStream
* QuicServerSession::CreateOutgoingDataStream() {
89 DLOG(ERROR
) << "Server push not yet supported";
93 QuicCryptoServerStream
* QuicServerSession::GetCryptoStream() {
94 return crypto_stream_
.get();