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. 4 5 #include "net/tools/quic/quic_server_session.h" 6 7 #include "base/logging.h" 8 #include "net/quic/reliable_quic_stream.h" 9 #include "net/tools/quic/quic_spdy_server_stream.h" 10 11 namespace net { 12 namespace tools { 13 14 QuicServerSession::QuicServerSession( 15 const QuicConfig& config, 16 QuicConnection* connection, 17 QuicSessionOwner* owner) 18 : QuicSession(connection, config, true), 19 owner_(owner) { 20 } 21 22 QuicServerSession::~QuicServerSession() { 23 } 24 25 void QuicServerSession::InitializeSession( 26 const QuicCryptoServerConfig& crypto_config) { 27 crypto_stream_.reset(CreateQuicCryptoServerStream(crypto_config)); 28 } 29 30 QuicCryptoServerStream* QuicServerSession::CreateQuicCryptoServerStream( 31 const QuicCryptoServerConfig& crypto_config) { 32 return new QuicCryptoServerStream(crypto_config, this); 33 } 34 35 void QuicServerSession::ConnectionClose(QuicErrorCode error, bool from_peer) { 36 QuicSession::ConnectionClose(error, from_peer); 37 owner_->OnConnectionClose(connection()->guid(), error); 38 } 39 40 bool QuicServerSession::ShouldCreateIncomingReliableStream(QuicStreamId id) { 41 if (id % 2 == 0) { 42 DLOG(INFO) << "Invalid incoming even stream_id:" << id; 43 connection()->SendConnectionClose(QUIC_INVALID_STREAM_ID); 44 return false; 45 } 46 if (GetNumOpenStreams() >= get_max_open_streams()) { 47 DLOG(INFO) << "Failed to create a new incoming stream with id:" << id 48 << " Already " << GetNumOpenStreams() << " open."; 49 connection()->SendConnectionClose(QUIC_TOO_MANY_OPEN_STREAMS); 50 return false; 51 } 52 return true; 53 } 54 55 ReliableQuicStream* QuicServerSession::CreateIncomingReliableStream( 56 QuicStreamId id) { 57 if (!ShouldCreateIncomingReliableStream(id)) { 58 return NULL; 59 } 60 61 return new QuicSpdyServerStream(id, this); 62 } 63 64 ReliableQuicStream* QuicServerSession::CreateOutgoingReliableStream() { 65 DLOG(ERROR) << "Server push not yet supported"; 66 return NULL; 67 } 68 69 QuicCryptoServerStream* QuicServerSession::GetCryptoStream() { 70 return crypto_stream_.get(); 71 } 72 73 } // namespace tools 74 } // namespace net 75