quic_server_session.cc revision f8ee788a64d60abd8f2d742a5fdedde054ecd910
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. 4 5#include "net/quic/quic_server_session.h" 6 7#include "base/logging.h" 8#include "net/quic/quic_connection.h" 9#include "net/quic/quic_spdy_server_stream.h" 10#include "net/quic/reliable_quic_stream.h" 11 12namespace net { 13 14QuicServerSession::QuicServerSession(const QuicConfig& config, 15 QuicConnection* connection, 16 QuicServerSessionVisitor* visitor) 17 : QuicSession(connection, config), 18 visitor_(visitor) {} 19 20QuicServerSession::~QuicServerSession() {} 21 22void QuicServerSession::InitializeSession( 23 const QuicCryptoServerConfig& crypto_config) { 24 crypto_stream_.reset(CreateQuicCryptoServerStream(crypto_config)); 25} 26 27QuicCryptoServerStream* QuicServerSession::CreateQuicCryptoServerStream( 28 const QuicCryptoServerConfig& crypto_config) { 29 return new QuicCryptoServerStream(crypto_config, this); 30} 31 32void QuicServerSession::OnConnectionClosed(QuicErrorCode error, 33 bool from_peer) { 34 QuicSession::OnConnectionClosed(error, from_peer); 35 // In the unlikely event we get a connection close while doing an asynchronous 36 // crypto event, make sure we cancel the callback. 37 if (crypto_stream_.get() != NULL) { 38 crypto_stream_->CancelOutstandingCallbacks(); 39 } 40 visitor_->OnConnectionClosed(connection()->connection_id(), error); 41} 42 43void QuicServerSession::OnWriteBlocked() { 44 QuicSession::OnWriteBlocked(); 45 visitor_->OnWriteBlocked(connection()); 46} 47 48bool QuicServerSession::ShouldCreateIncomingDataStream(QuicStreamId id) { 49 if (id % 2 == 0) { 50 DVLOG(1) << "Invalid incoming even stream_id:" << id; 51 connection()->SendConnectionClose(QUIC_INVALID_STREAM_ID); 52 return false; 53 } 54 if (GetNumOpenStreams() >= get_max_open_streams()) { 55 DVLOG(1) << "Failed to create a new incoming stream with id:" << id 56 << " Already " << GetNumOpenStreams() << " open."; 57 connection()->SendConnectionClose(QUIC_TOO_MANY_OPEN_STREAMS); 58 return false; 59 } 60 return true; 61} 62 63QuicDataStream* QuicServerSession::CreateIncomingDataStream( 64 QuicStreamId id) { 65 if (!ShouldCreateIncomingDataStream(id)) { 66 return NULL; 67 } 68 69 return new QuicSpdyServerStream(id, this); 70} 71 72QuicDataStream* QuicServerSession::CreateOutgoingDataStream() { 73 DLOG(ERROR) << "Server push not yet supported"; 74 return NULL; 75} 76 77QuicCryptoServerStream* QuicServerSession::GetCryptoStream() { 78 return crypto_stream_.get(); 79} 80 81} // namespace net 82